akhauriyash/Code-Regression huggingface dataset:
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let _ = lines.next().unwrap().unwrap();
    let a_line = lines.next().unwrap().unwrap();
    let splited = a_line.trim().split_whitespace();
    let mut a: Vec<i32> = splited.map(|s| s.parse().unwrap()).collect();
    a.sort_by(|a, b| b.cmp(a));

    let alice: i32 = a.iter().enumerate().filter(|&(i, _)| i % 2 == 0).map(|(_, x)| *x).sum();
    let bob: i32 = a.iter().enumerate().filter(|&(i, _)| i % 2 == 1).map(|(_, x)| *x).sum();

    writeln!(&mut writer, "{}", alice - bob).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"2
3 1", br"2
",
        ),
        (
            br"3
2 7 4", br"5
",
        ),
        (
            br"4
20 18 2 18", br"18
",
        ),
    ];

    #[test]
    fn test_b() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int fn(int A)
{
  if(A%2 == 1)
  {
    return (int)((A+1)%4 != 0);
  }
  else
  {
    return A+(int)((A)%4 != 0);
  }

  return -1;
}
//SOLVE
void solve(void)
{
  int A,B;
  cin>>A>>B;

  // for (int i = 0; i < 100; i++)
  // {
  //   cout<<fn(i)<<endl;
  //   cout<<"test"<<endl;
  // }

  cout<<(fn(B)^fn(A-1))<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
import sys


def resolve():
    S, T = map(str, input().split())
    A, B = map(int, input().split())
    U = input()

    if S == U:
        A -= 1
        print(str(A) + ' ' + str(B))
        return
    B -= 1
    print(str(A) + ' ' + str(B))


resolve()


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

int main(){
  int D;
  cin >> D;
  vector<int>c(27);
  for(int i=1;i<27;i++){
    cin >> c[i];
  }
  vector<vector<int>>s(D+1,vector<int>(27,0));
  vector<int>ma(D+1);
  int A;
  for(int i=1;i<=D;i++){
    for(int j=1;j<27;j++){
      cin >> s[i][j];
      if(j==1){
        ma[i]=s[i][1];
        A=j;
      }
      else{
        ma[i]=max(ma[i],s[i][j]);
        if(ma[i]==s[i][j]){
          A=j;
        }
      }
    }
    cout << A << endl;
  }
} 

Measured memory_bytes: 3680
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head


const int N = 1e3+10;
int n,m,clk,dp[N][N],vis[N][N];
char s[N][N];
void chkmin(int &a, int b) {a>b?a=b:0;}
queue<pii> q;
int main() {
	scanf("%d%d", &n, &m);
	REP(i,1,n) scanf("%s",s[i]+1);
	memset(dp,0x3f,sizeof dp);
	dp[0][1] = 0;
	REP(i,1,n) REP(j,1,m) {
		if (s[i][j]=='.') {
			dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
		}
		else { 
			q.push(pii(i,j)),++clk;
			while (q.size()) {
				pii u = q.front(); q.pop();
				int x=u.x,y=u.y;
				if (vis[x][y]==clk) continue;
				vis[x][y] = clk;
				chkmin(dp[i][j],min(dp[x-1][y],dp[x][y-1])+1);
				if (s[x-1][y]=='#') q.push(pii(x-1,y));
				if (s[x][y-1]=='#') q.push(pii(x,y-1));
			}
		}
	}
	printf("%d\n", dp[n][m]);
}









Measured memory_bytes: 5632
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


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] << ((i == v.size() - 1) ? "\n" : " ")
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>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


