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

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

  private static void solve(int N) {
    int ret = 0;
    for (int i = 1; i <= N; i++) {
      if (i % 2 == 0)
        continue;
      int count = 0;
      for (int j = 1; j <= i; j++) {
        if (i % j == 0)
          count++;
      }
      if (count == 8)
        ret++;
    }
    System.out.println(ret);
  }
}


Measured memory_bytes: 35816
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        k:i64,x:i64,
    }
    // x+k-1
    // x-k+1
    for p in x - k + 1..=x + k - 1 {
        println!("{}", p);
    }
}


Measured memory_bytes: 2152
N = int(input())
W = [int(e) for e in input().split()]

_ = sum(W)
ans = 0
Y = 100 ** 100
for i in range(N - 1):
    ans += W[i]
    _ -= W[i]
    X = abs(ans - _)
    if Y > X:
        Y = X
print(Y)

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

double xa, ya, xb, yb, xc, yc, xp, yp, x, y, z;
double m(double a, double b, double c, double d) {
	return a*d - b*c;
}
int main() {
	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &xa, &ya, &xb, &yb, &xc, &yc, &xp, &yp) != EOF) {
		x = m(xp-xa, yp-ya, xb-xa, yb-ya);
		y = m(xp-xb, yp-yb, xc-xb, yc-yb);
		z = m(xp-xc, yp-yc, xa-xc, ya-yc);
		if ((x<0 && y<0 && z<0) || (x>0 && y>0 && z>0)) printf("YES\n");
		else printf("NO\n");
	}
}


Measured memory_bytes: 3152
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    X = [0] * N
    X[0] = -sum(A) + 2*(sum(v for i, v in enumerate(A) if i % 2 == 0))
    for i in range(1,N):
        X[i] = 2*A[i-1] - X[i-1]
    return X
print(' '.join(str(i) for i in main()))


Measured memory_bytes: 14232
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

typedef long long ll;
#define rep(i, n) for(int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
using namespace std;

