akhauriyash/Code-Regression huggingface dataset:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N, Q = map(int, input().split())
    edge = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    cnt = [0]*N
    for i in range(Q):
        p, x = map(int, input().split())
        cnt[p-1] += x

    stk = []
    # visited = set()
    stk.append((0, -1))
    while len(stk):
        # print(stk, visited)
        v, par = stk.pop()
        # if not v in visited:
        #     visited.add(v)
        if v>0:
            cnt[v] += cnt[par]
        for i in edge[v]:
            if i!=par:
            # if not i in visited:
                stk.append((i, v))
        # par = v

    print(*cnt)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 56712
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

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


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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		long ans = 800*N;
		ans-=(N/15)*200;


		System.out.println(ans);

	}

	public static boolean isPalindromicStr(String s) {
		int h = 0;
		int t = s.length() - 1;
		while (h <= t) {
			if (s.charAt(h) != s.charAt(t)) {
				break;
			}
			h++;
			t--;
		}
		if (h > t) {
			return true;
		}
		return false;
	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 23252
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) * n != 0){
		int array[100];
		int i, j;
		int count = 0;
		
		for (i = 0; i < n; i++){
			scanf("%d", array + i);
		}
		for (i = 0; i < n - 1; i++){
			for (j = 0; j < n - i - 1; j++){
				if (array[j] > array[j + 1]){
					int tmp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = tmp;
					count++;
				}
			}
		}
		
		printf("%d\n", count);
	}
	
	return 0;
}

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

#define MOD (1000000000+7)

int main() {
	int N, M;

	cin >> N >> M;
	vector<int> S( N + 1 );
	for( int i = 1; i < N + 1; i++ ) {
		cin >> S[i];
	}
	vector<int> T( M + 1 );
	for( int i = 1; i < M + 1; i++ ) {
		cin >> T[i];
	}

	vector<vector<long long>> dp( N + 1, vector<long long>( M + 1 ) );
	vector<vector<long long>> sum( N + 1, vector<long long>( M + 1 ) );
	for( int i = 1; i < N + 1; i++ ) {
		for( int j = 1; j < M + 1; j++ ) {
			if( S[i] == T[j] ) {
				dp[i][j] = sum[i - 1][j - 1] + 1;
				dp[i][j] %= MOD;
			}
			sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + dp[i][j] + MOD;
			sum[i][j] %= MOD;
		}
	}
	long long ans = sum[N][M] + 1;
	ans %= MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 62976
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
 
 
int main() {
	const double PI = 3.14159265358979323846;
	double R,a;
	cin >> R;
 
	a = R*2 * PI;
 
	cout << a << endl;
 
	return 0;
}

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

using namespace std;


#define ll              long long
#define pb              push_back
#define nn           cout << "\n";



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t,a,b,i,j,c,d,e,f,n,k,m,w;



    cin>>n>>k;

      int dp[n+5],ht[n+5];

    for(i=1;i<=n;i++)
    {
        cin>>a;
        ht[i]=a;

    }

    dp[n]=0;
    for(i=n-1;i>=1;i--)
    {
        dp[i]=1000000000;
        for(j=1;j<=k&&(i+j)<=n;j++)
        {


        dp[i]=min(dp[i],(dp[i+j]+abs(ht[i]-ht[i+j])));
        }
    }

    cout<<dp[1]<<endl;
    return 0;
}