void solve() {
	int N, M; cin >> N >> M;
	print(N*(N - 1) / 2 + M * (M - 1) / 2);
}

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pos;
int main(){
  int H,W;cin>>H>>W;
  vector<string> S(H);for(int i=0;i<H;i++)cin>>S[i];
  
  pos vecs[8]={pos(-1,-1),pos(-1,0),pos(-1,1),pos(0,-1),
                  pos(0,1),pos(1,-1),pos(1,0),pos(1,1)};
  
  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      if(S[y][x]!='#'){
        int tmp=0;
        for(int i=0;i<8;i++){
          int X=x+vecs[i].first,Y=y+vecs[i].second;
          if(0<=X && X<W && 0<=Y && Y<H){
            if(S[Y][X]=='#')tmp++;
          }  
        }
        S[y][x]=to_string(tmp)[0];
      } 
    }
  }
  for(int y=0;y<H;y++)cout<<S[y]<<endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int N, Q, K[100];
string S;
ll DP[int(1e6 + 5)][3];

int main(){
  cin >> N >> S >> Q;
  for (int i = 0; i < Q; i++) cin >> K[i];

  for (int i = 0; i < Q; i++){
    DP[0][0] = 0; DP[0][1] = 0; DP[0][2] = 0;
    if (S[0] == 'D') DP[0][0] = 1;
    if (S[0] == 'M') DP[0][1] = 1;

    ll ans = 0;
    for (int j = 1; j < N; j++){
      for (int k = 0; k < 3; k++) DP[j][k] = DP[j - 1][k];

      if (j - K[i] >= 0){
        if (S[j - K[i]] == 'D'){
          DP[j][2] -= DP[j][1];
          DP[j][0]--;
        }
        if (S[j - K[i]] == 'M') DP[j][1]--;
      }

      if (S[j] == 'D') DP[j][0]++;
      if (S[j] == 'M'){
        DP[j][1]++;
        DP[j][2] += DP[j][0];
      }
      if (S[j] == 'C') ans += DP[j][2];
    }
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 24836
import java.util.*;
import java.io.*;
public class Main{
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      int n = Integer.parseInt(st.nextToken());
      int m = Integer.parseInt(st.nextToken());
      int k = Integer.parseInt(st.nextToken());
     long[] a = new long[n+1];
      st = new StringTokenizer(br.readLine());
      for(int i = 1; i <= n; i++)
        a[i] = Long.parseLong(st.nextToken()) + a[i-1];
       st = new StringTokenizer(br.readLine());
     long[] b = new long[m+1];
     int j = 1;
     int max = 0;
      for(int i = 1; i <= m; i++){
        b[i] = Long.parseLong(st.nextToken()) + b[i-1];
        if(b[j] <= k)
          j++;
      }
     j--;
     for(int i = 0; i <= n; i++){
       if(a[i] + b[j] <= k)
         max = Math.max(i+j, max);
       else if(j == 0)
         break;
       else
         j--;
     }
     out.println(max);
      out.close();
   }
}

Measured memory_bytes: 62588
#include<bits/stdc++.h>
#define pb push_back

using namespace std;

const int N=100005;

vector<int>e[N];
int mask[N],ans,n,m,cnt[20];

void dfs(int x,int fa){
	for(int v:e[x])if(v!=fa)dfs(v,x);
	memset(cnt,0,sizeof(cnt));
	for(int v:e[x])if(v!=fa)for(int i=0;i<m;i++)cnt[i]+=mask[v]>>i&1;
	int p=-1,q=-1;
	for(int i=m-1;i>=0;i--){
		if(cnt[i]>1){p=i;break;}
		if(cnt[i]==0)q=i;
	}
	if(p==-1)p=q;
	mask[x]+=1<<p;
	for(int i=p;i<m;i++)if(cnt[i])mask[x]+=1<<i;
}

int main(){
	scanf("%d",&n);
	m=log(n)/log(2)+1;
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),e[u].pb(v),e[v].pb(u);
	dfs(1,0);
	while((1<<ans)<=mask[1])ans++;
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 11776
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> a;
	int A, B, C;
	cin >> A >> B >> C;
	a.push_back(A);
	a.push_back(B);
	a.push_back(C);
	vsort(a);
	int tmp = a[2] * 10 + a[1];
	int rsl = tmp + a[0];
	cout << rsl << endl;

}


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

