akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
template <typename T = string>
struct RollingHash {
  T str;

  RollingHash(const T &s, int base = 10007, int mod = 1000000007) : str(s), base(base), mod(mod) {
    int n = str.size();
    hash_val.resize(n + 1);
    hash_val[0] = 0;
    power.resize(n + 1);
    power[0] = 1;
    REP(i, n) {
      hash_val[i + 1] = (hash_val[i] * base % mod + str[i]) % mod;
      power[i + 1] = power[i] * base % mod;
    }
  }

  long long get(int left, int right) {
    long long res = hash_val[right] - hash_val[left] * power[right - left] % mod;
    if (res < 0) res += mod;
    return res;
  }

  void add(const T &t) {
    for (auto c : t) {
      hash_val.emplace_back((hash_val.back() * base % mod + c) % mod);
      power.emplace_back(power.back() * base % mod);
    }
  }

  int lcp(int i, int j) {
    int n = str.size(), lb = 0, ub = n + 1 - max(i, j);
    while (ub - lb > 1) {
      int mid = (lb + ub) >> 1;
      (get(i, i + mid) == get(j, j + mid) ? lb : ub) = mid;
    }
    return lb;
  }

  template <typename U>
  int lcp(const RollingHash<U> &t, int i, int j) {
    int lb = 0, ub = min(static_cast<int>(str.size()) - i, static_cast<int>(t.str.size()) - j) + 1;
    while (ub - lb > 1) {
      int mid = (lb + ub) >> 1;
      (get(i, i + mid) == t.get(j, j + mid) ? lb : ub) = mid;
    }
    return lb;
  }

private:
  int base, mod;
  vector<long long> hash_val, power;
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  string s; cin >> s;
  RollingHash<> rh(s);
  int lb = 0, ub = n + 1;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    map<long long, vector<int> > mp;
    REP(i, n) {
      if (i + mid > n) break;
      mp[rh.get(i, i + mid)].emplace_back(i);
    }
    bool ok = false;
    for (auto pr : mp) {
      if (pr.second.size() >= 2) {
        if (pr.second.back() - pr.second.front() >= mid) ok = true;
      }
    }
    (ok ? lb : ub) = mid;
  }
  cout << lb << '\n';
  return 0;
}


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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = (N % 1000) / 100;
  c = (N % 100) / 10;
  d = N % 10;
  if (((a == b) && (b == c) )|| ((b == c) && (c == d))) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main(){
    int n,k;
    cin >>n>>k;
    int tmp=0;
    int count = 0;
    while(n>0){
        n/=k;
        count++;
    }

    cout <<count<<endl;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD (LL)(1e9+7)

int main(){
	int N, K, A[500];
	cin >> N >> K;
	int sum = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		sum += A[i];
	}

	int ans = 1;
	for(int i=1; i<=sqrt(sum)+1; i++){
		if(sum % i == 0){
			vector<int> tmp;
			for(int j=0; j<N; j++){
				tmp.PB(A[j]%i);
			}
			sort(tmp.begin(), tmp.end());
			reverse(tmp.begin(), tmp.end());

			vector<int> wa(N);
			for(int j=0; j<N; j++){
				wa[j] = tmp[j] + (j == 0 ? 0 : wa[j-1]);
			}

			for(int j=0; j<N-1; j++){ //jまで-
				if(i*(j+1) - wa[j] == wa[N-1] - wa[j]){
					if(wa[N-1] - wa[j] <= K) ans = max(ans, i);
				}
			}
		}

		if(sum % i == 0){
			i = sum / i;

			vector<int> tmp;
			for(int j=0; j<N; j++){
				tmp.PB(A[j]%i);
			}
			sort(tmp.begin(), tmp.end());
			reverse(tmp.begin(), tmp.end());

			vector<int> wa(N);
			for(int j=0; j<N; j++){
				wa[j] = tmp[j] + (j == 0 ? 0 : wa[j-1]);
			}

			for(int j=0; j<N-1; j++){ //jまで-
				if(i*(j+1) - wa[j] == wa[N-1] - wa[j]){
					if(wa[N-1] - wa[j] <= K) ans = max(ans, i);
				}
			}

			i = sum / i;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main () {
	int m, f, r;
	cin >> m >> f >> r ;
	while (!(m == -1 && f == -1 && r == -1)) {
		if (m == -1 || f == -1)
 	 	  	cout << 'F' << endl;	
		else if (m+f >= 80)
	       	cout << 'A' << endl;
		else if (m+f >= 65)	
 	        cout << 'B' << endl;
        else if (m+f >= 50) 
			cout << 'C' << endl;
	    else if (m+f >= 30) {
	    	if (r >= 50)
		 	   cout << 'C' << endl;
		    else 
		       cout << 'D' << endl; 
		}
	    else 
			cout << 'F' << endl;
		
        cin >> m >> f >> r ;
	}
}


Measured memory_bytes: 3024
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] arr = new int[n];
      for(int i = 0; i < n; i++)
        arr[i] = sc.nextInt();
        
      int[] leftSum = new int[n];
      leftSum[0] = arr[0];
      for(int i = 1; i < n; i++)
        leftSum[i] = leftSum[i-1] + arr[i];

      int[] rightSum = new int[n];
      rightSum[n-1] = arr[n-1];
      for(int i = n-2; i >= 0; i--) {
        rightSum[i] += rightSum[i+1] + arr[i];
      }
      int min = Integer.MAX_VALUE;
      for(int i = 0; i < n - 1; i++)
        min = Math.min(min, Math.abs(leftSum[i] - rightSum[i+1]));
      System.out.println(min);
  }
}

