akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
using namespace std;

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

  string q,repstr;
  int a,b;
  for(int i=0;i<n;i++){
    cin>>q;
    if(q== "print"){
        cin>>a>>b;
        for(int pos=a;pos<=b;pos++) cout<<str[pos];
        cout<<endl;
    }else if(q=="reverse"){
        cin>>a>>b;
        string revstr="";
        for(int j=b;j>=a;j--) revstr+=str[j];
        str.replace(a,b-a+1,revstr);
    }else if(q=="replace"){
        cin>>a>>b>>repstr;
        str.replace(a,b-a+1,repstr);
    }
  }
  return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>

int main()
{
    int a, b, k;

    std::cin >> a >> b >> k;
    if(2 * k - (b - a + 1) > 0){
        for(int i = a;i <= b;i++)
        std::cout << i <<"\n";

        return 0;
    }

    for (int i = a;i < a + k;i++){
        std::cout << i <<"\n";
    }
    for(int i = b - k + 1;i < b + 1;i++){
        std::cout << i <<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)

    var nMod int = n % 10

    if nMod == 3 {
        fmt.Println("bon")
        return
    }else if nMod == 0 || nMod == 1  || nMod == 6  || nMod == 8{
        fmt.Println("pon")
        return
    }else {
        fmt.Println("hon")
    }
}

Measured memory_bytes: 1752
# -*- coding: utf-8 -*-
# 整数の入力
# スペース区切りの整数の入力
import math
a, b = map(int, input().split())

connected_num = int(str(a) + str(b))
c = int(math.sqrt(connected_num))

