akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, lint> ppl;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;

const lint mod = 1e9 + 7;

typedef  struct ConvexHullTrick{
    deque<pll> dq;

    ConvexHullTrick()= default;

    void addline(lint a3, lint b3){
        while(dq.size() >= 2){
            int sz = dq.size();
            lint a1 = dq[sz-2].fi, b1 = dq[sz-2].se;
            lint a2 = dq[sz-1].fi, b2 = dq[sz-1].se;
            if(a1*b3-a3*b1 <= (b3-b1)*a2 + (a1-a3)*b2) dq.pop_back();
            else break;
        }
        dq.emplace_back(a3, b3);
    }

    lint getmin(lint x){
        while(dq.size() >= 2){
            lint a1 = dq[0].fi, b1 = dq[0].se;
            lint a2 = dq[1].fi, b2 = dq[1].se;
            if(a1*x + b1 >= a2*x + b2) dq.pop_front();
            else break;
        }
        return dq[0].fi * x + dq[0].se;
    }
}CHT;

int main(){
    int n;
    lint c;
    scanf("%d%lld", &n, &c);
    lint h[n];
    rep(i, n) scanf("%lld", &h[i]);

    lint dp[n];
    dp[0] = 0;
    CHT cht;
    cht.addline(-2*h[0], h[0]*h[0] + c);

    For(i, 1, n){
        dp[i] = cht.getmin(h[i]) + h[i]*h[i];
        cht.addline(-2*h[i], h[i]*h[i] + c + dp[i]);
    }

    printf("%lld\n", dp[n-1]);
}


Measured memory_bytes: 5504
a,b = map(int,input().split())

def f(x):
    if x < 0:
        return 0
    if x%4 == 0:
        return x
    if x%4 == 1:
        return x^(x-1)
    if x%4 == 2:
        return x^(x-1)^(x-2)
    return 0

print(f(b)^f(a-1))

Measured memory_bytes: 38480
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC

int main(){
    string s;cin>>s;
    int n=s.size(),total=0,x=1;
    vector<int> vec(2019);vec[0]=1;
    lint ans=0;
    for(int i=n-1;i>=0;i--){
        total+=(s[i]-'0')*x;
        total%=2019;
        ans+=vec[total];
        vec[total]++;
        x=x*10%2019;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3724
//stringray

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

/*#ifndef __LOCAL__ 
#pragma comment(linker,"/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif*/ 

using namespace std;
using namespace __gnu_pbds;

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

typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<set<int>> vsi;

#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define F first
#define S second
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0)


const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T>
istream& operator >> (istream& is,vector<T>& vec){
  for(T &x:vec)is>>x;
  //for(int i=0;i<vec.size();++i)is>>x[i];
  return is;
}

template<typename T>
ostream& operator << (ostream& os,vector<T>& vec){
  for(int i=0;i<vec.size();++i){
    os<<vec[i]<<(i+1==vec.size()?"":" ");
  }
  return os;
}

ll mpow(ll a, ll b){
  ll ret=1;
  while(b>0){
    if(b&1)ret=(ret*a)%mod;
    (a=a*a)%=mod;
    b>>=1LL;
  }
  return ret;
}

//#define int int64_t
//int a[N+2];
void solve(){
  int n,a,b;cin>>n>>a>>b;
  cout<<min(n*a,b)<<endl;
}
int32_t  main(){
  IOS;
  solve();
  return 0;
}



Measured memory_bytes: 256
abc = sorted(list(map(int, input().split())))

a0 = abc[2] - abc[0]
a1 = abc[2] - abc[1]

if (a0 + a1)%2 == 0:
  print((a0 + a1)//2)
else:
  print((a0 + a1 + 1)//2 + 1)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#define FOR(i,e) for(int i=0;i<(int)(e);i++)
using namespace std;

int main(){
  double pb[100][5001];
  int x,y,z;
  int v[100],e[100],a[100];

  while(cin >> x >> y >> z && (x||y||z)){

    FOR(i,x)cin >> v[i];
    FOR(i,y+1)e[i] = a[i] = 0;
    FOR(i,z){
      int n,m,l;
      cin >> n >> m >> l;
      e[n] = m; a[n] = l;
    }

    FOR(i,y+1)FOR(j,5001)pb[i][j] = 0.0;
    pb[0][0] = 1.0;

    FOR(i,y)FOR(j,5001){
      FOR(k,x){
	if(pb[i][j] == 0.0)continue;
	int next = min(y,i+v[k]),value = j;
	if(e[next] == 1)next = min(y,next+a[next]);
	else if(e[next] == 2)value = j + a[next];
	else if(e[next] == 3)value = max(0,j-a[next]);
	pb[next][value] += pb[i][j]/x;
      }
    }

    double ans = 0.0;
    FOR(i,5001)ans += pb[y][i] * i;
    cout << (int)(ans) << endl;
  }
}

Measured memory_bytes: 2864
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(N)]

def check(i):
    ANS=C
    for j in range(M):
        ANS+=A[i][j]*B[j]

    #print(ANS)

    if ANS>0:
        return 1
    else:
        return 0
        
    return 1

SUM=0
for i in range(N):
    SUM+=check(i)

print(SUM)

Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    killed = 0
    remain = A[0]
    for i, b in enumerate(B):
        target = remain + A[i + 1]
        power = B[i]
        killed += min(target, power)
        remain = max(min(target - power, A[i + 1]), 0)
    print(killed)


if __name__ == "__main__":
    main()


Measured memory_bytes: 82020
from math import ceil #切り上げ
import numpy as np
 
def inp(): return int(input()) #一個だけ読み取り
def inpm(): return map(int,input().split()) #mapオブジェクトで呼び出し
def inpl(): return list(map(int, input().split())) #数字リストをintで
def inpls(): return list(input().split()) #リストをstrで

K = inp()
A, B = inpl()

if K == A:
  print("OK")
else:
  S = A//K
  if S*K == A:
    print("OK")
  elif (S+1)*K <= B:
    print("OK")
  else:
    print("NG")

Measured memory_bytes: 27148
nums_count = int(input())
nums = list(map(int, input().split()))
swap_count = 0

for i in range(nums_count):
    for j in range(nums_count-1, i, -1):
        if nums[j-1] > nums[j]:
            nums[j-1], nums[j] = nums[j], nums[j-1]
            swap_count += 1

for num in nums[:-1]:
    print(num, end=' ')
print(nums[-1])

print(swap_count)


Measured memory_bytes: 5604
let () =
  let n = read_int () in
  let (tbl : (string, unit) Hashtbl.t) = Hashtbl.create n in
  for _ = 0 to n - 1 do
    match Scanf.scanf "%s %s\n" (fun inst str -> (inst, str)) with
    | ("insert", s) -> Hashtbl.add tbl s ()
    | ("find", s) -> print_endline (if Hashtbl.mem tbl s then "yes" else "no")
    | _ -> assert false
  done

Measured memory_bytes: 43872
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		System.out.println((b-a)*(b-a+1)/2-b);
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}


Measured memory_bytes: 22996
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] a) {
		int i[] = new int[10];
		Scanner scan = new Scanner(System.in);
		for (int j = 0; j < i.length; j++) {
			i[j] = scan.nextInt();
		}
		Arrays.sort(i);
		for (int k = 9; k >= 7; k--) {
			System.out.println(i[k]);
		}
	}

}

