akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
    int a,b,h;
    cin>>a>>b>>h;
    cout<<(a+b)*h/2<<"\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

class UnionFind():
    def __init__(self, n):
        self.parents = list(range(n))
        self.size = [1] * n

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.size[x] < self.size[y]:
                x,y = y,x
            self.parents[y] = x
            self.size[x] += self.size[y]

def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for i in range(M):
        a, b = map(lambda x: int(x)-1, input().split())
        uf.union(a,b)

    ans = [None] * N
    for i in range(N):
        ans[i] = uf.find(i)
    
    l = Counter(ans)
    print(max([*l.values()]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 105812
S_prime = input()
T = input()
C = []
for i in range(len(S_prime) - len(T) + 1):
  match = True
  for j in range(len(T)):
    if S_prime[i + j] == '?':
      continue
    elif S_prime[i + j] != T[j]:
      match = False
      break
  if match:
    C.append(i)
Ss = []
for c in C:
  S = ''
  for i, s in enumerate(S_prime):
    if i < c or i >= c + len(T):
      S += s if s != '?' else 'a'
    elif i == c:
      S += T
  Ss.append(S)
if Ss:
  print(sorted(Ss)[0])
else:
  print('UNRESTORABLE')
  

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

        int l1 = sc.nextInt();
        int l2 = sc.nextInt();
        int l3 = sc.nextInt();
        int s = 0;

        if (Math.pow(l1, 2) == Math.pow(l2, 2) + Math.pow(l3, 2))
            s = (l2 * l3) / 2;
        else if (Math.pow(l2, 2) == Math.pow(l1, 2) + Math.pow(l3, 2))
            s = (l1 * l3) / 2;
        else
            s = (l2 * l1) / 2;

        System.out.println(s);
    }
}












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

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

    vector< vector<long int> >a;
    a.reserve(100000);
    a.resize(n);
    for (int i = 0; i < n; i++) {
        a[i].reserve(100000);
        a[i].resize(m);
    }

    vector< vector<long int> >b;
    b.reserve(100000);
    b.resize(m);
    for (int i = 0; i < m; i++) {
        b[i].reserve(100000);
        b[i].resize(l);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }

    vector< vector<long int> >c;
    c.reserve(100000);
    c.resize(n);
    for (int i = 0; i < n; i++) {
        c[i].reserve(100000);
        c[i].resize(l);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            c[i][j] = 0;
            for (int k = 0; k < m; k++) {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << c[i][0];
        for (int j = 1; j < l; j++) {
            cout << " " << c[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4136
m=gets.to_i
bb=[]
ff=[]
rr=[]
vv=[]
1.upto(m){|n|
  b,f,r,v=gets.split(" ").map{|v|v=v.to_i}
  bb.push(b)
  ff.push(f)
  rr.push(r)
  vv.push(v)
}
b1,b2,b3=[]
BOR=[]
1.upto(20){|a|
  BOR.push("#")
}
1.upto(4){|n|
  1.upto(3){|s|
    de=[]
    1.upto(10){|b|
      de.push(0.to_i)
    }
    0.upto(m-1){|t|
      de[rr[t]-1]+=vv[t] if bb[t]==n&&ff[t]==s
    }
    print (" ")
    puts de.join(" ")
  }
puts BOR.join if n<4
}  

Measured memory_bytes: 6112
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;


signed main() {
	ll N,ans=0;
	cin >> N;
	vector<ll> A(N),SUMa(N,0);
	REP(i, N) {
		cin >> A[i];
	}
	for (int i = N - 2; i >= 0; i--) {
		SUMa[i] = (SUMa[i + 1] + A[i + 1])%MOD;
	}
	for (int i = 0; i < N; i++) {
		ans = (ans + A[i] * SUMa[i] % MOD) % MOD;
	}

	answer(ans);
	system("pause");
	return 0;
}

Measured memory_bytes: 6420
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())

    f(A, B, C, X)


def f(A, B, C, X):
    ans = 0
    for a in range(A + 1):
        for b in range(B + 1):
            for c in range(C + 1):
                s = a * 500 + b * 100 + c * 50
                if s == X:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_X=2*10e5+5;
ll x,i=1,j=1;
bool sieve[MAX_X+1];

void Eratosten(){
  memset(sieve,1,MAX_X);
  sieve[0]=0;
  sieve[1]=0;
  for(int i=0;i*i<=MAX_X;++i){
    if(sieve[i]){
        for(int p=i*i;p<=MAX_X;p+=i){
            sieve[p]=0;
        }
    }
  }
}

int main(){
  cin >> x;
  Eratosten();
  if(sieve[x]){cout << x;return 0;}
  while(!sieve[x+i]){
    ++i;
    //cout << x+i << " " << sieve[x+i] << endl;
  }
  cout << x+i;
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 2e5 + 5;
int n, m;
long long k, prea[N], preb[N];
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++){
        long long x;
        cin >> x;
        prea[i] = prea[i - 1] + x;
    }
    for(int i = 1; i <= m; i++){
        long long x;
        cin >> x;
        preb[i] = preb[i - 1] + x;
    }
 
    int ans = 0;
    for(int i = 1; i <= n; i++){
        long long sel = k - prea[i];
        if(sel < 0){
            break;
        }
        int l = 1, r = m, a = 0;
        while(l <= r){
            int mid = l + (r - l) / 2;
            if(sel >= preb[mid]){
                a = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        ans = max(ans, a + i);
    }
    for(int i = 1; i <= m; i++){
        long long sel = k - preb[i];
        if(sel < 0){
            break;
        }
        int l = 1, r = n, a = 0;
        while(l <= r){
            int mid = l + (r - l) / 2;
            if(sel >= prea[mid]){
                a = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        ans = max(ans, a + i);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 6764
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a[10]={1800,1600,1400,1200,1000,800,600,400};

int main(void){
	int x;
	scanf("%d",&x);
	for(int i=0;i<8;i++){
		if(x>=a[i]){
			printf("%d\n",i+1);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3824
M, K = map(int, input().split())

if K >= 2 ** M:
    print(-1)
elif K == 0:
    ans = []
    x = range(0, 2 ** M)
    y = range(0, 2 ** M)
    for xx, yy in zip(x, y):
        ans.append(xx)
        ans.append(yy)
    print(*ans)
else:
    if M == 1 and K == 1:
        print(-1)
        exit()
    t = 0
    for i in range(1, 2 ** M):
        if i == K: continue
        t ^= i
    if t == K:
        x = [i for i in range(0, 2 ** M) if i != K]
        ans = [K] + x + [K] + list(reversed(x))
        print(*ans)
    else:
        print(-1)


Measured memory_bytes: 66928
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int x[n];
    x[0]=0,x[1]=0;
    
    for(int i=0;i<n;i++){
        if(i%2==0) x[0]+=a[i];
        else x[0]-=a[i];
    }
    for(int i=0;i<n;i++){
        if(i%2!=0||i==0) x[1]+=a[i];
        else x[1]-=a[i];
    }
    for(int i=2;i<n;i++){
        if(i%2==0){
            x[i]=x[i-2]-2*a[i-2]+2*a[i-1];
        }
        else{
            x[i]=x[i-2]-2*a[i-2]+2*a[i-1];
        }
    }
    for(int i=0;i<n;i++){
        cout<<x[i]<<" ";
    }
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

int main() {
	long long A; std::cin >> A;
	std::string b; std::cin >> b;
	int B = (b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] - '0');
	std::cout << A * B / 100 << std::endl;

	return 0;
}

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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DLOG(...)
#endif

void debug(auto f) {
#if DEBUG
  f();
#endif
}

ll nN, aA, bB;
vector<ll> hH;

ll binsch(ll a, ll b, auto f) {
  while (a+1 < b) {
    ll m = (a + b) / 2;
    if (f(m))  b = m;
    else       a = m;
  }
  return b;
}

bool ftry(ll k) {
  ll sum = 0;
  for (ll i = 0; i < nN; i++) {
    ll m = hH.at(i) - k * bB;
    if (m <= 0)  continue;
    sum += (m + aA - bB - 1) / (aA - bB);
  }
  return sum <= k;
}

int main() {
  cin >> nN >> aA >> bB;
  hH.resize(nN);
  for (ll i = 0; i < nN; i++)  cin >> hH.at(i);
  ll ans = binsch(0, int(1e9), ftry);
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define f first
#define s second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    //ld a,b; cin >> a >> b;
    ll a; ld b; cin >> a >> b;
    cout<<(ll)(a*b)<<endl;
}

Measured memory_bytes: 3740
#include<stdio.h>

int main(){
    long long i;
    long long a, b, v, w, t;
    long long s;

    scanf("%lld%lld%lld%lld%lld", &a, &v, &b, &w, &t);

    s = (a > b) ? (a - b):(b - a);

    for(i = 0;i < t;i++){
        s = s + w - v;
        if(s <= 0){
            puts("YES");
            return 0;
        }
    }

    puts("NO");

    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int[] c = new int[n - 1];
		int[] s = new int[n - 1];
		int[] f = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 1; i++) {
			int time = 0;
			for (int j = i; j < n - 1; j++) {
				if (time < s[j]) {
					time = s[j];
				} else {
					// int q = (time - s[j]) / f[j];
					int r = (time - s[j]) % f[j];
					if (r != 0) {
						time += f[j] - r;
					}
				}
				time += c[j];
			}
			System.out.println(time);
		}

		System.out.println(0);
	}

}


Measured memory_bytes: 26584
#include <bits/stdc++.h>
using namespace std;
#define INF 9999999999;

long long n,W;
long long w[110];
long long v[110];
long long dp[110][110000];

int main() {
    cin >> n >> W;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i] >> v[i];
    }

    for (int i = 1; i < 110000; ++i) {
        dp[0][i] = INF;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 110000; ++j) {
            dp[i][j] = dp[i-1][j];
            if (j-v[i] < 0) continue;
            dp[i][j] = min(dp[i][j],
                           dp[i-1][j-v[i]] + w[i]);
        }
    }
    long long ans = 0;
    for (long long i = 0; i < 110000; ++i) {
        if (dp[n][i] <= W) {
            ans = max(ans, i);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 90416
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集 

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int a, b, c;
    cin >> a >> b >> c;
    if(a+b+c>=22)cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}


Measured memory_bytes: 3628
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                             //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

inline ll max(ll a, ll b)
{
  if(a>b) re a;
  else re b;
}

inline ll min(ll a, ll b)
{
  if(a>b) re b;
  else re a;
}

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

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    cin>>n;
    int a[n];
    take(a,n);
    map<int,int> s;
    m=0;
    forup(i,n)
    {
      s[a[i]]++;
    }
    for(auto x:s)
    {
      m+=((ll)(x.S)*(x.S-1))/2;
    }
    forup(i,n)
    {
      if(s[a[i]]>1)
      {
        ll z=s[a[i]];
        cout<<m-(z*(z-1))/2+((z-1)*(z-2))/2<<el;
      }
      else cout<<m<<el;

    }







  }


  return 0;
}


Measured memory_bytes: 8320
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#define MAX 1000000000000000000LL
long long inf=1000000007;
using namespace std;

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}
                  
int main(){
    int H,A[100001];
    cin>>H;
    for(int i=1; i<=H; i++){
        cin>>A[i];
    }
    for(int i=1; i<=H; i++){
        cout<<"node "<<i<<": key = "<<A[i]<<", ";
        if(parent(i)>=1)cout<<"parent key = "<<A[parent(i)]<<", ";
        if(left(i)<=H)cout<<"left key = "<<A[left(i)]<<", ";
        if(right(i)<=H)cout<<"right key = "<<A[right(i)]<<", ";
        cout<<endl;
    }
    return 0;

}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sgn(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int w[1100], s[1100], v[1100];
int idx[1100];
int dp[1100][22000];
signed main() {
    cin >> N;
    rep(i, N) {
        cin >> w[i] >> s[i] >> v[i];
        idx[i] = i;
    }
    sort(idx, idx + N, [](int l, int r) { return w[l] + s[l] < w[r] + s[r]; });
    rep(i, N) {
        int ii = idx[i];
        rep(j, 22000) {
            chmax(dp[i + 1][j], dp[i][j]);
            if (j <= s[ii] && j + w[ii] < 22000) {
                chmax(dp[i + 1][j + w[ii]], dp[i][j] + v[ii]);
            }
        }
    }
    cout << *max_element(dp[N], dp[N] + 22000) << endl;
}

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

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

int main()
{
  int a, b;
  cin >> a >> b;
  cout << gcd(a, b) << endl;
  return EXIT_SUCCESS;
}




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

using namespace std;

int main() {

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

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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,f,n) for(int i=f;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;

signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    map<char, map<char, int> > mp;

    for(int i = 1; i <= n; ++i){
        string s = to_string(i);
        mp[s.front()][s.back()]++;
    }

    int res = 0;
    for(int i = 1; i <= n; ++i){
        string s = to_string(i);
        res += mp[s.back()][s.front()];
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
mod = 10**9+7

dp = np.zeros([N+1,4,4,4],dtype=int)
dp[0,-1,-1,-1] = 1

for i in range(N):
  for c1 in range(4):
    for c2 in range(4):
      for c3 in range(4):
        if not dp[i,c1,c2,c3]:continue
        for a in range(4):
          if c1 == 0 and c3 == 1 and a == 2:continue
          if c1 == 0 and c2 == 1 and a == 2:continue
          if c2 == 0 and c3 == 1 and a == 2:continue
          if c2 == 0 and c3 == 2 and a == 1:continue
          if c2 == 1 and c3 == 0 and a == 2:continue
          dp[i+1,c2,c3,a] += dp[i,c1,c2,c3]
          dp[i+1,c2,c3,a] %= mod

print(dp[-1].sum()%mod)

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

std::vector<int> f (std::string const & s) {
    std::vector<int> ret (26, 0);
    for (auto c : s) {
        int index = static_cast<int> (c) - static_cast<int> ('a');
        ret[index] += 1;
    }

    return ret;
}

int main() {
    int n;
    std::cin >> n;

    std::vector<std::vector<int>> mem (n);
    std::vector<int> result (26);

    for (int i = 0; i < mem.size(); ++i) {
        std::string s;
        std::cin >> s;
        mem[i] = f (s);
    }

    for (int j = 0; j < result.size(); ++j) {
        int min = 50;
        for (int i = 0; i < mem.size(); ++i) {
            min = std::min (mem[i][j], min);
        }
        result[j] = min;
    }

    int length = 0;
    for (auto a : result)
        length += a;
    
    std::string ret (length, 'a');
    int index = 0;
    for (int i = 0; i < result.size(); ++i) {
        char c = static_cast<char>(i + 'a');
        for (int j = 0; j < result[i]; ++j) {
            ret[index] = c;
            ++index;
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    int cnt = 0;
    rep(i,3){
        if(s[i] == 'S'){
            cnt = 0;
        }
        else{
            ++cnt;
            ans = cnt;
        }
        // if(i == 0) continue;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	ll arr[n];
	int negative = 0;
	for(int i = 0; i < n;i++){
		cin >> arr[i];
		if(arr[i] < 0)
			negative++;
	}
	ll ans = 1;
	sort(arr,arr+n);
	if(n == k){
		for(int i = 0; i < n;i++){
			ans = ((ans*arr[i])%MOD + MOD)%MOD;
		}
		cout << ans << "\n";
	}
	else if(negative == n){
		if(k&1){
			for(int i = n-1; i > n-k-1;i--){
				ans = ((ans * arr[i])%MOD + MOD)%MOD;
			}
		}
		else{
			for(int i = 0; i < k;i++){
				ans = ((ans * arr[i])%MOD + MOD)%MOD;
			}
		}
		cout << ans << "\n";
	}
	else{
		int left = 0;
		int right = n-1;
		if(k&1){
			k--;
			ans = ((ans * arr[right])%MOD + MOD) %MOD;
			right--;
		}
		while(k){
			if(k > 1){
				ll temp = 1;
				if(arr[left] * arr[left+1] > arr[right]*arr[right-1]){
				    temp = ((arr[left] * arr[left+1])%MOD + MOD)%MOD;
					left += 2;
				}
				else{
					temp = ((arr[right] * arr[right-1])%MOD + MOD)%MOD;
					right -= 2;
				}
				ans = ((ans * temp)%MOD + MOD)%MOD;
				k -= 2;
			}
			else{
				ans = ((ans * arr[right--])%MOD + MOD)%MOD;
				k--;
			}
		}
		cout << ans << "\n";
	}
}

Measured memory_bytes: 5200
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;
int n,k;
int d[10];
bool check()
{
	int y=n;
	while(y/10>0)
	{
		int x=y%10;
		rep(i,0,k)
		{
			if(x==d[i])
			return 0;
		}
		y/=10;
	}
	rep(i,0,k)
	{
		if(y==d[i])
		return 0;
	}
	return 1;
}
int main() {
    ios::sync_with_stdio(false);
	cin>>n>>k;
	rep(i,0,k)
	cin>>d[i];
	while(1)
	{
		if(check())
		{
			cout<<n;
			return 0;
		}
		n++;
	}
}


Measured memory_bytes: 256
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans,n,k;
map<ll,ll> mp;
bool flag;
void solve()
{
    cin>>n>>k;vector<ll>ar(n);
    for(int i=0;i<n;i++)
        cin>>ar[i];
    sort(ar.begin(),ar.end());
    for(int i=0;i<n-k;i++)
        ans+=ar[i];
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    char a; cin>>a;
    if(isupper(a)){
        cout<<"A"<<endl;
    }else{
        cout<<"a"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {

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


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

typedef long long ll;
const int maxn = 1e5 + 10;
ll a[maxn], dp[maxn];
int n, rt, sz[maxn], dep[maxn], tid[maxn];

map <ll, int> mp;
vector <int> e[maxn];

void DFS(int u) {
  for (int v : e[u]) {
    dep[v] = dep[u] + 1;
    dp[rt] += dep[v];
    DFS(v);
  }
}

void dfs(int u) {
  for (int v : e[u]) {
    dp[v] = dp[u] + n - 2 * sz[v], dfs(v);
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    tid[i] = i, sz[i] = 1;
    scanf("%lld", a + i), mp[a[i]] = i;
  }
  sort(tid + 1, tid + n + 1, [] (int x, int y) {
    return a[x] > a[y];
  });
  rt = tid[n];
  for (int i = 1; i < n; i++) {
    int u = tid[i];
    ll val = a[u] + 2 * sz[u] - n;
    map <ll, int> :: iterator it = mp.find(val);
    if (it == mp.end()) {
      return puts("-1"), 0;
    }
    int v = it -> second;
    sz[v] += sz[u], e[v].push_back(u);
  }
  DFS(rt), dfs(rt);
  for (int i = 1; i <= n; i++) {
    if (a[i] != dp[i]) {
      return puts("-1"), 0;
    }
  }
  for (int u = 1; u <= n; u++) {
    for (int v : e[u]) {
      printf("%d %d\n", u, v);
    }
  }
  return 0;
}

Measured memory_bytes: 17408
def main():

    n = int(input())
    arr = list(map(int,input().split()))

    for i in range(1, len(arr)):
        j = i - 1
        v = arr[i]
        print(' '.join(map(str,arr)))
        while j >= 0 and arr[j] > v:
            arr[j+1] = arr[j]
            j -= 1
        arr[j+1] = v 
    print(' '.join(map(str,arr)))


main()

Measured memory_bytes: 7792
#N = int(input())
#a = [int(i) for i in input().split()]
#s = [[int(j) for j in input().split()] for i in range(N)]


N,T = [int(i) for i in input().split()]
CT = [[int(j) for j in input().split()] for i in range(N)]
res = 10**10
for c,t in CT:
    if t<=T:
        res=min(res,c)
if res==10**10:
    print("TLE")
else:
    print(res)


Measured memory_bytes: 2940
use proconio::input;

fn main() {
    input! {
        n: usize,
        s: String,
    }
    let mut cnt: [usize; 3] = [0; 3];
    let cs: Vec<_> = s.chars().collect();
    for &c in &cs {
        match c {
            'R' => cnt[0] += 1,
            'G' => cnt[1] += 1,
            'B' => cnt[2] += 1,
            _ => (),
        }
    }

    let mut cnt2 = 0;
    for l in 1..n {
        for i in 0..n {
            let j = i + l;
            let k = j + l;
            if k >= n {
                continue;
            }
            if cs[i] != cs[j] && cs[j] != cs[k] && cs[k] != cs[i] {
                cnt2 += 1;
            }
        }
    }
    println!("{}", cnt[0] * cnt[1] * cnt[2] - cnt2);
}


Measured memory_bytes: 2152
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int x = in.nextInt();
        int t = 0;
        final Map<Long, Integer> map = new HashMap<>();
        while (Math.pow(t, 5) < 1e18) {
            map.put((long) Math.pow(t, 5), t);
            map.put((long) Math.pow(-t, 5), -t);
            t++;
        }
        for (Map.Entry<Long, Integer> entry : map.entrySet()) {
            if (map.containsKey(x + entry.getKey())) {
                System.out.println(map.get(x + entry.getKey()) + " " + entry.getValue());
                return;
            }
        }
    }
}


Measured memory_bytes: 41320
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",max(max(a+b,a-b),a*b));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
#define int ll
const int inf=1039074182;
using namespace std;
int n,m,v,p;
int a[100005];
int sum[100005];
map <int,int> num;

signed main()
{
//	freopen("input.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin>>n>>m>>v>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		num[a[i]]++;
	}
	sort(a,a+n);
	reverse(a,a+n);
	sum[0]=a[0];
	for(int i=1;i<n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	int res=0;
	for(int i=0;i<n;i++)
	{
		if(i && a[i]==a[i-1]) continue;
		if(a[i]+m<a[p-1]) break;
		if(i<p)
		{
			res+=num[a[i]];
			continue;
		}
		int vote=v-(n-i);
		vote-=p-1;
//		cout<<i<<' '<<vote<<' '<<(a[i]+m)<<' '<<((i-1)-(p-2))<<' '<<sum[i-1]-sum[p-2]<<' '<<(a[i]+m)*((i-1)-(p-2))-(sum[i-1]-(p==1?0:sum[p-2]))<<endl;
		if(vote*m<=(a[i]+m)*((i-1)-(p-2))-(sum[i-1]-(p==1?0:sum[p-2]))) res+=num[a[i]];
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;++i)ans+=(n/i)*(2*i+i*(n/i-1))>>1;
	cout<<ans;
}

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


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10

int main() {
	int N, L;
	vector<string> vs;
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		string iptstr;
		cin >> iptstr;
		vs.push_back(iptstr);

	}
	sort(vs.begin(), vs.end());
	string ans;
	for (int i = 0; i < N; i++) {
		ans += vs[i];
	}
	cout << ans << endl;












	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
int main() {
	int x, y;
	char c1,c2;
	cin >> x;
	while (true) {
		cin >> c1;
		if (c1 == '=') {
			cout << x << endl;
			return 0;
		}
		else cin >> y;
		switch (c1) {
		case '+':x += y; break;
		case '-':x -= y; break;
		case '*':x *= y; break;
		case '/':x /= y; break;
		}
	}
}

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

int main(){
  string S;
  cin >> S;
  int count = 0;
  
  for (int i = 0; i < 4; i++){
    for (int j = 0; j < 4; j++){
      if (S.at(i) == S.at(j)){
        count++;
      }
    }
  }
  
  if (count == 8){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod -1000000007
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int a,b;
    cin>>a>>b;
    a *= b;
    for (int i=1;i<4;i++) {
        if ((a*i)%2) {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int top=-1,Stack[100];
void push(int x){
	Stack[++top] = x;
}
int pop(){
	return Stack[top--];
}
int main()
{	
	string str;
	int x,y;
	while(cin>>str){
		if(str!="+" && str!="-" && str!="*")
			push(atoi(str.c_str()));
		else{
			x = pop();
			y = pop();
			if(str== "+") push(x+y);
			if(str== "-") push(y-x);
			if(str== "*") push(x*y);
		}
	}
	cout<<pop()<<endl;
	return 0;
}
	




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

int main(){
  int a,b;
  cin >> a >> b;
  cout << a-b+1 << endl;
  return 0;
}


Measured memory_bytes: 256
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final int A = 26;
	void update(int[] ft, int i, int n, int x) {
		while (i < n) {
			ft[i] += x;
			i |= i + 1;
		}
	}
	int query(int[] ft, int i) {
		int x = 0;
		while (i >= 0) {
			x += ft[i];
			i &= i + 1; i--;
		}
		return x;
	}
	void main() {
		int n = sc.nextInt();
		byte[] cc = sc.next().getBytes();
		int[][] ft = new int[A][n];
		for (int i = 0; i < n; i++) {
			int a = cc[i] -= 'a';
			update(ft[a], i, n, 1);
		}
		int q = sc.nextInt();
		while (q-- > 0) {
			int t = sc.nextInt();
			if (t == 1) {
				int i = sc.nextInt() - 1;
				int a = cc[i];
				byte b = (byte) (sc.next().charAt(0) - 'a');
				if (a != b) {
					cc[i] = b;
					update(ft[a], i, n, -1);
					update(ft[b], i, n, 1);
				}
			} else {
				int l = sc.nextInt() - 1;
				int r = sc.nextInt() - 1;
				int cnt = 0;
				for (int a = 0; a < A; a++)
					if (query(ft[a], r) - query(ft[a], l - 1) > 0)
						cnt++;
				println(cnt);
			}
		}
	}
}


Measured memory_bytes: 127476
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<ll> a(n); rep(i, n)cin >> a[i];
	vector<vector<pair<ll,ll>>> dp(n + 1, vector<pair<ll,ll>>(2));
	dp[0][0] = make_pair(0, 1000);
	rep(i, n)
	{
		dp[i + 1][0] = dp[i][0];
		if (dp[i + 1][0].second < dp[i][1].first*a[i] + dp[i][1].second)
		{
			dp[i + 1][0] = make_pair(0, dp[i][1].first*a[i] + dp[i][1].second);
		}
		dp[i + 1][1] = dp[i][1];
		if (dp[i + 1][1].first == dp[i][0].second / a[i])
		{
			if (dp[i + 1][1].second < dp[i][0].second%a[i])
			{
				dp[i + 1][1] = make_pair(dp[i][0].second / a[i], dp[i][0].second % a[i]);
			}
		}
		else if (dp[i + 1][1].first < dp[i][0].second / a[i])
		{
			dp[i + 1][1] = make_pair(dp[i][0].second / a[i], dp[i][0].second % a[i]);
		}
	}
	cout << dp[n][0].second << endl;
}

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

int n, m, l, r, d1;
vector<pair<int,int>> e[100004];
bool visited[100004];
long long d[100004];
bool ok;
void dfs(int here){
	visited[here] = true;
	for(auto i : e[here]){
		int there = i.first;
		int dist = i.second;
		if(!visited[there]){	
			d[there] = d[here] + dist;
			dfs(there);
		}
		else
			if(d[here]+dist != d[there])	
				ok = false;
		}
	return;
}

int main() {
	cin>>n>>m;
	while(m--){
		cin>>l>>r>>d1;
		e[l].push_back({r,d1});
		e[r].push_back({l,-d1});
	}
	ok = true;
	memset(visited,false,sizeof(visited));
	memset(d,0,sizeof(d));
	for(int i = 1; i<=n;i++){
		if(visited[i])	continue;
		d[i] = 0;
		dfs(i);
	}
	cout<<(ok? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 11520
n, y = map(int, input().split())
y //= 1000

for y10 in range(y//10 + 1):
    if y10 > n:
        continue
    rest = y - 10 * y10
    tmp = rest - n + y10
    if tmp % 4 == 0:
        y5 = tmp // 4
        y1 = n - y10 -y5
        if y1 < 0 or y5 < 0:
            continue
        print(y10, y5, y1)
        exit()
print(-1, -1, -1)

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

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

	long long oneIndex = -1;
	
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == '1') {
			oneIndex++;
		}
		else {
			break;
		}
	}

	char ans;

	if (k - 1 <= oneIndex) {
		ans = '1';
	}
	else {
		ans = s.at(oneIndex + 1);
	}

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

Measured memory_bytes: 256
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << "\n";
#else
#define DEBUG(message)
#endif

const int MOD = 1000 * 1000 * 1000 + 7;

struct Solver {
  void solve() {
    int n, m;
    cin >> n >> m;

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

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

    int x = 0;
    for (int i = 0; i + 1 < n; i++) {
      x += 1LL * (a[i + 1] - a[i]) * (i + 1) % MOD * (n - i - 1) % MOD;
      if (x >= MOD) {
        x -= MOD;
      }
    }

    int y = 0;
    for (int i = 0; i + 1 < m; i++) {
      y += 1LL * (b[i + 1] - b[i]) * (i + 1) % MOD * (m - i - 1) % MOD;
      if (y >= MOD) {
        y -= MOD;
      }
    }

    cout << (1LL * x * y) % MOD << "\n";
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
//  cin >> t;
  for (int i = 1; i <= t; i++) {
    Solver().solve();
  }
  return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import copy

def main():
    N,M=MI()
    inf=10**10
    adj=[[inf]*N for _ in range(N)]
    for i in range(N):
        adj[i][i]=0
        
    
    for i in range(M):
        a,b,c=MI()
        a-=1
        b-=1
        adj[a][b]=c
        adj[b][a]=c
        
    d=copy.deepcopy(adj)
    
    def warshall_floyd(d):
            #d[i][j]: iからjへの最短距離
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j] = min(d[i][j],d[i][k] + d[k][j])
        return d
    
    ans=0
    d=warshall_floyd(d)
    
    for i in range(N):
        for j in range(N):
            if d[i][j]!=adj[i][j] and adj[i][j]!=inf:
                ans+=1
                
    print(ans//2)
    
        
    
    
        

main()


Measured memory_bytes: 43356