if connected_num == c*c:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8960
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int a[110];
int ans=100000000;
int main(){
	int x,b;
	scanf("%d",&x);
	for(int i=1;i<=x;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+x+1);
	for(int i=a[1];i<=a[x];i++){
		for(int j=1;j<=x;j++){
			 b+=abs(a[j]-i)*abs(a[j]-i);
			 
		}
		ans=min(b,ans);
		b=0;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
/*
[abc135] D - Digits Parade
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int M = 13;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
    gf& operator+=(const gf x) { return *this = (*this + x); }
};

int N;
string S;
gf dp[MAX_N + 1][M];

ll solve() {
    dp[0][0] = 1;
    for (int n = 0; n < N; n++) {
        for (int d = 0; d <= 9; d++) {
            if (S[n] == '?' || S[n] == '0' + d) {
                for (int m = 0; m < M; m++) {
                    dp[n + 1][(m * 10 + d) % M] += dp[n][m];
                }
            }
        }
    }

    return dp[N][5].n;
}

int main() {
    cin >> S;
    N = S.length();

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int cnt=0;
    while(a>=b)b*=2,cnt++;
    while(b>=c)c*=2,cnt++;
    if(cnt<=k)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3648
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
const long long int N = 6999999;
#define all(x) begin(x),end(x)
#define ll long long int
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll n,m,ans1 = 0,ans2 = 0,d = 1000000;
  cin >> n;
  vector <ll> v(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> v[i];
    ans1 += v[i];
  }
  for (int i = 0; i < n; ++i)
  {
    ans2 += v[i];
    ans1 -= v[i];
    d = min(abs(ans1-ans2),d);
  }
  cout << d << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
plus=[]
other=[]
d=list(map(int,input().split()))
for num in d:
    if num>0:
        plus.append(num)
    else:
        other.append(num)
if len(plus)>0:
    K=len(plus)
    if K==1:
        data=[]
        ans=plus[0]
        for q in other:
            data.append((ans,q))
            ans+=abs(q)
        print(ans)
        for some in data:
            x,y=some
            print(x,y)

    else:
        data=[]
        if len(other)>=1:
            ans=other[-1]
            for some in plus[1:]:
                data.append((ans,some))
                ans-=some
            other[-1]=ans
            ans=plus[0]
            for q in other:
                data.append((ans,q))
                ans+=abs(q)
            print(ans)
            for some in data:
                x,y=some
                print(x,y)
        else:
            plus.sort()
            ans=plus[0]
            for some in plus[1:-1]:
                data.append((ans,some))
                ans-=some
            data.append((plus[-1],ans))
            ans=plus[-1]-ans
            print(ans)
            for some in data:
                x,y=some
                print(x,y)
            
elif len(plus)==0:
    other.sort(reverse=True)
    data=[]
    ans=other[0]
    for q in other[1:]:
        data.append((ans,q))
        ans+=abs(q)
    print(ans)
    for some in data:
        x,y=some
        print(x,y)


Measured memory_bytes: 20772
import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int h = in.nextInt();
        int w = in.nextInt();
        int n = in.nextInt();
        ArrayList<Integer> numColors = new ArrayList<>();
        for (int i = 0; i < n; i++) numColors.add(in.nextInt());
        int curColor = 0;
        int[][] grid = new int[h][w];
        for (int i = 0; i < h; i += 2) {
            for (int j = 0; j < w; j++) {
                grid[i][j] = curColor + 1;
                numColors.set(curColor, numColors.get(curColor) - 1);
                if (numColors.get(curColor) == 0) curColor++;
            }
            if (i == h - 1) break;
            for (int j = w-1; j >= 0; j--) {
                grid[i+1][j] = curColor + 1;
                numColors.set(curColor, numColors.get(curColor) - 1);
                if (numColors.get(curColor) == 0) curColor++;
            }
        }
        
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                System.out.print(grid[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 24404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int a,b,c,k;cin>>a>>b>>c>>k;
  rep(i,k){
    if(a>=b)b*=2;
    else if(b>=c)c*=2;
  }
  if(a<b&&b<c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3608
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections


n,m = map(int,input().split())
edge = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
for i in edge[0]:
    if n-1 in edge[i]:
        print("POSSIBLE")
        sys.exit()
print("IMPOSSIBLE")

Measured memory_bytes: 38704
#include<stdio.h>

int main(void){
int t,a,v,i,max,num;

scanf("%d",&t);
max=-1;
for(i=0;i<t;i++){
scanf("%d%d",&a,&v);
if(max<v){
max=v;
num=a;
}
if(max==v){
if(num>a){
num=a;
}
}
}
printf("%d %d\n",num,max);

return 0;
}

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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
  int n;
  cin >> n;
  vector<ll>a(n);
  rep(i, 0, n)cin >> a[i];
  int cnt=1000;
  rep(i, 0, n){
    int temp=0;
    while(a[i]%2==0){
      a[i]/=2;
      temp++;
    }
    cnt = min(temp,cnt);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string O, E; cin >> O >> E;

  string result = "";
  rep(i, E.length()) { result += O[i]; result += E[i]; }
  if (O.length()>E.length()) result += O[O.length()-1];

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 999999999999
#define F first
#define S second
#define eb emplace_back
#define mp make_pair
#define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n'
#define dbg cout<<__LINE__ <<": 0manush\n"
#define read(x) freopen("input.txt","r",stdin)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 200009
#define mod 1000000007
using namespace std;

int main(){//read(x);
//fast;
ll r,g,h,i,j,x,t,y,z=0,e,f,a,b,c,d,n,l;
string s,u,v;
cin>>n;
l=0;
ll m[n];
for(i=0;i<n;i++){
    cin>>m[i];
    l=(l+m[i])%mod;
}a=0;
for(i=0;i<n-1;i++){
    l=(l+mod-m[i])%mod;
    a=(a+(l*m[i])%mod)%mod;
}
cout<<a<<endl;
}























Measured memory_bytes: 5192
from sys import stdin

N = int(stdin.readline().rstrip())
ans = 0
d = 0
M = [[0] * 10 for _ in range(10)]

for i in range(1, N + 1):
    s = str(i)
    M[int(s[0])][int(s[-1])] += 1

for i in range(10):
    for j in range(10):
        if i == j:
            d += M[i][j] * M[j][i]
        else:
            ans += M[i][j] * M[j][i]

print(ans + d)


Measured memory_bytes: 41324
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int N_S = S.length();
        int N_T = T.length();
        long[] ruiseki_S = new long[N_S+1];
        long[] ruiseki_T = new long[N_T+1];
        for (int i=0;i<N_S;i++) {
            int add=0;
            if (S.charAt(i)=='A') add=1;
            else add=2;
            ruiseki_S[i+1] = ruiseki_S[i]+add;
        }
        for (int i=0;i<N_T;i++) {
            int add=0;
            if (T.charAt(i)=='A') add=1;
            else add=2;
            ruiseki_T[i+1] = ruiseki_T[i]+add;
        }
        // System.out.println(Arrays.toString(ruiseki_S));
        // System.out.println(Arrays.toString(ruiseki_T));

        int Q = sc.nextInt();
        for (int i=0;i<Q;i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());
            int d = Integer.parseInt(sc.next());
            // System.out.println(((ruiseki_S[b]-ruiseki_S[a-1])-(ruiseki_T[d]-ruiseki_T[c-1]))%3);
            if (((ruiseki_S[b]-ruiseki_S[a-1])-(ruiseki_T[d]-ruiseki_T[c-1]))%3==0) System.out.println("YES");
            else System.out.println("NO");
        }
    }
}


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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    bool poor = false;
    if(A == B && B != C || B == C && A != B || A == C && A != B) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
typedef long long ll;

int main() {
	int k;
	char s[100001];
	scanf("%s", s);
	scanf("%d", &k);
	int len = strlen(s);
	for (int i = 0; i < len - 1; i++) {
		int l = ('z' - s[i] + 1) % 26;
		if (l <= k) {
			s[i] = 'a';
			k -= l;
		}
	}
	s[len - 1] = (s[len - 1] - 'a' + k % 26) % 26 + 'a';
	printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  ll n;
  cin >> n;
  ll a=n%10;
  if(a==3){
    cout << "bon" << endl;
  }
  else if((a==0)||(a==1)||(a==6)||(a==8)){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3100
#include <iostream>
typedef long long ll;

using namespace std;

int main() {
    string S;
    ll K;
    cin >> S >> K;

    for (int i = 0; i < S.length(); i++) {
        if (S[i] != '1' || i == K - 1) {
            cout << S[i] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<list>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

int n;
vector<ll> h;

int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll hi;
		cin >> hi;
		h.push_back(hi);
	}
	string ret = "Yes";
	ll tmp = 0;
	for (int i = 0; i < n - 1; i++) {
		if (h[i] - h[i + 1] > 0) {
			h[i]--;
			if (tmp < h[i])
				tmp = h[i];
			if (h[i + 1] < tmp) {
				ret = "No";
				break;
			}
		}
	}
	cout << ret << endl;
	return 0;
}

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

int main(){
    int n;
    char c;
    string bt;
    int bt_a=0,bt_b=0,bt_o=0,bt_ab=0;

    while(cin>>n){
        cin>>c;
        getline(cin,bt);

        if(bt=="A"){
            bt_a++;
        }else if(bt=="B"){
            bt_b++;
        }else if(bt=="O"){
            bt_o++;
        }else{
            bt_ab++;
        }
    }

    cout<<bt_a<<endl;
    cout<<bt_b<<endl;
    cout<<bt_ab<<endl;
    cout<<bt_o<<endl;
}

Measured memory_bytes: 1204
#include <stdio.h>

long long int gcd(long long int x, long long int y) {
    return y ? gcd(y, x % y) : x;
}

long long int lcm(long long int x, long long int y) {
    return x/gcd(x, y)*y;
}

int main()
{
    long long int x, y;

    while (scanf("%ld %ld", &x, &y) != EOF) {
        printf("%lld %lld\n", gcd(x, y), lcm(x, y));
    }

    return 0;
}

Measured memory_bytes: 1736
import java.util.*;
class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		String t=s.next(),u="",v="";
		int r=0;
		for(int i=0;i<t.length();++i) {
			v+=t.charAt(i);
			if(!u.equals(v)){
				u=v;
				v="";
				++r;
			}
		}
		System.out.println(r);
	}
}


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

const int MOD = (int)1e9+7;

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

  vector<int> abc(26,0);
  for(int i=0;i<N;i++){
    abc.at(S.at(i)-'a')++;
  }
  long long ans=1;
  for(int i=0;i<26;i++){
    ans*=abc.at(i)+1;
    ans%=MOD;
  }
  ans--;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
class Backfront:
    max_to_min = {}

    def add(self, x):
        if x - 1 in self.max_to_min:
            self.max_to_min[x] = self.max_to_min[x - 1]
            del self.max_to_min[x - 1]
        else:
            self.max_to_min[x] = x

    def longest_seq(self):
        return 1 + max([y - x for (y, x) in self.max_to_min.items()])

def main():
    n = int(input())

    backfront = Backfront()
    for _ in range(n):
        x = int(input())
        backfront.add(x)

    print("{0:d}".format(n - backfront.longest_seq()))

main()


Measured memory_bytes: 27148
L,R = map(int,input().split())
if R-L > 2019:
    print(0)
else:
    mi = 10**9
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            r = ((i%2019)*(j%2019))%2019
            if r < mi:
                mi = r
    print(mi)

Measured memory_bytes: 3060
/*  ex4_1
    hangan2020 */

#include <stdio.h>

//プロトタイプ宣言
int InspectorforGoldenApple (int Tree, int TreeperInspector );

main(void){
    int tree, tree_per_inspector, inspector_needed ;
    //入力
    scanf("%d %d", &tree, &tree_per_inspector);
    //監視員数を計算する関数の実施
    inspector_needed = InspectorforGoldenApple(tree, tree_per_inspector);
    //出力
    printf("%d\n", inspector_needed);
    return 0;
}

//関数定義
int InspectorforGoldenApple (int Tree, int TreeperInspector ){
    int InspectorNeeded;
    //入力Dは番号に基づく情報なので、ここで実際に監視員が監視する木の数を計算する
    TreeperInspector = TreeperInspector*2 + 1;
    /*木の総数が監視員ごとに観察される木の数に割りきれる場合以外に、
    必要な監視員数 = Tree/ TreeInspector */
    InspectorNeeded = Tree / TreeperInspector;
    if (Tree % TreeperInspector){
        InspectorNeeded++;
    }
    return(InspectorNeeded);
}

Measured memory_bytes: 128
n = int(input())
ans = ""
while n>=10:
    n%=10
if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
    ans = "hon"
elif n == 0 or n == 1 or n == 6 or n == 8:
    ans = "pon"
else:
    ans = "bon"
print(ans)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N; cin >> N;
    map<ll, ll> A;
    ll ans = 0;
    REP(n, N) {
        ll a; cin >> a;
        A[a]++;
        ans += a;
    }
    ll Q; cin >> Q;

    REP(q, Q) {
        ll B, C; cin >> B >> C;
        ll B_count = A[B];
        ans += (C-B)*B_count;
        A[C] += B_count;
        A[B] = 0;

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


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    int x = 0;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int sum = 4 * i;
        
        if(sum == n)
        {
            cout << "Yes" << endl;
            return 0;
        }
        
        while(sum < n)
        {
            x++;
            sum += x * 7;
            
            if(sum == n)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
        x = 0;
    }
    
    cout << "No" << endl; 
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

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

		int num = Integer.parseInt(sc.next());

		boolean yymm = (1 <= num % 100) && (num % 100 <= 12);
		boolean mmyy = (1 <= num / 100) && (num / 100 <= 12);

		String s = (yymm && mmyy) ? "AMBIGUOUS" :
				   (yymm && !mmyy) ? "YYMM" :
				   (!yymm && mmyy) ? "MMYY" :
				   (!yymm && !mmyy) ? "NA" : "";


		System.out.println(s);

		sc.close();
	}
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  int N, M;
  cin >> N >> M;
  vector<long long> a(N);
  vector<long long> b(N);
  vector<long long> c(M);
  vector<long long> d(M);

  vector<long long> ans(N);

  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < M; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < N; i++) {
    int min = 2000000000;
    for (int j = M - 1; j >= 0; j--) {
      long long dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (min > dist) {
        min = dist;
        ans[i] = j + 1;
      } else if (min == dist) {
        ans[i] = j + 1;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
import numpy as np
N,M = map(int,input().split())
X = list(map(int,input().split()))

if N < M:
  X = sorted(X,reverse = True)
  X_ = abs(np.array(X[1:]) - np.array(X[:M-1]))
  X_ = sorted(X_,reverse = True)
  print(sum(X_[N-1:]))
else:
  print('0')

Measured memory_bytes: 22984
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

template<int Size>
class FenwickTree
{
public:

	i64 sum(int n)
	{
		i64 ans = 0;

		while (n > 0)
		{
			ans += data[n];
			n -= (n & -n);
		}

		return ans;
	}

	void add(int n, i64 num)
	{
		while (n < Size)
		{
			data[n] += num;
			n += (n & -n);
		}
	}

	int search(i64 k)
	{
		int lo = 0, hi = Size - 1;
		int ans = 0;

		while (lo <= hi)
		{
			int mid = (lo + hi) / 2;

			i64 q = sum(mid);

			if (q >= k)
			{
				ans = mid;
				hi = mid - 1;
			}
			else
			{
				lo = mid + 1;
			}
		}

		return ans;
	}

private:
	int data[Size];
};

int w[2005], b[2005];
int nextw[2005], nextb[2005];
int table[2005][2005];
int widx[2005], bidx[2005];
FenwickTree<2005> wtree[2005];
FenwickTree<2005> btree[2005];

int solve(int endw, int endb)
{
	if (endw == 0 && endb == 0)
		return 0;

	if (table[endw][endb] != -1)
		return table[endw][endb];

	int& res = table[endw][endb];
	res = 987654321;

	if (endb != 0)
	{
		int bi = bidx[endb];
		int bd = btree[bi].sum(endb - 1);
		int wi = nextw[bi];
		int wd = wtree[wi].sum(endw);

		res = min(res, solve(endw, endb - 1) + bd + wd);
	}

	if (endw != 0)
	{
		int wi = widx[endw];
		int wd = wtree[wi].sum(endw - 1);
		int bi = nextb[wi];
		int bd = btree[bi].sum(endb);

		res = min(res, solve(endw - 1, endb) + bd + wd);
	}

	return res;
}

int main()
{
	int n;
	scanf("%d", &n);

	int wi = 1, bi = 1;

	for (int i = 1; i <= n; i++)
		nextw[i] = nextb[i] = n + 1;

	for (int i = 0; i < 2 * n; i++)
	{
		char c[2];
		int k;

		scanf("%s %d", c, &k);

		if (c[0] == 'W')
		{
			w[wi] = k;
			widx[k] = wi;

			for (int j = 1; j < bi; j++)
				if (nextw[j] == n + 1)
					nextw[j] = wi;

			wi++;
		}
		else
		{
			b[bi] = k;
			bidx[k] = bi;

			for (int j = 1; j < wi; j++)
				if (nextb[j] == n + 1)
					nextb[j] = bi;

			bi++;
		}
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = i; j <= n; j++)
		{
			wtree[i].add(w[j], 1);
			btree[i].add(b[j], 1);
		}
	}

	memset(table, -1, sizeof(table));

	printf("%d\n", solve(n, n));

	return 0;
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  int n; cin >> n;
  vi a(n);

  rep(i, n) cin >> a[i];
  int ans = 0;

  rep(i, n-2) {
    if (a[i] < a[i+1] && a[i+1] < a[i+2]) ++ans;
    else if (a[i] > a[i+1] && a[i+1] > a[i+2]) ++ans;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================


	int N;
	cin >> N;

	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i++) {
		S[i] += N;
		if (S[i] > 90) {
			S[i] -= 26;
		}
	}

	cout << S;
}




Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, const char * argv[])
{
 int h,m,s,S,h2;
 scanf("%d",&S);
 h=S/3600;
 m=(S%3600)/60;
 s=(S%3600)%60;
 printf("%d:%d:%d\n",h,m,s);
 return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a[4];
  cin>>a[0]>>a[1]>>a[2]>>a[3];
  sort(a,a+4);
  if(a[0]==a[1] && a[2]==a[3]){
    cout<<"yes"<<endl;
  }else cout<<"no"<<endl;

  return 0;
}



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

int main(){
    long long n,T;
    cin>>n>>T;
    long long t[n];
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    long long ans=0;
    for(int i=0;i<n-1;i++){
        if(t[i]+T<t[i+1]){
            ans+=T;
        }
        else ans+=t[i+1]-t[i];
    }
    ans+=T;
    cout<<ans;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m,p;
	int i,j,k;
	LL a,b,c,d;
	cin>>n;
	c=0,d=0;
	for(i=0;i<n;i++){
		cin>>a>>b;
		c+=a*b,d+=b;
	}
	d--;
	d+=(c-1)/9;
	cout<<d<<endl;
}

Measured memory_bytes: 256
class UnionFind
    attr_reader :set_size
    def initialize(n)
        @par = Array.new(n)
        n.times{ |i| @par[i] = i }
        @rank = Array.new(n, 0)
        @set_size = Array.new(n, 1)
    end

    def find(x)
        if @par[x] == x
            x
        else
            @par[x] = find(@par[x])
        end
    end

    def unite(x,y)
        x = find(x)
        y = find(y)
        return if x == y

        if @rank[x] < @rank[y]
            @par[x] = y
            @set_size[y] += @set_size[x]
        else
            @par[y] = x
            @set_size[x] += @set_size[y]
            @rank[x] += 1 if @rank[x] == @rank[y]
        end
    end

    def same?(x, y)
        find(x) == find(y)
    end
end


N, M, K = gets.split.map(&:to_i)
cs = gets.split.map(&:to_i)
edges = []
M.times do |i|
    a, b, w = gets.split.map(&:to_i)
    edges.push([w, a-1, b-1])
end
edges.sort!

uf = UnionFind.new(N)
first = []
N.times do |i|
    next if cs[i] == 0
    if first[cs[i]]
        uf.unite(i, first[cs[i]])
    else
        first[cs[i]] = i
    end
end

ans = 0
num = 0
edges.each do |w, a, b|
    if !uf.same?(a, b)
        num += 1
        ans += w
        uf.unite(a, b)
    end
    break if num == K-1
end
puts num == K-1 ? ans : -1

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

void fnInput(vector<int>& rvnSeqP, vector<int>& rvnSeqQ)
{
  int nSeqSiz;
  cin >> nSeqSiz;
  rvnSeqP.resize(nSeqSiz);
  rvnSeqQ.resize(nSeqSiz);

  for (int& rnSeqP : rvnSeqP)
    cin >> rnSeqP;
  for (int& rnSeqQ : rvnSeqQ)
    cin >> rnSeqQ;
}
  
int fnCountOrderGet(const vector<int>& cnrvnSeqP, const vector<int>& cnrvnSeqQ)
{
  vector<int> vnSeqX(cnrvnSeqP.size());
  int nCntP = 0;
  int nCntQ = 0;
  int nCntX = 0;

  iota(begin(vnSeqX), end(vnSeqX), 1);
  do {
    nCntX++;
    if (cnrvnSeqP == vnSeqX) nCntP = nCntX;
    if (cnrvnSeqQ == vnSeqX) nCntQ = nCntX;
  }
  while ( next_permutation(begin(vnSeqX), end(vnSeqX)) &&
          ( nCntP == 0 || nCntQ == 0 )                   );

  return abs(nCntP - nCntQ);
}
  
int main()
{
  vector<int> vnSeqP, vnSeqQ;

  fnInput(vnSeqP, vnSeqQ);
  cout << fnCountOrderGet(vnSeqP, vnSeqQ) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 200010, P = 1000000007;

int n;
int p[N], q[N], l[N], r[N];
pair<int, int> x[N], v[N];

int fw[N];

void add(int& x, int y) {
  if ((x += y) >= P)
    x -= P;
}

void ch(int k, int x) {
  for (; k <= n + 1; k += k & -k)
    add(fw[k], x);
}

int qry(int k) {
  int ret = 0;
  for (; k; k &= k - 1)
    add(ret, fw[k]);
  return ret;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i].first >> v[i].first;
    x[i].second = i;
    v[i].second = i;
  }
  sort(x + 1, x + n + 1);
  sort(v + 1, v + n + 1);
  for (int i = 1; i <= n; ++i) q[v[i].second] = i;
  for (int i = 1; i <= n; ++i) p[i] = q[x[i].second];
  r[1] = p[1];
  for (int i = 2; i <= n; ++i) r[i] = max(r[i - 1], p[i]);
  l[n] = p[n];
  for (int i = n - 1; i; --i) l[i] = min(l[i + 1], p[i]);
  ch(n + 1, 1);
  for (int i = n; i; --i)
    ch(l[i], qry(r[i] + 1));
  cout << qry(1) << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 7296
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <functional>
using namespace std;

typedef long long LL;
typedef pair<LL,int> pli;

const LL INF = (LL)1e18;

LL len[33][33];
int next[33][33];
char label[64];

struct packet{
	string name;
	int from, to;
	LL tm;

	packet(int f, int to, LL tm, const char *s):
		name(s), from(f), to(to), tm(tm) {}
	
	bool operator< (const packet &p) const{
		if(tm != p.tm){ return tm < p.tm; }
		return name < p.name;
	}
};

struct event{
	int type;	//-1: human   other: packet
	int pos;
	LL tm;

	bool operator< (const event &e) const{
		if(tm != e.tm){ return tm > e.tm; }
		return type < e.type;
	}
};

void solve(int n, int m){
	int f, t, d;

	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= n; ++j){
			len[i][j] = INF;
			next[i][j] = 0;
		}
		len[i][i] = 0;
		next[i][i] = i;
	}

	for(int i = 0; i < m; ++i){
		scanf("%d%d%d", &f, &t, &d);
		len[f][t] = len[t][f] = d;
		next[f][t] = t;
		next[t][f] = f;
	}

	for(int k = 1; k <= n; ++k)
	for(int i = 1; i <= n; ++i)
	for(int j = 1; j <= n; ++j){
		if(i == k || k == j){ continue; }
		LL &d1 = len[i][j];
		LL d2 = len[i][k] + len[k][j];
		if((d1 > d2) || (d1 == d2 && next[i][j] > next[i][k])){
			d1 = d2;
			next[i][j] = next[i][k];
		}
	}

	vector<vector<int> > wait(n + 1);
	scanf("%d", &m);
	vector<packet> ps;
	priority_queue<event> pqev;
	for(int i = 0; i < m; ++i){
		scanf("%d%d%d%s", &f, &t, &d, label);
		ps.push_back(packet(f, t, d, label));
		pqev.push((event){i, f, d});
	}

	vector<char> standby(n + 1, 1);

	while(!pqev.empty()){
		event ev = pqev.top();
		pqev.pop();
		if(ev.type >= 0){
			wait[ev.pos].push_back(ev.type);
			if(standby[ev.pos]){
				standby[ev.pos] = 0;
				pqev.push((event){-1, ev.pos, ev.tm});
			}
		}
		else{
			vector<int> &ws = wait[ev.pos];
			if(ws.empty()){
				standby[ev.pos] = 1;
				continue;
			}

			LL mintm = INF;
			for(int i = 0; i < ws.size(); ++i){
				mintm = min(mintm, ps[ws[i]].tm);
			}

			int to = 999;
			for(int i = 0; i < ws.size(); ++i){
				packet &p = ps[ws[i]];
				if(p.tm == mintm && to > next[p.from][p.to]){
					to = next[p.from][p.to];
				}
			}
			vector<int> send;
			for(int i = 0; i < ws.size(); ++i){
				packet &p = ps[ws[i]];
				if(p.tm <= ev.tm && next[ev.pos][p.to] == to){
					send.push_back(i);
				}
			}

			LL arvtm = ev.tm + len[ev.pos][to];
			for(int i = send.size() - 1; i >= 0; --i){
				int pn = ws[send[i]];
				packet &p = ps[pn];
				p.from = to;
				p.tm = arvtm;
				if(to != p.to){
					pqev.push((event){pn, to, arvtm});
				}
				ws.erase(ws.begin() + send[i]);
			}

			pqev.push((event){-1, ev.pos, ev.tm + 2 * len[ev.pos][to]});
		}
	}
	
	sort(ps.begin(), ps.end());
	for(int i = 0; i < ps.size(); ++i){
		printf("%s %lld\n", ps[i].name.c_str(), ps[i].tm);
	}
}