Measured memory_bytes: 26356
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		FastScanner sc=new FastScanner();
		int l=sc.nextInt(),r=sc.nextInt(),d=sc.nextInt();
		System.out.println((r/d)-(l-1)/d);
	
		
		
	}
		static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
}
}


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

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

  vector<int> h(n);
  for (auto&& e : h) {
    cin >> e;
  }

  vector<bool> f(n, true);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    if (h[a] <= h[b]) {
      f[a] = false;
    }
    if (h[b] <= h[a]) {
      f[b] = false;
    }
  }

  int ans = 0;
  for (auto&& e : f) {
    if (e) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

int main(){
    int n,m; cin>>n>>m;
    //answer
    vector<int> ac(n),wa(n);
    rep(i,m){
        int p;
        string s;
        cin>>p>>s;
        --p;
        //0:false 1:true
        //すでにACしたかどうか
        if(ac[p]) continue;
        if(s=="AC"){
            ac[p]=1;
        }
        else{
            wa[p]++;
        }
    }
    int A=0,W=0;
    rep(i,n){
        A+=ac[i];
        //acしたらWAの数を足す
        if(ac[i]) W+=wa[i];
    }
    cout<<A<<" "<<W<<endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
S = input()

max_num = 0

for i in range(1, N):
    common = set()
    X = S[:i]
    Y = S[i:]
    for c in X:
        if c in Y:
            common.add(c)
    if len(common) > max_num:
        max_num = len(common)

print(max_num)

Measured memory_bytes: 3060
#include<cstdio>  // 回溯输出 
#include<cstring>

const int maxn=3000+5;

char s[maxn],t[maxn];

int dp[maxn][maxn];

int max(int a,int b) { return a>b?a:b; }

void print_string(int,int); 

int main(){
	
	scanf("%s %s",s+1,t+1);

	memset(dp,0,sizeof(dp));

	int len1=strlen(s+1); 

	int len2=strlen(t+1);

	int ans=0;

	for(int i=1;i<=len1;i++){
	
		for(int j=1;j<=len2;j++){
	
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

			if(s[i]==t[j]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);

			if(i==len1 && j==len2) ans=max(ans,dp[i][j]);
		}
	}

	print_string(len1,len2); printf("\n");

	return 0;
}

void print_string(int i,int j){
	
	if(dp[i][j]==0) return ;
	
	if(s[i]==t[j] && dp[i][j]==dp[i-1][j-1]+1) {

		print_string(i-1,j-1);

		printf("%c",s[i]);
	}

	else {
	
		if(dp[i-1][j]==dp[i][j]) print_string(i-1,j);

		else print_string(i,j-1);
	}

	
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int x,k,d;
    cin >> x >> k >> d;
    if((abs(x)/d)>=k){
        cout << abs(x)-k*d;
        return 0;
    }
    long long int tmp=abs(x)/d;
    if((k-tmp)%2==0)cout << abs(x)-tmp*d;
    else cout << abs(abs(x)-(tmp+1)*d);
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
char a[200105];
int len;
long long ans=0;
int main(){
   scanf("%s",a+1);
   len=strlen(a+1);
   for(int i=1;i<=len;i++){
      ans+=(a[i]-'0');
      ans%=9;
   }
   if(ans==0) puts("Yes");
   else puts("No");
}


Measured memory_bytes: 3872
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

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

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

string s;

bool good(string x) {
    for (auto& c : x) if (c != x[0]) return false;
    return true;
}

string transform(string x, char c) {
    string y;

    FORN(i, x.size() - 1) {
        if (x[i] == c || x[i+1] == c) {
            y += c;
        }
        else {
            y += x[i];
        }
    }

    return y;
}

int main() {
    int res = INF;

    cin >> s;

    for (char c = 'a'; c <= 'z'; c++) {
        string t = s;

        int steps = 0;

        while (!good(t)) {
            t = transform(t, c);
            steps++;
        }

        res = min(res, steps);
    }

    cout << res << "\n";
    
    return 0;
}

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

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

const int N=2002;
LL td[2005];
LL t[2005];

int main(){
	LL n,m;
	LL i,j,k;
	LL s=0;
	LL a,b,c;
	cin>>n>>m;
	a=m*(m+1)/2;
	if(a>=MAX)a%=MAX;
	for(i=0;i<n;i++){
		cin>>t[i];
		s+=a*td[t[i]];
		for(j=0;j<t[i];j++){
			td[j]++;
		}
		if(s>=MAX)s%=MAX;
	}
	memset(td,0,sizeof(td));
	a=m*(m-1)/2;
	if(a>=MAX)a%=MAX;
	for(i=n-1;i>=0;i--){
		s+=a*td[t[i]];
		for(j=0;j<t[i];j++){
			td[j]++;
		}
		if(s>=MAX)s%=MAX;
	}
	cout<<s<<endl;
}


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

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

  vector<int> vec(N, 0);
  int cnt = 0;
  for (int i = 0; i + 1< N; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      cnt++;
    }
    vec[i + 1] = cnt;
  }

  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << vec[r] - vec[l] << endl;
  }    
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807


void solve(void)
{ 
  double X1,Y1,X2,Y2;
  cin>>X1>>Y1>>X2>>Y2;
  std::cout << std::fixed;
  cout << std::setprecision(8) <<sqrt((X1-X2)*(X1-X2) + (Y2 - Y1)* (Y2 - Y1))<<endl;


  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3272
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var ny = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => long.Parse(number));
		var n = ny[0];
		var y = ny[1];
		var exits = false;
		long count10000 = 0;
		long count5000 = 0;
		long count1000 = 0;
		if (10000 * n == y) {
			count10000 = n;
		} else {
			for (long ct10000 = n; ct10000 >= 0 && exits == false; --ct10000) {
				if (ct10000 * 10000 + (n - ct10000) * 5000 == y) {
					count10000 = ct10000;
					count5000 = n - ct10000;
				} else {
					for (long ct5000 = n - ct10000; ct5000 >= 0 && exits == false; --ct5000) {
						if (ct10000 * 10000 + ct5000 * 5000 + (n - ct10000 - ct5000) * 1000 == y) {
							count10000 = ct10000;
							count5000 = ct5000;
							count1000 = n - ct10000 - ct5000;
							exits = true;
						}
					}
				}
			}
		}

		if (count10000 != 0 || count5000 != 0 || count1000 != 0) {
			Console.WriteLine($"{count10000} {count5000} {count1000}");
		} else {
			Console.WriteLine("-1 -1 -1");
		}

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 13268
import itertools
def resolve():
    H,W,K = map(int,input().split())
    C = []
    for i in range(H):
        C.append(input())
    
    ans = 0
    for i in range(H+1):
        for j in range(W+1):
            for n in itertools.combinations(list(range(H)),i):
                for m in itertools.combinations(list(range(W)),j):
                    count = 0
                    for a in n:
                        for b in m:
                            if(C[a][b] == "#"): count +=1
                    if(count == K):
                        ans += 1
    print(ans)
resolve()

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

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

  cout << n*(n-1)/2+m*(m-1)/2 << endl;

  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n){
        cin >> w[i];
    }
    int diff = 10000000;
    rep(i, n){
        int x = 0, y = 0;
        for (int j = 0; j < i; j++){
            x += w[j];
        }
        for (int j = i; j < n; j++){
            y += w[j];
        }
        diff = min(diff, abs(x-y));
    }
    cout << diff << endl;
    return 0;
}   

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

