akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		String output = "";
		String[] sdata = input.split(" ");
		int[] idata = new int[3];
		boolean condition = true; // 入力された数値が条件範囲内かを確認するための変数
		int temp = 0; // 一時的にデータを保存しておく変数
		int number = 0; // 一時的にデータの要素番号を保存しておく変数

		for (int i = 0; i < sdata.length; i++) {
			idata[i] = Integer.parseInt(sdata[i]);
			if (idata[i] <= 0 || idata[i] > 10000) {
				condition = false;
				break;
			}
		}

		if (condition) {
			for (int i = 0; i < 3 - 1; i++) {
				temp = idata[i];
				number = i;
				for (int j = i + 1; j < 3; j++) {
					if (idata[j] < temp) {
						temp = idata[j];
						number = j;
					}
				}
				idata[number] = idata[i];
				idata[i] = temp;

			}

			output += "" + idata[0];

			for (int i = 1; i < 3; i++) {
				output += " " + idata[i];

			}
			System.out.println(output);
		}
	}

}



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

int main(){
  string S,T;
  cin>>S>>T;
  int A,B;
  cin>>A>>B;
  string U;
  cin>>U;
  if(S==U){
    A--;
  }
 else{
   B--;
 }
  cout<<A<<" "<<B<<endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    while (1)
    {
        string d[8];
        rep(i, 8)
        {
            cin >> d[i];
            if (cin.eof())
                return 0;
        }

        int st_x, st_y, ed_x, ed_y;
        rep(i, 8)
        {
            int flag = 0;
            rep(j, 8)
            {
                if (d[i][j] == '1')
                {
                    st_x = j, st_y = i;
                    flag = 1;
                    break;
                }
            }
            if (flag == 1)
                break;
        }
        rep(i, 8)
        {
            rep(j, 8)
            {
                if (d[i][j] == '1')
                {
                    ed_x = j, ed_y = i;
                }
            }
        }

        int dis_x = ed_x - st_x, dis_y = ed_y - st_y;

        if (dis_y == 0)
        {
            OP("C")
        }
        else if (dis_y == 1)
        {

            if (dis_x == 0)
                OP("G")
            if (dis_x == 1)
                OP("A")
            if (dis_x == 2)
                OP("E")
        }
        else if (dis_y == 2)
        {
            if (dis_x == -1)
                OP("D")
            if (dis_x == 1)
                OP("F")
        }
        else if (dis_y == 3)
        {
            OP("B")
        }
    }

    return 0;
}


Measured memory_bytes: 3140
program procon1
  integer :: N,K,J

  read(*,*) N,K
  if(mod(N,2).eq.0) then
     J=N/2
  else
     J=(N-1)/2+1
  endif
  if(J.lt.K) then
     write(*,'(a)') 'NO'
  else
     write(*,'(a)') 'YES'
  endif

end program procon1

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N,K;
    cin>>N>>K;
 
    vector<int>V(N);
    int i;
    for(i=0;i!=N;i++)
        cin>>V[i];
 
    int R,P,M;
    M = 0;
    for(R=0;R<=min(N,K);R++)
    {
        P = min(K-R,R);
        int l,r;
        for(l=0;l<=R;l++)
        {
            r = R-l;
 
            int m = 0;
            vector<int>Q;
            for(i=0;i<l;i++)
            {
                 Q.push_back(V[i]);
                 m += V[i];
            }
            for(i=N-1;i>=N-r;i--)
            {
                Q.push_back(V[i]);
                m += V[i];
            }
 
            sort(Q.begin(),Q.end());
            for(i=0;i<P && Q[i]<0;i++)
                m -= Q[i];
 
            M = max(m,M);
        }
    }
 
    cout<<M;
 
    return 0;
}

Measured memory_bytes: 256
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
import random
import bisect

#n,m,k = random.randint(1,1000),random.randint(1,1000),random.randint(1,10**8)
##a = [random.randint(1,10**5) for i in range(n)]
#b = [random.randint(1,10**5) for i in range(m)]

def solv():
	global a,b,n,m,k
	akari = [0]*(n+1)
	bkari = [0]*(m+1)
	for i in range(n):
		akari[i+1] = akari[i] + a[i]

	for i in range(m):
		bkari[i+1] = bkari[i] + b[i]

	def bin(ls,s,e,sikii):
		if e - s <= 1:
			return s
		mid = (s+e)//2
		if sikii < ls[mid]:return bin(ls,s,mid,sikii)
		else:return bin(ls,mid,e,sikii)

	ans = 0
	for i in range(n+1):
		time = akari[i]
		if k - time < 0:break
		#ref = bin(bkari,0,m+1,k-time)
		ref = bisect.bisect_right(bkari,k-time)
		ans = max(ans,ref+i)
	return ans