int main(){
	bool flg = false;
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		if(flg){
			puts("");
		}
		flg = true;
		solve(n, m);
	}
}

Measured memory_bytes: 1416
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int D = sc.nextInt();
    int N = sc.nextInt();
    if (N != 100) {
      System.out.println(N * (int) Math.pow(100, D));
    } else {
      System.out.println((N + 1) * (int) Math.pow(100, D));
    }
  }
}

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

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

  string s, t;
  cin >> s >> t;
  int count = 0;
  rep(i, s.length())
  {
    if (s.at(i) != t.at(i))
    {
      count++;
    }
  }
  cout << count << endl;

  return 0;
}

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

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

  vector<int> goods(n);
  ll total = 0;
  for (int i = 0; i < n; i++) {
    cin >> goods.at(i);
    total += goods.at(i);
  }
  sort(goods.rbegin(), goods.rend());

  if (goods.at(m-1) < total/(4.0*m)) printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 384
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
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)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	print(n*(n+1)//2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 24888
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	const int MAX_N = 1000;
	int n;
	cin >> n;
	int x[MAX_N] = { 0 };
	int y[MAX_N] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	//p=1 ???????????????????????¢
	double md = 0.0;
	for (int i = 0; i < n; i++) {
		md += fabs(x[i] - y[i]);
	}
	
	//p=2 ???????????????????????¢
	double ed = 0.0;
	for (int i = 0; i < n; i++) {
		ed += pow(fabs(x[i] - y[i]), 2);
	}
	ed = sqrt(ed);
	
	//p=3
	double a = 0.0;
	for (int i = 0; i < n; i++) {
		a += pow(fabs(x[i] - y[i]), 3);
	}
	a = pow(a, 1 / 3.0);
	
	//p=INF
	double b = abs(x[0] - y[0]);
	for (int i = 1; i < n; i++) {
		b = max<double>(b, fabs(x[i] - y[i]));
	}

	printf("%.6f\n%.6f\n%.6f\n%.6f\n", md, ed, a, b);

    return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }
// const ll sz = 2e6 + 5;
// vector<ll> fac(sz, 1);

// * ALways PASS arrays, strings etc to functions BY REFERENCE

int main() {
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    int t = 1;
    // cin >> t;
    
    while(t--) {
        int n;
        cin >> n;
        
        vector<ll> arr(n);
        for (auto &x: arr)
            cin >> x;
        
        sort(arr.begin(), arr.end());
        
        ll res = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (arr[i] == arr[j])
                    continue;
                for (int k = j+1; k < n; k++) {
                    if (arr[k] == arr[j])
                        continue;
                    if (arr[i] + arr[j] > arr[k])
                        ++res;
                }
            }
        }
        
        cout << res << endl;
    }
    
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	string s;
	cin >> s;
	bool flag = false;
	for(int i = 0;i < s.length() - 1;i++){
		if(s[i] == 'A' && s[i + 1] == 'C') flag = true;
	}
	if(flag) Yes();
	else No();
	return 0;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	n,k=MI()
	p=LI()

	for i in range(n):
		p[i]=p[i]/2+0.5
	#print(p)

	ans=sum(p[:k])
	now=sum(p[:k])

	for i in range(n-k):
		now=now-p[i]+p[i+k]
		ans=max(ans,now)
	print(ans)















if __name__ == "__main__":
	main()