int main() {
    string s;
    cin >> s;
    rep(i, s.size()) {
      if (i % 2 == 0) {
        cout << s[i];
      }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(1000000)

n = int(input())
lis = [[] for i in range(n)]

for i in range(n-1):
    u,v,w = map(int,input().split())
    lis[u-1].append((v-1,w%2))
    lis[v-1].append((u-1,w%2))

li = [-1] * n

def calc(i,c):
    li[i] = c
    for j, w in lis[i]:
        if li[j] < 0:
            calc(j, li[i]^w)

calc(0,0)

for d in li:
    print(d)

Measured memory_bytes: 76464
#include <stdio.h>
#include <string.h>
#define MAX_STRING_LENGTH 200001

int main() {
  int i, j, answer_length;
  char str[MAX_STRING_LENGTH];
  scanf("%s", str);
  for(i = 0; i < strlen(str); i++) {
    if(str[i] == 'A') {
      break;
    }
  }
  for(j = strlen(str) - 1; j > 0; j--) {
    if(str[j] == 'Z') {
      break;
    }
  }
  answer_length = j - i + 1;
  printf("%d\n", answer_length);
  return 0;
}


Measured memory_bytes: 384
import numpy as np
N = int(input())
A = [int(input()) for _ in range(N)]
MA = max(A)
ans = [MA] * N
MAI = np.argmax(np.array(A))
A[MAI] = 1
MA2 = max(A)
ans[MAI] = MA2
for a in ans :
    print(a)


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

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

    string S;
    cin >> S;
    S = "00" + S;

    int dp[N+1][N+1];
    dp[1][0] = 0;
    dp[1][1] = 1;
    for(int i = 2; i <= N; i++)
    {
        dp[i][0] = 0;
        for(int j = 1; j <= i; j++)
        {
            if(S[i] == '<') dp[i][j] = dp[i-1][j-1];
            else dp[i][j] = (dp[i-1][i-1] + (1000000007 - dp[i-1][j-1])) % 1000000007;
            dp[i][j] = (dp[i][j] + dp[i][j-1]) % 1000000007;
        }
    }
    cout << dp[N][N] << '\n';
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pint;
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());
signed main(void){
  string s;cin >> s;
  rep(i,s.length()){
    if(i%2==0&&s[i]=='L'){
      cout << "No" << endl;
      return 0;
    }
    if(i%2&&s[i]=='R'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

}


Measured memory_bytes: 256
N,M=map(int,input().split())
keys=[]
dp=[float("inf")]*pow(2,N)
dp[0]=0
for i in range(M):
    a,b=map(int,input().split())
    l=list(map(int,input().split()))
    num=0
    for j in l:
        num=num+pow(2,j-1)
    keys.append([a,num])
#print(keys)
for i in range(pow(2,N)):
    for j in range(M):
        dp[i|keys[j][1]]=min(dp[i|keys[j][1]],dp[i]+keys[j][0])
    #print(dp)
#print(dp)
if dp[pow(2,N)-1]==float("inf"):
    print(-1)
else:
    print(dp[pow(2,N)-1])

Measured memory_bytes: 75608
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
vector<pii> adj[1005];
ll dis[1005][1005];
ll temp[1005];

int main(){
   ll n;
   cin>>n;
   if(n<=599)cout<<8;
   else if(n<=799)cout<<7;
   else if(n<=999)cout<<6;
   else if(n<=1199)cout<<5;
   else if(n<=1399)cout<<4;
   else if(n<=1599)cout<<3;
   else if(n<=1799)cout<<2;
   else if(n<=1999)cout<<1;
   
   
   
   
}
	
 
    

Measured memory_bytes: 3660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String S = in.next();
			int a = 0;
			int b = 0;
			for(int i = 0; i < S.length(); i++) {
				if(S.charAt(i) == '0') {
					a++;
				}else{
					b++;
				}
			}
			out.println(Math.min(a, b) * 2);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 24276
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    
    String x = b.substring(0, 1);
    System.out.println("A" + x + "C");
  }
}

Measured memory_bytes: 21844
import collections
import sys
sys.setrecursionlimit(10**6+10)
N=int(input()) 
d=list(map(int, input().split())) 

  
  
c = collections.Counter(d)
c = dict(collections.Counter(d))

if d[0] != 0 or c[0]>1:
  print(0)
  sys.exit()
max_key = max(c.keys())


count = 1
for i in range(2,max_key+1):
  a = c.get(i, -1)
  b = c.get(i-1, -1)
  if a == -1 or b == -1:
    print(0)
    sys.exit()
  count = (count * (b**a))%998244353

print(count)

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

public class Main {
  private static long solve(int n) {
    long[][] count = new long[10][10];
    for (int i = 1; i <= n; i++) {
      int tail = i % 10;
      int head = i;
      while (head >= 10) {
        head /= 10;
      }
      count[head][tail]++;
    }
    
    long answer = 0;
    for (int head = 1; head <= 9; head++) {
      for (int tail = 1; tail <= 9; tail++) {
        answer += count[head][tail] * count[tail][head];
      }
    }
    return answer;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    out.println(solve(n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


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

#define LL long long

LL n, ans = 0;

LL arr[500];
bool ok[500];
int main(){
	cin >> n;

	for(LL i = 1; i < 500; i++){
		LL cur = 0, ops = 0;
		for(LL j = 1; j < 100; j++){
			if(cur + j > i) break;
			cur += j;
			ops++;
		}
		arr[i] = ops;
	}

	for(LL i = 2; i <= 1e6 + 5; i++){
		LL pow = 0;

		while((n % i) == 0){
			n = n/i;
			pow++;
		}
		ans += arr[pow];
		if(n == 1) break;
	}
	if(n != 1) ans++;
	cout << ans << endl;
}

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

using namespace std;
 
const int MX = 100 * 1000 + 7;
 
vector<int> g[MX];
bool was[MX];
int f[MX];
 
int dfs(int v) {
    if (was[v]) {
        return f[v];
    }
    was[v] = true;
    for(int to=0;to<g[v].size();to++) {
        f[v] = max(f[v], dfs(g[v][to]) + 1);
    }
    return f[v];
}
int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }
 
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, dfs(i));
    }
 
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

void solve() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if (A >= K) {
        cout << K << endl;
        return;
    }
    if (A + B >= K) {
        cout << A << endl;
        return;
    }
    int cs = K - A - B;
    cout << A - cs << endl;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3520
#include<cstdio>
#include<iostream>
int main(void){
  
  int a[100];
  int i;
 
  for(i=0;i<100;i++)
    a[i]=i+1;
  
  int j;
  int n;
  int count[100]={0};
  int max=0;
  
  for(j=0;j<100;j++){
    scanf("%d",&n);
    if(n==0)
      break;
    
    for(i=0;i<100;i++){
      if(a[i]==n){
	count[i]++;
      }
      if(count[i]>max){
	max=count[i];
      }
    }
  }

  for(i=0;i<100;i++){
    if(count[i]==max){
      printf("%d\n",a[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 1188
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int N;
int a[21][21];
int dp[25][1<<21];

void solve()
{
    dp[0][0] = 1;
    FOR (i, 1, N+1) {
        REP (j, (1<<N)-1) {
            if (dp[i-1][j] == 0) continue;
            REP (k, N) {
                if ((j & (1<<k)) == 0 && a[i-1][k]) {
                    dp[i][j|(1 << k)] += dp[i-1][j];
                    dp[i][j|(1 << k)] %= MOD;
                }
            }
        }
    }
    cout << dp[N][(1<<N)-1] << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP (i, N) REP (j, N) cin >> a[i][j];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 164096
def cb(n, k):
    ret = a = b = 1
    mod = 10**9 + 7
    for i in range(k):
        a *= n-i
        a %= mod
        b *= i + 1
        b %= mod
    m = mod-2
    while m > 0:
        if m % 2 != 0:
            ret *= b
            ret %= mod
        b *= b
        b %= mod
        m //= 2
    ret *= a
    ret %= mod
    return ret

def two_pow(n):
    ret = 1
    two = 2
    mod = 10 ** 9 + 7
    while n:
        if n & 1:
            n -= 1
            ret *= two
            ret %= mod
        two *= two
        two %= mod
        n //= 2
    return ret
N, a, b = map(int, input().split())
mod = 10 ** 9 + 7
print((two_pow(N) - 1 - cb(N, a) - cb(N, b)) % mod)

Measured memory_bytes: 38768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
const constexpr int INF = 1e9;

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

typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;
struct Less{
   bool operator()(const pair<string, int>&a, const pair<string, int>&b){
        if(a.first==b.first){
            return a.second < b.second;
        }
       return a.first < b.first;
    }
};
const constexpr ll MOD = 1e9 + 7;


ll extGCD(ll a, ll b, ll& x, ll& y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}
ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}

int x[110], y[110], h[110];
int main() {
    int N; cin >> N;
    REP(i, N){
        cin >> x[i] >> y[i] >> h[i];
    }
    
    for(int i=0; i<=100; ++i){
        for(int j=0; j<=100; ++j){
            
            int checker=-1;
            for(int k=0; k<N; ++k){
                
                if(h[k]!=0){
                    int temp = h[k]+abs(x[k]-i)+abs(y[k]-j);
                    if(checker==-1) {
                        checker = temp;
                    }else{
                        if(checker!=temp){
                            checker = -2;
                            break;
                        }
                    }
                }
            }
            if(checker==-2) continue;
            
            for(int k=0; k<N; ++k){
                if(h[k]==0){
                    int dist = abs(x[k]-i)+abs(y[k]-j);
                    if(checker > dist){
                        checker = -2;
                        break;
                    }
                }
            }
            if(checker==-2) continue;
            cout << i << " " << j << " " << checker << endl;
            return 0;
             
        }
    }
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H,N = map(int,input().split())
spells = [list(map(int,input().split())) for i in range(N)]
INF = 10**10
dp = [INF]*(H+1)
dp[0] = 0
for use in spells:
    damage = use[0]
    mp = use[1]
    for i in range(1,H+1):
        dp[i] = min(dp[max(0,i-damage)] + mp, dp[i])
print(dp[-1])


Measured memory_bytes: 74268
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, z = 0;
    vector<int> a = {0};
    string s;
    cin >> n >> k >> s;
    if (s[0] == '0') a.push_back(0);
    int l = 0;
    for (int i = 1; i <= n; i++) {
        if (s[i] != s[i - 1]) {
            a.push_back(i - l);
            l = i;
        }
    }
    for (int i = 0; i < 300005; i++) a.push_back(0);
    for (int i = 1; i < a.size(); i++) a[i] += a[i - 1];
    for (int i = 1; i <= n + 1; i++) {
        if (i % 2) {
            z = max(z, a[i + k + k] - a[i - 1]);
        }
    }
    cout << z;
}


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

#define int int_fast64_t

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

  int n; cin >> n;
  vector<int> a;
  copy_n(istream_iterator<int>(cin), n, back_inserter(a));

  map<int, int> cnt;
  for (auto x : a)
    ++cnt[x];
  
  int total = 0;
  for (auto& kv : cnt) {
    auto k = kv.first;
    auto v = kv.second;
    total += v*(v-1)/2;
  }
  for (auto x : a) {
    int v = cnt[x];
    int other = total - v*(v-1)/2;
    cout << other + (v-1)*(v-2)/2 << '\n';
  }
}



Measured memory_bytes: 11120
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  char c;
  cin>>c;
  c &= 0xE0;
  ++c;
  cout<<c<<"\n";
  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, Q, sum = 0;
  cin >> N;
  vector<ll> A(N), D(100001, 0);
  for(ll i = 0; i < N; i++) {
    cin >> A.at(i);
    D.at(A.at(i))++;
    sum += A.at(i);
  }
  cin >> Q;
  vector<ll> B(Q), C(Q);  
  for(ll i = 0; i < Q; i++) {
    cin >> B.at(i) >> C.at(i);
    sum += D.at(B.at(i)) * (C.at(i) - B.at(i));
    D.at(C.at(i)) += D.at(B.at(i));
    D.at(B.at(i)) = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 6428
N = int(input())
keta = len(list(str(N)))
ans = 0

for i in range(keta):
    if i % 2 == 1:
        continue
    if i+1 != keta:
        ans += len(range(10**i, (10**(i+1))-1)) + 1
    else:
        ans += len(range(10**i, N)) + 1

print(ans)

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

using namespace std;

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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int H, W;
string maps[500], ansr[500], ansb[500];

int main() {
	cin >> H >> W;
	REP(i, H) cin >> maps[i];
	
	copy(maps, maps + H, ansr);
	copy(maps, maps + H, ansb);
	
	REP(i, H) REP(j, W) {
		if (j == 0) ansr[i][j] = '#';
		else if (j == W - 1) ansb[i][j] = '#';
		else if (i % 2 & 1) ansr[i][j] = '#';
		else ansb[i][j] = '#';
	}
	
	REP(i, H) cout << ansr[i] << endl;
	REP(i, H) cout << ansb[i] << endl;
	
	return 0;
}


Measured memory_bytes: 1536
h, w, d = gets.split.map &:to_i
a = Array.new(h)
h.times do |i|
  a[i] = gets.split.map &:to_i
end
q = gets.to_i
l = Array.new(q)
r = Array.new(q)
q.times do |i|
  l[i], r[i] = gets.split.map &:to_i
end

pxy = Hash.new(h * w + 1)
h.times do |i|
  w.times do |j|
    pxy[a[i][j]] = [i, j]
  end
end

cum = Array.new(h * w + 1, 0)
(d + 1).upto(h * w) do |i|
  cum[i] = cum[i - d] + (pxy[i][0] - pxy[i-d][0]).abs + (pxy[i][1] - pxy[i-d][1]).abs
end

q.times do |i|
  p cum[r[i]] - cum[l[i]]
end


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

int main()
{
    int n, t, cnt = 0;
    string a[10], b[10], c[10], d[10];

    cin >> n >> t;
    
    cin >> a[0] >> b[0] >> c[0] >> d[0];
    for( int i = 1; i < n; i++ )
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        int diffa = 600 * ( a[i][0] - '0' ) + 60 * ( a[i][1] - '0' ) + 10 * ( a[i][3] - '0' ) + a[i][4] - '0';
        int diffb = 600 * ( c[i-1][0] - '0' ) + 60 * ( c[i-1][1] - '0' ) + 10 * ( c[i-1][3] - '0' ) + c[i-1][4] - '0';
        if( diffa - diffb >= t )
            cnt++;
    }

    cout << cnt << endl;

    for( int i = 1; i < n; i++ )
    {
        int diffa = 600 * ( a[i][0] - '0' ) + 60 * ( a[i][1] - '0' ) + 10 * ( a[i][3] - '0' ) + a[i][4] - '0';
        int diffb = 600 * ( c[i-1][0] - '0' ) + 60 * ( c[i-1][1] - '0' ) + 10 * ( c[i-1][3] - '0' ) + c[i-1][4] - '0';
        if( diffa - diffb >= t )
            cout << b[i] << " " << diffa - diffb << endl;
    }

    return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
const int maxn=500+9;
int n;
int a[maxn],lmt,b[maxn];


bool check(int g){
    for(int i=1;i<=n;++i)b[i]=a[i]%g;
    sort(b+1,b+n+1);
    int tot=lmt,cost=0;
    int t=n;
    for(int i=1;i<=t;++i){
        tot-=b[i];
        if(tot<0)return false;
        cost+=b[i];
        //b[i]=0;
        while(cost>0){
            int d=g-b[t];
            if(d<=cost){
                //b[t]=0;
                cost-=d;
                --t;
            }else{
                b[t]+=cost;
                cost=0;
            }
        }
    }
    return true;
}

int solve(){
	int sum=0;
	for(int i=1;i<=n;++i)sum+=a[i];
	
	int qt=sqrt(sum);
	vector <int> d;// divisor
	for(int i=1;i<=qt;++i)
	if(sum%i==0){
		d.push_back(i);
		if(check(sum/i))return sum/i;
	}
	int tot=d.size();
	for(int i=tot-1;i>=0;--i){
		if(check(d[i]))return d[i];
	}
}

void init(){
	cin>>n>>lmt;
	for(int i=1;i<=n;++i)cin>>a[i];
}
int main(){
	init();
	cout<<solve()<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	int n;
	char a[4];
	gets(a);

	if((a[0]==a[1]&&a[0]==a[2])||(a[1]==a[2]&&a[1]==a[3])){
		printf("Yes\n");
		return 0;
	}

	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nk = Input.ar;
        if (nk[1] == 0)
        {
            WriteLine((long)nk[0] * nk[0]);
            return;
        }
        var res = 0L;
        for(var i = nk[1] + 1; i <= nk[0]; i++)
        {
            res += (i - nk[1]) * (nk[0] / i);
            res += Max(0, nk[0] % i - nk[1] + 1);
        }
        WriteLine(res);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const double eps = 1e-11;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep(i,n)rep(j,n)rep(k,n) ans += gcd(i,gcd(j,k));
  cout << ans << endl;
  return 0;
}


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

int count_divisor(int n) {
  int res = 0;
  long long i = 1;
  for (; i * i < n; i++) {
    if (n % i == 0) {
      res += 2;
    }
  }
  if (i * i == n)
    res += 1;
  return res;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (i % 2 == 0)
      continue;
    if (count_divisor(i) == 8) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a, b;
	scanf("%d\n", &a);
	scanf("%d", &b);
	if(a==1&&b==2)
	printf("3");
	else if(a==2&&b==3)
	printf("1");
	else if (a==1&&b==3)
	printf("2");
	else if (a==2&&b==1)
	printf("3");
	else if (a==3&&b==2)
	printf("1");
	else if (a==3&&b==1)
	printf("2");
	return 0;
		
}

Measured memory_bytes: 1596
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        u,v=map(int,input().split())
        u-=1; v-=1
        E[u].append(v)

    # 各頂点から BFS を行い、全点間の距離をO(NM)で計算
    A=[None]*n
    for s in range(n):
        dist=[INF]*n
        dist[s]=0
        Q=deque([s])
        while(Q):
            v=Q.popleft()
            for nv in E[v]:
                if(dist[nv]!=INF): continue
                dist[nv]=dist[v]+1
                if(nv!=s): Q.append(nv)
            if(v==s): dist[v]=INF
        A[s]=dist

    d,v0=min((A[v][v],v) for v in range(n))
    if(d==INF):
        print(-1)
        return

    print(d)
    # v から v の最小のループを求める
    prev=[None]*n
    used=[0]*n
    used[0]=1
    Q=deque([v0])
    while(Q):
        flag=True
        v=Q.popleft()
        for nv in E[v]:
            if(nv==v0):
                flag=False
                break
            if(used[nv]): continue
            used[nv]=1
            prev[nv]=v
            Q.append(nv)
        if(not flag): break

    ans=[]
    while(v!=v0):
        ans.append(v)
        v=prev[v]

    ans.append(v0)
    print(*map(lambda x:x+1,ans[::-1]),sep='\n')
resolve()

Measured memory_bytes: 77148
def main():
    n, k = map(int, input().split())
    if k == 0:
        print(n * n)
        return
    c = 0
    for b in range(k + 1, n + 1):
        c += n // b * (b - k) + max(n % b - k + 1, 0)
    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[0]!='A')
    {
        cout<<"WA"<<endl;
        return 0;
    }
    if(isupper(s[1])||isupper(s[s.length()-1]))
    {
        cout<<"WA"<<endl;
        return 0;
    }
    int x=0;
    for(int i=2;i<s.length()-1;i++)
    {
        if(isupper(s[i])&&s[i]!='C')
        {
        cout<<"WA"<<endl;
        return 0;
        }    
        if(s[i]=='C')
            x++;
    }
    //cout<<x<<endl;
    if(x!=1)
    {
        cout<<"WA"<<endl;
        return 0;
    }
    cout<<"AC"<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    int m,ans=0;
    std::cin >>n ;
    int h;
    for (int i=0;i<n;i++){
        std::cin >>h;
        if (m<=h){
            m=h;
            ans++;
        }
    }
    std::cout << ans << std::endl;
    //else std::cout << 2*max(a,b)-1 << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
          using namespace std;
          #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
          #define M_PI 3.14159265358979323846
          #define data data_
          #define ff first
          #define ss second

          int main()
          {
          // clock_t begin = clock();
          // #ifndef ONLINE_JUDGE
          // freopen("input.txt", "r", stdin);
          // freopen("output.txt", "w", stdout);
          // #endif
          tani_nachi_ke  

          int a,b;
          cin >> a >> b;
          if(a < 10 && b < 10)
               cout << a*b << endl;
          else
               cout << -1 << endl;




          // #ifndef ONLINE_JUDGE 
          // clock_t end = clock();
          // cout<<endl<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
          // #endif 
          // return 0;
          }

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	string s, t;
	cin >> s >> t;
	s += s;
	REP(i, t.length()) {
		bool f = true;
		REP(j, t.length()) f &= (s[i+j] == t[j]);
		if (f) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
program test01
 implicit none
 character(len=10) S, T, U
 integer A, B

 read *, S, T
 read *, A, B
 read *, U

 S=trim(S)
 T=trim(T)
 U=trim(U)
 if ( U == S ) A=A-1
 if ( U == T ) B=B-1

 print '(i0,1x,i0)', A, B

endprogram test01


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

//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3", "Ofast", "unroll-loops", "fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#define int long long
#define endl '\n'

using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    int i, n = s.size();
    int l = (n - 1) / 2; l--;
    string a, b;
    a = s.substr(0, l + 1);
    int r = (n + 3) / 2; r--;
    b = s.substr(r, n - r);
    string revs = s, reva = a, revb = b;
    reverse(revs.begin(), revs.end());
    reverse(reva.begin(), reva.end());
    reverse(revb.begin(), revb.end());
    if (s == revs && a == reva && b == revb){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner input1 = new Scanner(System.in);
		
		int a = input1.nextInt();
		int x = 800 * a;
		int y = 200 * (a / 15);
		
		System.out.println(x-y);
		input1.close();
				
		
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
 
    if(a == 1){
        if(b == 2){
            cout << 3 << endl;
            return 0;
        }
        if(b == 3){
            cout << 2 << endl;
            return 0;
        }
 
    }
    if(a == 2){
        if(b == 1){
            cout << 3 << endl;
            return 0;
        }
        if(b == 3){
            cout << 1 << endl;
            return 0;
        }
    }
    if(a == 3){
        if(b == 1){
            cout << 2 << endl;
            return 0;
        }
        if(b == 2){
            cout << 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[2010][2010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[2010];
    rep(i,0,N) cin >> A[i];

    dp[0][0] = 0;
    vector<lpair> lp;
    rep(i,0,N) lp.push_back({A[i], i});
    sort(lp.begin(), lp.end(), greater<lpair>());
    rep(i,0,N){
        ll a = lp[i].first;
        ll pos = lp[i].second;
        rep(j,0,i+1){
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + a * abs(j-pos));
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a * abs(pos - (N-1-(i-j))));
        }
    }
    ll ans = 0;
    rep(i,0,N+1){
        ans = max(ans, dp[N][i]);
    }
    print(ans);
    

}

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

using namespace std;

long long dp[410][410];
long long C[410][410];

int main() {
	int n;
	cin >> n;
	vector<long long> a(n);

	memset(dp, 0x3f3f3f3f, sizeof dp);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		dp[i][i] = 0;
		if(i) dp[i-1][i] = a[i] + a[i-1];
		for(int j = 0; j <= i; j++){
			if(i)
				C[j][i] = C[j][i-1] + a[i];
			else
				C[j][i] = a[i];
		}
	}
	// dp[i][j] = min(dp[i][k]+dp[k+1][j])*2 for k in i+1, j-1
	// dp[i][i+1] = a[i]+a[i+1];
	
	for(int i = n-3; i >= 0; i--) {
		for(int j = i+2; j < n; j++) {
			for(int k = i; k < j; k++) {
				dp[i][j] = min(dp[i][j], (dp[i][k]+dp[k+1][j]) + C[i][j]);
			}
		}
	}

	cout << dp[0][n-1] << endl;
}


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

int main(){
  string s;
  cin >> s;
  int sum;
  int max = 0;
  int ssize = s.size();
  for(int i=0;i <= ssize;i++){
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
      sum++;
    }else{
      if(sum>max){
        max=sum;
      }
      sum = 0;
    }
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓

ll k, a, b;
bool J = false;



int main() {
	cin >> k >> a >> b;
	for (ll i = a; i <= b; i++) {
		if (i % k == 0) J = true;
	}
	if (J) cout << "OK" << endl;
	else cout << "NG" << endl;
	
	return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e6+5;
int a[4][4];
int b[4][4];
void solve(){
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			cin>>a[i][j];
		}
	}
	int n; 
	cin>>n; 
	for(int tc = 1;tc<=n;tc++){
		int x; 
		cin>>x; 
		for(int i=1;i<=3;i++){
			for(int j=1;j<=3;j++){
				if(a[i][j]==x)b[i][j] = 1;
			}
		}
	}
	bool can = false;
	for(int i=1;i<=3;i++){
		int cnt = 0;
		for(int j=1;j<=3;j++){
			cnt+=b[i][j];
		}
		if(cnt==3)can  = true;
		cnt = 0;
		for(int j=1;j<=3;j++){
			cnt+=b[j][i];
		}
		if(cnt==3)can  = true;

	}
	int cnt = 0;
	for(int i=1;i<=3;i++){
		cnt+=b[i][i];
	}
	if(cnt==3)can  = true;
	cnt = 0;
	for(int i=1;i<=3;i++){
		cnt+=b[i][4-i];
	}
	if(cnt==3)can  = true;
	if(can)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3608
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    A,B= map(int, sys.stdin.readline().split())
    n = (A+B)/2
    j = (A+B)%2
    if j == 0:
        print(int(n))
    else:
        print("IMPOSSIBLE")



Measured memory_bytes: 5708
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define F first
#define S second
using namespace std;

int Q = 1e7, h1, h2, cut = 10;
int n, s, D, l, r, up, mx, cnt, mxx, xx, a[30], b[400][30], la[400], u[400], ans[400], o[400];
pair<int, int> c[400][30];
bool v[400][30];

int f(int p, int q1, int q2) {
	int sz = q2 - q1 + 1;
	return p * sz * (sz + 1) / 2;
}

int main()
{
	int i, j, k, t, x, t1, t2;
	srand(time(NULL));
	cin >> D;
	for (i = 0; i < 26; i++) {
		scanf ("%d", &a[i]);
	}
	for (i = 1; i <= D; i++) {
		mxx = -2e9;
		for (j = 0; j < 26; j++) {
			scanf ("%d", &b[i][j]);
		}
		for (j = 0; j < 26; j++) {
			cnt = b[i][j];
			for (k = 0; k < 26; k++) {
				if (k == j) continue;
				cnt -= (i - o[k]) * a[k];
			}
			if (cnt > mxx) {
				xx = j;
				mxx = cnt;
			}
		}
		o[xx] = i;
		ans[i] = u[i] = xx;
	}
//	for (i = 1; i <= D; i++) {
//		ans[i] = u[i] = 1;
//	}
//	for(i = 1; i <= D; i++) {
//		printf("%d\n", ans[i] + 1);
//	}

	for (i = 1; i <= D; i++){
//		scanf ("%d", &t);
		t = u[i];
		s += b[i][t];
		la[t] = i;

		for (j = 0; j < 26; j++) {
			s -= a[j] * (i - la[j]);
		}
		v[i][t] = 1;
	}
//	cout << s << endl;
//	cin >> Q;
	for (i =0; i < 26; i++) {
		v[0][i] = 1;
		v[D + 1][i] = 1;
	}
	mx = s;
	while (Q--) {
//		scanf ("%d %d", &t1, &t2);
		t1 = rand() % D + 1;
		t2 = rand() % 26;
		if (u[t1] == t2) t2 = (t2 + 1) % 26;
		x = u[t1];
		s -= b[t1][x];
		v[t1][x] = 0;
		v[t1][t2] = 1;
		u[t1] = t2;
		s += b[t1][t2];
		for (l = t1 - 1; l >= 0; l--) if (v[l][x]) break;
		for (r = t1 + 1; r <= D + 1; r++) if (v[r][x]) break;
		s += f(a[x], l + 1, t1 - 1);
		s += f(a[x], t1 + 1, r - 1);
		s -= f(a[x], l + 1, r - 1);
		for (l = t1 - 1; l >= 0; l--) if (v[l][t2]) break;
		for (r = t1 + 1; r <= D +1; r++) if (v[r][t2]) break;
		s += f(a[t2], l + 1, r - 1);
		s -= f(a[t2], l + 1, t1 - 1);
		s -= f(a[t2], t1 + 1, r - 1);
		if (s > mx) {
			up = 0;
			for (i = 1; i <= D; i++) {
				ans[i] = u[i];
			}
			mx = s;
		} else up++;
		if (up == cut) {
			up = 0;
			memset(v, 0, sizeof(v));
			for (i =0; i < 26; i++) {
				v[0][i] = 1;
				v[D + 1][i] = 1;
			}
			for (i = 1; i <= D; i++) {
				u[i] = ans[i];
				v[i][ans[i]] = 1;
			}
			s = mx;
		}
	}
	for (i = 1; i <= D; i++) {
		printf("%d\n", ans[i] + 1);
	}
    return 0;
}


Measured memory_bytes: 3908
#include <bits/stdc++.h>
#define nl cout<<"\n"
#define fr(n) for(int i = 0; i<n; i++)
#define frr(j, n) for(int i = j; i<n; i++)
#define Mem(x) memset(x, 0, sizeof(x))
using namespace std;
typedef long long int lli;
lli dismatches(string s, string t){
    lli x = 0;
    fr(s.length()){
        if(s[i]!=t[i])x++;
    }
    return x;
}
int main(){
    string s, t;
    cin>>s>>t;
    lli ans = t.length();
    fr(s.length()-t.length()+1){
        ans = min(ans, dismatches(s.substr(i,t.length()), t));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))

#define equal equalll
#define less lesss
const int N = 1e5 + 10;
const long long INF = 1e9 + 19;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int n;
vector<int> e[N];
int use[N];

void read() {   
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int v,u;
        scanf("%d%d", &v, &u); v--; u--;
        e[v].pb(u);
        e[u].pb(v);
    }

}

int mxBit(int mask) {
    assert(mask != 0);
    int res = 0;
    for (; mask > 0; mask /= 2, res++);
    return res - 1;
}

int dfs(int v) {
    use[v] = 1;
    int sMask = 0;
    int dMask = 0;
    for (auto u: e[v])
        if (!use[u]) {
            int rMask = dfs(u);
            dMask |= sMask & rMask;
            sMask |= rMask;
        }
    int val = 0;
    if (dMask != 0) {
        val = mxBit(dMask) + 1;
    }
    for (int i = val; ; i++) {
        if ((sMask & pw(i)) == 0) {
            int res = ((sMask >> i) << i) | pw(i);
            return res;
        }
    }
    assert(false);
}

int solve(int st = 0) {
    for (int i = 0; i < n; i++)
        use[i] = 0; 
    int mask = dfs(st);
    return mxBit(mask);
}

void stress() {
    for (int tt = 0; ; tt++) {
        db(tt);
        n = rand() % 100 + 1; 
        for (int i = 0; i < n; i++)
            e[i].clear();
        for (int i = 1; i < n; i++) {
            int v = rand() % i;
            e[v].pb(i);
            e[i].pb(v);
        }
        set<int> val;
        for (int i = 0; i < n; i++)
            val.insert(solve(i));

        db(*val.begin());
        assert(val.size() == 1);
    }

}

int main(){
#ifdef HOME 
    freopen("in", "r", stdin);
#endif
    if (1) {
        read();
        cout << solve(0) << endl;
        //for (int i = 0; i < n; i++)
            //cout << solve(i) << " ";
        //cout << endl;
    }
    else {
        stress();
    }

    return 0;
}



Measured memory_bytes: 9472
class SegTree:
    X_unit = set()
    X_f = lambda x,y,z:y|z

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)

N = int(input())
S = list(input())
S = [set(i) for i in S]
Q = int(input())
Tree = SegTree(N)
Tree.build(S)

for i in range(Q):
    a,b,c = input().split()
    if a == '1':
        i = int(b)-1
        c = set(c)
        Tree.set_val(i,c)
    else:
        l = int(b)-1
        r = int(c)
        print(len(Tree.fold(l,r)))
      

Measured memory_bytes: 371772