Measured memory_bytes: 4404
//by xxj
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
	vector<ll> qz,hz;
	ll sum,ans;
};
node dat[800007];
int a[200007];
void push_up(int id){
	dat[id].ans=dat[id*2].ans+dat[id*2+1].ans;
	dat[id].sum=dat[id*2].sum+dat[id*2+1].sum;
	int j=dat[id*2+1].qz.size();
	int i=0;
	for (;i<dat[id*2].hz.size();i++){
		for (;j>0;j--){
			if (dat[id*2+1].qz[j-1]+dat[id*2].hz[i]>=0){
				continue;
			}
			else{
				break;
			}
		}
		dat[id].ans+=dat[id*2+1].qz.size()-j;
	}
	i=0;
	j=0;
	ll vi=dat[id*2].hz[i]+dat[id*2+1].sum,vj=dat[id*2+1].hz[j];
	while (true){
		if (vi>vj){
			dat[id].hz.push_back(vj);
			j++;
			if (j==dat[id*2+1].hz.size()){
				break;
			}
			vj=dat[id*2+1].hz[j];
		}
		else{
			dat[id].hz.push_back(vi);
			i++;
			if (i==dat[id*2].hz.size()){
				break;
			}
			vi=dat[id*2].hz[i]+dat[id*2+1].sum;
		}
	}
	if (i!=dat[id*2].hz.size()){
		for (;i<dat[id*2].hz.size();i++){
			dat[id].hz.push_back(dat[id*2].hz[i]+dat[id*2+1].sum);
		}
	}
	else{
		for (;j<dat[id*2+1].hz.size();j++){
			dat[id].hz.push_back(dat[id*2+1].hz[j]);
		}		
	}
	i=0;
	j=0;
	vi=dat[id*2].qz[i];
	vj=dat[id*2+1].qz[j]+dat[id*2].sum;
	while (true){
		if (vi>vj){
			dat[id].qz.push_back(vj);
			j++;
			if (j==dat[id*2+1].qz.size()){
				break;
			}
			vj=dat[id*2+1].qz[j]+dat[id*2].sum;
		}
		else{
			dat[id].qz.push_back(vi);
			i++;
			if (i==dat[id*2].qz.size()){
				break;
			}
			vi=dat[id*2].qz[i];
		}
	}
	if (i!=dat[id*2].qz.size()){
		for (;i<dat[id*2].qz.size();i++){
			dat[id].qz.push_back(dat[id*2].qz[i]);
		}
	}
	else{
		for (;j<dat[id*2+1].qz.size();j++){
			dat[id].qz.push_back(dat[id*2+1].qz[j]+dat[id*2].sum);
		}		
	}
}
void build(int l,int r,int id){
	if (l==r){
		dat[id].ans=(a[l]>=0);
		dat[id].sum=a[l];
		dat[id].qz.push_back(a[l]);
		dat[id].hz.push_back(a[l]);
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,id*2);
	build(mid+1,r,id*2+1);
	push_up(id);
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++){
		scanf("%d",a+i);
		a[i]-=k;
	}
	build(0,n-1,1);
	cout<<dat[1].ans<<endl;
	return 0;
}

Measured memory_bytes: 137968
#include <cstdio>
#include <cstring>
#include <algorithm>
int n, m, map[666][666];
bool vis[666][666];
struct Pair{
	int x, y;
};
Pair getnext(int a, int b){
	Pair tmp;
	if(a & 1){
		if(b == m) return (Pair){a + 1, b};
		return (Pair){a, b + 1};
	}
	else{
		if(b == 1) return (Pair){a + 1, b};
		return (Pair){a, b - 1};
	}
}
int ans = 0;
void dfs(int a, int b){
	if(a > n || b > m) return;
	Pair c = getnext(a, b);
	if(c.x > n) return;
	if(map[a][b] & 1) ans++, map[c.x][c.y]++, map[a][b]--, vis[a][b] = 1;
	dfs(c.x, c.y);
}

int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			scanf("%d", &map[i][j]);
	dfs(1, 1);
	printf("%d\n", ans);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(vis[i][j]){
				Pair tmp = getnext(i, j);
				printf("%d %d %d %d\n", i, j, tmp.x, tmp.y);
			}	
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;
ll n, k;
vector<ll> a, f;

bool check(ll t){
  ll remain = k;
  // cout << t << endl;
  for (int i = 0; i < n; ++i) {
    ll target = t / f[i];
    remain -= max(0ll, a[i] - target);
  }
  // cout << remain << endl;
  return remain >= 0;
}

void res(ll ok){
  cout << ok << endl;
}