Measured memory_bytes: 23508
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  long long N, A, B;
  scanf("%lld", &N);
  scanf("%lld", &A);
  scanf("%lld", &B);
  if ((A-B)%2==0){
    printf("%lld\n", (B-A)/2);
  } else {
    if ( (B-1) < (N-A) ){
      printf("%lld\n",(B+A-1)/2);
    } else {
      printf("%lld\n",(2*N-A-B+1)/2);
    }
  }
  return 0;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    string s;
    cin>>s;
    cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    long long max,min,a;
    int i,j,k;
    int tmp;
    int n;
    int m;
 
    scanf("%d",&n);
 
    scanf("%llu",&a);
    min = a;
 
    scanf("%llu",&a);
    max = a - min;
    if (min > a)
        min = a;
 
    for (i = 2; i < n; i++) {
        scanf("%lld",&a);
        if ( a-min > max)
            max = a-min;
        if (a < min)
            min = a;
    }
 
    printf("%lld\n",max);
    return 0;
}


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

const int N = 50;

ll C[N + 1][N + 1];

void ncp(int n = N) {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == i || j == 0) {
        C[i][j] = 1;
      } else {
        C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
      }
    }
  }
}

int main() {
  ncp();
  int n, a, b;
  cin >> n >> a >> b;
  vector<ll> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  sort(x.begin(), x.end(), greater<ll>());
  double sum = 0;
  
  for (int i = 0; i < a; i++) {
    sum += x[i];
  }
    
  double avg = sum / a;
  
  cout << fixed << std::setprecision(6) << avg << '\n';
  
  ll ans = 0;
  int used = 0, tot = 0;
  for (int i = 0; i < n; i++) {
    if (x[a - 1] == x[i]) {
      if (i < a)
        used += 1;
      tot += 1;
    }
  }
  
  if (x[0] == x[a - 1]) {
    for (ll i = a; i <= min(tot, b); i++) {
      ans += C[tot][i];
    }
  } else {
    ans = C[tot][tot - used];
  }

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


Measured memory_bytes: 3844
s = gets.chomp #.split("")
answer = ""

if s == "zyxwvutsrqponmlkjihgfedcba"
  answer = "-1"
else
  dict = ("a".."z").to_a #.reverse

  if s.size > 25
    i = -2

    while true
      s2 = s[0...i]
#      p sp
#      p s2

      dict_tmp = dict - s2.split("")

#      p dict_tmp

#      puts "1文字ずつ"
      # 1文字ずつ
      dict_tmp.each do |let|
        op = s2 + let
        if op > s
          puts op
          exit
        end
      end

      i -= 1
    end



  else
    dict -= s.split("")
    answer = s + dict[0]
  end

end

puts answer

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

int main()
{
		int x, y, temp, i;
for(i=1; i <=3000; i++)
{
		cin >> x >> y;
		if(x==0 && y==0) break;
		
		if(x>y)
{
			int temp = x;
			x = y;
			y = temp;
		}
		cout << x << " " << y <<endl;
	}
}


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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> v(m);
  int count = 0;
  for(int i=0; i<m; i++) {
    cin >> v[i];
    if(x<v[i]) count++;
  }
  cout << min(count, m-count) << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(){
int n;
int m;
cin >>n;
cin >>m;
int a[n];
a[0]=0;
int b;
int c;
b=0;
while(b<n-1){
cin >>c;
a[b+1]=a[b]+c;
b=b+1;}
int e;
e=0;
int d;
d=0;
b=0;
while(b<m){
cin >>c;
if(c>0){e=(e+a[d+c]-a[d])%100000;}
else{e=(e+a[d]-a[d+c])%100000;}
d=d+c;
b=b+1;}
cout <<e<<endl;}

Measured memory_bytes: 1548
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


#隣接リスト 1-index
def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n+1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def main():
    N, M = NMI()
    F = {}
    for _ in range(M):
        a, b = NMI()
        F[(a, b)] = 1
    tree = make_adjlist_nond(N, list(F.keys()))

    ans = 0
    seen = [0] * (N + 1)
    for start in range(1, N+1):
        que = deque()
        que.append(start)

        seen[start] = 1
        fri_cnt = 1
        while que:
            now = que.popleft()

            for goto in tree[now]:
                if seen[goto]:
                    continue
                seen[goto] = 1
                fri_cnt += 1
                que.append(goto)
        ans = max(fri_cnt, ans)
    print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 137768
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007

ll fun(ll x,ll n)
{
    ll r=1;
    while(n)
    {
    	if(n%2)
        r=(r*x)%mod;
        n/=2;
        x=(x*x)%mod;
    }
    return r;
}

ll f[200001];

void pre()
{
	f[0]=1;
	for(ll i=1;i<=200000;i++)
	{
		f[i]=(f[i-1]*i)%mod;
	//	cout<<f[i]<<" ";
	}
}

ll cal(ll n,ll r)
{
	ll x=fun(f[r],mod-2);
	ll y=fun(f[n-r],mod-2);
	return (f[n]*((x*y)%mod))%mod;
}

int main()
{
    ll n,i,r,m,c;
    pre();
    cin>>n>>m; 
    ll ans=1;
    for(i=2;i*i<=m;i++)
    {
        if(m%i==0)
        {
            c=0;
            while (m%i==0)
            {
                m/=i;
                c++;
            }
            //cout<<i<<" "<<c<<"  ";
            ans=(ans*cal(n+c-1,n-1))%mod;
            //cout<<ans<<" ";
        }
    }
    if(m>1)
    ans=(ans*n)%mod;
    std::cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;
using ll = long long;
const int INF = 999999999;

int H, W;
vector<vector<char>> s;
vector<vector<int>> cost;

int bfs() {
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    cost[0][0] = 0;

    while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        if (p == make_pair(H - 1, W - 1)) {
            return cost[p.first][p.second];
        }
        for (int i = 0; i < 4; ++i) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if (nx < 0 || ny < 0 | nx >= W || ny >= H) continue;
            if (s[ny][nx] == '#') continue;
            if (cost[ny][nx] != -1) continue;

            cost[ny][nx] = cost[p.first][p.second] + 1;
            que.push(make_pair(ny, nx));
        }
    }
    return -1;
}

