akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> A(n), B(n);
    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        A[i] = a;
        B[i] = a;
    }
    long long ans1 = 0;
    long long sum = 0;
    // 0, 2, 4･･･が正
    for(int i = 0; i < n; ++i) {
        sum += A[i];
        if(i % 2 == 0) {
            if(sum <= 0) {
                ans1 += abs(1 - sum);
                sum = 1;
            }
        } else {
            if(sum >= 0) {
                ans1 += abs(-1 - sum);
                sum = -1;
            }
        }
    }
    long long ans2 = 0;
    sum = 0;
    // 1, 3, 5･･･が正
    for(int i = 0; i < n; ++i) {
        sum += A[i];
        if(i % 2 == 1) {
            if(sum <= 0) {
                ans2 += abs(1 - sum);
                sum = 1;
            }
        } else {
            if(sum >= 0) {
                ans2 += abs(-1 - sum);
                sum = -1;
            }
        }
    }

    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 1024
while buf=gets do
        a,b,c,d,e,f = buf.split.map(&:to_i)
        x = ((e*c-b*f)*1.0/(a*e-b*d)*1000).round/1000.0
        y = ((a*f-c*d)*1.0/(a*e-b*d)*1000).round/1000.0
#       if x.to_s[0]=='-'
#               x*=-1
#       end
#       if y.to_s[0]=='-'
#               y*=-1
#       end
        printf("%.3f %.3f\n",x,y)

end

Measured memory_bytes: 8608
#include <iostream>

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

	int min, max, temp;
	long sum;

	std::cin >> temp;

	min = temp;
	max = temp;
	sum = temp;

	for (int i = 0; i < n - 1; i++) {
		std::cin >> temp;
		sum += temp;
		if (temp > max) {
			max = temp;
		}
		if (temp < min) {
			min = temp;
		}
	}

	std::cout << min << " " << max << " " << sum << std::endl;

}

Measured memory_bytes: 1168
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        long A;


        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextLong();

        }
        boolean flg = false;
        for (int i = 1; i < 10; i++) {
            if(A%i == 0 && A/i >= 1 && A/i <=9){
                flg = true;
            }

        }


        if(flg){
            System.out.println("Yes");
        }else{
            System.out.println("No");

        }

    }


}


Measured memory_bytes: 21716
//BUGSBUNNY
//IIT ROORKEE
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007
// #define mod 163577857 
// #define mod 998244353
#define rep(i,n) for (ll i = 0; i < n; i++)
#define repp(i,a,b) for(ll i = a ; i<b ; i++)
#define reppr(i,a,b) for(ll i = a-1 ; i>=b ; i--)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }


void solve();
signed main()
{
    //-------------------------------------------------------------------------------   
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        clock_t clk = clock();
    //-------------------------------------------------------------------------------   
    //-------------------------------------------------------------------------------
        int t = 1;
        // cin >> t;       
        rep(i,t)
        {
            // cout << "Case #" << i+1 << ": ";
            solve();
        }
    //-------------------------------------------------------------------------------
        clk = clock() - clk;
        cerr << fixed << setprecision(12) << "Time: " << ((double)clk)/CLOCKS_PER_SEC;
    //-------------------------------------------------------------------------------
}

void solve()
{
    // cout << pow(3985,5)*2 << endl;
    int x;
    cin >> x;
    repp(i,-2500,2500)
    {
        repp(j,-2500,2500)
        {
            int l = pow(i,5) - pow(j,5);
            if(l==x)
            {
                cout << i << ' ' << j << endl;
                return;
            }
        }
    }
}   

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

int n;

int main(){
	scanf("%d",&n);
	int m =n*(n-1) / 2;
	m-= n/2;
	printf("%d\n",m);
	int tar = n;
	if(n%2 == 0) tar++;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(j==tar-i) continue;
			printf("%d %d\n",i,j);
		}
	}
	return 0;
}

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

import heapq

def main():
    N, M = map(int, input().split())
    A = list(map(lambda x: -int(x), input().split()))

    heapq.heapify(A)

    for _ in range(M):
        a = -heapq.heappop(A)
        a //= 2

        heapq.heappush(A, -a)        
    
    print(-sum(A))



if __name__ == '__main__':
    main()