def karisolv():
	global a,b,n,m,k
	akari = [0]*(n+1)
	bkari = [0]*(m+1)
	for i in range(n):
		akari[i+1] = akari[i] + a[i]

	for i in range(m):
		bkari[i+1] = bkari[i] + b[i]

	ans = 0
	for i in range(n+1):
		time = akari[i]
		ref = 0
		if k - time <= 0:break
		cost = 0
		for j in range(m+1):
			if k - time - bkari[j] >= 0:
				ans = max(ans,j+i)
		
	return ans

def makedata():
	global a,b,n,m,k
	n,m,k = random.randint(1,10000),random.randint(1,10000),random.randint(1,1000000)
	a = [random.randint(1,10**5) for i in range(n)]
	b = [random.randint(1,10**5) for i in range(m)]
import sys
def main():
	for i in range(1000000):
		makedata()
		kari = karisolv()
		kotae = solv()
		if kari != kotae:
			print(n,m,k,a,b)
			sys.exit()
print(solv()-1)

Measured memory_bytes: 120528
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    vector<int> c(9);
    for(int i = 0;i < 9;++i)
        cin >> c.at(i);
    bool is = false;
    int a1,a2,a3,b1,b2,b3;
    for(int i = 0;i <= 100;++i)
    {
        a1 = i;
        b1 = c[0] - a1;
        b2 = c[1] - a1;
        b3 = c[2] - a1;
        a2 = c[3] - b1;
        a3 = c[6] - b1;
        if(a1 + b1 == c[0] && a1 + b2 == c[1] && a1 + b3 == c[2] && a2 + b1 == c[3] && a2 + b2 == c[4] && a2 + b3 == c[5] && a3 + b1 == c[6] && a3 + b2 == c[7] && a3 + b3 == c[8])
        {
            is = true;
        }
        
    } 
    cout << ( is ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int m,f,r;
	while(1){
		scanf("%d%d%d",&m,&f,&r);
		if((m == -1)&&(f == -1)&&(r == -1)){
			return 0;
		}else if((m == -1) || (f == -1)) printf("F\n");
		else if((m+f) >= 80) printf("A\n");
		else if(((m+f) >= 65) && ((m+f) < 80)) printf("B\n");
		else if(((m+f) >= 50) && ((m+f) < 65)) printf("C\n");
		else if(((m+f) >= 30) && ((m+f) < 50)){
			if(r >= 50 ){
				printf("C\n");
			} else{
				printf("D\n");
			}
		}
		else if(((m+f) < 30)) printf("F\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=k;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
const ll inf=1001001001001001;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}

int main(){
    int n,k;cin>>n>>k;
    ll ans=0,mi=inf;
    vi v(n);
    rep(i,n)cin>>v[i];
    rep(i,n)if(v[i]>0)ans+=v[i];
    vi sei(n);
    rep(i,n)if(v[i]>0)sei[i]=v[i];
    ll sum=0;
    rep(i,k)sum+=sei[i];
    REP(i,k,n){
        chmin(mi,sum);
        sum-=sei[i-k];
        sum+=sei[i];
    }
    chmin(mi,sum);
    sei=vi(n);
    rep(i,n)if(v[i]<0)sei[i]=-v[i];
    sum=0;
    rep(i,k)sum+=sei[i];
    REP(i,k,n){
        chmin(mi,sum);
        sum-=sei[i-k];
        sum+=sei[i];
    }
    chmin(mi,sum);
    out(ans-mi);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n,k;
  cin>>n>>k;
  bool flag=true;
  double border=k/2.0;
  while(flag)
  {
    if(n>border)
    {
      ll m=abs(n-k);
      ll diff=abs(n-m);
      n%=diff;
    }
    else flag=false;
  }
  cout<<n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int s,w;
    cin >> s >> w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }
    else cout<<"safe"<<endl;
}
    



Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
    long sum = 0, minsum = -1;
    int n; scanf("%d", &n);
    int x[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    int min = x[0], max = x[0];
    for(int i = 1; i < n; i++){
        if(x[i] < min) min = x[i];
        if(x[i] > max) max = x[i];
    }
    for(int p = min; p <= max; p++){
        for(int i = 0; i < n; i++){
            sum += (x[i] - p)*(x[i] - p);
        }
        if(minsum == -1) minsum = sum;
        if(minsum > sum) minsum = sum;
        sum = 0;
    }
    printf("%d\n", minsum);
    return 0;
}

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

int main(int argc, char const *argv[]) {
  int A, B, C;
   std::cin >> A >> B >> C;
   if(B/A > C){
     std::cout << C << '\n';
   }else{
     std::cout << B/A << '\n';
   }
  return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}

int main(){
int N,M;
cin>>N>>M;
float temp = 1.0 / (4.0*M);
int c = 0, total = 0;
vector<int> v(N);
for(auto& x: v) {cin>>x; total += x;}
sort(all(v),greater<int>());
temp *= total;
for(auto x: v) {
    if(x>=temp) {c++;}
    if(c==M) {cout<<"Yes"<<endl;return 0;}
}
cout<<"No"<<endl;
return 0;
}




Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
D = LI()

ans = 0

for i, d in enumerate(D):
    for j in range(i + 1, N):
        ans += (d * D[j])

print(ans)

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

int main (){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d){
  cout << "Left" << endl;
  }
  else if(a + b == c + d){
    cout << "Balanced"<< endl;
  }
  else {
    cout << "Right" << endl;
  }
}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  int cnt[100001] = {};
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    cnt[a]++;
  }

  int ans = 0; //出現する数の個数
  int s = 0;//2個以上偶数個出現する数の個数
  for(int i=0;i<=100000;i++){
    if(cnt[i]>=2 && cnt[i]%2==0) s++;
    if(cnt[i]>0) ans++;
  }

  if(s%2==0) cout << ans << endl;
  else cout << ans - 1 << endl;

  return 0;  
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e9;
typedef pair<int, int> pi;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, m;
    cin >> n >> m;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        if (a * a + b * b <= m * m) {
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
typedef long long ll;
int main()
{
    int h, w;
    cin >> h >> w;
    char C[h + 10][w + 10];
    rep(i, 0, h)
    {
        rep(j, 0, w) cin >> C[i][j];
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << C[i][j];
        }
        cout << endl;
        for (int j = 0; j < w; j++)
        {
            cout << C[i][j];
        }
        cout<<endl;
    }

}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
const int N=110;
char a[N][20],b[N][20];
int main(){
	int n,m;
	scanf("%d\n",&n);
	for (int i=1;i<=n;++i) cin>>a[i];
	scanf("%d\n",&m);
	for (int i=1;i<=m;++i) cin>>b[i];
	int ans=0;
	for (int i=1;i<=n;++i){
		int cnt=0;
		for (int j=1;j<=n;++j){
			if (strcmp(a[i],a[j])==0) ++cnt;
		}
		for (int j=1;j<=m;++j){
			if (strcmp(a[i],b[j])==0) --cnt;
		}
		ans=max(ans,cnt);
	}
	printf("%d\n",ans);
	return 0;
}

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

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