int bs(int maxv){
  ll ng = -1, ok = LLONG_MAX / 2;
  while(ok - ng >= 2){
    ll mid = (ok + ng) / 2;
    if(check(mid)) ok = mid;
    else ng = mid;
  }
  res(ok);
  return 0;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  a = vector<ll> (n);
  f = vector<ll> (n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(ALL(a));
  sort(RALL(f));
  // print(a);
  // print(f);
  bs(a[n-1]);
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
          int a = Input.ScanInt();
          
          Console.WriteLine(1110-a);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n)  { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }

using namespace std;

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

const int N = 2e5 + 10;

int n, m, q, LSize;
int L[N], ans[N], ban[N];

vector <int> c[N];

struct Ant {
    int x, y, d;
    Ant () {}
    Ant (int x, int y, int d) : x(x), y(y), d(d) {};
} A[N];

void Compress() {
    FOR(i, 1, q) L[i] = A[i].x + A[i].y;
    LSize = q;
    sort(L + 1, L + LSize + 1);
    LSize = unique(L + 1, L + LSize + 1) - (L + 1);
}

int Pos(int v) {
    return lower_bound(L + 1, L + LSize + 1, v) - L;
}

bool CMP(int x, int y) {
    return A[x].y < A[y].y;
}

struct State {
    int x, y, z;
    State () {}
    State (int x, int y, int z) : x(x), y(y), z(z) {}
    bool operator < (const State &that) const {
        if (x != that.x) return x < that.x;
        if (y != that.y) return y < that.y;
        return z < that.z;
    }
};

void Compute(const vector <int> &g) {
    vector <State> L;
    REP(p, 0, g.size()) {
        int i = g[p], x = A[i].x, y = A[i].y, d = A[i].d;
        if (d == 0) L.push_back(State(d, A[i].y, n - A[i].x));
            else L.push_back(State(d, n - A[i].x, m - A[i].y));
    }
    sort(L.begin(), L.end());
   // PR0(g, g.size());
    //REP(i, 0, g.size()) cout << L[i].z << endl;
    REP(i, 0, g.size()) ans[g[i]] = L[i].z;
}

void Solve(int idx) {
    sort(c[idx].begin(), c[idx].end(), CMP);
    if (L[idx] % 2 == 0) {
        FOR(f, 0, 1) {
            vector <int> g;
            REP(k, 0, c[idx].size()) {
                int i = c[idx][k];
                if (A[i].x % 2 != f) continue;
                g.push_back(i);
            }
            Compute(g);
        }
    } else {
        FOR(r, 0, 1) {
            vector <int> g;
            REP(k, 0, c[idx].size()) {
                int i = c[idx][k];
                if (A[i].d == 0) {
                    if (A[i].y % 2 == r) g.push_back(i);
                } else {
                    if (A[i].x % 2 == r) g.push_back(i);
                }
            }
            Compute(g);
        }
    }
}

int main() {
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // LOCAL
    scanf("%d%d%d", &n, &m, &q);
    FOR(i, 1, q) {
        char d[2]; int x, y; scanf("%d%d%s", &x, &y, d);
        A[i] = Ant(x, y, d[0] == 'E' ? 0 : 1);
    }
    /*FOR(i, 1, q)
        FOR(j, i + 1, q) assert((A[i].x == A[j].x && A[i].y == A[j].y) == false);*/
    Compress();
    FOR(i, 1, q) {
        int x = A[i].x, y = A[i].y, d = A[i].d;
        c[Pos(x + y)].push_back(i);
    }
    FOR(i, 1, LSize) Solve(i);
    vector <II> answ;
    FOR(i, 1, q) answ.push_back(II(ans[i], i));
    sort(answ.begin(), answ.end());
    FOR(i, 1, q) printf("%d\n", answ[i - 1].second);
    return 0;
}



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

#define ff first
#define ss second
#define mp make_pair
#define MOD 1000000007
#define oo 1000000000000000000

using namespace std;

int main(){

    int a, b;

    scanf("%d %d", &a, &b);

    if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) printf("Possible\n");
    else printf("Impossible\n");



    return 0;
}


Measured memory_bytes: 384
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=t.in(),r=t.in(),n=new Array(e),i=0;i<e;i++)n[i]=t.inr();for(var o=new Array(r),s=0;s<r;s++)o[s]=t.inr();for(var u=0;u<e-r+1;u++)for(var c=0;c<e-r+1;c++){for(var f=!0,a=0;a<r;a++){for(var l=0;l<r;l++)if(o[a][l]!=n[u+a][c+l]){f=!1;break}if(!f)break}if(f)return void console.log("Yes")}console.log("No")}}]);

