akhauriyash/Code-Regression huggingface dataset:
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
nb = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    t = collections.deque(list(input()))

    jump = [[0] * 26 for _ in range(len(s) + 1)]

    for i in range(len(s) - 1, -1, -1):
        jump[i] = jump[i + 1].copy()
        jump[i][ord(s[i]) - 97] = i + 1

    ans = 0
    point = 0
    while len(t) > 0:
        tmp = t.popleft()
        character = ord(tmp) - 97
        if jump[point][character] == 0 and point == 0:
            print(-1)
            exit(0)
        point = jump[point][character]
        if point == 0:
            t.appendleft(tmp)
            ans += 1

    print(ans * len(s) + point)


if __name__ == '__main__':
    main()


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


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

struct edge {int to; ll cost; };

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

ll GCD(ll a, ll b){
  if(b==0) return a;
  else return GCD(b, a%b);
}

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool start = false;
  int ans = 0, cnt = 0;
  for(int i=0; i<n; i++){
    if(s[i]=='R') cnt++;
    if(!start){
      if(s[i]=='W') start = true;
      continue;
    }
    if(s[i]=='R') ans++;
  }
  int tmp = 0;
  for(int i=0; i<cnt; i++){
    if(s[i]=='W') tmp++;
  }
  ans = min(ans, tmp);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3716
#include<stdio.h>

int main(void)
{
  int x[20000], y[20000];
  char op[128];
  int i=0, j;
  int result[20000];

  while(1)
    {
      scanf("%d %s %d", &x[i], &op[i], &y[i]);
      if (op[i] == '?')
	break;
      else if (op[i] == '+')
	result[i] = x[i] + y[i];
      else if (op[i] == '-')
	result[i] = x[i] - y[i];
      else if (op[i] == '*')
	result[i] = x[i] * y[i];
      else if (op[i] == '/')
	result[i] = x[i] / y[i];
      i++;
    }

  for(j=0;j<i;j++)
    {
      printf("%d\n", result[j]);
    }

  return 0;
}

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

int main(){
  int N;
  cin >> N;
  map<string,int> s,t;
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    if(s.count(S)){
      s.at(S)++;
    }else{
      s[S]=1;
    }
  }
  int M;
  cin >> M;
  for(int i=0;i<M;i++){
    string S;
    cin >> S;
    if(t.count(S)){
      t.at(S)++;
    }else{
      t[S]=1;
    }
  }
  int ma=0;
  for(auto p:s){
    if(t.count(p.first)){
      if(p.second-t.at(p.first)>ma){
        ma=p.second-t.at(p.first);
      }
    }else{
      if(p.second>ma){
        ma=p.second;
      }
    }
  }
  cout << ma << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mpr make_pair
#define MX 1000
#define ui unsigned int
#define ll long long
#define ld long double 
#define fi first
#define se second
#define endl '\n'
#define debug(bug) cout<<"akshat"<<" "<<bug<<endl
#define printarray(Aneveruse,neverusen) for(int neveruse=0;neveruse<neverusen;neveruse++) cout<<Aneveruse[neveruse]<<" "; cout<<endl
#define printvector(Aneveruse,neverusen) for(int neveruse=0;neveruse<neverusen;neveruse++) cout<<Aneveruse[neveruse]<<" "; cout<<endl
#define dd long double 
#define timetaken cerr<<clock()/double(CLOCKS_PER_SEC)<<endl
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)
const ll inf=1000000000000;
const int mod=1000000007;
// priority_queue <int, vector<int>, greater<int> > pq; //minimum priority queue
int n;
ll a[MX],s[MX],f[MX][MX];

int main()
{
  fast_io;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
     cin>>a[i];
     s[i]=s[i-1]+a[i];
  }

  for(int len=2;len<=n;len++)
  {
    for(int i=1;i<=n-len+1;i++)
    {
        int j=i+len-1;
        f[i][j]=1e18;
        for(int k=i;k<j;k++)
        {
          f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+s[j]-s[i-1]);
        }
    }
  }

  cout<<f[1][n]<<endl;

 
  return 0;
}




Measured memory_bytes: 3968
input_s = input()
elems = input_s.split('/')
date = [int(elem) for elem in elems]
year, month, day = date
if (year > 2019):
    print('TBD')
elif(year < 2019):
    print('Heisei')