using namespace std;
int main() {
  int i,j;
  int H,W; 
  cin >> H >> W;
  vector<string> lamp(H);
  for(i=0; i<H; i++){
    cin >> lamp.at(i);
  }
  //Lを計算
  vector<vector<int>> L(H, vector<int>(W));
  for(i=0; i<H; i++){
    if(lamp[i][0]=='#'){
      L[i][0]=0;
    }else{
      L[i][0]=1;
    }
    for(j=1; j<W; j++){
      if(lamp[i][j]=='#'){
        L[i][j]=0;
      }else{
        L[i][j]=L[i][j-1]+1;
      }
    }
  }
  //Rを計算
  vector<vector<int>> R(H, vector<int>(W));
  for(i=0; i<H; i++){
    if(lamp[i][W-1]=='#'){
      R[i][W-1]=0;
    }else{
      R[i][W-1]=1;
    }
    for(j=1; j<W; j++){
      if(lamp[i][W-1-j]=='#'){
        R[i][W-1-j]=0;
      }else{
        R[i][W-1-j]=R[i][W-j]+1;
      }
    }
  }
  //Uを計算
  vector<vector<int>> U(H, vector<int>(W));
  for(j=0; j<W; j++){
    if(lamp[0][j]=='#'){
      U[0][j]=0;
    }else{
      U[0][j]=1;
    }
    for(i=1; i<H; i++){
      if(lamp[i][j]=='#'){
        U[i][j]=0;
      }else{
        U[i][j]=U[i-1][j]+1;
      }
    }
  }
  //Dを計算
  vector<vector<int>> D(H, vector<int>(W));
  for(j=0; j<W; j++){
    if(lamp[H-1][j]=='#'){
      D[H-1][j]=0;
    }else{
      D[H-1][j]=1;
    }
    for(i=1; i<H; i++){
      if(lamp[H-1-i][j]=='#'){
        D[H-1-i][j]=0;
      }else{
        D[H-1-i][j]=D[H-i][j]+1;
      }
    }
  }
  int ans=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(ans<L[i][j]+R[i][j]+U[i][j]+D[i][j]-3){
        ans=L[i][j]+R[i][j]+U[i][j]+D[i][j]-3;
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 67200
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

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

  ll n,m;
  std::cin>>n>>m;

  std::string s;
  std::cin>>s;

  std::vector<P> dp(n+1);
  dp[n]={0,0};

  std::priority_queue<P,std::vector<P>,std::greater<P>> que;

  que.push({0,n});

  for(ll i=n-1;i>=0;i--){
    if(s[i]=='1'){
      dp[i]={MOD,-1};
    }else{
      bool isok=false;
      while(!isok){
        if(que.empty()){
          std::cout<<-1<<"\n";
          return 0;
        }
        P e=que.top();que.pop();
        if(e.second-i<=m){
          isok=true;
          dp[i]={e.first+1,e.second-i};
          que.push(e);
          que.push({dp[i].first,i});
        }
      }
    }
  }

  ll now=0;
  while(dp[now].second!=0){
    std::cout<<dp[now].second<<" ";
    now+=dp[now].second;
  }

  return 0;
}

Measured memory_bytes: 3956
#include<stdio.h>
#include<string.h>
typedef struct{
  char L[30];
  int P;
  int A;
  int B;
  int C;
  int D;
  int E;
  int F;
  int S;
  int M;
  int TTime;
  int DETime;
  double TP;
}Plants;

Plants PP[100],tmp2;

int main()
{
  int N,i,j;
  while(1){
    scanf("%d",&N);
    if(N==0)break;
    for(i=0;i<N;i++){
      scanf("%s",PP[i].L);
      scanf("%d%d%d%d%d%d%d%d%d",&PP[i].P,&PP[i].A,&PP[i].B,&PP[i].C,&PP[i].D,&PP[i].E,&PP[i].F,&PP[i].S,&PP[i].M);
      PP[i].TTime=PP[i].A+PP[i].B+PP[i].C+PP[i].D+PP[i].E;
      PP[i].DETime=PP[i].D+PP[i].E;
      PP[i].TP=PP[i].S*PP[i].F;
      if(PP[i].M!=1){
	PP[i].TP+=PP[i].S*PP[i].F*(PP[i].M-1);
      }
      PP[i].TP-=PP[i].P;
      if(PP[i].M==1){
      PP[i].TP/=PP[i].TTime;
      }
      else if(PP[i].M!=1){
	PP[i].TP/=PP[i].TTime+PP[i].DETime*(PP[i].M-1);
      }
    }

    for(i=0;i<N;i++){
      for(j=N-1;j>i;j--){
        if(PP[j].TP>PP[j-1].TP){
          tmp2=PP[j];
	  PP[j]=PP[j-1];
          PP[j-1]=tmp2;
	}

      }
    }
    for(i=0;i<N;i++){
      for(j=N-1;j>i;j--){
	if(PP[j].TP==PP[j-1].TP && strcmp(PP[j].L,PP[j-1].L)<0){
	  tmp2=PP[j];
	  PP[j]=PP[j-1];
          PP[j-1]=tmp2;

	}
      }
    }
    
    for(i=0;i<N;i++){
      printf("%s\n",PP[i].L);
    }
    printf("#\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
#define MAX 100000
using namespace std;
ll L = 1000000007;

int main()
{
	string s, t;
	cin >> s >> t;
	for (int i = s.size() - t.size(); i >= 0; i--) {
		//cout<<i<<endl;
		bool ok = true;
		for (int j = 0; j<t.size(); j++) {
			//cout<<s[i+j]<<t[j]<<i<<j<<endl;
			if (s[i + j] != '?'&&s[i + j] != t[j]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			s.replace(i, t.size(), t);
			for (int k = 0; k<s.size(); k++) {
				if (s[k] == '?')cout << 'a';
				else cout << s[k];
			}
			cout << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
}

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


Measured memory_bytes: 256
n = int(input())
nl = str(n)
ll = len(nl)
lis = []
ans = 0
if ll == 1:
  print(n)
  exit()
  
def countn(a,b):
  cur = 0
  if ll >= 3:
    cur += (10**(ll-2)-1)//9
    if a < int(nl[0]):
      cur += 10**(ll-2)
    elif a == int(nl[0]):
      nnl = nl[1:ll-1]
      if b > int(nl[-1]):
        cur += int(nnl)
      else:
        cur += (int(nnl)+1)
  elif ll == 2:
    if 10*a+b <= n:
      cur += 1
  if a == b:
    cur += 1
  return cur

for i in range(1, 10):
  for j in range(1, i+1):
    if i == j:
      ans += countn(i, j)*countn(j, i)
    else:
      ans += 2*countn(i, j)*countn(j, i)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 233333,inf=0x3f3f3f3f;
int n,dis[N],q[N];Vi e[N];
int bfs(int s){
	int f=0,r=1;q[f]=s;
	memset(dis,inf,sizeof(dis));dis[s]=0;int mx=s;
	while(f!=r){
		int u=q[f++];if(dis[u]>dis[mx])mx=u;
		rep(i,0,SZ(e[u])-1)if(dis[e[u][i]]>dis[u]+1){
			dis[e[u][i]]=dis[u]+1;q[r++]=e[u][i];
		}
	}
	return mx;
}
int main() {
	read(n);rep(i,1,n-1){
		int u,v;read(u);read(v);e[u].pb(v);e[v].pb(u);
	}
	int s=bfs(1),t=bfs(s);int c=dis[t]+1;
	if(c%3==2)puts("Second");else puts("First");
	return 0;
}


Measured memory_bytes: 14452
#import sys 
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
n = int(input())
b = n%10
if(b ==2 or b ==4 or b ==5 or b ==7 or b==9):
    print("hon")
elif(b ==0 or b ==1 or b ==6 or b ==8):
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9172
s=input()
c=0
n=int(len(s))
for i in range(n):
  if s[i]!=s[n-i-1]:
    c+=1
    print("No")
    break
if c==0:
  for i in range((n-1)//2):  
    if s[i]!=s[(n-3)//2-i]:
      c+=1
      print("No")
      break
    if s[(n+1)//2+i]!=s[n-i-1]:
      c+=1
      print("No")
      break
if c==0:
  print("Yes")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
int n,i,j,a[200],b,c;
while(cin>>n,n){
for(i=1;i<=n*2;i++)a[i]=2;
for(i=0;i<n;i++){cin>>j;a[j]=1;}
b=c=0;
for(j=1;;){
while(j<=n*2&&a[j]!=1)j++;
if(j>n*2)j=1;
else{
a[j]=0;j++;b++;
if(b==n)break;
}
while(j<=n*2&&a[j]!=2)j++;
if(j>n*2)j=1;
else{
a[j]=0;j++;c++;
if(c==n)break;
}
}
if(b==n)cout<<n-c<<endl<<"0"<<endl;else cout<<"0"<<endl<<n-b<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s;

	int k, l = 1;
	cin >> s >> k;
	std::vector<int> v;
	int n = (int)s.size();
	for(int i = 0; i < n - 1; ++i) {
		if(s[i] != s[i + 1]) {
			v.eb(l);
			l = 1;
		} else {
			++l;
		}
	}
	int res = 0;
	int m = (int)v.size();
	for(int i = 1; i < m; ++i) {
		res += v[i] / 2 * k;
	}
	if(m > 0) {
		if(s[0] != s[n - 1]) {
			res += v[0] / 2 * k + l / 2 * k;
		} else {
			res += v[0] / 2 + l / 2;
			res += (v[0] + l) / 2 * (k - 1);
		}
	} else {
		res += l * k / 2;
	}
	cout << res << endl;
	return 0;
}

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

n, k = map(int, input().split())
H = [int(input()) for i in range(n)]
H.sort()
ans = float('INF')

for i in range(n-k+1):
    d_height = H[k+i-1] - H[i]
    ans = min(ans, d_height)

print(ans)


Measured memory_bytes: 7384
x, y = map(int, input().split())

d = {1:300000, 2:200000, 3:100000}

if x == 1 and y == 1:
	print(10**6)
	exit()

su = 0
if x in d:
	su += d[x]
if y in d:
	su += d[y]
print(su)




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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


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

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


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

  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &i : A) cin >> i;
  map<int, int> cnt;
  lint ans = 0;
  for (int i = 0; i < N; i++) {
    int cur = A[i] - i;
    ans += cnt[cur];
    cnt[-A[i] - i]++;
  }

  cout << ans << "\n";
  return 0;

}


Measured memory_bytes: 21044
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int n,q;
int s,t;
int main()
{
	while(~scanf("%d",&n))
	{
		int ans = 0;
		for(int i = 1;i <= n;i++)
		{
			cin>>a[i];
		}
		cin>>q;
		for(int j = 1;j <= q;j++)
		{
			scanf("%d",&t);
			for(int i = 1;i <= n;i++)
			{		
				if(t == a[i])
				{
					ans++;
					break;
				}	
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
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> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA

int main(){
    ll x,y; cin >> x >> y;
    ll ans=0;
    while(x<=y){
        x*=2;
        ans++;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define umapi unordered_map<ll, ll>
#define umapc unordered_map<char, int>
#define endl "\n"
using namespace std;

/*
            ॐ
    || Jai Shree Ram ||  
 
 */


void solve()
{
    int n;
    cin>>n;

    if(n%1000 == 0) {
        cout<<0;
    } else {
        int ans = 1000 - (n%1000);
        cout<<ans;
    }
}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}




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

public class Passer
{
    public int weight { get; set; }
    public int ptime { get; set; }
    public int startend { get; set; }
}
public class hello
{
    public static void Main()
    {
        while (true)
        {
            var passers = new List<Passer>();
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var w = int.Parse(line[0]);
                var a = int.Parse(line[1]);
                var b = int.Parse(line[2]);
                passers.Add(new Passer { weight = w, ptime = a, startend = 1 });
                passers.Add(new Passer { weight = w, ptime = b, startend = 2 });
            }
            var wtotal = 0;
            var pass = passers.OrderBy(xx => xx.ptime).ThenByDescending(xy => xy.startend);
            foreach (var x in pass) 
            {
                if (x.startend == 1)
                {
                    wtotal += x.weight;
                    if (wtotal > 150) { Console.WriteLine("NG"); goto loopend; }
                }
                else wtotal -= x.weight;
            }
            Console.WriteLine("OK");
            loopend:;
        }
    }
}

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

#define int long long

bool used[100000000] = {};

signed main() {
  int n;
  cin >> n;

  vector<int> d(n);
  for ( int i = 0; i < n; i++ ) cin >> d[i];

  for ( int i = 1; i < 7; i++ ) {
    for ( int j = 0; j <= n-i; j++ ) {
      int num = 0;
      for ( int k = j; k < j+i; k++ ) {
	num *= 10;
	num += d[k];	
      }
      used[num] = true;      
    }
  }

  for ( int i = 0; i < 100000000; i++ ) {
    if ( !used[i] ) {
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}



Measured memory_bytes: 4028
#include<cstring>
#include<cstdio>
#include<map>
using namespace std;
const int MAXN=20;
const unsigned int HASH=103U,MOD=1000000007U;

map<pair<unsigned int,unsigned int>,int> cnt;
char str[MAXN*2];

int main()
{
	int n;
	scanf("%d%s",&n,str);
	for(int s=0;s<(1<<n);s++)
	{
		unsigned int a=0,b=0;
		for(int i=0;i<n;i++)
			if(s&(1<<i))
				a=(1LLU*a*HASH+str[i]-'a'+1)%MOD;
			else
				b=(1LLU*b*HASH+str[i]-'a'+1)%MOD;
		cnt[make_pair(a,b)]++;
	}
	
	long long ans=0;
	for(int s=0;s<(1<<n);s++)
	{
		unsigned int a=0,b=0;
		for(int i=0;i<n;i++)
			if(s&(1<<i))
				b=(1LLU*b*HASH+str[2*n-i-1]-'a'+1)%MOD;
			else
				a=(1LLU*a*HASH+str[2*n-i-1]-'a'+1)%MOD;
		ans+=cnt[make_pair(a,b)];
	}
	
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 33024
def rest(num):
    return num % 10

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
Foods = [A,B,C,D,E]
res = 0

poplist=[]
for idx in range(5):
    if Foods[idx]%10==0:
        res += Foods[idx]
        poplist.append(idx)
while len(poplist)>0:
    idx = max(poplist)
    Foods.pop(idx)
    poplist.pop(poplist.index(idx))

while len(Foods) > 0:
    idx = Foods.index(max(Foods, key=rest))
    if len(Foods)>1:
        res += (Foods[idx]//10)*10+10
    else:
        res += Foods[idx]
    Foods.pop(idx)



print(res)


Measured memory_bytes: 3064
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <cstring>
#define INF 1000001
typedef long long llong;
using namespace std;



int main() {

	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3080
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new Tuple!(int, long)[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2].to!long);
        G[s[1]-1] ~= tuple(s[0]-1, s[2].to!long);
    }

    long mst_cost = 0;
    auto H = new Tuple!(int, long)[][](N);
    auto P = new Tuple!(int, long)[](N);
    auto D = new int[](N);
    auto used = new bool[](N);
    auto q = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[2] > b[2]")();
    q.insert(tuple(-1, 0, 0L));

    while (!q.empty) {
        auto t = q.front;
        auto from = t[0];
        auto cur = t[1];
        auto d = t[2];
        q.removeFront;
        if (used[cur]) continue;
        used[cur] = true;
        mst_cost += d;
        if (from != -1) {
            H[from] ~= tuple(cur, d);
            H[cur] ~= tuple(from, d);
        }
        foreach (m; G[cur]) {
            auto tar = m[0];
            auto nd = m[1];
            if (used[tar]) continue;
            q.insert(tuple(cur, tar, nd));
        }
    }

    void dfs(int n, int p, long c, int d) {
        P[n] = tuple(p, c);
        D[n] = d;
        foreach (to; H[n]) if (to[0] != p) dfs(to[0], n, to[1], d+1);
    }

    dfs(0, -1, 0, 0);


    auto Q = readln.chomp.to!int;
    while (Q--) {
        s = readln.split.map!(to!int);
        auto a = s[0]-1;
        auto b = s[1]-1;
        if (D[a] > D[b]) swap(a, b);
        long maxv = -1;
        while (D[b] > D[a]) {
            maxv = max(maxv, P[b][1]);
            b = P[b][0];
        }
        while (a != b) {
            maxv = max(maxv, P[a][1]);
            a = P[a][0];
            maxv = max(maxv, P[b][1]);
            b = P[b][0];
        }
        writeln(mst_cost - maxv);
    }
}


Measured memory_bytes: 43772
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n,x,t;cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;

    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long fAB = 4*A*B;
        long CAB = C-A-B;
        if (CAB < 1 || CAB * CAB <= fAB) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

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

int main(){
    int N,T,min_c=1001;
    
    cin>>N>>T;
    for(int i=0;i<N;i++){
        int t,c;
        cin>>c>>t;
        if(t<=T){
            min_c = min(min_c,c);
        }
    }
    if(min_c == 1001)cout<<"TLE"<<endl;
    else cout<<min_c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

inline void read (int& s) {
	s = 0;
	static char c = getchar ();
	while (c < '0' || c > '9') c = getchar ();
	while (c >= '0' && c <= '9') {
		s = (s << 3) + (s << 1) + (c & 15);
		c = getchar ();
	}
	return ;
}

const int N = 100003;
int n, a[N];

int main () {
	read (n);
	int i;
	for (i = 1; i <= n; ++i) read (a[i]);
	for (i = 1; i < n; ++i) {
		if (a[i] > a[i + 1]) {
			if (a[i] - a[i + 1] > 1) {
				puts ("No");
				return 0;
			}
			else {
				--a[i];
				if (a[i] < a[i - 1]) {
					puts ("No");
					return 0;
				}
			}
		}
		else if (a[i] - 1 >= a[i - 1]) -- a[i];
	}
	puts ("Yes");
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 != 0) ans -= vec.at(i);
    else ans += vec.at(i);
  }
  cout << ans << endl;
}

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

int main()
{
    char s[4];
    char a[4];
    int b[4];
    b[0]=1;
    b[1]=1;
    int k=1;
    int flag=0;
    for(int i=0;i<4;i++)
    {
        cin>>s[i];
    }
    a[0]=s[0];
    for(int i=1;i<4;i++)
    {
        for(int j=0;j<k;j++)
        {
            if(s[i]==a[j])
            {
                b[j]++;
                flag=1;
            }
        }
        if(flag==0)
        {
            a[k]=s[i];
            k++;
        }
        flag=0;
    }
    if(b[0]==2&&b[1]==2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)

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


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define rep(i,x) for(ll i = 0;i<x;i++)
#define REP(i,x) for(ll i = 1;i<=x;i++)
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 62;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T, class U> inline bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool change(T& a,U& b){if(a > b){swap(a,b);return 1;}return 0;}
template<class T>
T gcd(T a,T b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
template<class T>
T lcm(T a,T b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
template<class T>
inline bool isp(T n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
vector<ll> fac(cmax),finv(cmax),inv(cmax);

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if(fac[0] == 0)COMinit();
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //1.入力
    ll N;
    cin >> N;
    vector<ll> vec(N);
    vecin(vec);
    //2.尺取り法の実装
    ll ans = 0;
    ll now = 0,migi = 0;//今のsum,今の右
    rep(i,N){
        chmax(migi,i);
        for(ll j = migi;j < N;j++){
            if((now ^ vec[j]) == now + vec[j]){
                migi++;
                now += vec[j];
            }
            else{
                break;
            }
        }
        now -= vec[i];
        ans += migi - i;
    }
    //3.出力
    cout << ans << "\n";
}

Measured memory_bytes: 28260
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> dp(100005, 1LL<<60);
    dp[0] = 0;
    int n, w;
    cin >> n >> w;
    while(n--)
    {
        int wi, vi;
        cin >> wi >> vi;
        for(int i = 100005-1; i >= 0; i--)
            if(i+vi < 100005)
                dp[i+vi] = min(dp[i+vi], dp[i]+wi);
    }
    int mx = 0;
    for(int i = 0; i < 100005; i++)
        if(dp[i] <= w)
            mx = i;
    cout << mx << endl;
}

Measured memory_bytes: 3872
stack = []
top = -1

def push(x):
    global stack
    global top

    top += 1
    stack.append(x)

def pop2():
    global top
    global stack

    top -= 1
    stack.pop()

def main():
    global top
    global stack

    S = input()
    ans = 0

    for i in range(len(S)):
        if i == 0:
            push(S[0])
            continue

        push(S[i])
        if stack[top] != stack[top-1]:
            pop2()
            pop2()
            ans += 2
            continue

    return ans

print(main())


Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
int F(int x)
{
	return x%2?3*x+1:x/2;
}
set<int> s;
int main()
{
	int x,ans=1;
	cin>>x;
	while(s.find(x)==s.end())
	{
		s.insert(x);
		x=F(x);
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
counter = 0
for i in range(n):
  a = list(map(int, input().split()))
  if sum([b[i]*a[i] for i in range(m)]) + c > 0:
    counter += 1
print(counter)


Measured memory_bytes: 2940
using System;

namespace fight3
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long A = long.Parse(input[0]);
            decimal B = decimal.Parse(input[1]);
            decimal C = Math.Floor(A * B);
            Console.WriteLine(C);
        }
    }
}

Measured memory_bytes: 18096
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_113
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] xy = ReadInts();

            Console.WriteLine(xy[0] + xy[1] / 2);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main()
{
    long long int n, y;

    cin >> n >> y;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if ((i*10000 + j*5000 + (n-(i+j))*1000) == y && n-(i+j) >= 0) {
                cout << i << " " << j << " " << n-(i+j) << endl;
                return (0);
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
#if l[i] == l[j]: continue
s = input()

if s[-1] == "s":
    print(s+"es")
else:
    print(s+"s")


Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,A[200005],B[200005],C[200005],ans,le,ri,mid;
map <long long,long long> mp;
int main() {
           cin>>m;
           for(long long i=1;i<m;i++) {
                      cin>>a;
                      A[a]++;
           }
           for(long long i=1;i<=m;i++) {
                      cout<<A[i]<<endl;
           }
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

//挿入ソート
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    int a[101]={};
    REP(i,n) cin>>a[i];

    REP(j,n){
        cout<<a[j];
        if(j<n-1) cout<<" ";
        else cout<<endl;
    }

    //            []
    //[][][][][][]
    //  []<<すいー
    //[]>>[][][[][][]
    FOR(i,1,n){
        int tmp = a[i];
        int pos = i-1;
        while(pos>=0 && a[pos]>tmp){
            a[pos+1] = a[pos];
            pos--;
        }
        a[pos+1]=tmp;
        
        REP(j,n){
            cout<<a[j];
            if(j<n-1) cout<<" ";
            else cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3172
// 2017/07/26 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

	int p[100];
	for(int i=0; i<N; i++){
		cin >> p[i];
	}

	sort(p, p+N);

	for(int A=N; A>=1; A--){
		if(p[N-A]>=A){
			cout << A << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    int board[100][100]={};
    int x=0,y=0,a;
    FOR(i,0,n){
        cin>>a;
        FOR(j,0,a){
            board[x][y]=i+1;
            if(x%2==0){
                if(y==w-1){
                    x++;
                }else{
                    y++;
                }
            }else{
                if(y==0){
                    x++;
                }else{
                    y--;
                }
            }
        }
    }
    FOR(i,0,h){
        FOR(j,0,w){
            cout<<board[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 384