int main(){

    int n,w;

    cin >> n >> w;

    vector<int> c(n),v(n);
    ll vs=0;
    ll cs=0;
    rep(i,n){
        cin >> c[i]>> v[i];
        vs+=v[i];
        cs+=c[i];
    }
    vector<ll> dp(1e+6,1e+13);
    dp[vs]=cs;
    dp[0]=0;

    for(int i=0;i<n;i++){
        for(int j=0;j<=vs;j++){
            if(j+v[i]<=vs&&dp[j+v[i]]<=cs){
               dp[j]=max(dp[0],min(dp[j],dp[j+v[i]]-c[i]));
            }
        }
    }

    

    for(int i=vs;i>=0;i--){
        if(dp[i]<=w){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

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

string S, T; int cnt;

int main() {
	cin >> S >> T;
	if (S[0] == T[0]) cnt++;
	if (S[1] == T[1]) cnt++;
	if (S[2] == T[2]) cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
start = list()
end = list()

for i in range(N):
  A, B = map(int, input().split())
  start.append(A)
  end.append(B)
start.sort()
end.sort()
if N % 2 == 1:
  print(end[int(N/2)] - start[int(N/2)] + 1)
else:
  first = (start[int(N/2)-1] + start[int(N/2)]) / 2
  last = (end[int(N/2)-1] + end[int(N/2)]) / 2
  print(int((last - first)*2 + 1))

Measured memory_bytes: 25372
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int main(){
    int n,nn;
    cin>>n;
    nn=n;
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    if(nn%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
n, x, y = map(int, input().split())
x_i = x - 1
y_i = y - 1

c = [0 for _ in range(n - 1)]
for left_i in range(n):
    for right_i in range(left_i + 1, n):
        dis = 0
        if left_i <= x_i:
            if right_i <= x_i:
                dis = right_i - left_i
                c[dis - 1] += 1
            elif x_i < right_i <= y_i:
                dis_1 = right_i - left_i
                dis_2 = x_i - left_i + 1 + y_i - right_i
                c[min(dis_1, dis_2) - 1] += 1
            else:
                dis = x_i - left_i + right_i - y_i + 1
                c[dis - 1] += 1
        elif x_i < left_i < y_i:
            dis_1 = right_i - left_i
            dis_2 = left_i - x_i + 1 + abs(right_i - y_i)
            c[min(dis_1, dis_2) - 1] += 1
        else:
            dis = right_i - left_i
            c[dis - 1] += 1

for i in c:
    print(i)

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
ll z, w, a[2005];
int main() {
	std::cin >> n >> z >> w;

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

	if (n == 1)
		std::cout << std::abs(a[0] - w) << std::endl;
	else
		std::cout << std::max(std::abs(a[n - 1] - w), std::abs(a[n - 2] - a[n - 1])) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll SORT(int n, vector<pair<ll, ll>> &v, int start){
  sort(v.begin()+start, v.end());
  return v[n-1].first;
}


int main(void){
 
  ll n;
  cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  ll a_sum = 0;
  ll b_sum = 0;

  REP(i, n){
    ll x;
    cin>>x;
    a[i] = x;
    a_sum += x;
  }

  REP(i, n){
    ll x;
    cin>>x;
    b[i] = x;
    b_sum += x;
  }

  ll sum_b = 0;
  ll sum_a = 0;

  REP(i, n){
    if(a[i] > b[i]){
      sum_b += a[i]-b[i];
    }else{
      sum_a += (b[i]-a[i])/2 + (b[i]-a[i])%2;
    }
  }

  if(a_sum > b_sum){
    cout<<"No"<<endl;
    return 0;
  }else{
    if(sum_b > b_sum-a_sum){
      cout<<"No"<<endl;
    }else if(sum_a > b_sum-a_sum){
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }
  }


  return 0;

}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'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'};

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

int main(){
    ll n, p; cin >> n >> p;
    ll i = 2;
    map<ll, ll> mp;
    while(p >= i*i){
        if(p % i == 0){
            mp[i]++;
            p /= i;
        }else{
            i++;
        }
    }
    mp[p]++;
    ll ans = 1;
    for(auto &x:mp){
        if(x.second >= n){
            ll k = x.second / n;
            ans *=  (ll)pow(x.first, k);
        }
    }
    cout << ans << endl;
}

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

const long long int INF = 1e17;

long long int dis[305][305], g[305][305];

int main(void) {
    long long int n, m, l;
    cin >> n >> m >> l;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            dis[i][j] = INF;
        }
        dis[i][i] = 0;
    }
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        dis[a][b] = dis[b][a] = c;
    }
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (dis[i][k] + dis[k][j] < dis[i][j]) {
                    dis[i][j] = dis[i][k] + dis[k][j];
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            g[i][j] = dis[i][j] <= l ? 1LL : INF;
        }
        g[i][i] = 0;
    }
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (g[i][k] + g[k][j] < g[i][j]) {
                    g[i][j] = g[i][k] + g[k][j];
                }
            }
        }
    }
    int q;
    cin >> q;
    for(int i = 1; i <= q; i++) {
        int s, t;
        cin >> s >> t;
        if(g[s][t] < INF) cout << g[s][t] - 1 << "\n";
        else cout << -1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if((a<=c && c<=b)||(b<=c && c<=a)){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------


int main(){
  int N,K;
  cin >> N >> K;
  vector<pair<ll,ll>> p(N);
  for(int i=0; i<N; i++){
    ll x,y;
    cin >> x >> y;
    p[i] = make_pair(x,y);
  }
  vector<ll> x(N),y(N);
  for(int i=0; i<N; i++){
    tie(x[i],y[i]) = p[i];
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  ll ans = INF;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      for(int k=0; k<N; k++){
        for(int l=k+1; l<N; l++){
          int cnt = 0;
          for(int m=0; m<N; m++) if(x[i]<=p[m].first && p[m].first<=x[j] && y[k]<=p[m].second && p[m].second<=y[l]) cnt++;
          if(cnt < K) continue;
          chmin(ans,(x[j]-x[i])*(y[l]-y[k]));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math

K = int(input())
ans = 0
l = []
for i in range(K+1):
    l.append([0]*(K+1))

for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            num = math.gcd(math.gcd(i, j), k)
            if i == j:
                if j == k:
                    ans += num
                else:
                    ans += 3*num
            else:
                if j == k:
                    ans += 3*num
                else:
                    ans += 6*num

print(ans)

Measured memory_bytes: 9228
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

ll dp[3020][3020];//dp[index][weight]

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  if(n%2==1){
    cout << "No" << endl;
    return 0;
  }
  string t1,t2;
  rep(i,n/2){
    t1+=s[i];
    t2+=s[i+n/2];
  }
//  cout << t1 << ' ' << t2 << endl;
  if(t1==t2)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;
    cin>>a>>b;
    if(a>b){
        cout<<2*a-1;
        return 0;
    }
    else if(b>a){
        cout<<2*b-1;
        return 0;
    }
    else{
        cout<<2*a;
        return 0;
    }
}


Measured memory_bytes: 256
import Control.Monad
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

readString = map BS.unpack . BS.words

getIntList = readIntList <$> BS.getLine

getNString n = map readString <$> replicateM n BS.getLine

simulate :: Array (Int, Int) Char -> (Int, Int) -> (Int, Int) -> String
simulate sss p p'
  | left && up = "Impossible"
  | right && down = "Impossible"
  | p == p' = "Possible"
  | right = simulate sss (h, w + 1) p'
  | down = simulate sss (h + 1, w) p'
  | otherwise = "Impossible"
  where
    (h, w) = p
    left = sss ! (h, w - 1) == '#'
    right = sss ! (h, w + 1) == '#'
    up = sss ! (h - 1, w) == '#'
    down = sss ! (h + 1, w) == '#'

main = do
  [h, w] <- getIntList
  sss <- getNString h
  let dots = replicate (w + 2) "."
  let sss' = concat (dots ++ (map (\x -> "." ++ x ++ ".") (map head sss)) ++ dots)
  let sss'' = listArray ((0, 0), (h + 1, w + 1)) sss'
  putStrLn $ simulate sss'' (1, 1) (h, w)


Measured memory_bytes: 3788
#include<cstdio>
#include<cctype>
#include<cstring>
#include<utility>
#include<algorithm>
#define FN "duty"

inline int read() {
	int x;char ch;while(!isdigit(ch=getchar()));
	for(x=ch^'0';isdigit(ch=getchar());x=(x<<3)+(x<<1)+(ch^'0'));
	return x;
}

const int maxn=2000+5;

int n,m,q;

struct Baoling {

	int a[maxn];
	std::pair<int,std::pair<bool,bool> > t[maxn<<2];
	
	inline void update(int rt) {
		t[rt].first=t[rt<<1].first+t[rt<<1|1].first;
		if(t[rt<<1].second.second && t[rt<<1|1].second.first) --t[rt].first;
		t[rt].second.first=t[rt<<1].second.first;
		t[rt].second.second=t[rt<<1|1].second.second;
	}
	
	void build(int rt,int l,int r) {
		if(l==r) {
			t[rt].first=t[rt].second.first=t[rt].second.second=a[l];
			return ;
		}
		int mid=(l+r)>>1;
		build(rt<<1,l,mid);
		build(rt<<1|1,mid+1,r);
		update(rt);
	}
	
	std::pair<int,std::pair<bool,bool> > query(int rt,int l,int r,int L,int R) {
		if(L<=l && r<=R) return t[rt];
		int mid=(l+r)>>1,ans=0;
		bool fl=false;
		if(L<=mid) {
			ans+=query(rt<<1,l,mid,L,R).first;
			fl=true;
		}
		if(R>mid) {
			ans+=query(rt<<1|1,mid+1,r,L,R).first;
			if(fl && t[rt<<1].second.second && t[rt<<1|1].second.first) --ans;
		}
		return std::make_pair(ans,std::make_pair(t[rt<<1].second.first,t[rt<<1|1].second.second));
	}

	int work() {
		std::swap(n,m);
		char ch;while(!isdigit(ch=getchar()));
		a[1]=ch-'0';
		for(int i=2;i<=n;i++) a[i]=getchar()-'0';
		build(1,1,n);
		while(q--) {
			int yl,y2;
			yl=read(),yl=read();
			y2=read(),y2=read();
			printf("%d\n",query(1,1,n,yl,y2).first);
		}
		return 0;
	}

}T;

int G[maxn][maxn];
int sum[maxn][maxn];
int edg[2][maxn][maxn];

int main() {
	n=read(),m=read(),q=read();
	if(n==1) return T.work(); 
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) {
			char ch;while(!isdigit(ch=getchar()));
			G[i][j]=ch-'0';
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+G[i][j];
			edg[0][i][j]=edg[0][i-1][j]+edg[0][i][j-1]-edg[0][i-1][j-1];
			edg[1][i][j]=edg[1][i-1][j]+edg[1][i][j-1]-edg[1][i-1][j-1];
			if(G[i-1][j] && G[i][j]) ++edg[0][i][j];
			if(G[i][j-1] && G[i][j]) ++edg[1][i][j];
		}
	while(q--) {
		int a=read(),b=read(),c=read(),d=read();
		int point=sum[c][d]-sum[a-1][d]-sum[c][b-1]+sum[a-1][b-1];
		int e1=edg[0][c][d]-edg[0][a][d]-edg[0][c][b-1]+edg[0][a][b-1];
		int e2=edg[1][c][d]-edg[1][a-1][d]-edg[1][c][b]+edg[1][a-1][b];
		printf("%d\n",point-e1-e2);
	}
}

Measured memory_bytes: 64512
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

S = input()
M = 13
DP = [0] * M
DP[0] = 1

mul = 1
for i in range(len(S) - 1, -1, -1):
    s = S[i]
    newDP = [0] * M
    if s == '?':
        for k in range(10):
            for j in range(M):
                newDP[(mul * k + j) % M] += DP[j]
    else:
        k = int(s)
        for j in range(M):
            newDP[(mul * k + j) % M] += DP[j]
    DP = [x % MOD for x in newDP]
    mul *= 10
    mul %= M

print(DP[5])


Measured memory_bytes: 45236
def Distance(X,Y,p):
    s=0
    for x,y in zip(X,Y):
        s+=abs(x-y)**p
    print(s**(1/p))
    
n=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))

for p in range(1,4):
    Distance(X,Y,p)
print(max(abs(x-y) for x,y in zip(X,Y)))


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef pair<int,int> ii;

int N,m,par[1010];

int find(int x) { 
  if( x == par[x] ) return x;
  return par[x] = find(par[x]);
}

void unit(int x,int y) {
  x = find(x), y = find(y);
  if( x != y ) par[x] = y;
}

int main(){
  cin >> N >> m;
  int cost = N+1,c,d;
  rep(i,N+2) par[i] = i;
  rep(i,m){
    cin >> c >> d;
    REP(j,c,d) unit(j,j+1);
  }
  map<int,int> group;
  REP(i,1,N+1) ++group[find(i)];
  for(map<int,int>::iterator it = group.begin(); it != group.end(); it++ ){
    if( it->second <= 1 ) continue;
    cost += ( it->second - 1 ) * 2;
  }
  cout << cost << endl;
  return 0;
}
/********
 * 1000 *
 ********/
/*********************
 * go on to the next *
 *********************/
/**************
 * thank you! *
 **************/
/**************
 * help me... *
 **************/

Measured memory_bytes: 1244
from sys import stdin
import sys
import math

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# A, B = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
S = input()
T = input()
# print(T[:-1])
if S == T[:-1] and len(S) == len(T)-1:
    print('Yes')
else:
    print("No")


Measured memory_bytes: 9024
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

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

	vector<int> a(n);
	for(auto &x : a) cin >> x;

	int s = accumulate(a.begin(), a.end(), 0);
	int c = 0;
	for(auto &x : a) {
		if(x * 4 * m >= s) c++; 
	}

	cout << (c >= m ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), putchar(), scanf()
#include <stdbool.h>

bool
leap_year(int year)
{
	if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
		return true;
	else
		return false;
}

int
main(int argc, char **argv)
{
	int a, b;
	int i;

	bool b_first = true;
	while (true)
	{
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0)
			break;

		if (!b_first)
			putchar('\n');

		b_first = false;
		bool b_none = true;
		for (i = a; i <= b; ++i)
		{
			if (leap_year(i))
			{
				printf("%d\n", i);
				b_none = false;
			}
		}

		if (b_none)
			printf("NA\n");
	}

	return 0;
}

Measured memory_bytes: 616
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <random>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

int n, q;
string s;
set<int> st[26]; // ある文字の出現いちを記録(0-indexed)

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s >> q;

  for (int i = 0; i < n; ++i)
  {
    st[s[i] - 'a'].insert(i);
  }
  for (int i = 0; i < 26; ++i)
  {
    st[i].insert(n);
  }

  while (q--)
  {
    int t;
    cin >> t;
    if (t == 1)
    {
      int i;
      char c;
      cin >> i >> c;
      --i;
      for (int j = 0; j < 26; ++j)
      {
        auto itr = st[j].find(i);
        if (itr != st[j].end())
        {
          st[j].erase(itr);
          break;
        }
      }
      st[c - 'a'].insert(i);
    }
    else
    {
      int l, r;
      cin >> l >> r;
      --l;
      int cnt = 0;
      for (int i = 0; i < 26; ++i)
      {
        int nl = *st[i].lower_bound(l);
        if (r > nl)
          ++cnt;
      }
      cout << cnt << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long A,B,C,D,S1,S2;
  cin >> A >> B >> C >> D;
  
  S1=A*B;
  S2=C*D;
  
  if (S1<=S2){
    cout << S2 << endl;
  }
  else {
    cout << S1 << endl;
  }
}

Measured memory_bytes: 256
def dfs(i,Str,res):
    if i==num-1:
        if res==7:
            print(Str+"=7")
            exit()
        return
    dfs(i+1,Str+"+"+S[i+1],res+int(S[i+1]))
    dfs(i+1,Str+"-"+S[i+1],res-int(S[i+1]))    

S=input()
num=len(S)
dfs(0,S[0],int(S[0]))

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

#define ll long long

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

    int k;
    cin >> k;

    int even = k / 2;
    int odd = k - even;

    cout << even * odd << endl;

    return 0;
}



Measured memory_bytes: 256
import math
from numba import jit

k=int(input())

@jit
def f():
  ans=0
  for a in range(1,k+1):
    for b in range(1,k+1):
      for c in range(1,k+1):
        g=math.gcd(math.gcd(a,b),c)
        ans+=g
  return ans

print(f())




Measured memory_bytes: 111048
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int total_sum=0;
	int N;
	int A;
	cin>>N;
	int arr[N+1];
	arr[0]=0;
	for(int i=1;i<=N;i++){
		cin>>A;
		arr[i]=arr[i-1]+A;
	}
	int min_sum=100000;
	// for(int i=0;i<=N;i++)
	// 	cout<<arr[i]<<" ";
	for(int i=1;i<N;i++){
		if(abs(arr[i]-(arr[N]-arr[i]))<min_sum)
			min_sum=abs(arr[i]-(arr[N]-arr[i]));
	}
	cout<<min_sum;
  return 0;
}


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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		if ((N+1)/2>=K) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef long long ll;
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;