Measured memory_bytes: 7372
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
  ll n, k;
  cin >> n >> k;

  if(k % 2 == 0) {
    ll x, y;
    x=n/k;
    y=(n+k/2)/k;
    cout << x*x*x+y*y*y;
    return 0;
  } else {
    ll x;
    x = n/k;
    cout << x*x*x;
    return 0;
  }
}

Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	scanner.Scan()
	str := strings2.Split(scanner.Text(), " ")
	n, _ := strconv.Atoi(str[0])
	k, _ := strconv.Atoi(str[1])
	q, _ := strconv.Atoi(str[2])
	
	scores := make([]int, n)
	
	for i := 0; i < q; i++ {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		scores[a-1] += 1
	}
	
	for _, s := range scores {
		if s+k-q > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 3968
n,m=map(int,input().split())
h=list(map(int,input().split()))
c=[0 for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>=h[b-1]:
        c[b-1]+=1
    if h[b-1]>=h[a-1]:
        c[a-1]+=1
count=0
for i in range(n):
    if c[i]==0:
        count+=1
print(count)

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

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

//aを0とする

int kuniku(int i,int j){
    return 500005*i+j;
}

int main(){
    int n; cin >> n;
    string s; cin >> s;
    BinaryIndexedTree< int > bit(500005*31);
    for(int i=1;i<=n;i++){
        int c=s[i-1]-'a';
        bit.add(kuniku(c,i),1);
    }
    int q; cin >> q;
    vector<int> anss; //答え保存用
    for(int i=0;i<q;i++){
        int t,j; cin >> t >> j; 
        if(t==1){
            char c; cin >> c;
            bit.add(kuniku(s[j-1]-'a',j),-1);
            bit.add(kuniku(c-'a',j),1);
            s[j-1]=c;
            //cout << s << endl;
        }else if(t==2){
            int c;cin >> c;
            int ans=0;
            for(int i=0;i<30;i++){
                if(bit.sum(kuniku(i,c))-bit.sum(kuniku(i,j-1))>0) ans++; 
            }
            //cout << ans << endl;
            anss.push_back(ans);
        }
    }
    for(int i=0;i<anss.size();i++){
        cout << anss[i] << endl;
    }
    return 0;
}

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

int main(){
  int A[100];

  for (int i = 0; i < 3; i++){
    cin >> A[i];
  }

  swap(A[0], A[1]);
  swap(A[0], A[2]);

  for (int i = 0; i < 3; i++){
    if (i != 0){
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;

  return 0;
}

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

#define rep(i, j, k) for(int i = (int) j; i < (int) k; ++i)
#define sz(x) ((int) (x).size())
#define ll long long
#define mp make_pair
#define pii pair<int, int >
#define fi first
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define zero(x) memset((x), (0), sizeof (x))
#define zerox(x, y) memset((x), (y), sizeof (x))

using namespace std;
const int N = 100100;

int p[N];
int n;

int main()
{
#ifdef PIT
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif //PIT

	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	rep(i, 1, 1+n) cin >> p[i];
	// vector<int > id; 
	// id.clear();
	int t = 0;
	rep(i, 1, n) if(i == p[i]) {
		swap(p[i], p[i+1]);
		++t;
	}
	if(n == p[n]) ++t;
	cout << t << endl;
	
#ifdef PIT
flush(cout);
cerr << endl << "Time: " << (clock() / double(CLOCKS_PER_SEC)) << endl;
#endif //PIT
	return 0;
}


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

int main(){
  int t;
  std::cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    std::cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) std::cin >> v[i];
    int maxi = 0, mini = 1e9;
    for (int i = 1; i < n; i++) {
      maxi = max(maxi, v[i] - v[i - 1]);
      mini = min(mini, v[i] - v[i - 1]);
    }
    std::cout << maxi << " " << -min(0, mini) << std::endl;
  }
  return 0;
}



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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main(){
    CININIT;
    int n;
    while(cin>>n){
        if(n==0) break;
        bool table[21][21];

        rep(i,21) rep(j,21) table[i][j]=false;
        for(int i=0;i<n;i++){
            int a,b;
            cin>>a>>b;
            table[a][b] = true;
        }

        int m;cin>>m;
        int x=10,y=10;
        int cnt=0;
        rep(i,m){
            char d;
            int l;
            cin>>d>>l;
            for(int j=0;j<l;j++){
                if(d=='N') y+=1;
                if(d=='E') x+=1;
                if(d=='S') y-=1;
                if(d=='W') x-=1;
                assert(x>=0 and x<=20 and y<=20 and y>=0);
                if(table[x][y]){
                    cnt++;
                    table[x][y]=false;
                }
            }
        }

        if(n==cnt){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3088
n = int(input())
A = [int(i) for i in input().split()]

B = []

for i, a in zip(range(1, n+1), A):
    B.append(a-i)

B.sort()
m = B[n//2]

ans = 0

for b in B:
    ans += abs(b-m)

print(ans)

Measured memory_bytes: 26180
import java.util.Random;
import java.util.Scanner;

public class Main {
	private static final int K = 26;
	private static Random rand = new Random(System.currentTimeMillis());

	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var d = sc.nextInt();
		var c = new int[K];
		var s = new int[d][K];
		for (var i = 0; i < K; i++) {
			c[i] = sc.nextInt();
		}
		for (var i = 0; i < d; i++) {
			for (var j = 0; j < K; j++) {
				s[i][j] = sc.nextInt();
			}
		}
		sc.close();

		var t = create(c, s, d);
		var max = score(c, s, t, d);
		for (var i = 0; i < 100; i++) {
			var t2 = create(c, s, d);
			var sum = score(c, s, t2, d);
			//System.out.println(sum);
			if (max < sum) {
				t = t2;
				max = sum;
			}
		}

		for (var i = 0; i < d; i++) {
			System.out.println(t[i]);
		}
	}

	private static int score(int[] c, int[][] s, int[] t, int d) {
		var sum = 0;
		var last = new int[K];
		for (var i = 0; i < d; i++) {
			var ti = t[i] - 1;
			sum += s[i][ti];
			last[ti] = i + 1;
			for (var j = 0; j < K; j++) {
				sum -= ((i + 1) - last[j]) * c[j];
			}
		}

		return sum;
	}

	private static int[] create(int[] c, int[][] s, int d) {
		var t = new int[d];
		var last = new int[K];
		for (var i = 0; i < d; i++) {
			var v = new int[K];
			for (var j = 0; j < K; j++) {
				v[j] = s[i][j] + (((i + 1) - last[j]) * c[j]);
			}
			t[i] = rand(v) + 1;
			last[t[i] - 1] = i + 1;
		}
		return t;
	}

	private static int rand(int[] v) {
		var sum = 0;
		for (var i = 0; i < v.length; i++) {
			sum += v[i];
		}
		var value = rand.nextInt(sum);
		var index = 0;
		sum = 0;
		for (var i = 0; i < v.length; i++) {
			sum += v[i];
			if (value < sum) {
				break;
			}
			index++;
		}
		//System.out.printf("%d %d %d\r\n", value, sum, index);
		return index;
	}
}


Measured memory_bytes: 51148
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    int N = sc.nextInt();
    sc.nextLine();
    String tmp = sc.nextLine();
    String Spl[] = tmp.split(" ");
    int A[] = new int[N];
    long ans = 0;
    for (int i=0;i<N;i++){
      A[i] = Integer.parseInt(Spl[i]);
      ans += A[i];
    }
    if (H<=ans){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }      
  }
}


Measured memory_bytes: 47532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string a;
int main(){
    //freopen("input.txt","r",stdin);
    cin>>a;
    string ans="";
    for(int i=0;i<a.size();i+=2)
        ans+=a[i];
    cout<<ans;
   
}
    

Measured memory_bytes: 512
fun main(args: Array<String>?) {
    fun Pair<Int, Int>.neighbor(): List<Pair<Int, Int>> {
        return listOf<Pair<Int, Int>>(first + 1 to second, first - 1 to second, first to second + 1, first to second - 1)
    }
    val (height, width) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(height){ readLine()!!.trim().split(' ').map(String::toInt)}
    val areas = (0 until height).flatMap{y -> (0 until width).map{x -> Pair(y, x)}}.sortedBy { state[it.first][it.second] }
    val memo = Array(height){Array(width){null as Pair<Int, Int>?} }
    var count = 0
    for (current in areas) {
        val neighbor = current.neighbor().filter{(i, j) -> i in 0 until height && j in 0 until width && state[current.first][current.second] > state[i][j] }.map{(i, j) -> memo[i][j] }
        if (neighbor.contains(null) || neighbor.distinct().size > 1) {
            ++count
        }else {
            memo[current.first][current.second] = neighbor.firstOrNull() ?: current
        }
    }
    println(count)
}


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

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

def main():
    M=10**9
    S=I()
    if S<=M:
        print(0,0,0,S,1,0)
    else:
        #座標の面積公式を移行して，右辺をMの倍数になるように調整
        x1y2=M-S%M
        if S%M==0:
            x1y2=0
        x1=x1y2
        y2=1
        x2=10**9
        y1=(S+x1y2)//M
        print(0,0,x1,y1,x2,y2)


main()


Measured memory_bytes: 38256
#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 dp[5500][5500];

int main() {
    int n;
    string s;
    cin >> n >> s;
    for (int i = n-1; i >= 0; i--) {
        for (int j = n-1; j >= 0; j--) {
            if (s[i] != s[j]) {
                dp[i][j] = 0;
            }
            else {
                dp[i][j] = dp[i+1][j+1] + 1;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            ans = max(min(dp[i][j], j-i), ans);
        }
    }
    cout << ans << endl;
}


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

int main(){
    int n=0, sum=0, ave=0;
    int a, b;
    while(scanf("%d,%d",&a,&b) > 0){
        n++;
        sum += a*b;
        ave += b;
    }
    ave = int(round(double(ave)/n));
    cout << sum << '\n' << ave << endl;
    return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int n, x, y;
int dist(int a, int b) {
    int res = b-a;
    res = min(res, abs(x-a)+abs(y-b)+1);
    res = min(res, abs(x-b)+abs(y-a)+1);
    return res;
}

int main() {
    cin >> n >> x >> y;
    --x;
    --y;

    int mx = n-y+x;
    map<int, int> mp;
    rep(i, n-1) {
        srep(j, i+1, n) {
            int d = dist(i, j);
            mp[d]++;
            // cout << i+1 << " " << j+1 << " " << d << endl;
        }
    }
    rep(i, n-1) {
        cout << mp[i+1] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int color[100010];
vector<pair<int,int>> G[100010];

void dfs(int i,int c){
  color[i]=c;
  
  for(auto u:G[i]){
    if(color[u.first]!=-1) continue;
    if(u.second%2==0) dfs(u.first,c);
    else dfs(u.first,1-c);
  }
}

int main(){
  int n;
  cin>>n;
   
  int u,v,w;
  rep(i,n-1){
    cin>>u>>v>>w;
    G[u].push_back({v,w});
    G[v].push_back({u,w});
  }
  
  rep(i,n+1) color[i]=-1;
  
  dfs(1,0);
  rep(i,n) cout<<color[i+1]<<endl;
  
  return 0;
}

Measured memory_bytes: 43520
def main():
    n, m = map(int, input().split())
    to = [0]*(n+1)
    h = [None] + list(map(int, input().split()))
    for _ in range(m):
        a, b = map(int, input().split())
        to[a] = max(to[a], h[b])
        to[b] = max(to[b], h[a])
    ans = 0
    for i in range(1, n+1):
        if h[i] > to[i]:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 20884
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    l=[0 for i in 1:n+1]
    l[1],l[2]=2,1
    for i in 3:n+1
        l[i]=l[i-1]+l[i-2]
    end
    println(l[n+1])
end
main()

Measured memory_bytes: 166420
# ABC106D - AtCoder Express 2
from itertools import accumulate as acc


def main():
    # 2D cumulative sum
    N, M, Q, *X = map(int, open(0).read().split())
    LR, PQ = X[: 2 * M], X[2 * M :]
    imos = [[0] * (N + 1) for _ in range(N + 1)]
    for l, r in zip(*[iter(LR)] * 2):
        imos[l][r] += 1
    imos = [list(acc(a[::-1]))[::-1] for a in zip(*[acc(a) for a in imos])]
    ans = []
    for p, q in zip(*[iter(PQ)] * 2):
        ans.append(imos[q][p])
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 57672
using System;
using System.Text;

namespace Atcoder
{
    class Program
    //diverta 2019 Programming Contest A - Consecutive Integers
    {
        private static void Main(string[] args)
        {
            var nk = Console.ReadLine()?.Split(' ');
            var n = int.Parse(nk[0]);
            var k = int.Parse(nk[1]);
            Console.WriteLine( n - k + 1);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(((abs(b-a)<=d) && (abs(c-b)<= d)) || abs(c-a) <=d)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
def solve():
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))
    a_line = []
    for i, i_cnt in enumerate(a):
        color = i+1
        for j in range(i_cnt):
            a_line.append(color)
    # wごとに区切ってlistに詰める
    ans = [['']*w for _ in range(h)]
    cur = 0
    for i in range(h):
        for j in range(w):
            ans[i][j] = str(a_line[cur])
            cur += 1
    for i in range(h):
        print(' '.join(ans[i] if i%2==0 else reversed(ans[i])))

solve()

Measured memory_bytes: 4084
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, M;

  std::cin >> N >> M;

  std::cout << ((100ULL * (N - M) + 1900ULL * M) << M) << std::endl;

  return 0;
}


Measured memory_bytes: 256
A, B = map(int, input().split())
def f(x):
    if x % 2 == 1:
        tmp = (x + 1) / 2
        if tmp % 2 == 0:
            return 0
        else:
            return 1
    else:
        return f(x-1) ^ x
print(f(A-1)^f(B))

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define INF 1000000009

class UnionFind {
private:
    int n;
    vector<int> par;
public:
    UnionFind(int n) : n(n), par(n, -1) {}

    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }

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

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x != y) {
            if (par[x] > par[y]) swap(x, y);
            par[x] += par[y];
            par[y] = x;
        }
    }

    int set_size(int x) { return -par[root(x)]; }

    int size() const { return n; }
};

int main() {
    int N, x, y;
    pii X[100000], Y[100000];
    cin >> N;
    REP(i, N) {
        cin >> x >> y;
        X[i] = {x, i};
        Y[i] = {y, i};
    }
    sort(X, X + N);
    sort(Y, Y + N);

    vector<pair<int, pii>> edges;
    REP(i, N - 1) {
        edges.push_back({X[i + 1].first - X[i].first, {X[i + 1].second, X[i].second}});
        edges.push_back({Y[i + 1].first - Y[i].first, {Y[i + 1].second, Y[i].second}});
    }
    sort(edges.begin(), edges.begin() + (N - 1) * 2);

    UnionFind uf(N);
    int cost = 0;
    REP(i, (N - 1) * 2) {
        auto e = edges[i];
        if (!uf.same(e.second.first, e.second.second)) {
            uf.unite(e.second.first, e.second.second);
            cost += e.first;
        }
        if (uf.set_size(0) == N) break;
    }
    cout << cost << endl;
    return 0;
}

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

class Main {
    private static boolean isRightTriangle(int a, int b, int c) {
        return a * a + b * b == c * c;
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (n-- > 0) {
            int[] triangle = new int[3];
            for (int i = 0; i < 3; i++) {
                triangle[i] = scanner.nextInt();
            }
            Arrays.sort(triangle);
            if (isRightTriangle(triangle[0], triangle[1], triangle[2])) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }

    public static void main(String... args) {
        solve();
    }
}

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

using namespace std;

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

    vector<int> vt(3, 0);
    for (auto c:s) vt[c - 'a']++;
    sort(vt.begin(), vt.end());

    if (vt[2] - vt[0] <= 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    D = int(input().strip())
    C = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    S = np.empty((D, 26), dtype=np.int32)
    for i in range(D):
        s = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
        S[i, :] = s[:]
    M = 10000
    RD = np.random.randint(D, size=(M, ), dtype=np.int32)
    RQ = np.random.randint(26, size=(M, ), dtype=np.int32)
    DQ = np.stack([RD, RQ]).T
    return D, C, S, M, DQ


@njit
def diff_satisfaction(C, S, d, p, last):
    """d日目にコンテストpを開催するときの、満足度の更新量を求める
    """
    v = 0
    for i in range(26):
        v -= C[i] * (d - last[i])
    v += C[p] * (d - last[p])
    v += S[d, p]
    return v


@njit
def change_schedule(D, C, S, T, d, q, cumsat):
    """d日目のコンテストをqに変更する
    """
    p = T[d]
    dp1, dq1 = -1, -1
    dp3, dq3 = D, D
    for i in range(0, d):
        if T[i] == p: 
            dp1 = i
        if T[i] == q:
            dq1 = i
    for i in range(D-1, d, -1):
        if T[i] == p:
            dp3 = i
        if T[i] == q:
            dq3 = i
    cumsat = cumsat - S[d, p] + S[d, q] - C[p] * (dp3-d) * (d-dp1) + C[q] * (dq3-d) * (d-dq1)
    return cumsat


@njit
def greedy(D, C, S):
    T = np.zeros(D, dtype=np.int32)
    last = -np.ones(26, dtype=np.int32)
    cumsat = 0
    for d in range(D):
        max_p = 0
        max_diff = -999999999

        # select contest greedily
        for p in range(26):
            diff = diff_satisfaction(C, S, d, p, last)
            if diff > max_diff:
                max_p = p
                max_diff = diff
        
        # update schedule
        cumsat += max_diff
        T[d] = max_p
        last[max_p] = d
    return cumsat, T


@njit
def solve(D, C, S, M, DQ):
    cumsat, T = greedy(D, C, S)
    for i in range(M):
        d, q = DQ[i, :]
        newsat = change_schedule(D, C, S, T, d, q, cumsat)
        if newsat > cumsat:
            cumsat = newsat
            T[d] = q
    for t in T:
        print(t+1)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main() {
    int N, M, X, Y, count1=0,count2=0, result=0;
    cin >> N >> M >> X >> Y;
    vector <int> x(N);
    vector <int> y(M);
    bool st1=false, st2=false;
    
    for(int i = 0; i < N; i++) cin >> x.at(i);
    for(int i = 0; i < M; i++) cin >> y.at(i);
    
    for(int Z = X+1; Z <= Y; Z++){
        for(int i = 0; i < x.size(); i++){
            if(x.at(i) < Z) count1 += 1;
            if(count1 == N) st1 = true;
            else st1 = false;
            }
        for(int i = 0; i < y.size(); i++){
            if(y.at(i) >= Z) count2 += 1;
            if(count2 == M) st2 = true;
            else st2 = false;
            }
        count1 = 0;
        count2 = 0;
        if(st1 && st2) result +=1;
        }
    
    if(result > 0) cout << "No War" << endl;
    else cout << "War" << endl;
}

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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	string s;
	cin >> s;
	int sum = 700;
	if (s[0] == 'o') {
		sum = sum + 100;
	}
	if (s[1] == 'o') {
		sum = sum + 100;
	}
	if (s[2] == 'o') {
		sum = sum + 100;
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int sx,sy,gx,gy;
int k;
bool bad[205][205];
int n,m;
int dp[205][205][6];
int dx[7]={0,1,1,0,-1,-1,0};
int dy[2][7]={{1,0,-1,-1,-1,0,0},{1,1,0,-1,0,1,0}};
int main(){
	cin>>sx>>sy>>gx>>gy;
	cin>>k;
	rep(i,k){
		int x,y; cin>>x>>y;
		bad[100+x][100+y] = 1;
	}
	cin>>n>>m;
	rep(i,n+105) rep(j,m+105) rep(b,6) dp[i][j][b] = INF;
	dp[100+sx][100+sy][0] = 0;
	priority_queue<P2,vector<P2>,greater<P2> >que;
	que.push(mp(mp(0,100+sx),mp(100+sy,0)));
	while(!que.empty()){
		P2 p = que.top(); que.pop();
		if(dp[p.fi.sc][p.sc.fi][p.sc.sc] != p.fi.fi) continue;
		int cd = (p.fi.sc-100) * (p.sc.fi-100) * p.sc.sc;
		cd = abs(cd);
		cd = (cd%6+6)%6;
		int f = p.fi.sc % 2;
		rep(k,7){
			int nx = p.fi.sc+dx[k];
			int ny = p.sc.fi+dy[f][k];
			int nz = (p.sc.sc+1)%6;
			if(abs(nx-100) <= n && abs(ny-100) <= m && dp[nx][ny][nz] > p.fi.fi+(k!=cd) && !bad[nx][ny]){
				dp[nx][ny][nz] = p.fi.fi+(k!=cd);
				que.push(mp( mp(dp[nx][ny][nz],nx),mp(ny,nz) ));
			}
		}
	}
	int ans = INF;
	rep(k,6) ans = min(ans,dp[gx+100][gy+100][k]);
	if(ans > 1e8) ans = -1;
	cout<<ans<<endl;
}


Measured memory_bytes: 4208
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        x: u64
    }

    let mut ret = 1;
    for b in 2..x+1 {
        for p in (2..).take_while(|&p| b.pow(p) <= x) {
            if x - ret > x - b.pow(p) {
                ret = b.pow(p);
            }
        }
    }
    println!("{}", ret);
}

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

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

    vector<vector<int64_t>> D(N, vector<int64_t>(2));
    for (int64_t i = 0; i < N; i++) {
        cin >> D[i][0] >> D[i][1];
    }

    bool ans = false;
    for (int64_t i = 2; i < N; i++) {
        bool ok = true;
        for (int64_t j = 0; j < 3; j++) {
            if (D[i - j][0] != D[i - j][1]) {
                ok = false;
            }
        }

        if (ok) {
            ans = true;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3628
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Ncan = 0
Ktmp = 0
for i in range(N):
    if(Ktmp + A[i] > K):
        break
    Ktmp += A[i]
    Ncan += 1

Mcan = 0
for i in range(M):
    if(Ktmp + B[i] > K):
        break
    Ktmp += B[i]
    Mcan += 1

ans = 0

while(1):
    while(1):
        if(Mcan >= M):
            break
        if(Ktmp + B[Mcan] > K):
            break
        Ktmp += B[Mcan]
        Mcan += 1
    anstmp = Ncan + Mcan
    ans = max(ans, anstmp)

    Ncan -= 1
    if(Ncan == -1):
        break
    Ktmp -= A[Ncan]

print(ans)

Measured memory_bytes: 40452