int main() {
    cin >> H >> W;
    s = vector<vector<char>>(H, vector<char>(W, -1));
    int white = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> s[i][j];
            if (s[i][j] == '.') white++;
        }
    }
    cost = vector<vector<int>>(H, vector<int>(W, -1));
    int min_cost = bfs();
    if (min_cost == -1) cout << -1 << endl;
    else cout << white - (min_cost + 1) << endl;
}

Measured memory_bytes: 256
import sys

n = int(input())
h_list = [int(x) for x in input().split(" ")]

dp = [sys.maxsize] * len(h_list)
dp[0] = 0
dp[1] = abs(h_list[1] - h_list[0])
for i in range(2, len(dp)):
  dp[i] = min(dp[i - 1] + abs(h_list[i] - h_list[i-1]), dp[i - 2] + abs(h_list[i] - h_list[i - 2]))

print(dp[-1])

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

int main(void) {
  int K, S, counter;
  cin >> K >> S;

  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      int Z = S - X - Y;
      if (0 <= Z && Z <= K) {
        ++counter;
      }
    }
  }

  cout << counter << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N 100000

typedef struct{
  int par, left_child, right_sibling, depth;
  char status[15];
}Node;

Node tree[N];
int n, nchild[N];
char root[N];

void calc_depth(int p, int d){
  tree[p].depth = d;
  if(tree[p].right_sibling != -1) calc_depth(tree[p].right_sibling, d);
  if(tree[p].left_child != -1) calc_depth(tree[p].left_child, d+1);
}

void print_node(int p, int cnt, int size){
  if(cnt + 1 == size) printf("%d", p);
  else{
    printf("%d, ", p);
    print_node(tree[p].right_sibling, cnt + 1, size);
  }
}

