akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
 

int main() {
  int x, y;
  cin >> x >> y;
  int group[] = {0, 1, 9, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if (group[x] == group[y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b := nextInt(), nextInt()
	add, sub, mul := a+b, a-b, a*b
	max := add
	if max < sub {
		max = sub
	}
	if max < mul {
		max = mul
	}

	fmt.Println(max)
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

string s1, s2, s3;
int a, b;

int main()
{
    cin >> s1 >> s2;
    cin >> a >> b;
    cin >> s3;
    if(s3 == s1) cout << a - 1 << ' ' << b << endl;
    else if(s3 == s2) cout << a << ' ' << b - 1 << endl;
    else cout << a << ' ' << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define el "\n"
#define F first
#define S second
#define PI 3.14159265358979323846  /* pi */
#define FOR(i,a,b) for(int i = a; i < b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define RI(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(n)-1)
#define SQR(x) (x)*(x)
#define all(v)  	((v).begin()),((v).end())
#define degreesToRadians(angleDegrees) (angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / PI) // Converts radians to degrees.
typedef long long ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef long double ld;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
const double EPS = 1e-9;
const int N = 1e3+2, M = 3e5+5, OO = 0x3f3f3f3f;
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
// int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Direction
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
  long long n;
  cin>>n;
  long long p = 100;
  long long r = 1;
  long long ans = p, count=0;
  while(ans<n){
    ans = ans + (ans*r)/100;
    // cout<<ans<<" ";
    count++;
  }
  cout<<count<<endl;
	return 0;

}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N, A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> A >> B;
    int ans = min(A * N, B);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int num[100000+5],a[100000+5],c[100000+5],s[100000+5],t[100000+5],cnt;
long long N,ans;
void merge(int a[],int l,int m,int r){
	int i=l,j=m+1,p=i;
	while(i<=m||j<=r){
		if(i<=m&&(j>r||a[i]<=a[j])) t[p++]=a[i++],ans+=j-m-1;
		else t[p++]=a[j++];
	}
	for(int i=l;i<=r;i++){
		a[i]=t[i];
	}
}
void sort(int a[], int l, int r) {
if (l >= r) return ;
int mid = (l + r) / 2;
sort(a, l, mid); 
sort(a, mid + 1, r); 
merge(a, l, mid, r);
}
bool check(int n){
	ans=0;
	for(int i=1;i<=N;i++){
	     if(a[i]>n) c[i]=1;
	     if(a[i]==n) c[i]=1;
		 if(a[i]<n) c[i]=-1;  	
	}
	s[0]=0;
	for(int i=1;i<=N;i++){
		s[i]=s[i-1]+c[i];
	}
	sort(s,0,N);
	if(ans<=(long long)N*(N+1)/4) return true;
	else return false;
}
int main(){
   cin>>N;
    for(int i = 1 ; i <= N ; ++i) {cin>>a[i];num[i] = a[i];}
    
    sort(num + 1,num + N + 1);
    cnt = unique(num + 1,num + N + 1) - num - 1;
    int L = 1,R = cnt;
    while(L < R) {
        int mid = (L + R + 1) /2;
        if(check(num[mid])) L = mid;
        else R = mid-1;
    }
    cout<<num[R]<<endl;
    return 0;
}


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

int main(){
  int N;
  string s;
  cin >> N;
  
  for(int i=0;i<N;i++){
    cin >> s;
    if(s=="Y"){
      cout << "Four" << endl;
      break;
    }
  }
  if(s!="Y"){
    cout << "Three" << endl;
  }
}

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

using namespace std;

int main(void) {

	int x1, y1, x2, y2, x3, y3, x4, y4;

	cin >> x1 >> y1 >> x2 >> y2;

	x3 = x2 - y2 + y1;

	y3 = y2 + x2 - x1;

	x4 = x3 + x1 - x2;

	y4 = y3 + y1 - y2;

	printf("%d %d %d %d\n", x3, y3, x4, y4);

	return 0;
}

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

int main(){
  int a,b,c;
  cin >>a >>b >>c;
  if(a==b && b==c && c==a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
  int A,B,C,D,res;
  cin >> A >> B >> C >> D;
  res = (A + B) - (C + D);
  
  if (res > 0){
    cout << "Left" << endl;
  }
  else if(res < 0){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(it,beg,end) for(__typeof(beg) X=beg,Y=end,it=(X>Y?X-1:X);it!=(X>Y?Y-1:Y);it+=(X>Y?-1:1))
using namespace std;
#define ll long long
#define pb emplace_back
#define mp make_pair
inline void read1(ll &n) {
	char c;n=0;ll x=1;
	while (!isdigit(c=fgetc(stdin))&&c!='-');
	if (c=='-') x=-1, c=fgetc(stdin);
	while (isdigit(c)) n=n*10+c-'0',c=fgetc(stdin);
	n*=x;
}
inline void read1(int &n) {ll x;read1(x);n=x;}
#define read2(a,b) {read1(a);read1(b);}
#define read3(a,b,c) {read1(a);read1(b);read1(c);}
#define read4(a,b,c,d) {read1(a);read1(b);read1(c);read1(d);}
// -------------------- Standard Template --------------------
string s; 
int main() {
	cin>>s;
	if (s.substr(0,4)=="YAKI") {
		printf("Yes");
	} else {
		printf("No");
	}
	return 0;
}


Measured memory_bytes: 256
/*
author : seryu
title : Tokio Marine 2020 A_"Nickname"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

void solve()
{
	string s;
	cin >> s;
	cout << s.substr(0,3) << endl;
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3632
S = input()[::-1]
find_w = False
w_count = 0
result = 0
 
for i, c in enumerate(S):
    if not find_w:
        if c == "B":
            continue
        else:
            find_w = True
            w_count += 1
    else:
        if c == "B":
            result += w_count
        else:
            w_count += 1
 
print(result)

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

vector<int>v;
vector<int>ans;
int res;
int sumOfDigits (int n)
{
    int sum = 0;

    while (n)
    {
        sum += n % 10;
        n /= 10;
    }

    return sum;
}


ll fastpow(ll a,ll b){
if(!b)
    return 1;

ll  sq=fastpow(a,b/2);
sq*=sq;
if(b%2!=0)
    sq*=a;

    return sq;

}
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

const int maxx=1e3+100;
int c[maxx];
int n,m,d;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int n;
cin>>n;

vector<int>v;

for(int i=1;i<=9;i++)
    v.push_back(i*111);

  for(auto s:v){
    if(n<=s)
    {
        cout<<s<<"\n";
        break;
    }
  }




	return 0;
}







Measured memory_bytes: 3644
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    this.root = new BinaryTree.Node(key, null, null, null);

    this.insert = (key) => {
      let x = this.root, y;
      let newNode = new BinaryTree.Node(key, null, null, null);
      while (x != null) {
        y = x;
        x = x[key < x.key ? 'left' : 'right'];
      }
      newNode.parent = y;
      y[key < y.key ? 'left' : 'right'] = newNode;
    }
  }

  ineorder() {
    let str = '';
    let f = (n) => {
      if (n === null) return;
      f(n.left);
      str += ` ${n.key}`;
      f(n.right);
    }
    f(this.root)
    console.log(str);
  }

  preorder(n = this.root) {
    if (n === null) return;
    process.stdout.write(` ${n.key}`);
    this.preorder(n.left);
    this.preorder(n.right);
  }

  print() {
    this.ineorder();
    this.preorder(); console.log();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  const commands = lines.map((line) => line.split(' '));
  commands.forEach(function(cmd) {
    switch(cmd[0].charAt(0)) {
    case 'i': tree.insert(Number(cmd[1])); break;
    default: tree.print(); break;
    }
  });

})();



Measured memory_bytes: 316716
# -*- coding: utf-8 -*-

MOD = 1000000007

N = int(input())
S1 = input()
S2 = input()

ptns = []
i = 0
# パターンXとYに分けて区切る
while i < N:
    if S1[i] == S2[i]:
        ptns.append('X')
        i += 1
    else:
        ptns.append('Y')
        i += 2

if ptns[0] == 'X':
    ans = 3
elif ptns[0] == 'Y':
    ans = 6
for i in range(1, len(ptns)):
    # XとYの並びを4つパターン毎に処理
    if ptns[i-1] == 'X' and ptns[i] == 'X':
        ans *= 2
    elif ptns[i-1] == 'X' and ptns[i] == 'Y':
        ans *= 2
    elif ptns[i-1] == 'Y' and ptns[i] == 'X':
        ans *= 1
    elif ptns[i-1] == 'Y' and ptns[i] == 'Y':
        ans *= 3
    ans %= MOD
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N;
  cin >> N;
  vector<string> s(N);

  rep(i, N){
    cin >> s[i];
  }

  sort(s.begin(), s.end());
  vector<pair<int, string> > a;// かずと、番号
  int cnt = 1;
  int max_cnt = 0;
  rep(i, N-1){
    if(s[i] == s[i+1]) {
      cnt++;
    } else {
      a.push_back(make_pair(cnt, s[i]));
      max_cnt = max(max_cnt, cnt);
      cnt = 1;
    }
  }
  max_cnt = max(max_cnt, cnt);
  a.push_back(make_pair(cnt, s[N-1]));

  rep(i, a.size()){
    // cout << a[i].first << " " << a[i].second << endl;
    if (max_cnt == a[i].first){
      cout << a[i].second << endl;
    }
  }
  
}


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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  float a,b,n;
  cin>>a>>n;
  b=2*n-a;
  cout<<b<<endl;
}

Measured memory_bytes: 256
N,x = map(int,input().split())
a = [int(i) for i in input().split()]

ans = 0
for i in range(N):
    if i == 0:
        if a[i] > x:
            ans += a[i] - x
            a[i] = x
    else:
        tmp = a[i] + a[i-1]
        if tmp > x:
            ans += tmp - x
            a[i] -= tmp - x

print(ans)

Measured memory_bytes: 14668
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include <cassert>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main(){
	ll x;
	cin >> x;
	if (x >= 30) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }


}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m,s,g;
vector<pair<int,string> >edge[45];
string dp[45];
struct S{
    int v; string s;
    bool operator <(const S &a)const{
        return s > a.s;
    }
    S(int a,string b){
        v = a; s = b;
    }
};
int a[3005],b[3005]; string c[3005];
int main(){
    while(1){
        scanf("%d%d%d%d",&n,&m,&s,&g);
        if(n==0) return 0;
        for(int i=0;i<n;i++){
            edge[i].clear();
            dp[i] = "1";
        }
        for(int i=0;i<m;i++){
            cin >> a[i] >> b[i] >> c[i];
        }
        dp[g] = ""; bool bad = 0;
        for(int t=0;t<1000;t++){
            bool upd = 0;
            for(int i=0;i<m;i++){
                if(dp[b[i]] != "1" && (dp[a[i]]=="1" || dp[a[i]] > c[i]+dp[b[i]])){
                    dp[a[i]] = c[i]+dp[b[i]]; upd = 1;
                    if(t > 500 && a[i] == s) bad = 1;
                }
            }
        }
        if(bad || dp[s] == "1") puts("NO");
        else cout << dp[s] << endl;
    }
}

Measured memory_bytes: 6276
#include <stdio.h>
int main(void){
    int a,b,c,count=0,i;
    scanf("%d%d%d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(i>c){break;}
        if(i*2>c){
            if(b>=c){count++;}
            break;
        }
        if(c%i==0){count++;}
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 596
#各桁の和を計算する関数
def findSumOfDigits(n):
  sum = 0
  while( n > 0):
    sum += int(n) % 10
    n = int(n) / 10
  return int(sum)

N = int(input())
total = findSumOfDigits(N)
if N % total == 0:
  print("Yes")
else:
  print("No")


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

class Atcoder
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().Split().Select(long.Parse).ToArray();

        var a = s[0];
        var b = s[1];

        var ans = a - b * 2;
        if (ans < 0) ans = 0;

        Console.WriteLine(ans);
    }
}

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

int A[20];
int x[20][20];
int y[20][20];
int ans = 0;

void update(string str, int n) {
  // ビット列に変換
  bitset<15> bits(str, 0, n, 'F', 'T');

  bool is_consistent = true;
  for (int i = 0; i < n; i++)
    if (bits.test(i)) {
      // 生成したビット列と各正直者の証言が整合しているか確認
      for (int j = 0; j < A[i]; j++) {
        if ((bits.test(x[i][j] - 1)) ^ y[i][j]) is_consistent = false;
      }
    }

  if (is_consistent) ans = max(ans, (int)bits.count());
}

void dfs(string cur, int n, int depth) {
  if (depth == n) {
    update(cur, n);
    return;
  }
  dfs("T" + cur, n, depth + 1);
  dfs("F" + cur, n, depth + 1);
}

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

  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
    for (int j = 0; j < A[i]; ++j) {
      scanf("%d%d", &x[i][j], &y[i][j]);
    }
  }

  string start;
  dfs(start, N, 0);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import heapq as hq


def resolve():
    N,M = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(N)]
    AB.sort()
    q=[]
    sm =0
    counter =0
    for i in range(1,M+1):
        while counter <N and AB[counter][0]<=i:
            hq.heappush(q,-AB[counter][1])
            counter += 1

        if not q:
            continue
        sm -= hq.heappop(q)
    print(sm)


    

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 75480
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

ll cnt[26] = {};
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    ll n = S.length();
    ll ans = n * (n + 1) / 2 + 1;
    rep(i, n) cnt[S[i] - 'a']++;
    rep(i, 26) ans -= cnt[i] * (cnt[i] + 1) / 2;
    cout << ans << endl;

    return 0;
}


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

int main() {
  int n; 
  cin>>n;
  vector<int> p(n);
  rep(i,n) cin>>p.at(i);
  //前が全部大きければ増える
  int c=0;
  int m=n+1;
  rep(i,n){
    if(m>p.at(i)){ 
      c++;
      m=min(m,p.at(i));
    }
    else{   
      
    }
  }
  
  cout<<c<<endl;
}




 







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

public class Main {
	static final int mod = (int) 1e9 + 7;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int[] DX8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, DY8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	static final String nextLine = "\n";

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), m = fs.nextInt();
		int ans = n*(n-1)/2 + m*(m-1)/2;
		System.out.println(ans);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

/*
bool is_753(int n) {
    string n_str = to_string(n);
    int cnt7 = count(n_str.begin(), n_str.end(), '7');
    int cnt5 = count(n_str.begin(), n_str.end(), '5');
    int cnt3 = count(n_str.begin(), n_str.end(), '3');
    if (cnt7 > 1 && cnt5 > 1 && cnt3 > 1) {
        return true;
    }
    else {
        return false;
    }
}
*/

bool is_753(string s) {
    /*
    int cnt_7 = count(s.cbegin(), s.cend(), '7');
    int cnt_5 = count(s.cbegin(), s.cend(), '5');
    int cnt_3 = count(s.cbegin(), s.cend(), '3');
    */
    int cnt_7 = count(s.begin(), s.end(), '7');
    int cnt_5 = count(s.begin(), s.end(), '5');
    int cnt_3 = count(s.begin(), s.end(), '3');
    if (cnt_7 >= 1 && cnt_5 >= 1 && cnt_3 >= 1) {
        return true;
    }
    else {
        return false;
    }
}

int search(string s, int n) {
    if (stoi(s) > n) {
        return 0;
    }
    int self_753 = 0;
    if (is_753(s)) {
        self_753 = 1;
    }
    if (s.size()-1 < to_string(n).size()) {
        int add_3 = search(s + '3', n);
        int add_5 = search(s + '5', n);
        int add_7 = search(s + '7', n);
        return self_753 + add_3 + add_5 + add_7;
    }
    else {
        return self_753;
    }
}

int main() {
    int n, ans;
    cin >> n;
    ans = search("0", n);
    cout << ans << endl;
}


Measured memory_bytes: 256
//http://arc080.contest.atcoder.jp/tasks/arc080_a
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int v[n];
    vector<int> tp;
    for(int i=0;i<n;i++)
    {
        int co = 0;
        cin>>v[i];
        int t = v[i];
        while(t>0 && t%2==0)
        {
            t=t/2;
            ++co;
        }
        tp.push_back(co);
    }
    sort(tp.begin(),tp.end());
    int i = 0,j = n-1;
    while(i<j)
    {
        //cout<<v[i]<<' '<<v[j]<<'\n';
        if(tp[i] + tp[j] < 2)
        {
            cout<<"No\n";
            return 0;
        }
        ++i;
        --j;
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 1148
N,A,B = list(map(int,input().split()))
l=list(map(int,input().split()))

c=0
for i in range(len(l)-1):
	if (l[i+1]-l[i])*A<B:
		c+=(l[i+1]-l[i])*A
	else:
		c+=B

print(c)


Measured memory_bytes: 14224
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){
    
    string s, t, ans = "~";
    cin >> s >> t;
    for(ll i = 0; i + t.size() <= s.size(); i++){
        string tmp = s;
        ll flg = 1;
        rep(j, t.size()){
            if(tmp[i + j] == '?' || tmp[i + j] == t[j])tmp[i + j] = t[j];
            else flg = 0;
        }
        if(flg == 0)continue;
        rep(j, tmp.size())if(tmp[j] == '?')tmp[j] = 'a';
        chmin(ans, tmp);
    }
    if(ans == "~")cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;

    return 0;
}

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

n = int(input())

P = list(map(int, input().split()))

cnt = 0
for i in range(len(P)-2) : 
    if P[i] == min(P[i], P[i+1], P[i+2]) and P[i+2] == max(P[i], P[i+1], P[i+2]) : 
        cnt += 1
    elif P[i] == max(P[i], P[i+1], P[i+2]) and P[i+2] == min(P[i], P[i+1], P[i+2]) : 
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let n: usize = get_one();
    let ds = divisors(n);
    let mut ans = 0;
    for d in &ds[1..] {
        let mut m = n;
        while m % d == 0 {
            m = m / d;
        }
        if m % d == 1 { ans += 1; }
    }
    ans += divisors((n as i64 - 1) as usize)[1..].len();
    println!("{}", ans);
}

fn divisors(n: usize) -> Vec<usize> {
    let mut ds = Vec::new();
    for i in 1..n+1 {
        if i * i > n { break; }
        if n % i == 0 {
            ds.push(i);
            let z = n / i;
            if z != i { ds.push(z); }
        }
    }
    return ds;
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

#[allow(dead_code)]
fn vec_min(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MAX, std::cmp::min)
}

#[allow(dead_code)]
fn vec_max(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MIN, std::cmp::max)
}

#[allow(dead_code)]
fn vec_sum(xs: &Vec<i64>) -> i64 {
    xs.iter().fold(0, |acc, &x| acc+x)
}


Measured memory_bytes: 2144
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}

static const ULLONG UL_HUGE_DIVIDER = 1000000007LLU;
static const LLONG LL_HUGE_DIVIDER = 1000000007LL;

//static void ABC111D_RobotArms();
static void ABC112A_ProgrammingEducation();

#if 1
int main()
{
	//ABC111D_RobotArms();
	ABC112A_ProgrammingEducation();
	fflush(stdout);
	return 0;
}
#endif

static void ABC112A_ProgrammingEducation()
{
	int N;
	scanf(" %d", &N);

	if (N == 1) {
		printf("Hello World\n");
	}
	else {
		int A, B;
		scanf(" %d %d", &A, &B);
		printf("%d\n", A + B);
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int l1=s1.length();
    int l2=s2.length();
    if(l1>l2)
    {
        printf("GREATER\n");
    }
    else if(l1<l2)
    {
        printf("LESS\n");
    }
    else
    {
        int flag=0;
        for(int i=0;i<l1;i++)
        {
            if(s1[i]>s2[i])
            {
                flag=1;
                break;
            }
            else if(s1[i]<s2[i])
            {
                flag=-1;
                break;
            }
        }
        if(flag==1)
            printf("GREATER\n");
        else if(flag==-1)
            printf("LESS\n");
        else
            printf("EQUAL\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n[10],i,j,w;
	
	for(i=0;i<=9;i++){
		scanf("%d",&n[i]);
	}
	for(i=0;i<10;i++){
		for(j=i+1;j<10;j++){
			if(n[i]<n[j]){
				w=n[i];
				n[i]=n[j];
				n[j]=w;
			}
		}
	}
	for(i=0;i<=2;i++){
		printf("%d\n",n[i]);
	}
	return 0;
}

Measured memory_bytes: 1028
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    long S,L;
    long Ri = 1;
    if(A>B){
      L=A;
      S=B;
    }else{
      L=B;
      S=A;
    }
    long X = L%S;
    for(long i = 1;i<=S;i++){
      if((i*L)%S==0){
        Ri = i;
        i = S+1;
      }
    }
    System.out.println(Ri*L);
   }
}

Measured memory_bytes: 35688
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 3010;
const ll mod = 1e9 + 7;
ll dp[N][N];

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

    VI ma(n);
    REP(i,m){
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        ma[l] = max(ma[l], r);
    }

    VI r(n);
    REP(i,n){
        r[i] = max(i, ma[i]);;
        if (i > 0) r[i] = max(r[i], r[i-1]);;
    }

    VI ones(n+1);
    REP(i,n) ones[i+1] = ones[i] + (s[i] == '1');

    dp[0][0] = 1;
    REP(i,n){
        int one = ones[r[i]+1];
        if (i > 0) one -= ones[r[i-1]+1];
        // cout << one << endl;

        int d = r[i] - i + 1;
        REP(j,N-one+1){
            int next = j + one;
            if (next < d) dp[i+1][next] = (dp[i+1][next] + dp[i][j]) % mod;
            if (next > 0) dp[i+1][next-1] = (dp[i+1][next-1] + dp[i][j]) % mod;
        }
    }

    // REP(i,n+1){
    //     REP(j,6){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[n][0] << endl;

    return 0;
}






Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
typedef vector<P> VP;
struct UNKO{
    LL pos;
    char st;
    int id;
    bool operator<(const UNKO& r){
        if(pos==r.pos)return st<r.st;
        else return pos<r.pos;
    }
    UNKO(){
        pos=0;st='-';id=-1;
    }
    UNKO(LL p,char s,int i){
        pos=p;st=s;id=i;
    }
    void print(){
        string s;
        cout<<"("<<pos<<","<<st<<","<<id<<")";
    }
};
void input(VP& unko,vector<UNKO>& kuso,int N,int w,int d){
    kuso.reserve(2*N);
    for(int i = 0; i < N; i++){
        LL x,y;
        char dir;
        cin>>x>>y>>dir;
        LL Rx=(w-x),Ry=(d-y);
        LL S,T;
        switch(dir){
            case 'W':
                S=(x<=y)?(y-x):(d+w+d+Rx+y);
                T=(x<=Ry)?(y+x):(d+x-Ry);
                break;
            case 'E':
                S=(Rx<=Ry)?(d+w+Ry-Rx):(d+x+Ry);
                T=(Rx<=y)?(d+w+Ry+Rx):(d+w+d+Rx-y);
                break;
            case 'N':
                S=(x<=Ry)?(y+x):(d+x-Ry);
                T=(Rx<=Ry)?(d+w+Ry-Rx):(d+x+Ry);
                break;
            case 'S':
                S=(Rx<=y)?(d+w+Ry+Rx):(d+w+d+Rx-y);
                T=(x<=y)?(y-x):(d+w+d+Rx+y);
                break;
        }
        UNKO ss=UNKO(S,'S',i);
        UNKO tt=UNKO(T,'T',i);
//        ss.print();
//        tt.print();
        kuso.push_back(ss);
        kuso.push_back(tt);

    }
    sort(kuso.begin(),kuso.end());
    for(int i=0;i<2*N;i++){
        int ii=kuso[i].id;
        if(kuso[i].st=='S')unko[ii].first=i;
        else unko[ii].second=i;
    }
}
int INF =1001;
int greedy(int bg,vector<UNKO> unko,VP& idl,int N){
    //for(int i=0;i<2*N;i++)cout<<unko[i].st;cout<<endl;
    //for(int i=0;i<2*N;i++)cout<<unko[i].id;cout<<endl;
    N*=2;
    stack<int> s;
    int index=bg,res=1;
    for(int i=0;i<N;i++){
        if(unko[i].st=='S'){
            int lid=i;
            int rid=idl[unko[i].id].second;
            LL lp=unko[lid].pos;
            LL rp=unko[rid].pos;
            if(lp<rp){
                if(lp<=unko[bg].pos&&unko[bg].pos<=rp)
                    unko[lid].st=unko[rid].st='-';
            }
            else{
                if(lp<=unko[bg].pos||unko[bg].pos<=rp)
                    unko[lid].st=unko[rid].st='-';
            }
        }
    }
    index=(index+1)%N;
    while(index!=bg){
        if(unko[index].st=='S')s.push(index);
        if(unko[index].st=='T'){
    //        cout<<unko[index].id;
            res++;
            while(s.empty()==false){
                int id=s.top();s.pop();
                unko[id].st='-';
                id=idl[unko[id].id].second;
                unko[id].st='-';
            }
        }
        index=(index+1)%N;
    }
//    cout<<endl;
    if(s.empty()==false)return INF;
    else return res;
}


int main() {
    int N,W,D;
    cin>>N>>W>>D;
    vector<UNKO> line;
    VP index(N);
    input(index,line,N,W,D);
    int res=INF;
    for(int i=0;i<2*N;i++){
        if(line[i].st=='T')
        res=min(res,greedy(i,line,index,N));

    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
const int N=5005;
int n,k,sum;
int a[N],dp[N][N];
bool check(int x)
{
	memset(dp,0,sizeof(dp));
	if(x==1)
	{
		dp[2][0]=1;
		dp[2][a[2]]=1;
		for(int i=3;i<=n;i++)
		{
			for(int j=0;j<=k;j++)
			{
				dp[i][j]=dp[i-1][j];
				if(j>=a[i])
					dp[i][j]=dp[i-1][j]|dp[i-1][j-a[i]];	
			}
		}
	}
	else
	{
		dp[1][0]=1;
		dp[1][a[1]]=1;
		for(int i=2;i<=n;i++)
		{
			if(x==i)
			{
				for(int j=0;j<=k;j++)
					dp[i][j]=dp[i-1][j];
				continue;
			}
			for(int j=0;j<=k;j++)
			{
				dp[i][j]=dp[i-1][j];
				if(j>=a[i])
					dp[i][j]=dp[i-1][j]||dp[i-1][j-a[i]];	
			}
		}
	}
	/*
	printf("x:%d\n",x);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=k;j++)	
			printf("%d ",dp[i][j]);
		printf("\n");
	}
	*/
	for(int i=k-a[x];i<k;i++)
		if(dp[n][i])
			return true;
	return false;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);	
		a[i]=min(a[i],k);
	}
	if(n==1)
	{
		if(a[1]>=k)
			printf("0\n");
		else
			printf("1\n");
		return 0;
	}
	sort(a+1,a+n+1);
	int lb=0,ub=n+1;
	while(lb+1<ub)
	{
		int mid=(lb+ub)/2;
		if(check(mid))	
			ub=mid;
		else 
			lb=mid;
	}
	printf("%d\n",lb);
	return 0;
}


Measured memory_bytes: 98176
#include <iostream>

using namespace std;

int main()
{
    int A, B, C;

    cin >> A >> B >> C;

    if (A > B) {
        int  tmp = A;
        A = B;
        B = tmp;
    }
    if (C >= A && C <= B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
struct UnionFind {
    vector<int> data;

    UnionFind(int sz) { data.assign(sz, -1); }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y)
            return (false);
        if(data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if(data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }
    bool isSame(int x, int y) { return find(x) == find(y); }
    ll size(int k) { return (-data[find(k)]); }
};
int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }
    map<int, int> mp;
    for(int i = 0; i < n; i++) {
        mp[uf.find(i)]++;
    }
    cout << mp.size() - 1 << endl;
}


Measured memory_bytes: 7560
from typing import List

A_MAX = 300000


class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """

    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


def main():
    N, K = list(map(int, input().split()))
    A = [int(input()) for _ in range(N)]
    result = solve(A, K)
    print(result)


def solve(A: List[int], K: int) -> int:
    sg = SegTree([0] * (A_MAX + 1), lambda x, y: max(x, y), 0)
    for a in A:
        n = sg.query(max(0, a - K), min(A_MAX, a + K) + 1)
        sg.update(a, n + 1)
    return sg.query(0, A_MAX + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 108068
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    ld A, B, N;
    cin >> A >> B >> N;
    ll x = min(B - 1, N);
    ll ans = floor(A * x / B) - A * floor(x / B);
    cout << ans << endl;
}


Measured memory_bytes: 3732
#include <stdio.h>
 int main(void){
    long int a,b,n;
    scanf("%ld %ld %ld",&n,&a,&b);
    if ((b - a) % 2 == 0){
        printf("%ld",((b - a) / 2));
    }else{
        if (b - 1 <= n - a){
            printf("%ld",(((b - a) / 2) + 1) +  (a - 1));
        }else{
            printf("%ld",(((b - a) / 2) + 1) + (n - b));
        }
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, A[1 << 20], cnt = 0;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		if (A[i] == cnt + 1) cnt++;
	}
	if (cnt == 0) cout << "-1" << endl;
	else cout << N - cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
h, w, k = gets.split.map(&:to_i)
M = 10 ** 9 + 7

a = [0]
(w-1).times do
    a.map! {|e| e.even? ? [(e << 1) + 1, e << 1] : e << 1}.flatten!
end

dp = Array.new(w, 0)
dp[0] = 1

h.times do 
    x = Array.new(w, 0)

    a.each do |e|
        i = 0
        while i < w
            if e[i] == 1
                x[i] += dp[i+1]
                x[i+1] += dp[i]
                i += 1
            else
                x[i] += dp[i]
            end
            i += 1
        end
    end
    dp = x.map{|e| e % M}
end

p dp[k-1]

Measured memory_bytes: 1916
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
typedef pair<int,int> P;
int s2i(string str){
  int x=0;
  istringstream iss(str);
  iss >> x;
  return x;
}
int main(){
  int n;
  cin >> n;
 
  while(n!=0){
    int i,j,k;
    vector<P> v;
    P p;
    
    string str,buf;
    getline(cin,str);
    for(i=0;i<n;i++){
      getline(cin,str);
      //cout << str << endl;
      stringstream ss(str);
      ss >> buf;
      p.second=s2i(buf)*(-1);
      vector <int> b;
      while(ss>>buf){
        b.push_back(s2i(buf));
      }
      bool s=false;
      int c=0; 
      p.first=0;
      for(j=0;j<b.size();j++){
        if(c==9){
          p.first+=b[j];
        }else{
          if(s){
            p.first+=b[j];
            if(b[j-1]+b[j]==10){
              if(j<b.size()-1)
                p.first+=b[j+1];
            }
            c++;
            s=false;
          }else{
            p.first+=b[j];
            if(b[j]==10) {
              if(j<b.size()-1)
                p.first+=b[j+1];
              if(j<b.size()-2)
                p.first+=b[j+2];
              c++;
            }else{
              s=true;
            }
          }
        }
      }
      v.push_back(p);
    }
    sort(v.begin(),v.end(),greater<P>());
    for(i=0;i<v.size();i++){
      cout << -1*v[i].second << " " << v[i].first << endl;
    }
 
    cin >> n;
    }
  return 0;
}

Measured memory_bytes: 1248
mai= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
min2= ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
a= input()
if a in mai:
    print('a')
elif a in min2:
    print('A')

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,t = LI()
    a = [LI() for _ in range(n)]
    r = inf
    for c, d in a:
        if d > t:
            continue
        if r > c:
            r = c
    if r == inf:
        return 'TLE'

    return r


print(main())


Measured memory_bytes: 6732
n, m = map(int, input().split())

ab = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    ab[a-1].append(b)
    ab[b-1].append(a)

for i in ab[0]:
    if n in ab[i-1]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Measured memory_bytes: 41744
sx,sy,tx,ty=list(map(int,input().split()))
ans="U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(tx-sx+1)+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int x, y, i, ans=0, a, b;
  scanf("%d %d", &x, &y);
  for(i=0; i<x+1; i++){
    a = x - i;
    if(2*i+4*a==y) ans = 1;
  }
  if(ans) printf("Yes");
  else printf("No");
}

Measured memory_bytes: 1736
L,R = map(int,input().split())
ans = 3000
for i in range(L,R+1):
  if(i%2019==0):
    ans = 0
    break
if ans>0:
  for i in range(L,R+1):
    for j in range(i+1,R+1):
      k = (i*j)%2019
      ans = min(ans,k)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a=0,b=0,c=0,d=0;
    int n;
    cin>> n;
    for(int i=0;i<n;i++){
        string s;
        cin >>s;
        if(s=="AC") a++;
        if(s=="WA") b++;
        if(s=="TLE") c++;
        if(s=="RE") d++;
    }
    cout << "AC x " << a <<endl;
    cout << "WA x " << b <<endl;
    cout << "TLE x "<< c <<endl;
    cout << "RE x " << d <<endl;
}


Measured memory_bytes: 3632
using System;

namespace ITP1_2_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strAry = Console.ReadLine().Split(' ');
            int[] intAry = new int[3];
            intAry[0] = int.Parse(strAry[0]);
            intAry[1] = int.Parse(strAry[1]);
            intAry[2] = int.Parse(strAry[2]);
            Array.Sort(intAry);
            Console.WriteLine("{0} {1} {2}", intAry[0], intAry[1], intAry[2]);
        }
    }
}

Measured memory_bytes: 9268