else:
    if(month > 4):
        print('TBD')
    elif(month < 4):
        print('Heisei')
    else:
        print('Heisei')


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
    int N,p[100];
    scanf("%d",&N);
    int i;
    int c;
    c=0;
    for(i=1;i<=N;i++){
        scanf("%d",&p[i]);
        if(i!=p[i]){
            c=c+1;
        }
        if(c>2){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int N; cin >> N;
    int ans = 0;
    if(N % 2 == 0){
        N /= 2;
        while(N > 0){
            ans += N / 5;
            N /= 5;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
#define EPS (1e-15)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point {
public:
	double x, y;
	Point() {}
	Point(double xx, double yy) {
		x = xx;
		y = yy;
	}
	Point operator + (Point& p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point& p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }

	double norm() { return x * x + y * y; }
	double abs() { return sqrt(norm()); }

	bool operator == (const Point& p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};
struct Segment {
	Point p1, p2;
};
typedef Point Vector;
typedef Segment Line;
class Circle {
public:
	Point c;
	double r;
	Circle(Point cc, double rr) {
		c = cc;
		r = rr;
	}
};

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}
Point project(Segment s, Point p) {
	Vector hepo = p - s.p1;
	Vector base = s.p2 - s.p1;
	Vector t = base * (dot(p - s.p1, base) / base.norm());
	Point x = s.p1 + t;
	return x;
}
int main() {
	Point p1, p2, p, x, t;
	cin >> p1.x >> p1.y >> p2.x >> p2.y;
	Segment s;
	s.p1 = p1;
	s.p2 = p2;
	int q;
	cin >> q;
	while (q--) {
		cin >> p.x >> p.y;
		t = project(s, p);
		t = (t - p)*2;
		x = p + t;
		printf("%.9lf %.9lf\n", x.x, x.y);
	}
}


Measured memory_bytes: 3276
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	long long int a,s,d,f,g[100000],h,i,j,z,x,c,q[4];
	while(1){
			scanf("%lld %lld %lld",&a,&s,&d);
			if(a==0&&s==0&&d==0)	break;
		scanf("%lld",&f);
		for(i=0;i<f;i++)	scanf("%lld",&g[i]);
		q[0]=a*a+s*s;
		q[1]=a*a+d*d;
		q[2]=s*s+d*d;
		for(i=0;i<f;i++){
			j=(g[i]*2)*(g[i]*2);
			if(j<=q[0]&&j<=q[1]&&j<=q[2])	printf("NA\n");
			else	printf("OK\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    if(a == 1) ans += 3e5;
    else if(a == 2) ans += 2e5;
    else if(a == 3) ans += 1e5;
    if(b == 1) ans += 3e5;
    else if(b == 2) ans += 2e5;
    else if(b == 3) ans += 1e5;
    if(a == 1 && b == 1) ans += 4e5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math

x = int(input())
p = 1
flag = 0

while flag == 0:
    p = 1
    for i in range(2, int(math.sqrt(x))):
        if x % i == 0:
            p = 0
            break
    if p == 0:
        x += 1
    else:
        flag = 1

print(x)


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64

#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#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, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e17 + 1;
constexpr int INF = 1e9 + 1;
//int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };


void solve() {
	string S, T; cin >> S >> T;
	int N = S.size(), M = T.size();
	ll ans = INF;
	REP(i, N - M + 1) {
		int cnt = 0;
		REP(j, M) {
			if (S[i + j] != T[j])cnt++;
		}
		chmin(ans, cnt);
	}
	print(ans);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();

}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        if (N.length() == 3) {
            getPro(Integer.parseInt(N.substring(2)));
        } else if (N.length() == 2) {
            getPro(Integer.parseInt(N.substring(1)));
        } else {
            getPro(Integer.parseInt(N.substring(0)));
        }

    }

    private static void getPro(int num){
        if (num == 2 || num == 4 || num == 5 ||num == 7 ||num == 9) {
            System.out.println("hon");
        } else if (num == 0 || num == 1 || num == 6 ||num == 8) {
            System.out.println("pon");
        } else {
            System.out.println("bon");
        }
    }
}

Measured memory_bytes: 26996
L = list(input())
mod = 10**9 + 7

dp = [[0]*2 for _ in range(len(L)+1)]

# 最初は1が確定なため
dp[1][0] = 1
dp[1][1] = 2

for i in range(1, len(L)):
    if L[i] == "0":
        dp[i+1][1] = dp[i][1]
        dp[i+1][0] = 3*dp[i][0]
    else:
        dp[i+1][1] = 2*dp[i][1]
        dp[i+1][0] = 3*dp[i][0] + dp[i][1]
    dp[i+1][0] %= mod
    dp[i+1][1] %= mod
print(sum(dp[len(L)]) % mod)


Measured memory_bytes: 20296
#include<stdio.h>
#include<iostream>
using namespace std;

string O,E;
int main (){
    cin >> O >> E;
    int l = O.length();
    int m = E.length();
    for(int i=0; i<l+m; i++){
        if( i % 2 == 0) cout << O[i/2];
        if( i % 2 == 1) cout << E[(i-1)/2];
    }
    cout << endl;
    return 0;
}


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


Measured memory_bytes: 2756
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
#define ll long long
typedef vector<int> vi;
//macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
int mod = 1e9+7;
/////////////////////////////////////////////////////////////SEGMENT  TREES////////////////////////////////////////////////
// const int N = 100000;  
// int n;
// int tree[2 * N]; 

// void build( int arr[])  
// {   
//     for (int i=0; i<n; i++) // insert leaf nodes in tree     
//         tree[n+i] = arr[i]; 
       
//     for (int i = n - 1; i > 0; --i) // build the tree by calculating parents add function here      
//         tree[i] = tree[i<<1] + tree[i<<1 | 1];     
// } 

// void updateTreeNode(int p, int value)  
// {   
//     tree[p+n] = value; 
//     p = p+n;

//     for (int i=p; i > 1; i >>= 1) 
//         tree[i>>1] = tree[i] + tree[i^1]; 
// } 
  
// // function to get sum on interval [l, r) 
// int query(int l, int r)  
// {  
//     int res = 0; 
      
//     // loop to find the sum in the range 
//     for (l += n, r += n; l < r; l >>= 1, r >>= 1) 
//     { 
//         if (l&1)  
//             res += tree[l++]; 
      
//         if (r&1)  
//             res += tree[--r]; 
//     } 
      
//     return res; 
// }

/////////////////////////////////////////////////////**********************/////////////////////////////////////////////////

// int gcd(int a,int b){
// 	if(b == 0){
// 		return a;
// 	}
// 	return gcd(b,a%b);
// }

void solution(){
	ll n,k;
	cin >> n >> k;
	vector<ll> nums(n);
	for(ll& x : nums){
		cin >> x; 
	}
	vector<ll> dp(n,INT_MAX);
	dp[0] = 0;
	for(int i=1;i<n;i++){
		for(int j=1;j<=k;j++){
			dp[i] = min(dp[i],(i-j >=0 ? (dp[i-j]+abs(nums[i] - nums[i-j])) : INT_MAX));
		}
	}
	cout << dp[n-1] << endl;
	return;
}
 
 
// void solution(){ //read a whole line from the input, possibly containing spaces
// 	string s;
// 	getline(cin,s);
// }
int main(){
	
    fio; // fast input output
    int t;
    t = 1;
    // cin >> t;
    while(t--){
    	// cout << "Case #" << t  << ": ";
        solution();
    }
    return 0;
};

Measured memory_bytes: 4780
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int N;
	cin >> N;
	vector<ll> X(N),X_sort(N);
	
	REP(i, N) {
		cin >> X[i];
		X_sort[i] = X[i];
	}
	sort(X_sort.begin(), X_sort.end());
	ll middle1 = X_sort[N / 2 - 1];
	ll middle2 = X_sort[N / 2];

	REP(i, N) {
		if (X[i] <= middle1) {
			cout << middle2 << endl;
		}
		else {
			cout << middle1 << endl;
		}
	}


	system("pause");
	return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
ll solve(ll x) {
	if (x == 0) {
		return 0;
	}
	return 1 + 2ll * solve(x / 2);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	ll H;
	cin >> H;
	cout << solve(H) << '\n';
	return 0;
}


Measured memory_bytes: 256
N,Q=gets.chomp.split(" ").map(&:to_i)
queues = []
N.times do
    name,time=gets.chomp.split(" ")
    queues.push([name, time.to_i])
end

cnt = 0
while !queues.empty? do
    queue = queues.shift
    if queue[1] <= Q
        cnt += queue[1]
        puts "#{queue[0]} #{cnt}"
    else
        cnt += Q
        queue[1] -= Q
        queues.push(queue)
    end
end


Measured memory_bytes: 13712
#include<bits/stdc++.h>
using namespace std;
long long Q,H,S,D,N;
int main(){
    cin>>Q>>H>>S>>D>>N;
    if(N%2==0)cout<<min(min(min(Q*8,H*4),S*2),D)*N/2;
    else cout<<min(min(Q*4,H*2),S)+min(min(min(Q*8,H*4),S*2),D)*(N-1)/2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a;
    cin>>n;
    std::deque<long long int> deq;
    for (int i=0;i<3*n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    sort(deq.begin(),deq.end());
    long long int sum=0;
    for (int i=0;i<n;i++) {
        deq.pop_front();
        deq.pop_back();
        long long int tmp=deq.back();
        deq.pop_back();
        sum+=tmp;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 6032
#include <iostream>
#include <stdio.h>
using namespace std;
typedef pair<int,int> P;
int p,q,a,n;

P add(P a,P b){
    P res = {a.first*b.second+a.second*b.first,a.second*b.second};
    return res;
}

int dfs(int len,int num,int mul,P frac){
    if(frac.first*q==frac.second*p) return 1;
    if(frac.first*q>frac.second*p) return 0;
    int cnt = 0;
    if(len!=n) for(int i=num;mul*i<=a;i++) cnt += dfs(len+1,i,mul*i,add(frac,P(1,i)));
    return cnt;
}

int main(){
    while(1){
        scanf("%d%d%d%d",&p,&q,&a,&n);
        if(p==0) return 0;
        int ans = 0;
        printf("%d\n",dfs(0,1,1,P(0,1)));
    }
}


Measured memory_bytes: 3152
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        _n: usize,
        k: usize,
        s: chars,
    }
    let mut s = s;
    s[k-1] = s[k-1].to_lowercase().next().unwrap();
    println!("{}", s.into_iter().collect::<String>());
}

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

int main() {
    int X;
    cin >> X;
    ll sum = 0;
    while (X >= 5) {
        if (X >= 500) {
            sum += 1000;
            X -= 500;
        } else if (X >= 5) {
            sum += 5;
            X -= 5;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3596
/*alurquiza*/
//https://matcomgrader.com/problem/9623/dictionary-search/
//Segment Tree + binary search
#include <bits/stdc++.h>

using namespace::std;


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	// freopen("milkvisits.in","r",stdin);
	// freopen("milkvisits.out","w",stdout);

	int N,DR;
	cin >> N >> DR;

	cout << DR + (100) * (10 - min(N,10)) << '\n';


	return 0;
}

//g++ -std=c++11 -Wall DS.cpp -o main

Measured memory_bytes: 256
int m,n,P[1000],b[500],r[500],i,j,t;
char C[1000][1000],V[1000];
int h(x,y){return y?h(y,x%y):x;}
int g(x,y){return x>y?h(x,y):h(y,x);}
int match(s){int i=m;for(;i<m+n;i++)if(C[s][i]&&!V[i])if(V[i]=1,P[i]<0||match(P[i]))return P[s]=i,P[i]=s,1;return 0;}
main(){
  for(;scanf("%d%d",&m,&n),m;printf("%d\n",t)){
    memset(&C,0,sizeof(C)),memset(&P,0xff,sizeof(P));
    for(i=0;i<m;i++)scanf("%d",b+i);
    for(j=0;j<n;j++)scanf("%d",r+j);
    for(i=0;i<m;i++)for(j=0;j<n;j++)C[i][j+m]=C[j+m][i]=g(b[i],r[j])>=2;
    for(t=i=0;i<m;i++)memset(&V,0,sizeof(V)),t+=match(i);
  }
  return 0;
}

Measured memory_bytes: 1608
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define MAX 100004

vector<int> v[MAX];
int dist[MAX];
bool color[MAX];
int parent[MAX];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for (int i = 1; i < n+1; i++) {
		dist[i] = -1;
	}
	dist[1] = 0;
	parent[1] = -1;
	queue<int> p,q,r;
	q.push(1);
	int now;
	while (!q.empty()) {
		now = q.front();
		q.pop();
		for (int i = 0; i < v[now].size(); i++) {
			int next = v[now][i];
			if (dist[next] == -1) { 
			dist[next] = dist[now] + 1; 
			parent[next] = now;
			q.push(next);
			}
		}
		if (dist[n] != -1) { break; }
	}
	int d = dist[n];
	d = (d - 1) / 2;
	int bound = n;
	for (int i = 0; i < d; i++) {
		bound = parent[bound];
	}
	int fineck = 1; int sunuke = 1;
	p.push(1); r.push(n);
	for (int i = 1; i <= n; i++) {
		dist[i] = -1;
	}
	dist[1] = 0;
	while (!p.empty()) {
		now = p.front();
		p.pop();
		for (int i = 0; i < v[now].size(); i++) {
			int next = v[now][i];
			if (dist[next] == -1 && next != bound) {
				dist[next] = dist[now] + 1;
				fineck++;
				p.push(next);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		dist[i] = -1;
	}
	dist[n] = 0;
	bound = parent[bound];
	while (!r.empty()) {
		now = r.front();
		r.pop();
		for (int i = 0; i < v[now].size(); i++) {
			int next = v[now][i];
			if (dist[next] == -1 && next != bound) {
				dist[next] = dist[now] + 1;
				sunuke++;
				r.push(next);
			}
		}
	}
	if (fineck > sunuke) { cout << "Fennec" << endl; }
	else { cout << "Snuke" << endl; }
}

Measured memory_bytes: 6656
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for j in range(1,W+1):
        print('#',end='')
    print()
    for i in range(2,H):
        print('#',end='')
        for j in range(1,W-1):
            print('.',end='')
        print('#',end='')
        print()
    for j in range(1,W+1):
        print('#',end='')
    print()
    print()



Measured memory_bytes: 7000
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  ll X;cin>>X;
  int fh = X / 500;
  int f = (X - fh*500) / 5;
  p(fh*1000+f*5);
  return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String args[]) throws IOException {
		@SuppressWarnings("resource")
		Scanner cin = new Scanner(System.in);
		ArrayList<String> inLines = new ArrayList<String>();
		for (; cin.hasNext();) {
			inLines.add(cin.nextLine());
		}
		Solver solver = new Solver();
		solver.solve(inLines);
	}
}

class Solver {
	int N;
	String str;

	public void solve(ArrayList<String> inLines) {
		N = Integer.parseInt(inLines.get(0));
		str = inLines.get(1);

		animals = new char[N];
		animals[0] = 'S';
		animals[1] = 'S';
		if (check()) {
			System.out.println(animals);
			return;
		}
		animals[0] = 'S';
		animals[1] = 'W';
		if (check()) {
			System.out.println(animals);
			return;
		}
		animals[0] = 'W';
		animals[1] = 'S';
		if (check()) {
			System.out.println(animals);
			return;
		}
		animals[0] = 'W';
		animals[1] = 'W';
		if (check()) {
			System.out.println(animals);
			return;
		}
		System.out.println(-1);
	}

	char[] animals;

	private boolean check() {
		for (int i = 1; i < N - 1; i++) {
			if (animals[i] == 'S') {
				if (str.charAt(i) == 'o') {
					animals[i + 1] = animals[i - 1];
				} else {
					animals[i + 1] = animals[i - 1] == 'S' ? 'W' : 'S';
				}
			}
			if (animals[i] == 'W') {
				if (str.charAt(i) == 'x') {
					animals[i + 1] = animals[i - 1];
				} else {
					animals[i + 1] = animals[i - 1] == 'S' ? 'W' : 'S';
				}
			}
		}

		if (animals[N - 1] == 'S') {
			if (str.charAt(N - 1) == 'o' && animals[N - 2] != animals[0]) {
				return false;
			}
			if (str.charAt(N - 1) == 'x' && animals[N - 2] == animals[0]) {
				return false;
			}
		}
		if (animals[N - 1] == 'W') {
			if (str.charAt(N - 1) == 'o' && animals[N - 2] == animals[0]) {
				return false;
			}
			if (str.charAt(N - 1) == 'x' && animals[N - 2] != animals[0]) {
				return false;
			}
		}
		if (animals[0] == 'S') {
			if (str.charAt(0) == 'o' && animals[N - 1] != animals[1]) {
				return false;
			}
			if (str.charAt(0) == 'x' && animals[N - 1] == animals[1]) {
				return false;
			}
		}
		if (animals[0] == 'W') {
			if (str.charAt(0) == 'o' && animals[N - 1] == animals[1]) {
				return false;
			}
			if (str.charAt(0) == 'x' && animals[N - 1] != animals[1]) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 26956
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: i32 = sc.read();
    let mut ans = 0;
    for i in 1..40000 {
        if i * i <= n {
            ans = i * i;
        }
    }
    println!("{}", ans)
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim(){
	int u, minv;
	int d[MAX], p[MAX], color[MAX];

	for(int i=0;i<n;i++){
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
	}

	d[0] = 0;

	while(1){
		minv = INFTY;
		u = -1;
		for(int i=0;i<n;i++){
			if(minv > d[i] && color[i] != BLACK){
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		color[u] = BLACK;
		for(int v=0;v<n;v++){
			if(color[v] != BLACK && M[u][v] !=INFTY){
				if(d[v] > M[u][v]){
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	int sum = 0;
	for(int i=0;i<n;i++){
		if(p[i] != -1) sum += M[i][p[i]];
	}

	return sum;
}

int main(){
	cin >> n;

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int e; cin >> e;
			M[i][j] = (e == -1) ? INFTY : e;
		}
	}

	cout << prim() << endl;

	return 0;
}

Measured memory_bytes: 3132
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
int add(int n)
{
	int s=0;
	while(n>=10)
	{
		s+=n%10;
		n/=10;
	}
	s+=n;
	return s;
}
int main()
{
	int n,i,ans=1e9;
	cin>>n;
	int l=1,r=n-1;
	while(l<=r)
	{
		int sum=0;
		sum=add(l)+add(r);
		ans=min(ans,sum);
		l++;
		r--;
	}
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;



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

	cin >> N;
	vector<int>v;
	string s = to_string(N);
	for (int i = 0; i < s.size(); i++) {
		v.push_back(N % 10);
		N /= 10;
	}
	reverse(v.begin(), v.end());
	vector<vector<vector<vector<vector<int>>>>>dp(v.size(),  vector<vector<vector<vector<int>>>>(2, vector<vector<vector<int>>>(2, vector<vector<int>>(2, vector<int>(2)))));
	for (int i = 0; i < v[0]; i++) {
		if (i != 3 && i != 5 && i != 7)continue;
		dp[0][0][i == 3][i == 5][i == 7] = 1;
	}
	if(v[0]==3||v[0]==5||v[0]==7)dp[0][1][v[0] == 3][v[0] == 5][v[0] == 7] = 1;
	for (int i = 0; i < v.size() - 1; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				for (int l = 0; l < 2; l++) {
					for (int m = 0; m < 2; m++) {
						for (int d = 0; d < 10; d++) {
							if (d != 3 && d != 5 && d != 7)continue;
							if (j&&d > v[i + 1])break;
							dp[i + 1][j&(d == v[i + 1])][k | (d == 3)][l | (d == 5)][m | (d == 7)] += dp[i][j][k][l][m];
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int j = 0; j < 2; j++) {
		ans += dp.back()[j][1][1][1];
	}
	for (int i = 3; i < s.size(); i++) {
		vector<vector<vector<vector<int>>>>ddp(i, vector<vector<vector<int>>>(2, vector<vector<int>>(2, vector<int>(2))));
		ddp[0][1][0][0] = 1;
		ddp[0][0][1][0] = 1;
		ddp[0][0][0][1] = 1;
		for (int j = 1; j < i; j++) {
			for (int k = 0; k < 2; k++) {
				for (int l = 0; l < 2; l++) {
					for (int m = 0; m < 2; m++) {
						for (int d = 3; d <= 7; d += 2) {
							ddp[j][k | (d == 3)][l | (d == 5)][m | (d == 7)] += ddp[j - 1][k][l][m];
						}
					}
				}
			}
		}
		ans += ddp.back()[1][1][1];
	}
	cout << ans << endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> masu(H, vector<char>(W));
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> masu.at(i).at(j);
    }
  }
  
  vector<bool> h_w(H, true);
  vector<bool> w_w(W, true);
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(masu.at(i).at(j) == '#'){
        h_w.at(i) = false;
        break;
      }
    }
  }
  
  for(int i = 0; i < W; i++){
    for(int j = 0; j < H; j++){
      if(masu.at(j).at(i) == '#'){
        w_w.at(i) = false;
        break;
      }
    }
  }
  
  for(int i = 0; i < H; i++){
    if(h_w.at(i) == false){
      for(int j = 0; j < W; j++){
        if(w_w.at(j) == false)
          cout << masu.at(i).at(j);
      }
      cout << endl;
    }
  }

}


Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>

#define rep(i,n) for((i)=0;i<(int)(n);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)

using namespace std;



int main() {
	int N;
	long long ans = 0;
	int color[200] ;//0:未探索 1:探索中 2:探索済み->再度見つけたらout
	int depth[200];//0:根 
	string S[200];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			color[j] = 0;
			depth[j] = -1;
		}
		queue<int> que;
		que.push(i);
		depth[i] = 0;
		color[i] = 1;
		bool isFailed = 0;
		int d = 0;
		while (!isFailed && !que.empty()) {
			int x = que.front();
			que.pop();
			for (int p = 0; p < N; p++) {
				if (S[x][p] == '0')continue;
					
				//隣接したもので足されてなければ追加
				if (x != p && color[p] == 0) {
					color[p] = 1;
					depth[p] = depth[x] + 1;
					que.push(p);
				}
				if (x != p &&  depth[x] != depth[p] +1 && color[p] == 2 )
					isFailed = 1;
			}
			//探索終わり
			color[x] = 2;

		}
		int minD = -1;
		for (int j = 0; j < N; j++)
			minD = max(depth[j], minD);
		if (minD != 0 && !isFailed)ans = max(minD, ans);
	}

	if (ans > 300 || ans <= 0)cout << "-1";
	else cout << ans+1;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())
	//https://atcoder.jp/contests/abc165/tasks/abc165_f
	//https://www.dropbox.com/sh/nx3tnilzqz7df8a/AAA0887IQFx5BcrZcrpRD7uga/ABC165/F?dl=0&subfolder_nav_tracking=1

	n := nextInt()
	yen := nextInt()

	x := -1
	y := -1
	z := -1

	for i := 0; i <= yen/1000; i++ {
		xx := yen + 4000*i - 5000*n
		yy := 10000*n - 9000*i - yen
		if xx >= 0 && xx%5000 == 0 && yy >= 0 && yy%5000 == 0 {
			x = xx / 5000
			y = yy / 5000
			z = i
			break
		}
	}
	fmt.Fprintln(out, x, y, z)

	//	fmt.Fprintln(out, "[DEBUG]]", a)
	//fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 640
def nCk(n, k):
    ans = 1
    i = 0
    while i < k:
        ans *= n - i
        i += 1
    i = 1
    while i <= k:
        ans /= i
        i += 1
    return ans

def main():
    [N, P] = map(int, raw_input().split())
    even = 0
    odd = 0
    A = map(int, raw_input().split())
    i = 0
    while i < N:
        if 0 == A[i] & 1:
            even += 1
        else:
            odd += 1
        i += 1
    i = P
    k = 0
    while i <= odd:
        k += nCk(odd, i)
        i += 2
    print((2 ** even) * k)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2696
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    if (H < W) swap(H, W);
    cout << (N + H - 1) / H << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    char c = '1';
    rep(i, s.size()) {
        if(s[i] != '1' || i+1 == k) {
            c = s[i];
            break;
        } 
    }
    cout << c << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <assert.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILL(x,c) memset(x,c,sizeof(x))

using namespace std;

const double eps = 1e-8;

#define PB push_back
#define MP make_pair

typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long double> VD;
typedef pair<int,int> PII;
typedef long long int64;
typedef long long LL;
typedef unsigned int UI;
typedef long double LD;
typedef unsigned long long ULL;

const int MOD = 1000000007;

LL usum[2000000];
LL dp[2000000][2];
int last[2000000];
int a[2000000];

int main() {
    int n;
    cin >> n;
    REP(i, n) scanf("%d", &a[i]);
    for (int i = 1; i < n; ++i) {
        a[i] ^= a[i - 1];
    }
    // REP(i, n) cout << a[i] << " "; cout << endl;
    int count0 = 0;
    REP(i, n) {
        if (a[i] == 0) {
            ++count0;
        }
    }
    LL ans = 0;
    if (a[n - 1] == 0) {
        --count0;
        int res = 1;
        REP(i, count0) res = res * 2 % MOD;
        ans = (ans + res) % MOD;
    }

    count0 = 0;
    REP(i, n) {
        if (i == n - 1 && a[i] != 0) {
            ans = (ans + 1 + dp[a[i]][0] + usum[a[i]] * (count0 - last[a[i]])) % MOD;
        }
        if (a[n - 1] == 0 && a[i] != 0) {
            ans = (ans + 1 + dp[a[i]][0] + usum[a[i]] * (count0 - last[a[i]])) % MOD;
        }
        if (a[i] != 0) {
            int nsum = (usum[a[i]] + 1 + dp[a[i]][0] + usum[a[i]] * (count0 - last[a[i]])) % MOD;;
            dp[a[i]][0] = (dp[a[i]][0] + usum[a[i]] * (count0 - last[a[i]])) % MOD;
            usum[a[i]] = nsum;
            last[a[i]] = count0;
        } else {
            ++count0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 36992
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=1e5+5;
int a[N],k,n;ll f[N][2],res;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	memset(f,0xef,sizeof(f));
	f[0][0]=0;
	fp(i,1,n){
		if(!a[i])f[i][0]=max(f[i-1][0],f[i-1][1]);
		else{
			f[i][0]=max(f[i-1][0]+(a[i]>>1),max(f[i-1][1]+(a[i]>>1),f[i-1][1]+((a[i]-1)>>1)+1));
			f[i][1]=max(f[i-1][0]+((a[i]-1)>>1),max(f[i-1][1]+((a[i]-1)>>1),a[i]>=2?f[i-1][1]+((a[i]-2)>>1)+1:0));
		}
	}
	printf("%lld\n",max(f[n][0],f[n][1]));
	return 0;
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> s(M);
    vector<int> c(M);
    vector<int> ans(N,0);
    int a = 0;

    for (int i = 0; i < M; ++i) {
        cin >> s[i] >> c[i];
    }

    for (int l = 0; l < M; ++l) {
        if ((N>1)&&((s[l])==1)&&(c[l])==0){
            cout << -1 << endl;
            return 0;
        }
        for (int j = 0; j < l; ++j) {
            if ((s[l] == s[j])&&(c[l]!=c[j])){
                cout << -1 << endl;
                return 0;
            }
        }
        ans[s[l]-1] = c[l];
    }


    if((N>1)&&(ans[0])==0) ans[0]=1;

    for (int k = 0; k < N; ++k) {
        cout << ans[k];
    }
    return 0;
}


Measured memory_bytes: 256
use std::vec::Vec;
use std::collections::HashSet;


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let k: usize = read();
    if k % 2 == 0 {
       println!("{}", (k / 2) * (k / 2));
    } else {
        println!("{}", (k / 2) * (k / 2 + 1));
    }
}

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





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a.at(i);
	sort(revall(a));
	ll ans = 1, cnt = 0;
	rep(i,n - 1){
		if(a.at(i) == a.at(i + 1)){
			cnt++;
			ans *= a.at(i);
			i++;
		}
		if(cnt == 2) break;
	}
	if(cnt == 2) cout << ans << endl;
	else cout << 0 << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		static int n;
		static long[] a;

		static long[,] dp;

		static void Main(string[] args)
		{
			n = int.Parse(Console.ReadLine());
			a = Console.ReadLine().Split().Select(long.Parse).ToArray();

			dp = new long[n + 1, n + 1];

			for (int len = 1; len <= n; len++) {
				for (int i = 0; i + len <= n; i++) {
					int j = i + len;
					if ((n - len) % 2 == 0) {
						dp[i, j] = Math.Max(dp[i + 1, j] + a[i], dp[i, j - 1] + a[j - 1]);
					} else {
						dp[i, j] = Math.Min(dp[i + 1, j] - a[i], dp[i, j - 1] - a[j - 1]);
					}
				}
			}
			Console.WriteLine(dp[0, n]);
		}
	}
}


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

using namespace std;

signed main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    string t = "ABC";
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            cnt++;
        }
    }
    cout << cnt << "\n";
    return false;
}

Measured memory_bytes: 256
#coding utf-8

N = int(input())
s = list(input())
t = list(input())
Flg = True
for i in range(N,-1,-1):
    if s[N-i:N] == t[:i]:
        ans = 2 * N - i
        Flg = False
        break

if Flg:
    ans = 2 * N
    if s[-1] == t[0]:
        ans = 2 * N - 1
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int main()
{
    int N,i,j,count=1, max;
    scanf("%d", &N);
    int H[N];
    for(i=0; i<N;i++)
    scanf("%d", &H[i]);

    max = H[0];

    for(j=1; j<N; j++)
    {
        if(H[j]>=max)
        {
            max = H[j];
            count++;
        }
    }
    printf("%d\n", count);

    return 0;

}


Measured memory_bytes: 1688
#include<bits/stdc++.h>
    using namespace std;
	
    int main(){
    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
		int n;
		cin>>n;
		int a1[n],b1[n],c1[n];
		for(int i=0;i<n;i++){
			cin>>a1[i]>>b1[i]>>c1[i];
		}
		int dp[n][3];
		dp[0][0]=a1[0];
		dp[0][1]=b1[0];
		dp[0][2]=c1[0];
		for(int i=1;i<n;i++){
			dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a1[i];
			dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b1[i];
			dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c1[i];
		}
		cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<"\n";
        return 0;
    }

Measured memory_bytes: 2560
while True:
	n = input()
	if n == 0:
		break
	
	array = map(int,raw_input().split())
	aray = []
	count = 0
	while array != aray:
		aray = array
		agency = []
		for i in xrange(n):
			agency.append(array.count(array[i]))
		array = agency
		count += 1
		
	print count - 1
	
	string = ""
	for var in array:
		string += str(var) + " "
		
	print string[:len(string) - 1]

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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    lld S,W;
    cin >> S >> W;
    if(S <= W){
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3632
from collections import Counter
from itertools import product
import numpy as np

n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]

xlist = np.array([[0 for j in range(n)] for i in range(n)])
for (l,r),i in Counter(rails).items():
    xlist[l-1,r-1]=i

sumsumlist = np.cumsum(np.cumsum(xlist,axis=1),axis=0)


for (p,q) in qs:
    if p>1:
        ans = sumsumlist[q-1][q-1] - sumsumlist[q-1][p-2] - sumsumlist[p-2][q-1] + sumsumlist[p-2][p-2]
    elif p==1:
        ans = sumsumlist[q-1][q-1]

    print(ans)


Measured memory_bytes: 54076
import java.util.Scanner;
     
    class Main{
    	public static void main(String arg[]) {
    		Scanner sc = new Scanner(System.in);
    		int A = sc.nextInt();
    		int B = sc.nextInt();
    		int C = sc.nextInt();
    		int D = sc.nextInt();
    		sc.close();
    		int[] Alice = new int[102];
    		int[] Bob = new int[102];
    		
    		int ans = Math.min(B, D) - Math.max(A, C);
          	if(ans >= 0){
            	System.out.println( ans );
            }else{
              	System.out.println( 0 );
            }
    	}
    }

Measured memory_bytes: 23252
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

from collections import Counter
ca = Counter(a)
d = n % 2
if d == 1:
    z = ca.pop(0) if 0 in ca else 0
    if z != 1:
        print(0)
        exit()

for i in range(1 + d, n + d, 2):
    if ca[i] != 2:
        print(0)
        exit()

print(pow(2,n//2, MOD))

Measured memory_bytes: 14692