Measured memory_bytes: 14180
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n,int k) {
	//nのk桁目
	rep(i, k-1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N;
	cin >> N;
	if (N == 10 || N == 100 || N == 1000 || N == 10000 || N == 100000)
		cout << 10;
	else
		cout << DIGITSUM(N);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <istream>
#include <vector>
using namespace std;

int main()
{

	std::vector<int> v;



	string text = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
	stringstream ss{text};
	string buf;
	while (std::getline(ss, buf, ',')){
		v.push_back(std::stoi(buf));
	}

	int K;
	cin >> K;

	cout << v[K-1] << endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<vector<int> > a(n,vector<int>(n-1));
  rep(i,n)rep(j,n-1){
    cin >> a[i][j];
    a[i][j]--;
  }
  rep(i,n){
    reverse(all(a[i]));
  }
  set<i_i> st1;
  set<i_i> st2;
  int day=0;
  while(1){
    set<i_i> st1; // 初期化
    if(st2.empty()){
      rep(i,n){ //初回のみループ回す
        if(a[i].empty()) continue;
        if(a[a[i].back()].empty()) continue;
        if(a[a[i].back()].back()==i){
          int mn=min(i,a[i].back());
          int mx=max(i,a[i].back());
          st1.insert(i_i(mn,mx));
        }
      }
    }
    else{
      for(auto c:st2){
        int i=c.first;
        if(a[i].size()&&a[a[i].back()].size()&&a[a[i].back()].back()==i){
          int mn=min(i,a[i].back());
          int mx=max(i,a[i].back());
          st1.insert(i_i(mn,mx));
        }
        i=c.second;
        if(a[i].size()&&a[a[i].back()].size()&&a[a[i].back()].back()==i){
          int mn=min(i,a[i].back());
          int mx=max(i,a[i].back());
          st1.insert(i_i(mn,mx));
        }
      }
    }
    if(st1.empty()){
      bool f=1;
      rep(i,n){
        if(a[i].size()) f=0;
      }
      if(f) break;
      else{
        cout << -1 << endl;
        return 0;
      }
    }
    st2=st1; //次の周期ではst1は空である必要があるので2にコピー
    for(auto c:st1){
      a[c.first].pop_back();
      a[c.second].pop_back();
    }
    day++;
  }
  cout << day << endl;
}

Measured memory_bytes: 4224
#include<iostream>
#include<string>
using namespace std;
int a[100];
int main(){
	for(;;){
		int m,f,r;
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		else if(m==-1){
			cout<<"F"<<endl;
		}
		else if(f==-1){
			cout<<"F"<<endl;
		}
		else if(80<=m+f){
			cout<<"A"<<endl;
		}
		else if(65<=m+f&&m+f<80){
			cout<<"B"<<endl;
		}
		else if(50<=m+f&&m+f<65){
			cout<<"C"<<endl;
		}
		else if(30<=m+f&&m+f<50&&50<=r){
			cout<<"C"<<endl;
		}
		else if(30<=m+f&&m+f<50){
			cout<<"D"<<endl;
		}
		else cout<<"F"<<endl;
	}
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>

using namespace std;

/*??°?????????????????°*/
int W, H, ans;
int tile[20][20];

/*??¢??°??????????????????*/
void DPS(int x, int y);

int main() {
	int sx = 0, sy = 0;
	string str;

	while (cin >> W >> H, W, H) {
		/*??\???*/
		for (int i = 0; i < H; i++) {
			cin >> str;
			for (int j = 0; j < W; j++) {
				tile[i][j] = (str[j] == '#') ? 0 : 1;
				
				if (str[j] == '@') {
					sx = j;
					sy = i;
				}
			}
		}

		ans = 0;
		DPS(sx, sy);

		cout << ans << endl;
	}
}

void DPS(int x, int y) {
	if (tile[y][x]) {
		tile[y][x] = 0;
		ans++;
		
		if (x - 1 >= 0)	DPS(x - 1, y);
		if (x + 1 < W)	DPS(x + 1, y);
		if (y - 1 >= 0)	DPS(x, y - 1);
		if (y + 1 < H)	DPS(x, y + 1);
	}

	return;
}

Measured memory_bytes: 1208
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for(int i = n - 1; i >= 0; i--) {
        ll tmp = 0;
        a[i] += ans;
        tmp = b[i] - (a[i] % b[i]);
        if(a[i] % b[i] == 0) continue;
        ans += tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
n = int(input())
res_map = dict()
s = input()
tmp_map = dict()
for j in s:
    if j not in tmp_map:
        tmp_map[j] = 1
    else:
        tmp_map[j] += 1
for j in tmp_map.keys():
    res_map[j] = tmp_map[j]

for i in range(n - 1):
    s = input()
    tmp_map = dict()
    for j in s:
        if j not in tmp_map:
            tmp_map[j] = 1
        else:
            tmp_map[j] += 1
    for j in res_map.keys():
        if j in tmp_map:
            res_map[j] = min(res_map[j], tmp_map[j])
        else:
            res_map[j] = 0

res = ""
for i in res_map.keys():
    res += i * res_map[i]

res = sorted(res)
print("".join(res))


Measured memory_bytes: 9080
using System;
using System.Collections.Generic;

namespace ABC131 {
	class Task : IComparable<Task> {
		public int a,
		b;
		public Task(int i_a, int i_b) {
			a = i_a;
			b = i_b;
		}
		public int CompareTo(Task other) {
			int bSub = this.b - other.b;
			if (bSub != 0) {
				return bSub;
			}
			return this.a - other.a;
		}
	}
	class Program {
		static void Main(string[] args) {
			// 入力
			int N = int.Parse(Console.ReadLine());
			List<Task> taskList = new List<Task>(N);
			for (int i = 0; i < N; i++) {
				int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
				taskList.Add(new Task(array[0], array[1]));
			}
			// 処理
			// 締切が早い順からやって、無理だったら他のどんなやり方でも無理だと分かる
			// (1)taskListを締切が早い順にソートする
			// (2)taskListを先頭から見ていって可能かどうかを判定
			// (1)
			taskList.Sort();
			// (2)
			int totalTime = 0;
			Boolean finishable = true;
			foreach (Task task in taskList) {
				totalTime += task.a;
				if (totalTime > task.b) {
					finishable = false;
					break;
				}
			}
			if (finishable) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}
		}
	}
}

Measured memory_bytes: 25376
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 2e5 + 1;
const long long MNN = 5e3 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, p[MXN], ans;
vector<pair<int, pair<int, int> > > q;

struct point{
    int x, y, ind;
}a[MXN];

bool cmp(point a, point b){
    return a.x < b.x;
}

bool cmp2(point a, point b){
    return a.y < b.y;
}

int batya(int x){
    if(p[x] == x){
        return x;
    }
    return batya(p[x]);
}


int main () {
    srand(time(0));
    cin >> n;
    for(int i = 1; i <= n; i++){
        p[i] = i;
        cin >> a[i].x >> a[i].y;
        a[i].ind = i;
    }
    sort(a + 1, a + n + 1, cmp);
    for(int i = 1; i < n; i++){
        q.pb({a[i + 1].x - a[i].x, {a[i + 1].ind, a[i].ind}});
    }
    sort(a + 1, a + n + 1, cmp2);
    for(int i = 1; i < n; i++){
        q.pb({a[i + 1].y - a[i].y, {a[i + 1].ind, a[i].ind}});
    }
    sort(q.begin(), q.end());
    for(int i = 0; i < q.size(); i++){
        int c = q[i].F, u = q[i].S.F, v = q[i].S.S;
        int uBatya = batya(u);
        int vBatya = batya(v);
        if(uBatya == vBatya){
            continue;
        }else{
            if(rand() % 2 == 1){
                p[uBatya] = vBatya;
                p[v] = vBatya;
                p[u] = vBatya;
            }else{
                p[vBatya] = uBatya;
                p[v] = uBatya;
                p[u] = uBatya;
            }
            ans += c;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define PB push_back
#define PII pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAXN = 2e5 + 10 , INF = 1e9;

int main() {
    int n;
    cin >> n;
    int l = 1 , r = n + 1;
    cout << l - 1 << endl;
    string s , s2;
    cin >> s;
    if(s == "Vacant") {
        return 0;
    }
    while(1) {
        int mid = (r + l) / 2;
        cout << mid - 1 << endl;
        cin >> s2;
        int dis = mid - l - 1;
        if(s2 == "Vacant") {
            return 0;
        }
        else if(s2 == s) {
            if(dis % 2 == 0) {
                r = mid;
            }
            else {
                l = mid;
                s = s2;
            }
        }
        else {
            if(dis % 2) {
                r = mid;
            }
            else {
                l = mid;
                s = s2;
            }
        }
    } 
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a,b,c; cin>>a>>b>>c;
  deque<char>A;
  deque<char>B;
  deque<char>C;
  for(int i=0;i<a.size();i++){
    A.push_back(a[i]);
  }
  for(int i=0;i<b.size();i++){
    B.push_back(b[i]);
  }
  for(int i=0;i<c.size();i++){
    C.push_back(c[i]);
  }
  
  char next=A[0];
  A.pop_front();
  for(int i=0; i<300;i++){
    if(next=='a' && A.size()>0){
      next=A[0];
      A.pop_front();
    }
    if(next=='a' && A.size()==0){
      cout<<"A"<<endl;
      break;
    }
    
    if(next=='b'&& B.size()>0){
      next=B[0];
      B.pop_front();
    }
    if(next=='b' && B.size()==0){
      cout<<"B"<<endl;
      break;
    }
    
    if(next=='c'&& C.size()>0){
      next=C[0];
      C.pop_front();
    }
    if(next=='c' && C.size()==0){
      cout<<"C"<<endl;
      break;
    }
  }
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    vs s(2);
    rep(i,2)cin >> s[i];
    if(s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[0][2] == s[1][0])
    cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.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;
}

const ll INF = LONG_LONG_MAX / 2;

vector<ll> as;
vector<pair<ll, int>> bs; // {value, initial_pos}
vector<vector<ll>> dp;

void solve(const int N) {
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            auto v = bs[i + j].first;
            auto pos = bs[i + j].second;
            if (i > 0) {
                chmax(dp[i][j], dp[i - 1][j] + v * abs(i - pos));
            }
            if (j > 0) {
                chmax(dp[i][j], dp[i][j - 1] + v * abs(N - j + 1 - pos));
            }
        }
    }
}

int main(void) {
    int N;
    cin >> N;

    as.resize(N + 1);
    bs.resize(N + 1);
    bs[0] = { INF, 0 };
    for (int i = 1; i <= N; i++) {
        cin >> as[i];
        bs[i] = { as[i], i };
    }
    sort(bs.begin(), bs.end());
    reverse(bs.begin(), bs.end());

    dp.resize(N + 1, vector<ll>(N + 1, 0));

    solve(N);

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= N; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        chmax(ans, dp[i][N - i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 34676
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  static long long A[401];
  copy_n(istream_iterator<int>(cin), N, A + 1);
  partial_sum(A + 1, A + N + 1, A + 1);
  static long long F[401][401];
  static int G[401][401];
  for (auto i = 0; i < N; ++i)
    G[i][i + 1] = i;
  for (auto i = 2; i <= N; ++i)
    for (auto j = 0; j <= N - i; ++j) {
      auto k = j + i;
      F[j][k] = LLONG_MAX;
      for (auto g = G[j][k - 1]; g <= G[j + 1][k]; ++g)
        if (F[j][g] + F[g][k] < F[j][k]) {
          F[j][k] = F[j][g] + F[g][k];
          G[j][k] = g;
        }
      F[j][k] += A[k] - A[j];
    }
  cout << F[0][N] << endl;
  return 0;
}


Measured memory_bytes: 2176
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n, k = map(int,input().split())
    A = list(map(int,input().split()))
    for i in range(k,n):
        if A[i-k] < A[i]:
            print("Yes")
        else:
            print("No")

if __name__=='__main__':
    main()

Measured memory_bytes: 31616
import * as fs from 'fs';
 
const input = parseInt(fs.readFileSync("/dev/stdin", "utf8")).toString();

const fp = input[input.length - 1];
 
if(new Set(['2', '4', '5', '7', '9']).has(fp)) {
  console.log('hon');
}else if(new Set(['0', '1', '6', '8']).has(fp)) {
  console.log('pon');
} else {
  console.log('bon');
}

Measured memory_bytes: 29596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
    execute();
    }

    private static void execute() throws IOException {
        BufferedReader br =
                new BufferedReader(new InputStreamReader(System.in));
        System.out.println(isHaiku(br.readLine().split(" ")));
    }

    public static String isHaiku(String[] sentences) {
        if (sentences.length != 3) {
            return "NO";
        }
        List<String> haiku = new LinkedList<>(Arrays.asList("5","7","5"));
        for (String str : sentences) {
            if (haiku.contains(str)) {
                haiku.remove(str);
            }
        }
        return haiku.isEmpty() ? "YES" : "NO";
    }
}

Measured memory_bytes: 21204
#include <cstdio>
#include <cctype>
#include <algorithm>
int N,M,A[262155],G,F[262155];
struct Ad{
	int x,id;
	inline bool operator < (const Ad &c) const{
		return x>c.x;
	}
	inline bool operator == (const Ad &c) const{
		return id==c.id&&(~id)&&(~c.id);
	}
}F1[262155],F2[262155],S[5];
inline void read(int &Res){
	char ch=getchar();
	for (Res=0;!isdigit(ch);ch=getchar());
	for (;isdigit(ch);ch=getchar()) Res=(Res<<3)+(Res<<1)+ch-48;
}
int main(){
	read(M),N=1<<M;
	for (int i=0;i<N;++i) read(A[i]),F1[i]=(Ad){A[i],i},F2[i]=(Ad){0,-1};
	for (int i=0;i<N;++i){
		for (int j=0,k;j<M;++j) if (!((i>>j)&1)){
			k=i|(1<<j),S[0]=F1[i],S[1]=F2[i],S[2]=F1[k],S[3]=F2[k];
			std::sort(S,S+4),G=std::unique(S,S+4)-S,F1[k]=S[0],F2[k]=S[1];
			if (G<2) F2[k]=(Ad){0,-1};
			if (G<1) F1[k]=(Ad){0,-1};
		}
	}
	for (int i=1;i<N;++i) F[i]=std::max(F[i-1],F1[i].x+F2[i].x),printf("%d\n",F[i]);
	return 0;
}

Measured memory_bytes: 9088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		if(p[0] <= 9 && p[1] <= 9)
			Console.WriteLine(p[0] * p[1]);
		else
			Console.WriteLine(-1);
	}
	

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



Measured memory_bytes: 13140
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String N = sc.nextLine();
		
		char[] n = N.toCharArray();
		
		//10桁以外は除外
		if (N.length() == 1) {
			System.out.println(N);
			return;
		}
		
		int not9 = -1;
		for (int i = 0; i < N.length(); i++) {
			if (n[i] != '9') {
				not9 = i;
				break;
			}
		}
		
		int ans = (N.length() - 1) * 9;
		if (not9 == -1) {
			ans += 9;
		} else if (not9 == 0 && N.replaceAll("9", "").length() == 1) {
			ans += Character.getNumericValue(n[0]);
		} else if (not9 == 0 && N.replaceAll("9", "").length() != 1) {
			int head = Character.getNumericValue(n[0]);
			ans += n[0] == '1' ? 0 : head - 1;
		} else {
			ans += 8;
		}
		
		System.out.println(ans);
	}
	
}

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

using namespace std;

int main(){
	string s;
	cin>>s;
	long long ans = 0;
	for(int i = 0 ; i < s.size() ; i++){
		ans += s[i] - '0';
	}
	cout<<(ans % 9 == 0 ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifdef APURBA
#define HERE cout<<"here - "<<__LINE__<<"\n";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)
{
    cout<<endl;
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cout << *it << " = " << a << " ";
    err(++it, args...);
}
#else
#define HERE
#define debug(args...)
#endif
const int N = 1e6+5;
const ll mod = 1e9+7 ;
typedef pair<int,int> pii;

void TEST_CASES(int cas)
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans = max({a*c, a*d , b*c, b*d});
    cout<<ans<<endl;
}



/*

*/

int main()
{
#ifndef APURBA
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int t=1,cas=0;
    //cin>>t;
    while(t--)
    {
        TEST_CASES(++cas);
    }
    return 0;
}



template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int H, W;
vector<string> maze;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool seen[410][410];
ll numb = 0, numw = 0;

void dfs(int y, int x) {
    seen[y][x] = true;
    if (maze[y][x] == '#') numb++;
    else numw++;

    rep(i, 4) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
        if (maze[y][x] == maze[ny][nx]) continue;
        if (seen[ny][nx]) continue;
        dfs(ny, nx);
    }
}

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

    cin >> H >> W;
    maze.resize(H);
    rep(i, H) cin >> maze[i];

    ll res = 0;
    rep(i, H) rep(j, W) {
        if (maze[i][j] == '.' || seen[i][j]) continue;
        numb = numw = 0;
        dfs(i, j);
        res += numb * numw;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 18048
#include <stdio.h>
#include <limits.h>

const int MAX_M = 1000;

int main() {
  int m;
  long long sumA[1 + MAX_M + 1];
  long long minCost[1 + MAX_M + 1][1 + MAX_M + 1];
  int minK[1 + MAX_M + 1][1 + MAX_M + 1];
  scanf("%d", &m);
  sumA[0] = 0;
  for (int i = 1; i <= m; i++) {
    int ai;
    scanf("%d", &ai);
    sumA[i] = sumA[i - 1] + ai;
  }
  for (int i = 1; i <= m; i++) {
    minCost[i][i] = 0;
    minK[i][i] = i;
  }
  for (int d = 1; d < m; d++) {
    for (int i = 1; i + d <= m; i++) {
      int j = i + d;
      minCost[i][j] = LONG_LONG_MAX;
      for (int k = minK[i][j - 1]; k <= minK[i + 1][j]; k++) {
        if (minCost[i][j] > minCost[i][k] + minCost[k + 1][j] + (sumA[j] - sumA[i - 1])) {
          minCost[i][j] = minCost[i][k] + minCost[k + 1][j] + (sumA[j] - sumA[i - 1]);
          minK[i][j] = k;
        }
      }
    }
  }
  printf("%lld\n", minCost[1][m]);
  return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N = 0;
    int L = 0;
    cin >> N  >> L;

    vector<int> taste(N);

    //各味
    for (int i = 0; i < N; ++i) {
        taste.at(i) = L + i;
    }
    //味の総和=アップルパイ
    //absがminのものを選ぶ
    int tasteSum = 0;
    int tasteBad = INT_MAX;
    for (int i = 0; i < N; ++i) {
        tasteSum += taste.at(i);
        int tasteabs = abs(taste.at(i));
        tasteBad = min(tasteBad,tasteabs);
    }
    //absがminになっている配列の要素番号を指定
    int minabsnumber = 0;
    for (int i = 0; i < N; ++i) {
        if(abs(taste.at(i)) == tasteBad) minabsnumber = i;
    }
        cout << tasteSum - taste.at(minabsnumber);

    return 0;
}

Measured memory_bytes: 256
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
A, B, C, D = map(int, input().split())

x = B // C
y = B // D
z = B // lcm(C, D)
num1 = (B - (x + y - z))

x = A // C
y = A // D
z = A // lcm(C, D)
num2 = (A - (x + y - z))
  
num = num1 - num2

if A % C != 0 and A % D != 0:
  num += 1
  
print(num)


Measured memory_bytes: 5052
n = int(input())
li = list(map(int,input().split()))
an = 1000000

for i in range(n):
    if an > abs(sum(li[0:i+1]) - sum(li[i+1:])):
        an = abs(sum(li[0:i+1]) - sum(li[i+1:]))

print(an)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::BTreeMap;

fn main() {
  let n = read::<i64>();
  let mut ang = vec![];
  let mut map: BTreeMap<String, i64> = BTreeMap::new();

  for _ in 0..n {
    ang.push(read::<String>());
  }

  let mut ans: i64 = 0;

  for i in ang {
    let mut item = i.chars().collect::<Vec<char>>();
    item.sort();

    let mut ang_i = String::from("");
    for i in item.iter() {
      ang_i.push(*i);
    }
    if map.contains_key(&ang_i) {
      let current = map.get_mut(&ang_i).unwrap();
      ans += *current;
      *current += 1;
    } else {
      map.insert(ang_i, 1);
    }
  }
  println!("{:?}", ans);
}


Measured memory_bytes: 14584
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, A;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		if (A % 2 == 0 && A % 3 != 0 && A % 5 != 0) {
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int suti = scan.nextInt();
    int i, j, k;
    int check;
    boolean atteru = false,tigau = true;
    for (i = 1; i <= 9; i++ ) {
      for(k = 0;k <= 9; k++){
        check = 1000*i + 100*i + 10*i + k;
        if (check == suti) {
          atteru = true;
          tigau = false;
        }
      }
    }
    for (i = 0; i <= 9; i++ ) {
      for(k = 1;k <= 9; k++){
        check = 1000*k + 100*i + 10*i + i;
        if (check == suti) {
          atteru = true;
          tigau = false;
        }
      }
    }
    if(atteru == true){
      System.out.println("Yes");
    } else if (tigau == true) {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23892
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <tuple>
#include <stdlib.h>
using namespace std;
typedef long long int ll;

int main()
{
	int N,tmp,ato,mae;
	cin >> N;
	vector<int>L(N);
	ll ans = 0;
	for (int i = 0; i < N; i++)cin >> L[i];
	sort(L.begin(), L.end());
	for (int i = 0; i < N-2; i++)
	{
		for (int j = i+1; j < N-1; j++)
		{
			 ato = lower_bound(L.begin(), L.end(), L[j] + L[i])-L.begin();
			 mae = upper_bound(L.begin(), L.end(), L[j] - L[i])-L.begin();
			tmp= max(ato - max(mae,j), 0);
			ans += tmp;
			if (tmp != 0) {
				if (i <= ato - 1 && i >= max(mae,j) )ans--;
				if (j <= ato - 1 && j >= max(j,mae) )ans--;
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int dp(int i,int n,int*arr,int*memo){

  if(i==n-1){
    return 0;
  }

  if(memo[i]!=-1)return memo[i];

  int a1 = abs(arr[i+1]-arr[i])+dp(i+1,n,arr,memo);

  int a2=INT_MAX;

  if(i+2<=n-1)a2=abs(arr[i+2]-arr[i])+dp(i+2,n,arr,memo);

  memo[i]=min(a1,a2);
  return min(a1,a2);

}



int main() {
  // FILE;
  SPEED;
  
  int n;
  cin>>n;

  int arr[n];
  int memo[n];
  for(int i=0;i<n;i++)memo[i]=-1;
  fain(arr);
  cout<<dp(0,n,arr,memo)<<endl; 

}

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

using namespace std;

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

	string s;
	cin >> s;

	int n = s.size();

	vector<vector<int> > dp(n + 1, vector<int> (2));

	dp[1][0] = 1;
	for(int i = 0; i < n; ++i) {
		if(i + 2 <= n) {
			dp[i + 2][1] = max(dp[i + 2][1], dp[i][0] + 1);
			if(i > 1 && s.substr(i - 2, 2) != s.substr(i, 2)) {
				dp[i + 2][1] = max(dp[i + 2][1], dp[i][1] + 1);
			}
		}
		if(i > 0 && s[i] != s[i - 1]) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + 1);
		}
		if(i > 1) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + 1);
		}
	}

	cout << max(dp[n][0], dp[n][1]) << '\n';

	return 0;
}


Measured memory_bytes: 11412
#include <bits/stdc++.h>
#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, q;
    string S;
    cin >> n >> S >> q;
    set<int> s[26];
    rep(i,n) s[(int)(S[i] - 'a')].insert(i);
    vector<int> ans;
    rep(i,q){
        int a;
        cin >> a;
        if(a == 1){
            int b;
            char c;
            cin >> b >> c;
            b--;
            s[(int)(S[b] - 'a')].erase(b);
            s[(int)(c - 'a')].insert(b);
            S[b] = c;
        }
        else{
            int l, r;
            cin >> l >> r;
            l--, r--;
            int sum = 0;
            rep(j, 26){
                auto it = s[j].lower_bound(l);
                if(it != s[j].end()){
                    if(*it <= r){
                        sum++;
                    }
                }
            }
            ans.push_back(sum);
        }
    }
    for(auto i : ans){
        cout << i << endl;
    }
}

Measured memory_bytes: 27472
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<int> dp(3);
int arr[3];
int main()
{ int n,a,b,c;
  cin>>n;
  for(int m=0;m<3;m++)
  cin>>dp[m];
  for(int k=1;k<n;k++)
	{   vector<int> new_dp(3);
		for(int l=0;l<3;l++)
		cin>>arr[l];
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
		{ if(i==j) continue;
		  else
		  new_dp[j]= max(new_dp[j],dp[i]+arr[j]);
		}
		dp=new_dp;
	}
 int ans =0;
 for(auto x:dp)
 ans=max(ans,x);
 cout<<ans;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include <cstdio>


int main()
{
	long long int m, n;
	scanf("%lld%lld", &m, &n);
	if (n == 0)
		printf("%lld", m*m);
	else 
	{
		long long sum = m - n;
		long long ans = (sum + 1)*sum / 2;
		for (int i = n + 1;i <= m - n;i++)
		{
			ans += (m-i)/ i*(i - n);
			if (m%i >= n)ans += m%i - n+1;
		}
		printf("%lld",ans );
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
  int i, x, n;
  cin >> n;

  for(i=1; i <= n; i++){
    x=i;
    if(x%3 == 0){
      cout << ' ' << i;
    }
    else {
      while(x){
        if(x%10==3){
          cout << ' ' << i;
          break;
        }
        x/=10;
      }
    }
  }
  cout << endl;
  return 0;
}



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

int main(){
    string s[2];
    vector<char> b;
    rep(i,2){
        cin >> s[i];
    }
    if(s[0].size() == s[1].size()){
        int size = s[0].size();
        rep(i,size){
            if(s[0][i] != s[1][i]){
                int a=(int)s[0][i];
                int b=(int)s[1][i];
                if(a > b){
                    cout << "GREATER" << endl;
                    return 0;
                }else{
                    cout << "LESS" << endl;
                    return 0;
                }
            }
        }
        cout << "EQUAL" << endl;
        return 0;
    }
    if(s[0].size() < s[1].size()){
        cout << "LESS" << endl;
        return 0;
    }else{
        cout << "GREATER" << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 10000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288
 
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;




int main(){
    FAST_IO ;
    int N ; cin >> N ;
    int cnt[N+2] ;
    memset(cnt, 0, sizeof(cnt)) ;
    for( int i = 0 ; i < N - 1 ; i++ ){
        int x ; cin >> x ;
        cnt[x]++ ;
    }
    
    for( int i = 1 ; i <= N ; i++ )
        cout << cnt[i] << endl ;
    return 0 ;
}
 
 

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

using namespace std;

const double PI = (acos(-1));

int main ()
{
    double a, b, x; cin >> a >> b >> x;

    double theta = 0;

    if (2*x > a * a * b)
        theta = atan( 2 * ( b/a - x / (a * a * a)) );
    else
        theta = atan( (a * b * b) / (2 * x) );

    theta *= 180 / PI;

    cout << setprecision(10) << fixed << theta << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vvll G(N, vll(0));
  vll color(N, -1); //0が黒、1が白
  
  for(int i = 0; i < N-1; i++){
    ll a, b;
    cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b); G.at(b).push_back(a);
  }
  vll fs(N, false);
  function<void(int, int)> func = [&](int uu, int before){
    if(uu == N-1) fs.at(uu) = true;

    for(int i = 0; i < G.at(uu).size(); i++){
      int next = G.at(uu).at(i);
      if(next == before) continue;
      func(next, uu);
      if(fs.at(next)) fs.at(uu) = true;
    }
  };

  func(0, 0);
  
  queue<int> fque1, fque2, sque1, sque2;
  fque1.push(0); sque1.push(N-1);

  while(true){
    bool fng = true;
    while(!fque1.empty()){
      int v = fque1.front(); fque1.pop();
      if(color.at(v) != -1) continue;
      color.at(v) = 0;
      for(int i = 0; i < G.at(v).size(); i++){
        int next = G.at(v).at(i);
        if(color.at(next) != -1) continue;
        if(fs.at(next)) fque1.push(next);
        else fque2.push(next);
      }
      fng = false;
      break;
    }
    while(fng && !fque2.empty()){
      int v = fque2.front(); fque2.pop();
      if(color.at(v) != -1) continue;
      color.at(v) = 1;
      for(int i = 0; i < G.at(v).size(); i++){
        int next = G.at(v).at(i);
        if(color.at(next) != -1) continue;
        if(fs.at(next)) fque1.push(next);
        else fque2.push(next);
      }
      fng = false;
      break;
    }
    if(fng){
      cout << "Snuke" << endl;
      return 0;
    }

    bool sng = true;
    while(!sque1.empty()){
      int v = sque1.front(); sque1.pop();
      if(color.at(v) != -1) continue;
      color.at(v) = 0;
      for(int i = 0; i < G.at(v).size(); i++){
        int next = G.at(v).at(i);
        if(color.at(next) != -1) continue;
        if(fs.at(next)) sque1.push(next);
        else sque2.push(next);
      }
      sng = false;
      break;
    }
    while(sng && !sque2.empty()){
      int v = sque2.front(); sque2.pop();
      if(color.at(v) != -1) continue;
      color.at(v) = 0;
      for(int i = 0; i < G.at(v).size(); i++){
        int next = G.at(v).at(i);
        if(color.at(next) != -1) continue;
        if(fs.at(next)) sque1.push(next);
        else sque2.push(next);
      }
      sng = false;
      break;
    }
    if(sng){
      cout << "Fennec" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 18176