int main() {
    int a1,a2,a3; cin >> a1 >> a2 >> a3;
    cout << max(a1, max(a2, a3)) - min(a1, min(a2, a3)) << endl;
}

Measured memory_bytes: 256
public class Main{

  public static void main(String[] a)
  {
    for (int i = 1;i < 10 ; i++ ) {
      for (int j = 1;j< 10 ;j++ ) {
        System.out.println(i+"x"+j+"="+(i*j));
      }
      
    }
  }
}

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

std_map = [list(map(int, input().split())) for i in range(n)]
ch_map = [list(map(int, input().split())) for i in range(m)]

results = [[] for i in range(n)]

for std in std_map:
    print(min(enumerate([abs(std[0] - ch[0]) + abs(std[1] - ch[1]) for ch in ch_map], 1), key=lambda x: x[1])[0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 1, 0, -1, -1, -1, 0, 1};
vector<int> dx = {0, 1, 1, 1, 0, -1, -1, -1};
int main(){
  while (1){
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0){
      break;
    }
    vector<vector<int>> c(h + 2, vector<int>(w + 2, 0));
    for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
        cin >> c[i][j];
      }
    }
    int ans = 0;
    vector<vector<bool>> used(h + 2, vector<bool>(w + 2, false));
    for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
        if (!used[i][j] && c[i][j] == 1){
          used[i][j] = true;
          ans++;
          queue<pair<int, int>> Q;
          Q.push(make_pair(i, j));
          while (!Q.empty()){
            int y = Q.front().first;
            int x = Q.front().second;
            Q.pop();
            for (int k = 0; k < 8; k++){
              int y2 = y + dy[k];
              int x2 = x + dx[k];
              if (!used[y2][x2] && c[y2][x2] == 1){
                used[y2][x2] = true;
                Q.push(make_pair(y2, x2));
              }
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    if( b - a == c - b ) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
string s;
int main()
{
	cin >> s;
	if(s[5] > '0' ){
		cout << "TBD";
	}else if(s[6] > '4'){
		cout << "TBD";
	}else{
		cout << "Heisei";
	}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long
int n,k;
string s;
int main(){
  cin>>n>>k>>s;
  k--;
  if(s[k]=='A')s[k]='a';
  if(s[k]=='B')s[k]='b';
  if(s[k]=='C')s[k]='c';
  cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
def I(): return int(input())
X = I()
kouho = []
for i in range(1000):
    kouho.append(i**5)
for a in kouho:
    for b in kouho:
        if a<b:
            continue
        if a+b==X:
            print(int(a**(1/5)),int(-b**(1/5)))
            break
        if a-b==X:
            print(int(a**(1/5)),int(b**(1/5)))
            break


Measured memory_bytes: 9452
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=998244353;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

const ll NUM=3010;
auto dp=make_vec<ll>(NUM,NUM,2);

int main(){
    ll N,S;
    cin>>N>>S;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];

    
    REP(i,NUM) REP(j,NUM) REP(k,2) dp[i][j][k]=0;
    dp[0][0][1]=1;
    REP(i,N){
        dp[i+1][0][0]=dp[i][0][0]+dp[i][0][1];
        dp[i+1][0][1]=dp[i][0][1]+1;
        
    }
    REP(i,N){
        REP2(j,1,S+1){
            dp[i+1][j][0]=dp[i][j][0]+dp[i][j][1];
            dp[i+1][j][1]=dp[i][j][1];
            if(j-A[i]>=0) dp[i+1][j][1]+=dp[i][j-A[i]][1];
            dp[i+1][j][0]%=MOD;
            dp[i+1][j][1]%=MOD;
        }
    }

    cout<<(dp[N][S][0]+dp[N][S][1])%MOD<<endl;

}

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

typedef long long ll;
typedef unsigned long long ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 3e3 + 5;
const int mod = 1e9 + 7;
using namespace std;
int n, m;
int dp[N][N];
string s, ss;

int solve(int i, int j) {
    if (i == n || j == m) return 0;
    int &ret = dp[i][j];
    if (~ret) return ret;
    if (s[i] == ss[j]) return ret = 1 + solve(i + 1, j + 1);
    return ret = max(solve(i + 1, j), solve(i, j + 1));
}

int main() {
    IO;
    cin >> s >> ss;
    n = (int) s.size();
    m = (int) ss.size();
    //cout<<s<<endl<<ss<<endl;
    memset(dp, -1, sizeof(dp));
    solve(0, 0);
    int i = 0, j = 0;
    string ans = "";
    while (i < n and j < m) {
        if (s[i] == ss[j]) {
            ans += s[i];
            i++, j++;
        } else if (dp[i + 1][j] > dp[i][j + 1])
            i++;
        else j++;
    }
    cout << ans;


}

Measured memory_bytes: 35840
#include <iostream>

using namespace std;

int main(void)
{
    int stones_cnt;
    string stones;

    cin >> stones_cnt;
    cin >> stones;
    
    int red_cnt = 0;
    for(int i = 0; i < stones_cnt; i++){
        if(stones[i] == 'R'){
            red_cnt += 1;
        }
    }

    int left_red_cnt = 0;
    for(int i = 0; i < red_cnt; i++){
        if(stones[i] == 'R'){
            left_red_cnt += 1;
        }
    }

    cout << red_cnt - left_red_cnt << endl;

    return 0;
}

Measured memory_bytes: 3740
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;


int A[100010];
ll B[100010];
int main() {
	int N; cin >> N;
	REP(i, N) {
		cin >> A[i];
	}
	SORT(A, N);

	int mid = N/ 2;
	B[mid] = A[0];
	if (N % 2 == 1) {
		REP(i, mid) {
			if (i % 2 == 0) {
				B[mid - i - 1] = A[N - i - 1];
				B[mid + i + 1] = A[N - 1 - i - 1];
			}
			if (i % 2 == 1) {
				B[mid - i - 1] = A[i];
				B[mid + i + 1] = A[i+1];
			}
		}
	}
	if (N % 2 == 0) {
		REP(i, mid) {
			if (i % 2 == 0) {
				B[mid - i - 1] = A[N - i - 1];
				B[mid + i + 1] = A[N - 1 - i - 1];
			}
			if (i % 2 == 1) {
				B[mid - i - 1] = A[i];
				B[mid + i + 1] = A[i + 1];
			}
		}
	}

	ll ans1 = 0;
	REP(i, N - 1) {
		ans1 += abs(B[i] - B[i + 1]);
	}

	REVERSE(A, N);
	B[mid] = A[0];
	if (N % 2 == 1) {
		REP(i, mid) {
			if (i % 2 == 0) {
				B[mid - i - 1] = A[N - i - 1];
				B[mid + i + 1] = A[N - 1 - i - 1];
			}
			if (i % 2 == 1) {
				B[mid - i - 1] = A[i];
				B[mid + i + 1] = A[i + 1];
			}
		}
	}
	if (N % 2 == 0) {
		REP(i, mid) {
			if (i % 2 == 0) {
				B[mid - i - 1] = A[N - i - 1];
				B[mid + i + 1] = A[N - 1 - i - 1];
			}
			if (i % 2 == 1) {
				B[mid - i - 1] = A[i];
				B[mid + i + 1] = A[i + 1];
			}
		}
	}


	ll ans2 = 0;
	REP(i, N - 1) {
		ans2 += abs(B[i] - B[i + 1]);
	}
	cout << max(ans1, ans2) << endl;
}




Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

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

  unordered_map<string, int> mp;

  mp["SUN"] = 0;
  mp["MON"] = 1;
  mp["TUE"] = 2;
  mp["WED"] = 3;
  mp["THU"] = 4;
  mp["FRI"] = 5;
  mp["SAT"] = 6;

  cout << 7  - mp[s] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	for(int i = s.size() - t.size(); i >= 0; i--){
		bool ok = true;
		rep(j,t.size()){
			if(!(s.at(i + j) == '?' || s.at(i + j) == t.at(j))) ok = false;
		}
		if(ok){
			rep(j,t.size()){
				s.at(i + j) = t.at(j);
			}
			rep(i,s.size()){
				if(s.at(i) == '?') cout << 'a';
				else cout << s.at(i);
			}
			cout << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
public class Main
{
    public static void main(String[] args)
    {
	for(int i = 1; i <= 9; ++i){
	    for(int j = 1; j <=9 ; ++j){
		System.out.println( i + "x" + j + "=" + (i * j) );
	    }
	}
    }
}

Measured memory_bytes: 16856
# -*- coding: utf-8 -*-
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0, abs(h[0] - h[1])]
    for i in range(2, n):
        min_cost = float('inf')
        for j in range(max(i - k, 0), i):
            cost = dp[j] + abs(h[j] - h[i])
            if min_cost > cost:
                min_cost = cost
        dp.append(min_cost)


    print(dp[-1])


if __name__ == "__main__":
    main()


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

int main() {
  int a, b,c,d;
  cin >> a >> b >> c >> d;

  if (a+b<c+d) {
    cout << "Right" << endl;
  }else if (a+b>c+d) {
      cout << "Left" << endl;
    }else{ cout << "Balanced" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int ans=1;
    for (int i=0; i<n; i++) {
        if(ans*2<ans+k){
            ans*=2;
        }
        else{
            ans+=k;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
	int n;
	cin >> n;
	string s;
	int c = 0;
	int d = 0;
	cin >> s;
	rep(i, n) {
		if (s.at(i) == 'R') {
			c++;
		}
	}
	rep(j, c) {
		if (s.at(j) != 'R')
			d++;
	}
	cout << d << endl;
	return 0;
}

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

#define ll long long 
int main() {
  
  ll N, K;
  cin >> N >> K;
  
  if (K % 2) {
    cout << (N/K) * (N/K) * (N/K) << endl;
  } else {
    ll k = K / 2;
    cout << (N/K) * (N/K) * (N/K) + (N/k - N/K) * (N/k - N/K) * (N/k - N/K) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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


    int ans = 0;

    int n = s.size();
    rep(i,n)if(s[i] != t[i])ans++;

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




Measured memory_bytes: 3860
class Segtree():
    def __init__(self, n):
        self.num = 1 << (n - 1).bit_length()
        self.tree = [0] * 2 * self.num
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = max(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = max(self.tree[k], self.tree[k ^ 1])
            k >>= 1

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


n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]

a_max = max(a) + 1
seg_dp = Segtree(a_max)
for ai in a:
    tmp = seg_dp.query(max(ai - k, 0), min(ai + k + 1, a_max))
    seg_dp.update(ai, tmp + 1)
print(max(seg_dp.tree))


Measured memory_bytes: 143916
#include<stdio.h>
#define MOD 1000000007;
int main(){
	char c;
	long long int dp[5]={0,1,0,0,0};
	int j;

	while((c=getchar())!='\n')
		if(c=='?'){
			for(j=4; j>0;j--){
				dp[j]=(dp[j]*3+dp[j-1])%MOD;
			}
		}else{
			dp[c-'A'+2]=(dp[c-'A'+2]+dp[c-'A'+1])%MOD;
		}
	printf("%lld\n", dp[4]);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int Cast(char);

int main(){
  int i, n;
  char c;
  string str;
  string::iterator iter;

  while(cin >> str){
    iter = str.begin();

    while(iter != str.end()){
      if(*iter == '@'){
	n = Cast(*(iter+1));
	c = *(iter+2);
	iter = str.erase(iter, iter+3);

	for(i=0; i<n; ++i)
	  iter = str.insert(iter, c);
      }

      ++iter;
    }
    cout << str << endl;
  }

  return 0;
}

int Cast(char c){
  int x;
  x = c - 48;
  return x;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max =0;
		int i = 0;

		while(max <= n) {
			i++;
			max = i*i;
			if(max > n) {
				i--;
			}
		}

		System.out.println(i*i);
	}
}

Measured memory_bytes: 23124
import itertools
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5) #ルートn以上で割れることはない
    data = [i + 1 for i in range(2, n, 2)] #最初から3スタートの奇数にしておく
    while True:
        p = data[0]
        if limit < p: #ここでイコールが入るとlimitが素数の時にlimit^2が残ってダメ。
            return prime + data
        prime.append(p) #ここで一番最初に取り出した素数を加える。
        data = [e for e in data if e % p != 0] #残りでその素数で割れない数字を取得。

Sosu = get_sieve_of_eratosthenes(100)
#print(Sosu)
N = int(input())
limit = 1
for i in range(N):
  limit *= i+1
ans = 0
A = [0]*len(Sosu)
for i in range(1,N+1):
  now = i*1
  for j in range(len(Sosu)):
    while now%Sosu[j] == 0:
      A[j] += 1
      now //= Sosu[j]
    if now == 1:
      break
#print(A)
ans = 0
for i in A:
  if i >= 74:
    ans +=1
T = list(itertools.permutations(A,2)) #順列
for L in T:
  first,second = L
  if first >= 4 and second >= 14:
    ans += 1
  if first >= 2 and second >= 24:
    ans += 1
T = list(itertools.permutations(A,3)) #順列
#print(T)
temp = 0
for L in T:
  first,second,third = L
  if first >= 2 and second >= 4 and third >= 4:
    temp += 1
temp = temp//2
ans += temp
print(ans)

Measured memory_bytes: 69648
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<numeric>
#include<stdio.h>

using std::cout;
using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

#define INF 999999999;
#define MOD 1000000007

using ulli = unsigned long long int;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

ulli N;
vector<ulli> X;

int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
    
    cin >> N;
    ulli inp;
    for(ulli i = 0; i < N; i++){
        cin >> inp;
        X.push_back(inp);
    }
    vector<ulli> Y = X;
    sort(Y.begin(), Y.end());
    for(int i = 0; i < N; i++){
        if(Y[N/2-1] >= X[i]) cout << Y[N/2] << "\n";
        else if(Y[N/2] <= X[i]) cout << Y[N/2-1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 5488
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun main(args: Array<String>) {
    val (N, K, Q) = readIntList()
    val A = Array(Q) {
        readInt()
    }
    val point = Array(N) { 0 }
    for (i in A) {
        point[i-1]++
    }
    for (i in 0 until N) {
        println(
            if (K - Q + point[i] > 0) {
                "Yes"
            } else {
                "No"
            }
        )
    }
}

Measured memory_bytes: 48024
#include <bits/stdc++.h>
  #pragma GCC target ("avx2")
  #pragma GCC optimization ("O3")
  #pragma GCC optimization ("unroll-loops")
  using ll = long long;

  #define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
  #define br cout<< "\n";
  #define endl "\n"
  #define vi vector<int>
  #define vii vector<ll>
  #define pb push_back
  #define eb emplace_back
  #define mp make_pair
  #define lb lower_bound
  #define ub upper_bound
  #define rep(i,a,b) for(ll i=a; i<=b;i++)
  #define all(v) begin(v),end(v)
  #define minv(a) *min_element(all(a))
  #define maxv(a) *max_element(all(a))
  #define outputv(a) for(auto i:a) cout<<i<<" ";br;
  #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  #define outputvp(a) for(auto j:a) {cout<<j.first<<" " << j.second << ",",br;}
  using namespace std;

  ll mod = 1e9+7;
  ll inf = 1000000000000000000;

  ll power( ll base, ll power, ll mod);
  ll bc(ll n, ll k);

  void inout(){
      #ifndef ONLINE_JUDGE
          // for getting input from input.txt
          freopen("/home/logan/contest/ongoing/input.txt", "r", stdin);
          // for writing output to output.txt
          freopen("/home/logan/contest/ongoing/output.txt", "w", stdout);
      #endif
  }



 




  int main(){
    FastIO
    //inout();
    string s; cin >> s;
    cout << s.substr(0,3) << endl;
    
 


    return 0;
  }
 

 ll power( ll base, ll power, ll mod){
      ll res = 1;
      while( power ){
        if(power%2) res= (res*base)%mod, power--;
        else base= (base * base)%mod, power/=2;
      }

      return res;
  }

  ll bc(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
  
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 



Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
 
int main()
{
  int max = 0, curr, slen, tlen, i, j;
  char s[1001], t[1001];
  scanf("%s\n%s", s, t);
  slen = strlen(s);
  tlen = strlen(t);
  for(i = 0; i < (slen - tlen + 1); i++)
  {
  	curr = 0;
  	for(j = 0; j < tlen; j++)
  	{
  		if(s[i + j] == t[j]) ++curr;
  	}
  	if(curr > max) max = curr;
  }
  printf("%d", tlen - max);
  return 0;
}

Measured memory_bytes: 1728
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.next().toInt()
    val m = sc.next().toInt()
    val aList = (0 until n).map { sc.next() }
    val bList = (0 until m).map { sc.next() }
    println(problem54b(aList, bList))
}

fun problem54b(aList:List<String>, bList:List<String>): String {
    val bListY = bList.size
    val bListX = bList[0].length
    aList.forEachIndexed { i, s ->
        if (i + bListY - 1 > aList.size - 1) return@forEachIndexed
        (0 until aList[0].length).forEach { j ->
            if (j + bListX > aList[0].length) return@forEach
            val subSquare = aList.drop(i).map { it.substring(j, j + bListX) }.take(bListY)
            if (subSquare == bList) return "Yes"
        }
    }
    return "No"
}

Measured memory_bytes: 34464
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int bfs(int sy,int sx,int n);
int d[22][22][22];
// 構造体
struct P{
  int y;
  int x;
  int c;
  P(int y,int x,int c):y(y),x(x),c(c){}
};
int dy[]={0,0,0,1,-1,-1,-1,1,1};  //    スプリンクラーの
int dx[]={0,1,-1,0,0,-1,1,-1,1};  // 　　座標
int ddy[]={-2,-2,-2,-1,0,1,2,2,2,1,0,-1};
int ddx[]={-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
int main(){
  int sy,sx,y,x;
  int n;
  while(1){
    memset( d , 0 , sizeof(d) );
    cin >> sx >> sy;
    if(!sy && !sx)break;
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> x >> y;
      for(int j=0;j<9;j++){
        int ty = y + dy[j];
        int tx = x + dx[j];
        if(0<=ty && ty<10 && 0<=tx && tx<10){
          d[ty][tx][i] = 1;
        }
      }
    }
    int ret = bfs( sy  , sx  , n);
    if(ret == 1){
      cout << "OK" << endl;
    }else {
      cout << "NA" << endl;
    }
  }
}
int bfs(int sy,int sx,int n){
  queue<P> que;
  que.push( P(sy,sx,0) );
  
  while(!que.empty()){
    P p = que.front();que.pop();
    if(p.c == n){
      return 1;
    }
    for(int i=0;i<12;i++){
      int ty = p.y + ddy[i];
      int tx = p.x + ddx[i];
      if(0<=ty && ty<10 && 0<=tx && tx<10){
        if(d[ty][tx][p.c] == 1){
          que.push( P( ty , tx , p.c + 1 ) );
        }
      }
    }
  }
  return -1;
}

Measured memory_bytes: 1256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = (n - 1); i >= 0; i--)
#define PI 3.141592653589793

using namespace std;
using ll = long long;

int to[200000];

int main() {

	int n;
	ll xo;
	cin >> n;
	vector<ll> a(n);
	 rep(i, n) {
		 cin >> a[i];
		 if (i == 0)xo = a[i];
		 else xo ^= a[i];
	 }

	 rep(i, n) {
		 ll ans = xo ^ a[i];
		 cout << ans << endl;
	 }
	return 0;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<P>> vvp;
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 MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> st(26,set<int>({MAX}));
  
  rep(i,n){
    st[s[i]-'a'].insert(i);
  }
  
  while(q--){
    int type; cin >> type;
    if(type==1){
      int idx; char nc;
      cin >> idx >> nc;
      idx--;
      int pc=s[idx];
      st[pc-'a'].erase(idx);
      st[nc-'a'].insert(idx);
      s[idx]=nc;
    }
    else{
      int l,r;
      cin >> l >> r;
      l--;
      int cnt=0;
      rep(i,26){
        if(st[i].empty())continue;
        int lidx=*st[i].lower_bound(l);
        int ridx=*st[i].lower_bound(r);
        if(ridx>lidx)cnt++;
      }
      cout << cnt << endl;
    }
  }
  
  
  return 0;     
}


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

int main() {
	int n, a;
	vector<int> A;
	vector<vector<int>> AA;
	cin >> n;
	bool check[100] = { 1 };
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a;
			A.push_back(a);
		}
		AA.push_back(A); A.clear();
	}
	for (int i = 0; i < AA.size(); i++) {
		int b = 0, c = 0; check[i] = 1;
		for (int j = 0; j < AA[i].size(); j++) {
			if (b >= c) {
				if (AA[i][j] > b)b = AA[i][j];
				else {
					if (AA[i][j] > c)c = AA[i][j];
					else {
						check[i] = 0; break;
					}
				}
			}
			else {
				if (AA[i][j] > c)c = AA[i][j];
				else {
					if (AA[i][j] > b)b = AA[i][j];
					else {
						check[i] = 0; break;
					}
				}
			}
		}
	}
	for (int i = 0; i < AA.size(); i++) {
		if (check[i])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int h, w;

int bfs(vector<string>& maze, int i, int j) {
	queue<pair<int, int>> q;
	q.push({i, j});
	int ans = -1;
	while (!q.empty()) {
		ans ++;
		int x = q.size();
		while (x--) {
			pair<int, int> cor = q.front();
			if (cor.first+1<h && maze[cor.first+1][cor.second]=='.') {
				maze[cor.first+1][cor.second] = '#';
				q.push({cor.first+1, cor.second});
			}
			if (cor.first-1>=0 && maze[cor.first-1][cor.second]=='.') {
				maze[cor.first-1][cor.second] = '#';
				q.push({cor.first-1, cor.second});
			}
			if (cor.second-1>=0 && maze[cor.first][cor.second-1]=='.') {
				maze[cor.first][cor.second-1] = '#';
				q.push({cor.first, cor.second-1});
			}
			if (cor.second+1<w && maze[cor.first][cor.second+1]=='.') {
				maze[cor.first][cor.second+1] = '#';
				q.push({cor.first, cor.second+1});
			}
			q.pop();
		}
	}
	return ans;
}

int main() {
	/*#ifndef Judge
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/

	cin >> h >> w;
	vector<string> maze;

	for (int i=0; i<h; i++) {
		string s;
		for (int j=0; j<w; j++) {
			char c; cin >> c;
			s.push_back(c);
		}
		maze.push_back(s);
	}

	int mx = -1;

	for (int i=0; i<h; i++) {
		for (int j=0; j<w; j++) {
			if (maze[i][j] == '.') {
				vector<string> m = maze;
				m[i][j] = '#';
				int sqr = bfs(m, i, j);
				if (sqr > mx) mx = sqr;
			}
		}
	}

	cout << mx << '\n';
	return 0;
}

Measured memory_bytes: 256
/**

F(i,W) = max( include ith item , exclude ith item )

Here ,
include ith item = F(i-1,W-w[i]) + v[i]
exclude ith item = F(i-1,W)

Base case:

F(i,W<0)     = INT_MIN
F(i<=0,W==0) = 0

**/

/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>using indexed_set = tree<TIn, null_type, less<TIn>,rb_tree_tag, tree_order_statistics_node_update>;

/**

PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

**/

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

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 1e2+7;
const int nmax2 = 1e5+7;
const LL LINF = 1e17;

template <class T>
string to_str(T x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

int n,MAX_WEIGHT;

LL w[nmax];
LL v[nmax];
LL dp[nmax][nmax2];

//LL solve(int pos,int W) /** maximum value to get using maximum weight W **/
//{
//    if(W<0) return INT_MIN; /** if anytime W<0 , not possible **/
//    if(W==0) return 0; /** if anytime W=0 , OK . return 0 **/
//
//    if(pos==0 && W>0) return 0; /** Done with n items , still W left , OK . return 0 **/
//
//    LL &ret = dp[pos][W];
//    if(ret!=-1) return ret;
//
//    LL inc = solve(pos-1,W-w[pos]) + v[pos];
//    LL exc = solve(pos-1,W);
//
//    return ret = max(inc,exc);
//}

LL solve(int pos,int W) /** maximum value to get using maximum weight W **/
{
    if(W>MAX_WEIGHT) return INT_MIN;

    if(pos>n)
    {
        return W<=MAX_WEIGHT ? 0 : INT_MIN;
    }

    LL &ret = dp[pos][W];
    if(ret!=-1) return ret;

    LL inc = solve(pos+1,W+w[pos]) + v[pos];
    LL exc = solve(pos+1,W);

    return ret = max(inc,exc);
}

int main()
{
    optimizeIO();

    cin>>n>>MAX_WEIGHT;

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

    memset(dp,-1,sizeof dp);

    cout<<solve(0,0)<<endl;

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




Measured memory_bytes: 87228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T>
void chmax(T &a, T b) {if (a < b) a = b;} 

ll dp[110][10010];

int main(int argc, char **argv)
{
	ll N, W; cin >> N >> W;
	vector<ll> value(N), weight(N);
	for (ll i = 0; i < N; ++i) cin >> value[i] >> weight[i];

	for (ll i = 0; i < N; ++i)
	{
		for (ll w = 0; w <= W; ++w)
		{
			chmax(dp[i+1][w], dp[i][w]);
			if (w-weight[i]>=0)chmax(dp[i+1][w], dp[i+1][w-weight[i]]+value[i]);
		}
	}
	std::cout << dp[N][W] << std::endl;
}



Measured memory_bytes: 10924
def main():
    A1, A2, A3 = map(int, input().split())
    cand = [abs(A1-A2) + abs(A2-A3), abs(A1-A3)+abs(A3-A2), abs(A2-A1)+abs(A1-A3)]
    return min(cand)

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 2940
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;
//再帰関数による深さ優先探索
void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;//訪問完了
}

void dfs(){
  int u;
  //初期化
  for(u=0;u<n;u++)color[u]=WHITE;
  tt=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE)dfs_visit(u);
  }
  for(u=0;u<n;u++){
  printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  //隣接行列を作る
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}



Measured memory_bytes: 2108