main(){
  int i, j, r;
  scanf("%d", &n);
  memset(root, 1, n);
  for(i=0;i<n;i++) tree[i].left_child = tree[i].right_sibling = -1;
  for(i=0;i<n;i++){
    int idx;
    scanf("%d", &idx);
    scanf("%d", &nchild[idx]);
    if(nchild[idx] == 0) strcpy(tree[idx].status, "leaf");
    else strcpy(tree[idx].status, "internal node");
    for(j=0;j<nchild[idx];j++){
      int in, pre;
      scanf("%d", &in);
      tree[in].par = idx;
      root[in] = 0;
      if(j == 0) tree[idx].left_child = in;
      else tree[pre].right_sibling = in;
      pre = in;
    }
  }
  for(i=0;i<n;i++) if(root[i]) r = i;
  tree[r].par = -1;
  strcpy(tree[r].status, "root");
  calc_depth(r, 0);
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, %s, [", i, tree[i].par, tree[i].depth, tree[i].status);
    if(tree[i].left_child != -1) print_node(tree[i].left_child, 0, nchild[i]);
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 6768
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

int main(void){
	long k=nextlong();
	int n=50;
	int m=k%n;
	printf("%d\n", n);
	for(int i=0; i<n; i++){
		long a=i+k/n;
		if(i<m){
			a=a+n-m+1;
		}else{
			a=a-m;
		}
		printf("%ld ", a);
	}
	putchar(10);
}


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

int main()
{
	string str;
	getline(cin,str);

	for(int i=0;i<str.size();++i){
		if(str[i] >= 'a' && str[i] <= 'z'){
			str[i] -= ('a'-'A');
		}else if(str[i] >= 'A' && str[i] <= 'Z'){
			str[i] += ('a'-'A');
		}
	}

	cout << str << endl;

	return 0;
}

Measured memory_bytes: 1176
#include<iostream>
using namespace std;
int main(){
  int A[3];
  int mini,max,mid;
  cin >> A[0] >> A[1] >> A[2];
  mini = 0;max = 2;
  if(A[mini] > A[1])mini = 1;
  if(A[mini] > A[2])mini = 2;
  if(A[max] < A[1])max = 1;
  if(A[max] < A[0])max = 0;
  if(max + mini == 1){
    mid = 2;
  }else if(max + mini == 2){
    mid = 1;
  }else if(max + mini == 3){
    mid = 0;
  }
  cout << A[max]*10+A[mid]+A[mini] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
const int MAX = 100; //配列の最大サイズ

void output(int array_data[], int count){
    int i;

    for(i = 0; i < count; i++){
        if( i > 0){
            printf(" ");
        }
        printf("%d", array_data[i]);
    }
    printf("\n");
}

void insert_sort(int array_data[], int count){
    int i,j;
    int v;

    for(i = 1; i < count ; i++){
        v = array_data[i];
        j = i - 1;
        while(j >= 0 && array_data[j] > v){
            array_data[j + 1] = array_data[j];
            j--;
        }
        array_data[j + 1] = v;
        output(array_data, count);
    }
}

int main(){
    int i;
    int count;
    int array_input[MAX];

    scanf("%d", &count); // 配列のサイズを入力

    for(i = 0; i < count; i++){
        scanf("%d", &array_input[i]); // 配列データの受け取り
    }

    // 入力値を出力
    output(array_input, count);

    // ソートの実行
    insert_sort(array_input, count);

    // 並び変え後の出力
    // output(array_input, count);

    return 0;
}



Measured memory_bytes: 2720
#include <iostream>

using namespace std;

int main()
{

    int N,X,T;
    cin>>N>>X>>T;
    int A;
    if(N%X==0)
    {
        A=N/X;
    }
    else
    {
    A=N/X+1;
    }
    cout<<A*T;
    return 0;
}



Measured memory_bytes: 3564
#include<stdio.h>

int main(){
	int n,s[100000],q,t,c=0,i;
	int left,mid,right;

	scanf("%d",&n);

	for(i=0;i<n;i++)
		scanf("%d",&s[i]);

	scanf("%d",&q);

	for(i=0;i<q;i++){
		scanf("%d",&t);

		//seach
		left=0;
		right=n;
		while(left<right){
			mid=(left+right)/2;
			if(s[mid]==t){
				c++;
				break;
			}
			else if(t<s[mid])
				right=mid;
			else
				left=mid+1;
		}


	}
	printf("%d\n",c);

	return 0;
}


Measured memory_bytes: 2244
n,l = [int(i) for i in input().split()]
a=[int(i) for i in input().split()]
#b=[int(i) for i in input().split()]

max_len   = a[0]+a[1]
max_joint = 1

for i in range(1,n-1):
    len = a[i] + a[i+1]
    if len > max_len:
        max_len   = len
        max_joint = i+1


if max_len < l:
    print("Impossible")
    exit()
else:
    print("Possible")
    for i in range(1,max_joint):
        print(i)
    for i in range(n-1, max_joint, -1):
        print(i)
    print(max_joint)


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

import heapq

INF = 10 ** 10

def dijkstra(n, G, s):
    dist = [INF] * n
    dist[s] = 0
    h = []
    heapq.heappush(h, (0, s))

    while h:
        # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
        d, v = heapq.heappop(h)
        if dist[v] < d:
            continue
        # vから到達可能な頂点について、距離が短くなれば更新
        for end, cost in G[v]:
            if dist[end] > dist[v] + cost:
                dist[end] = dist[v] + cost
                heapq.heappush(h, (dist[end], end))
    return dist


H, W = map(int, input().split())
N = H * W
ch, cw = map(lambda x:int(x)-1, input().split())
gh, gw = map(lambda x:int(x)-1, input().split())

s = []
es = tuple([] for i in range(N))

for h in range(H):
   s.append(input().rstrip('\n'))

for h in range(H):
    for w in range(W):
        if s[h][w] != '.':
            continue
        a = h*W+w
        esappend = es[a].append
        for dh in (-2, -1, 0, 1, 2):
            for dw in (-2, -1, 0, 1, 2):
                if dh == 0 and dw == 0:
                    continue
                nh = h + dh
                nw = w + dw
                if 0 <= nh and nh < H and 0 <= nw and nw < W and s[nh][nw] == '.':
                    b = nh*W+nw
                    if (dh, dw) in [(-1,0),(1,0),(0,-1),(0,1)]:
                        esappend((b, 0))
                    else:
                        esappend((b, 1))

dist = dijkstra(N, es, ch*W+cw)
if dist[gh*W+gw] == INF:
    print(-1)
else:
    print(dist[gh*W+gw])

Measured memory_bytes: 358456
#coding: utf-8
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort()
y.sort()
if(x[-1]<y[0] and X<y[0] and x[-1]<Y):
    print("No War")
else:
    print("War")    


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    cout << u << endl;
    return u;
}


int main() {
    ll l, r, d;
    cin >> l >> r >> d;
    ll r_ ,l_;
    if(r % d != 0){
        r_ = r/d;
    } else {
        r_ = r/d;
    }
    if(l % d != 0){
        l_ = l/d + 1;
    } else {
        l_ = l/d;
    }
    cout << r_ - l_ + 1 << endl;

}



Measured memory_bytes: 3632
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
int N, K;
vector<LL> a;






//サブ関数
//入力
void input()
{
	cin >> N >> K;
	REP(i, N) {
		LL tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
}

vector<LL> make_imos(vector<LL> a, bool onlyPositive)
{
	vector<LL> imos(1, 0);
	REP(i, (int)a.size()) {
		//正の数だけ採用の場合
		if (onlyPositive) {
			if (a[i] > 0) {
				imos.push_back(imos[i] + a[i]);
			}
			else {
				imos.push_back(imos[i]);
			}
		}
		//全て採用の場合
		else {
			imos.push_back(imos[i] + a[i]);
		}
	}
	imos.push_back(imos.back());
	return imos;
}

//計算
void calc()
{
	auto onlypos = make_imos(a, true);
	auto all = make_imos(a, false);

	LL ans = -1ll * INF*INF;
	FOR(i, 1, N - K + 2) {
		LL left = onlypos[i - 1];
		LL center = all[i + K - 1] - all[i - 1];
		LL right = onlypos.back() - onlypos[i + K - 1];
		LL tmp = left + (center > 0 ? center : 0) + right;
		ans = max(ans, tmp);
	}
	cout << ans << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	//debug();
	
	return 0;
}


Measured memory_bytes: 4452
#include<stdio.h>
#include<string.h>

int main(){

  char str[100002]={0};
  int i,j;

  while(scanf("%s",str)!=EOF){

    int jcnt=0,icnt=0;

    for(i=0;i<strlen(str);i++){
	if(str[i]=='J' && str[i+1]=='O' && str[i+2]=='I'){
	 jcnt++;
	}
	else if(str[i]=='I' && str[i+1]=='O' && str[i+2]=='I'){
	  icnt++;
	}
    }
	printf("%d\n%d\n",jcnt,icnt);

      }

  return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
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...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
int N;
vector<int> A;

int main() {
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int cnt = 1;
    int ans = 1;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 0) {
            cnt *= 2;
        }
        ans *= 3;
    }
    cout << ans - cnt << endl;
}


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

using namespace std;

int n;
int a[55], b[55], c[55];
int res;

int32_t main()
{
  cin >> n;
  for (int i=1; i<=n; i++) cin >> a[i];
  for (int i=1; i<=n; i++) cin >> b[i];
  for (int i=1; i<n; i++) cin >> c[i];
  a[n + 1] = 1e9;
  for (int i=1; i<=n; i++)
  {
    res += b[a[i]];
    if (a[i]==a[i+1]-1) res += c[a[i]];
  }
  cout << res;
  return 0;
}

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

int main() {
    while(true) {
        vector<vector<int>> log;
        int N, M; cin >> N >> M;
        if (N == 0 && M == 0) break;
        for (int i = 0; i < M; i++) {
            log.push_back(vector<int>(721));
        }
        int r; cin >> r;
        for (int i = 0; i < r; i++) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            m--;
            if (s == 0) log[m][t - 540]--;
            else        log[m][t - 540]++;
        }
        for (int m = 0; m < M; m++) {
            for(int t = 1; t <= 720; t++) {
                log[m][t] += log[m][t-1];
            }
        }
        int q; cin >> q;
        for (int i = 0; i < q; i++) {
            int ans = 0;
            int s, e, m; cin >> s >> e >> m;
            m--;
            for(int t = s; t < e; t++) {
                if (log[m][t - 540] > 0) ans++;
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 30564
#include <cstdio>
#include <cctype>
#include <utility>
#include <complex>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int n; (n = in()), ~n;) {
		complex<double> c = {1, 0};
		while (--n)
			c += c / abs(c) * 1i;
		printf("%.2lf\n%.2lf\n", c.real(), c.imag());
	}
}


Measured memory_bytes: 2580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<ll> ans(n);
    for(int bit=1;bit<1000000005;bit*=2){
        ll xors=a[0]&bit;
        for(int i=1;i<n;i++){
            xors=xors^(a[i]&bit);
        }
        if(xors==0){
            for(int i=0;i<n;i++){
                int num=a[i]&bit;
                if(num>0){
                    ans[i]+=bit;
                }
            }
        }else{
            for(int i=0;i<n;i++){
                int num=a[i]&bit;
                if(num==0){
                    ans[i]+=bit;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 6356
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define ln() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007; // 998244353 , 1000000007
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
	bool operator>(const edge& right) const {
		return cost > right.cost;
	}
};

struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
	bool operator>(const point& right) const {
		return x == right.x ? y > right.y : x > right.x;
	}
};

ll bisect_left(ll arr[], ll arr_size, ll key) {
	return distance(arr, lower_bound(arr, arr + arr_size, key));
}

ll bisect_left(vector<ll> vc, ll key) {
	return lower_bound(vc.begin(), vc.end(), key) - vc.begin();
}

ll pow_mod(ll a, ll x) {
	if (x == 0) return 1;
	if (x == 1) return a % MOD;
	ll ret = pow_mod(a, x / 2);
	if (x % 2 == 0) ret = (ret*ret) % MOD;
	else ret = ((a % MOD) * ((ret*ret) % MOD)) % MOD;
	return ret;
}

void build_mod_fact(ll arr[], ll n) {
	arr[0] = 1;
	repi(i, 1, n + 1) {
		arr[i] = (arr[i - 1] * i) % MOD;
	}
	return;
}

void build_mod_fact_inv(ll arr_fact[], ll arr_fact_inv[], ll n) {
	arr_fact_inv[n] = pow_mod(arr_fact[n], MOD - 2);
	repd(i, n - 1, -1) {
		arr_fact_inv[i] = (arr_fact_inv[i + 1] * (i + 1)) % MOD;
	}
	return;
}

ll comb_mod(ll n, ll r, ll arr_fact[], ll arr_fact_inv[]) {
	return (((arr_fact[n] * arr_fact_inv[n - r]) % MOD) * arr_fact_inv[r]) % MOD;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}


///////////////////////////////////////////////////////////////////////////////////////

ll x, y, z, k;
vector<ll> a, b, c;
vector<ll> ab, abc;

int main() {
	cin >> x >> y >> z >> k;
	ll t;
	repi(i, 0, x) {
		cin >> t;
		a.push_back(t);
	}
	repi(i, 0, y) {
		cin >> t;
		b.push_back(t);
	}
	repi(i, 0, z) {
		cin >> t;
		c.push_back(t);
	}


	repi(i, 0, x) {
		repi(j, 0, y) {
			ab.push_back(a[i] + b[j]);
		}
	}

	sort(ab.begin(), ab.end(), greater<ll>());

	repi(i, 0, min(x*y, k)) {
		repi(j, 0, z) {
			abc.push_back(ab[i] + c[j]);
		}
	}

	sort(abc.begin(), abc.end(), greater<ll>());

	repi(i, 0, k) {
		cout << abc[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 43156
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int x;
	scanf("%d", &x);
	ll ans = 1;
	rep(i, 2, 1001){
		for(ll c=i*i; c<=x; c*=i){
			ans = std::max(ans, c);
		}
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
            public static void main(String args[]) throws Exception
            {
                    Scanner input=new Scanner(System.in);
             String x=input.nextLine();
             int c=x.charAt(0);
             char res=(char) (c+1);
             
        System.out.println(res);
            }
}

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

int main() {
	ll n,a,b;
	cin >> n >> a >> b;
	ll res = b - a;
	if (res % 2 == 0) {
		ll ans = res / 2;
		cout << ans << endl;
	}
	else {
		ll up = n - b;
		ll down = a- 1;
		ll ans = min(up,down)+1+(b-a-1)/2;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define repb(i,n) for(int i = (int)n;i >= 0;i--)
#define reps(i,m,n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i,m,n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v,n) sort(v,v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
#define ll long long int
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
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;}
//vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
using namespace std;
int main(int argc, char const *argv[]) {
    int n,m,t,p;
    int tmp[2][101][101];
    while (cin >> n >> m >> t >> p, n || m || t || p)
    {
        rep(i,2){
            rep(j,101){
                rep(k,101){
                    tmp[i][j][k] = 0;
                }
            }
        }
        rep(y,m){
            rep(x,n){
                tmp[0][y][x] = 1;
            }
        }
        int d, c;
        rep(i,t){
            cin >> d >> c;
            rep(y,101){
                rep(x,101){
                    tmp[(i + 1) % 2][y][x] = 0;
                }
            }
            if(d==1){
                rep(y, m)
                {
                    rep(x, n)
                    {
                        tmp[(i + 1) % 2][y][x] = tmp[i % 2][y][x+c];
                    }
                }
                rep(x,c){
                    rep(y,m){
                        tmp[(i + 1) % 2][y][x] += tmp[i % 2][y][c-x-1];
                    }
                }
            }
            else{
                rep(y, m)
                {
                    rep(x, n)
                    {
                        tmp[(i + 1) % 2][y][x] = tmp[i % 2][y+c][x];
                    }
                }
                rep(x, n)
                {
                    rep(y, c)
                    {
                        tmp[(i + 1) % 2][y][x] += tmp[i % 2][c-y-1][x];
                    }
                }
            }

        }
        int x, y;
        rep(i,p){
            cin >> x >> y;
            cout <<tmp[t%2][y][x] << endl;
        }
    }
    return 0;
}



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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<string> w(n);
    for(int i=0; i<n; i++) cin>>w[i];

    for(int i=0; i<n; i++){
        int cnt=0;
        for(int j=0; j<n; j++){
            if(w[i]==w[j]) cnt++;
        }
        if(cnt>1){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i=0; i<n; i++){
        char tail;
        if(i==0){
            tail=w[i][w[i].size()-1];
        }
        else{
            if(w[i][0]!=tail){
                cout << "No" << endl;
                return 0;
            }
            tail=w[i][w[i].size()-1];
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AOJ
{
	class Program
	{
		public static void Main(string[] args)
		{
			var a = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToList();
			Console.WriteLine("{0} {1}",a[0]*a[1],(a[0]+a[1])*2);
		}
	}
}

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

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            for(int i; (i = int.Parse(Console.ReadLine())) != 0;) {
                var list = new List<KeyValuePair<int, string>>();
                while(i-- != 0) {
                    var input = Console.ReadLine().Split();
                    var time = 0;
                    for(int m = 1; m <= 8; m += 2) {
                        time += int.Parse(input[m]) * 60 + int.Parse(input[m + 1]);
                    }
                    list.Add(new KeyValuePair<int, string>(time, input[0]));
                }
                list.Sort((v1, v2) => v1.Key - v2.Key);
                Console.WriteLine(list[0].Value);
                Console.WriteLine(list[1].Value);
                Console.WriteLine(list[list.Count - 2].Value);
            }
        }
    }
}

Measured memory_bytes: 5980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	int a=0,b=getchar();
	while(!isdigit(b))b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a;
}
int n,m,a[5];
int main(){
	memset(a,-1,sizeof(a));
	n=read(),m=read();
	while(m--){
		int x=read(),y=read();
		if(a[x]!=-1 and a[x]!=y)return puts("-1"),0;
		a[x]=y;
	}
	if(n!=1 and a[1]==0)return puts("-1"),0;
	for(int i=1;i<=n;i++){
		if(a[i]!=-1)cout << a[i];
		else if(i!=1 or n==1)cout << 0;
		else cout << 1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int a;
	int s=1000000000;
	int c=0;
	for(int i=0;i<n;i++){
	
		cin>>a;
		while(a%2==0){
		
			a/=2;
			c++;
		}
		if(c==0){
		
			cout<<0;
			return 0;
		}
		if(c<s){
		
			s=c;
		}
		c=0;
	}
	cout<<s<<'\n';
	return 0;
}


Measured memory_bytes: 3548
H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

Ch += 1
Cw += 1
Dh += 1
Dw += 1


S = ['#'*(W+4)]
S.append('#'*(W+4))
for k in range(H):
  S.append('##' + input() + '##')
S.append('#'*(W+4))
S.append('#'*(W+4))

foo = [[-1 for _ in range(W+4)] for _ in range(H+4)]
for k in range(2, H+2):
  for j in range(2, W+2):
    if S[k][j] == '.':
      foo[k][j] = 10**6

foo[Ch][Cw] = 0

now = []
new = [(Ch, Cw)]
while len(new) > 0:
  item = new.pop()
  now.append(item)
  x = item[0]
  y = item[1]
  if foo[x+1][y] == 10**6:
    foo[x+1][y] = 0
    new.append((x+1, y))
  if foo[x][y+1] == 10**6:
    foo[x][y+1] = 0
    new.append((x, y+1))
  if foo[x-1][y] == 10**6:
    foo[x-1][y] = 0
    new.append((x-1, y))
  if foo[x][y-1] == 10**6:
    foo[x][y-1] = 0
    new.append((x, y-1))


ans = 0
while foo[Dh][Dw] == 10**6:
  if len(now) == 0:
    print(-1)
    exit() 
  ans += 1
  while len(now) > 0:
    item = now.pop()
    x = item[0]
    y = item[1]
    if foo[x+2][y+2] > ans:
      foo[x+2][y+2] = ans
      new.append((x+2, y+2))
    if foo[x+2][y+1] > ans:
      foo[x+2][y+1] = ans
      new.append((x+2, y+1))
    if foo[x+2][y] > ans:
      foo[x+2][y] = ans
      new.append((x+2, y))
    if foo[x+2][y-1] > ans:
      foo[x+2][y-1] = ans
      new.append((x+2, y-1))
    if foo[x+2][y-2] > ans:
      foo[x+2][y-2] = ans
      new.append((x+2, y-2))
    if foo[x+1][y+2] > ans:
      foo[x+1][y+2] = ans
      new.append((x+1, y+2))
    if foo[x+1][y-2] > ans:
      foo[x+1][y-2] = ans
      new.append((x+1, y-2))
    if foo[x][y+2] > ans:
      foo[x][y+2] = ans
      new.append((x, y+2))
    if foo[x][y-2] > ans:
      foo[x][y-2] = ans
      new.append((x, y-2))
    if foo[x-2][y+2] > ans:
      foo[x-2][y+2] = ans
      new.append((x-2, y+2))
    if foo[x-2][y+1] > ans:
      foo[x-2][y+1] = ans
      new.append((x-2, y+1))
    if foo[x-2][y] > ans:
      foo[x-2][y] = ans
      new.append((x-2, y))
    if foo[x-2][y-1] > ans:
      foo[x-2][y-1] = ans
      new.append((x-2, y-1))
    if foo[x-2][y-2] > ans:
      foo[x-2][y-2] = ans
      new.append((x-2, y-2))
    if foo[x-1][y+2] > ans:
      foo[x-1][y+2] = ans
      new.append((x-1, y+2))
    if foo[x-1][y-2] > ans:
      foo[x-1][y-2] = ans
      new.append((x-1, y-2))
    if foo[x-1][y-1] > ans:
      foo[x-1][y-1] = ans
      new.append((x-1, y-1))
    if foo[x-1][y+1] > ans:
      foo[x-1][y+1] = ans
      new.append((x-1, y+1))
    if foo[x+1][y+1] > ans:
      foo[x+1][y+1] = ans
      new.append((x+1, y+1))
    if foo[x+1][y-1] > ans:
      foo[x+1][y-1] = ans
      new.append((x+1, y-1))
      
  while len(new) > 0:
    item = new.pop()
    now.append(item)
    x = item[0]
    y = item[1]
    if foo[x+1][y] == 10**6:
      foo[x+1][y] = 0
      new.append((x+1, y))
    if foo[x][y+1] == 10**6:
      foo[x][y+1] = 0
      new.append((x, y+1))
    if foo[x-1][y] == 10**6:
      foo[x-1][y] = 0
      new.append((x-1, y))
    if foo[x][y-1] == 10**6:
      foo[x][y-1] = 0
      new.append((x, y-1))
print(ans)

Measured memory_bytes: 95232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;++i)
int main(){
   string s;cin>>s;int n=s.size();string ss="";
   for(int i=0;i<n;i++){
    if(s[i]=='B'&&i!=0){ss=ss.substr(0,ss.size()-1);}
    else if(s[i]=='1'||s[i]=='0'){ss+=s[i];}
   }
   cout<<ss<< endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include <cstdio>
#include<vector>
#include<iostream>
 
using namespace std;
 
int main(){
    int n,k;
    int tmp;
    int min = 1000000000;
    cin >> n >> k;
    vector<int> data;
    for (int i = 0; i < n; i++){
        scanf("%d", &tmp);
        data.push_back(tmp);
    }
    sort(data.begin(),data.end(),greater<int>());
    for (int i = 0; i < data.size() - k + 1; i++){
        if (min > data[i]-data[i+k-1]){
            min = data[i]-data[i+k-1];
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    ll N, A, B; cin>>N>>A>>B; cout<<min(A*N, B)<<endl;
    return 0;
}


Measured memory_bytes: 3576
n = int(input())
a = list(map(int,input().split()))

b = [[] for _ in range(n)]
for i in range(n):
    b[i] = [i for i in range(max(0,a[i]-1),a[i]+2)]


def dfs(i,v,n,b):
    if i==n:
        if v==0:
            return 1
        else:
            return 0
    else:
        res = 0
        for j in b[i]:
            res += dfs(i+1,v*(j%2),n,b)

        return res
    

ans = dfs(0,1,n,b)
print(ans)

Measured memory_bytes: 9212
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
typedef struct
{
    char name[10];
    long long num;

}ball;
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int i;
  int a[n];
  for(i = 0;i < n;i++)
  {
      cin>>a[i];
  }
  double res = 0,z = 0;;
  for(i = 0;i < k;i++)
  {
      z+=a[i];
  }
  res = z;
  for(i = k;i<n;i++)
  {
      z = z-a[i-k];
      z+=a[i];
      if(z>res)
        res = z;
  }
  res+=k;
  printf("%.12lf",res/2);


}


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

long long l,r,i,j,k,f;

int main()
{
	cin >> l >> r;	
	k=l%2019;
	if(l+2019-k <= r || l+k%3+670 <= r)
	{
		cout << 0;
		return 0;
	}
	long long mn=k*(k+1)%2019;
	for(int i=0;i<r-l;i++)
		for(int j=i+1;j <= r-l;j++)
			mn=min((k+i)*(k+j)%2019,mn);
	cout << mn;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
struct node
{
    ll x,y;
    node(ll x=0,ll y=0):x(x),y(y){}
    bool operator<(const node&o)const
    {
        if(y==o.y) return x<o.x;
        return y>o.y;
    }
}a[N];
ll n,m;
set<int>s;
set<int>::iterator it;
int main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=m;i++)
        s.insert(i);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&a[i].x,&a[i].y),a[i].x;
    sort(a+1,a+1+n);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        if(s.size()==0) break;
        ll t=a[i].x;
        it=s.lower_bound(t);
        if(it!=s.end())
        {
            s.erase(*it);
            ans+=a[i].y;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 6528
n,m = map(int,input().split())
list1 = [list(map(int,input().split())) for i in range(m) ]

keylist = [0,1000000]

for i in range(m):
	if keylist[0] < list1[i][0]:
		keylist[0] = list1[i][0]
	if keylist[1] > list1[i][1]:
		keylist[1] = list1[i][1]
if keylist[0] > keylist[1]:
	print(0)
else:
	print(keylist[1]-keylist[0]+1)

Measured memory_bytes: 27340
import java.util.*;public class Main{public static void main(String[] args) {Scanner sc =new Scanner(System.in);int n=sc.nextInt(),c=n,m=sc.nextInt();int num[]=new int[n+1];for(;n>0;n--) num[n]=n;for(;m>0;m--){String []s=sc.next().split(",");int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]),t=num[a];num[a]=num[b];num[b]=t;}for(;n<c;n++)System.out.println(num[n+1]);}}

Measured memory_bytes: 17196
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int cnt = k;
    int ans = 1;
    while(cnt < n){
        cnt += (k-1);
        ans++;
    }

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

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

int main() {
  char c;
  cin >> c;
  if (c == 'S') cout << "Cloudy" << endl;
  else if (c == 'C') cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
def submit():
    s = input()
    t = input()
    char_set = set(s)
    next_char = {c: -1 for c in char_set}
    char_list = {(c, len(s)): -1 for c in char_set}

    for i in reversed(range(len(s))):
        for c in char_set:
            if c == s[i]:
                char_list[(c, i)] = i
            else:
                char_list[(c, i)] = char_list[(c, i + 1)]
            
    loop = 0
    curr = 0
    for c in t:
        # 実現不可能
        if c not in char_set:
            print(-1)
            return
        if char_list[(c, curr)] < 0:
            loop += 1
            curr = 0
        curr = char_list[(c, curr)] + 1
    print(loop * len(s) + curr)
        

submit()

Measured memory_bytes: 270012