Measured memory_bytes: 31756
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    int x;
    int n;
    set<int> s;
    cin >> x >> n;
    for(int i=0;i<n;i++) {
        int e;
        cin >> e;
        s.insert(e);
    }
    for(int i=0;;i++) {
        int n1 = abs(x-i);
        int n2 =abs(x+i);
        if(s.find(n1)==s.end()) {
            cout << n1 << endl;
            return;
            break;
        }
        else if(s.find(n2)==s.end()) {
            cout << n2 << endl;
            return;
            break;
        }
    }
}

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

//--n1m5


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  vvi a(n, vi(n));

  rep(i,0,n) rep(j,0,n) cin >> a[i][j];

  vi dp(1<<n);
  dp[0] = 1;
  const ll mod = 1e9+7;

  rep(msk,0,1<<n) {
    int i = __builtin_popcount(msk);
    rep(j,0,n) {
      if (msk&(1<<j)) continue;
      if (not a[i][j]) continue;
      dp[msk|(1<<j)] += dp[msk];
      dp[msk|(1<<j)] %= mod;
    }
  }

  cout  << dp.back() << '\n';
}

Measured memory_bytes: 8448
#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(){
  string s;
  cin >> s;
  int N = s.size();
  bool isok[N];
  fill(isok,isok+N,false);
  for(int i=0;i<N;i++){
    if(s[i]=='A' || s[i]=='T' || s[i]=='C' || s[i]=='G'){
      isok[i] = true;
    }
  }

  int cnt[N];
  for(int i=0;i<N;i++){
    if(!isok[i]) cnt[i] = 0;
    else if(isok[i] && i==0) cnt[i] = 1;
    else if(isok[i]) cnt[i] = cnt[i-1] + 1;
  }

  cout << *max_element(cnt,cnt+N) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007ll
#define INF (1 << 28)    // for x <= 10^9
#define INFL (1ll << 60) // for x <=10^19
#define EPS (1e-10)
 
using namespace std;
 
using ll = long long;
 
ll gcd(ll a, ll b) {
  if (a < b)
    return gcd(b, a);
 
  while (b != 0) {
    int r = a % b;
    a = b;
    b = r;
  }
 
  return a;
}
 
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
 
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
 
  ll toA = (a - 1) - ((a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d));
  ll toB = b - (b / c + b / d - b / lcm(c, d));
  cout << toB - toA << endl;
}

Measured memory_bytes: 256