int main() {

    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;

    if (x - r < 0) {
        cout << "No" << endl;
        return 0;
    }
    if (x + r > w) {
        cout << "No" << endl;
        return 0;
    }
    if (y - r < 0) {
        cout << "No" << endl;
        return 0;
    }
    if (y + r > h) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

}



Measured memory_bytes: 3120
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int n;						
	int *number;
	int i, j;		
	int count;	
	int total;		
	
	while (scanf("%d",&n) != EOF) {
	
		count = 0;
		
		number=(int*)malloc(sizeof(int)*(n + 1));
		
		for (i = 0; i < (n + 1); i++) {
			number[i] = i;
		}
		
		
		for (i = 2; i < (n + 1); i++) {
			if (number[i] != 0) {	
				for (j = 2 * i; j < (n + 1); j += i) {
					if (number[j] != 0) {
						number[j] = 0;
						count++;	
					}
				}
			}
		}
		
		total = n - (count + 1);
		
		printf("%d\n", total);
		
		free(number);
	}
	
	return 0;
}



Measured memory_bytes: 5880
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
#define ll long long
//{{{ read()
inline int read() {
    register int x = 0, f = 1;
    register char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + (ch ^ 48), ch = getchar();
    return x * f;
}
//}}}
const double Pi = acos(-1);
int main() {
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    int a = read(), b = read(), h = read(), m = read();
    double t1 = 1.0 * (h * 60 + m) / (12 * 60) * Pi * 2, t2 = 1.0 * m / 60 * Pi * 2;
    double x1 = a * cos(t1), y1 = a * sin(t1), x2 = b * cos(t2), y2 = b * sin(t2);
    printf("%.10lf\n", sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
    return 0;
}

Measured memory_bytes: 4128
M, D = gets.split(' ').map(&:to_i)

ans = 0
1.upto(M) do |i|
	1.upto(D) do |j|
		j1 = j / 10
		j2 = j % 10
		next if j1 <= 1
		next if j2 <= 1
		if i == j1 * j2
			ans += 1
		end
	end
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<numeric>
#include<iomanip>
#include<cmath>
using namespace std;

typedef long long ll;
const long double EPS = 0.00001;
#define Equals(a,b) abs(a-b) < EPS

ll getcombination(int a, int b){
    ll ret = 1;
    for(int i = 0; i < b; i++){
        ret *= (a-i);
        ret /= (i+1);
    }
    return ret;
}

int main(){
    int n, a, b;
    ll v;

    cin >> n >> a >> b;
    vector<ll> value(n);
    map<ll, int> appear;

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

    sort(value.rbegin(), value.rend());

    ll accum = accumulate(value.begin(), value.begin() + a, 0ll);
    map<ll, int> used;
    for(int i = 0; i < a; i++)  used[value[i]]++;

    long double maxave = (long double)accum / a;
    ll ans = 1;

    for(auto x : used){
        ans *= getcombination(appear[x.first], used[x.first]);
    }

    for(int i = a; i < b; i++){
        accum += value[i];
        if(Equals(accum/(long double)(i+1),maxave)){
            used[value[i]]++;
            ll tmp = 1;
            for(auto x : used){
                tmp *= getcombination(appear[x.first], used[x.first]);
            }
            ans += tmp;
        }else{
            break;
        }
    }

    cout << fixed << setprecision(7) << maxave << endl << ans << endl;

    return 0;
}


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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))

typedef long long ll;

int main()
{
std:
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n,k;
    cin>>n>>k;
    int cnt=1;
    cnt*=k;
    for(int i=n-1;i>0;i--){
        cnt*=k-1;
    }
    cout<<cnt;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	int adp[n];
	int bdp[n];
	int cdp[n];
	memset(adp,0,sizeof(adp));memset(bdp,0,sizeof(bdp));memset(cdp,0,sizeof(cdp));
	adp[0]=a[0];bdp[0]=b[0];cdp[0]=c[0];
	for(int i=1;i<n;i++){
		adp[i]=a[i]+max({bdp[i-1],cdp[i-1]});
		bdp[i]=b[i]+max({adp[i-1],cdp[i-1]});
		cdp[i]=c[i]+max({bdp[i-1],adp[i-1]});
	}
	cout<<max({adp[n-1],bdp[n-1],cdp[n-1]});
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    map<char, bool> ma1;
    map<char, bool> ma2;
    int ans = 0;

    for(int i=1; i<N; i++){
        int cnt = 0;
        for(char c='a'; c<='z'; c++) ma1[c] = false, ma2[c] = false;

        for(int j=0; j<i; j++) ma1[s[j]] = true;
        for(int j=i; j<N; j++) ma2[s[j]] = true;

        for(char c='a'; c<='z'; c++) if(ma1[c] == true && ma2[c] == true) cnt++;
        ans = max(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256