akhauriyash/Code-Regression huggingface dataset:
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void solve(){
	string a,b;cin>>a>>b;
	cout<<b+a;
}

int32_t main()
{
	
	fast;int t=1;
	//cin>>t;
	while(t--){
		solve();
	}

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
S = str(input())
T = str(input())

if S == T :
  print ("Yes")
  exit()
  
for _ in range(len(S)) :
  S = S[len(S)-1] + S
  S = S[0:-1]
  #print(S)
  if S == T :
    print ("Yes")
    exit()
  
print ("No")


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
	cin>>n>>s;
	int x = 0, mx = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'I') {
			x++;
		}else {
			x--;
		}
		mx = max(mx, x);
	}
	cout<<mx<<endl;
	return 0;
}
/*
5
IIDID
Output:2

7
DDIDDII
Output:0

10
IIIIIDDDDD
Output:5

10
DDDDDIIIII
Output:0
*/


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define f(n) for(int i=0;i<n;++i)
#define REP(i,n) for(long long i = 0;i < n;++i)
int geko[200] = {};
int main(){
	int n;
	cin >> n;

	REP(i,n){
		int tmp;
		cin >> tmp;
		geko[tmp]++;
	}
	for(int i = 1;i >= 0;++i){
		int cnt = 0;
		for(int q = i;q <= 100;++q){
			cnt += geko[q];
		}
		if(cnt < i){
			cout << i-1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3120
N,K=map(int,input().split())
h_list=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=float("inf")
    for j in range(1,min(i,K)+1):
        dp[i]=min(dp[i],dp[i-j]+abs(h_list[i-j]-h_list[i]))
print(dp[-1])

Measured memory_bytes: 85312
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <queue>
using namespace std;


int main(){
    unsigned long long n, k;
    cin >> n >> k;
    cout << min(n - k * (n / k), -((long long)(n - k * (n / k)) - k));
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
#define lli long long int
#include<vector>
#include<algorithm>
int main(){
  int n,i;
  cin>>n;
  vector<int>a(n);
  vector<int>b;
  vector<int>c;
  int maxi=0;
  for(i=0;i<n;i++){
    cin>>a[i];
    maxi=max(maxi,a[i]);
    b.push_back(maxi);
  }
  maxi=0;
  for(i=n-1;i>=0;i--){
    //cin>>a[i];
    maxi=max(maxi,a[i]);
    c.push_back(maxi);
  }//cout<<" j  "<<b[2];
  int k=c.size();
  cout<<c[k-2]<<"\n";
  for(i=1;i<n-1;i++)
    cout<<(max(b[i-1],c[k-2-i]))<<"\n";
  cout<<b[b.size()-2]<<"\n";
  return 0;
}

Measured memory_bytes: 4084
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){

  int a, b, c;
  cin >> a >> b >> c;

  if(a == b && b == c)
    FINA(1);
  else if(a == b || b == c || a == c)
    FINA(2);
  else
    FINA(3);

 return 0;
}


Measured memory_bytes: 256
//Ash176-AtCoder: 1 A-Nickname
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define clock cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
#define forie(a,n) for(int i=(a);i<=(n);i++)
#define forje(a,n) for(int j=(a);j<=(n);j++)
#define forke(a,n) for(int k=(a);k<=(n);k++)
#define fori(n) for(int i=0;i<n;++i)
#define forj(n) for (int j=0;j<n;++j)
#define rev(s)  reverse(s.begin(), s.end()) 
#define initblock(v,d) memset(v,d,sizeof(v))
#define ll long long
#define ull unsigned long long
#define re return 
using namespace std;
void Ash() 
{ 	
#ifndef ONLINE_JUDGE 
freopen("input.txt", "r", stdin); freopen("error.txt", "w", stderr); freopen("output.txt", "w", stdout); 
#endif 
}

void solve() { string s; cin >> s; cout << s.substr(0,3); }

int main() { fast; Ash(); solve(); clock; return 0; } 

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

int64_t minll(int64_t a, int64_t b){
    if(a < b) return a;
    return b;
}

int64_t comb(int64_t a, int64_t b){
    if(a < 0 || b < 0 || b > a) return 0;
    if(b == 0 || a == b) return 1;
    return (comb(a-1,b-1)+comb(a-1,b))%1000000007;
}

int main() {
    int64_t n, a, b;
    cin >> n >> a >> b;
    int64_t mod = 1000000007;
    int64_t c = minll(n,200000);
    vector<int64_t> pp(32);
    pp[0] = 2; //2^2^0%mod
    rep(i,31){
        int64_t ppi = pp[i];
        pp[i+1] = ppi*ppi%mod;
    }
    int64_t pw = 1;
    rep(i,32){
        if(n>>i&1) pw = pw*pp[i]%mod;
    }

    vector<int64_t> fact(c+1);
    vector<int64_t> finv(c+1);
    vector<int64_t> inv(c+1);
    rep(i,c+1){
        if(i == 0 || i == 1){
            fact[i] = 1;
            finv[i] = 1;
            inv[i] = 1;
        }
        else{
            fact[i] = fact[i-1]*i%mod;
            inv[i] = mod-(inv[mod%i]*(mod/i)%mod);
            finv[i] = finv[i-1]*inv[i]%mod;
        }
    }
    vector<int64_t> perm(c+1);
    rep(i,c+1){
        if(i == 0) perm[i] = 1;
        else perm[i] = perm[i-1]*(n+1-i)%mod;
    }
    int64_t ca = perm[a]*finv[a]%mod;
    int64_t cb = perm[b]*finv[b]%mod;

    int64_t ans = (3*mod+pw-1-ca-cb)%mod;
    cout << ans << endl;
    /*cout << pw << " " << ca << " " << cb << endl;
    rep(i,c+1){
        cout << perm[i] << " ";
    }
    cout << endl;*/
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
typedef long long ll;
const int N = 1e5 + 7;
using namespace std;
int n, m;
ll a[N], ans = 1e18;
int main() {
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%lld",&a[i]);
    rep(l,1,n-m+1) {
        int r = l+m-1;
        if(a[r]<=0) {
            ans = min(ans,abs(a[l]-0));
        }
        else if(a[l]>=0) {
            ans = min(ans,abs(a[r]-0));
        }
        else {
            ans = min(ans,min(abs(a[l]-0)+abs(a[l]-a[r]),abs(a[r]-0)+abs(a[l]-a[r])));
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio();
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int x=0,y=0,i,n,d,ans;
    cin>>n;
    ans=n;
    string s;
    cin>>s;
    long long int red[n]={0},white[n]={0};
    for(i=0;i<n;i++){
        if(i>0)
            red[i]=red[i-1];
        if(s[i]=='W'){
            red[i]+=1;
            x+=1;
        }
        else
            y+=1;
    }
    //for(i=0;i<n;i++){
      //  cout<<red[i]<<" ";
    //}
    ans=min(x,y);
    for(i=n-1;i>=0;i--){
        if(i<n-1)
            white[i]=white[i+1];
        if(s[i]=='R')
            white[i]+=1;
        if(white[i]<=red[i-1]&&i>=0)
            ans=min(ans,red[i-1]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 6868
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 2*1000*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

void sol( ){
    ll a, b, c, d ;
    cin >> a >> b >> c >> d ;
    ll ans = b*d ;
    ans = max( ans, a*c ) ;
    ans = max( ans, a*d ) ;
    ans = max( ans, b*c ) ;
    cout << ans << nl ;
}

signed main( ){
  timesaver ;
//  int t = 1 ; cin >> t ; while(t--)
  {
      sol( );
  }
}

Measured memory_bytes: 3648
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        boolean ok = true;
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(scanner.next());
            if (a % 2 == 1) continue;
            if (a % 3 != 0 && a % 5 != 0) {
                ok = false;
            }
        }
        System.out.println(ok ? "APPROVED" : "DENIED");
    }

}



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

int main(){
  ll l,r;
  cin >> l >> r;
  ll ans = 100100100;
  ll cnt = 0;
  bool flag = false;
  if( r-l < 100000 ){
    for(ll i=l;i<r;i++){
      for(ll j=i+1;j<=r;j++){
        ll pre = ans;
        ans = min((i*j)%2019,ans);
        if( pre == ans ){
          cnt++;
          if( cnt > 100000 ) flag = true;
        }else{
          cnt = 0;
        }
      }
    }
  }else{
    for(ll i=r;i>l;i--){
      ll pre = ans;
      ans = min(i*(i-1)%2019,ans);
      if( ans == pre ){
        cnt++;
        if( cnt == 10000 ) break;
      }
    }
  }
       
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# n, m, l = 3, 2, 3
# matrixA = [[1, 2],[0, 3],[4, 5]]
# matrixB = [[1, 2, 1],[0, 3, 2]]

n, m, l = map(int, input().split())
matrixA = [list(map(int, input().split())) for i in range(n)]
matrixB = [list(map(int, input().split())) for j in range(m)]

# Output用の行列を初期作成
ans = [[0 for i in range(l)] for j in range(n)]
#
for N in range(n):
    for L in range(l):
        sum = 0
        for M in range(m):
            sum += matrixA[N][M] * matrixB[M][L]
        ans[N][L] = sum
    print(*ans[N])



Measured memory_bytes: 7044
//ABC116-C
fun main(args: Array<String>) {
    val N = nextInt()
    val H = listOfInt().toIntArray()
    var ans = 0
    while (H.sum() > 0) {
        var l = 0
        while (l < N && H[l] == 0) l += 1
        var r = l
        while (r < N && H[r] > 0) r += 1
        for (n in l until r) H[n] -= 1
        ans += 1
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

Measured memory_bytes: 37868
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<P> a;
    rep(i, m){
        int x, y;
        cin >> x >> y;
        a.emplace_back(x, y);
    }
    sort(a.begin(), a.end());

    vector<int> min(n+1), max(n+1);
    rep(i, n){
        min[i+1] = max[i+1] = i+1;
    }

    rep(i, m){
        int y = a[i].second;
        min[y+1] = min[y];
        max[y] = max[y+1];
    }

    for(int i = 1; i < n; i++){
        cout << max[i] - min[i] + 1 << " ";
    }
    cout << max[n] - min[n] + 1 << endl;

    return 0;
}



Measured memory_bytes: 7536
#include<iostream>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
enum {GO=1,GET=2,LOST=3};
/*
  [bgÍ4íÞ
  }XÌy <= 50
  50 * 50 * (100*50) * 4
  dp[ith][jth turn][syojikin] = p^[
*/
const int N = 53;
const int M = 5001;
double dp[N][M];
//event,eventvalue
//¡ñæÌ}XÉiÞ±ÆÍÈ¢Æ¼è·éB
double solve(int n,int X,int *rt,int *event,int *eval,int sum){
  double ret = 0;
  rep(i,n+1)rep(j,M)dp[i][j] = 0;
  dp[0][0] = 1;
  rep(i,n){
    rep(j,sum+1){
      rep(k,X){
	int next = i + rt[k];
	int nextm = j;
	if (next < n){
	  if (event[next] == 1){
	    next += eval[next];
	  }else if (event[next] == 2){
	    nextm += eval[next];
	  }else if (event[next] == 3){
	    nextm -= eval[next];
	  }
	}
	next = min(n,next);
	nextm= max(0,nextm);
	dp[next][nextm] += (dp[i][j] * 1./(double)X);
      }
    }
  }
  rep(i,sum+1){
    ret += i * dp[n][i];
  }
  return ret;
}

main(){
  int X,n,z;
  while(cin>>X>>n>>z && X){
    int event[n],eval[n],rt[X];
    rep(i,n)event[i] = 0;
    rep(i,X)cin>>rt[i];
    int sum = 0;
    rep(i,z){
      int tmp;cin>>tmp;
      cin>>event[tmp]>>eval[tmp];
      if (event[tmp] == 2)sum += eval[tmp];
    }
    sum++;
    double ans = solve(n,X,rt,event,eval,sum);
    printf("%lld\n",(ll)ans);
  }
  
}

Measured memory_bytes: 2860
#include "bits/stdc++.h"

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


int fin(vector<pii> vec,int x){
    rep(i,vec.size()){
        if(vec[i].first==x)return vec[i].second;
    }
    return -1;
}

int main(){
    int a,b;
    while(cin>>a>>b){
        static vector<pii> used[1000001];
        rep(i,1000001)used[i].clear();
        string ans="";
        int c=0;
        a*=10;
        while(1){
            int x=a/b;
            int y=a%b;
//            cout<<x<<" "<<y<<endl;
            if(y==0){ans+='0'+x;cout<<ans<<endl;break;}
            int res=-1;
            if( used[y].size() && (res = fin(used[y],x))!=-1 ){
                cout<<ans<<endl;
                rep(i,res)cout<<" ";
                rep(i,ans.size()-res)cout<<'^';
                cout<<endl;
                break;
            }
            ans+='0'+x;
            used[y].pb(pii(x,c));
            a-=b*x;
            c++;
            a*=10;
        }
    }
    
}

Measured memory_bytes: 24656
#include <stdio.h>
#define maxn 200010
int L[maxn],R[maxn],lc,rc;
char s[maxn];
int main(){
	int n,k,c,i;
	scanf("%d%d%d%s",&n,&k,&c,s+1);
	for(i=1;i<=n;){//正向寻找
		if(s[i]=='o'){
			L[++lc]=i,i+=c;
			if(lc==k)break;
		}
		i++;
	}
	for(i=n;i>=1;){//反向寻找
		if(s[i]=='o'){
			R[++rc]=i,i-=c;
			if(rc==k)break;
		}
		i--;
	}
	for(i=1;i<=k;i++)//重合工作日的寻找
		if(L[i]==R[k-i+1])printf("%d\n",L[i]);
	return 0;
}


Measured memory_bytes: 3200
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int n, a[101];
double av;
int main(){
    cin >> n;
    REP(i,n){
        cin >> a[i];
        av += a[i];
    }
    av /= n;

    double ret = 1124514;
    int reti = -1;
    REP(i,n){
        if (ret > abs(a[i]-av)){
            reti = i;
            ret = abs(a[i]-av);
        }
    }

    cout << reti << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string b;
int res,temp;

int main()
{

    cin >> b;
   for (int i = 0 ; i < b.size(); i++)
   {
       if (b[i] == 'A' || b[i] == 'T' || b[i] == 'G' || b[i] == 'C')
       temp++;
       else
       {
           if (temp != 0)
            if (temp > res) res = temp;
           temp = 0;
       }
   }
   if (temp != 0) if (temp > res) res = temp;
   cout << res << endl;
    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++) cin >> x.at(i) >> y.at(i);
  vector<int> r;
  for (int i = 0; i < N; i++) r.push_back(i);
  double ans = 0.0;
  do {
    for (int i = 0; i < N-1; i++) {
      int diffx = abs(x.at(r.at(i)) - x.at(r.at(i+1)));
      int diffy = abs(y.at(r.at(i)) - y.at(r.at(i+1)));
      ans += pow(pow(diffx, 2.0) + pow(diffy, 2.0), 0.5);
    }
  } while (next_permutation(r.begin(), r.end()));
  int factorial = 1;
  int cnt = N;
  while (cnt != 1) {
    factorial *= cnt;
    cnt--;
  }
  ans /= factorial;
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
s=input()
x=n
a=[]
while x!=0:
  for i in range(min(m,x),0,-1):
    if s[x-i]=="0":a.append(i);break
    if i==1:print(-1);exit()
  x-=i
print(*a[::-1])

Measured memory_bytes: 6372
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


class UnionFind {
public:
    vector<int> Parent;
    UnionFind(int N){
        Parent.resize(N, -1);
        return;
    }

    bool unite(int a, int b){
        a = root(a);
        b = root(b);
        if(a==b) return false;
        
        if(a < b) swap(a, b);
        Parent[a] += Parent[b];
        Parent[b] = a;
        return true;
    }
    
    bool same(int a, int b){
        if(root(a) == root(b)) return true;
        return false;
    }
    
    int root(int a){
        if(Parent[a] < 0) return a;
        return Parent[a] = root(Parent[a]);
    }
    
    int size(int a){
        return -Parent[root(a)];
    }
    
};


int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M);
    vector<int> B(M);
    for(int i=0; i<M; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        A[i] = a; B[i] = b;
    }
    
    vector<ll> Ans(M+1);
    Ans[M] = (ll)N * (N-1) / 2;
    UnionFind U(N);
    for(int i=M-1; i>=0; i--){
        if(U.same(A[i], B[i])){
            Ans[i] = Ans[i+1];
        }else{
            Ans[i] = Ans[i+1] - (ll)U.size(A[i]) * U.size(B[i]);
            U.unite(A[i], B[i]);
        }
    }
    
    for(int i=1; i<M+1; i++){
        cout << Ans[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3328
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;
 
ll modulo(ll a, ll b, ll n){
    long long x=1, y=a; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n; 
        }
        y = (y*y) % n;
        b /= 2;
    }
    return x % n;
}

ll dp[200009];

int main()
{
    SYNC
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,W;
    in(n)>>W;
    l(i,0,n)
    {
        ll w,v; in(w)>>v;
        for(ll j=0; j<=(W-w); j++)
        {
            dp[j]=max(dp[j],dp[j+w]+v);
        }
    }
    o(dp[0])<<endl;
    
 
    
 
}


Measured memory_bytes: 4380
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;
vector<long long> p;
LL n;

long long pow_(long long a, long long n){
    if(n==0) return 1;
    long long re=pow_(a*a,n/2);
    if(n%2==1) re= re*a;
    return re;
}
vector<pair<LL,LL>> conn (vector<pair<LL,LL>> a, vector<pair<LL,LL>> b){
    REP(i,b.size()){
        a.push_back(make_pair(b[i].FI,b[i].SE));
    }
    sort(ALL(a));
    FOR(i,1,a.size()){
        if(a[i].FI<=a[i-1].SE){
            a[i].SE=max(a[i].SE,a[i-1].SE);
            a[i].FI=a[i-1].FI;
            a[i-1].FI=a[i-1].SE=0;
        }
    }
    a.erase(remove(a.begin(),a.end(),make_pair(0ll,0ll)),a.end());
    return a;
}
bool chk(LL a, vector<pair<LL,LL>> &b){
    for(auto x : b){
        if(a>=x.FI && a<=x.SE) return true;
    }
    return false;
}
int solve(int d){
    vector<pair<LL,LL>> ng;
    LL mod=pow_(10,d+1);
    ng.push_back(MP(pow_(10,d)*9,pow_(10,d+1)-1));
    REP(i,n){
        vector<pair<LL,LL>> neu;
        for(auto x: ng){
            LL l=(x.FI-p[i]%mod+mod)%mod;
            LL u=(x.SE-p[i]%mod+mod)%mod;
            if(l==0 or l>u) return 9;
            neu.push_back(make_pair(l,u));
        }
        ng=conn(ng,neu);
    }
    int re=0;
    FOR(i,0,9)if(chk(pow_(10,d)*i,ng)){
        re=9-i;
        break;
    }
    return re;
}

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

    cin >> n;
    REP(i,n){
        LL tmp;cin >> tmp;
        p.push_back(tmp);
    }

    int ans=0;
    REP(i,17) {
        ans+=solve(i);
    }
    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  ll N, P;
  cin >> N >> P;
  ll ans = 1;
  if (N == 1) {
    ans = P;
  }
  else {
    for (ll i = 1; i <= sqrt(P) + 1; i++) {
      ll K = pow(i, N);
      if (K > P) {
        break;
      }
      if (P % K == 0) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

//#define DEBUG

ll slove(ll a){
  if(a%4==0)return a;
  else if(a%4==1)return 1;
  else if(a%4==2)return (a+1);
  else if(a%4==3)return 0;
}

int main_(){
  ll A,B;
  cin>>A>>B;
  if(A==0)cout<<slove(B)<<endl;
  else cout<<(slove(B)^slove(A-1))<<endl;
  return 0;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  vector<string>test;
  /*
   * input for debug
   */
  for(int i=0;i<test.size();++i){
    stringbuf buf;
    streambuf*out=cout.rdbuf(&buf);
    cout<<test[i]<<flush;
    cout.rdbuf(out);
    streambuf*in=cin.rdbuf(&buf);
    main_();
    cin.rdbuf(in);
    cout<<"---------------------"<<endl;
  }
#else
  main_();
#endif

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;

int n, tot;
LL f[305][305];
struct EDGE { 
	int u, v;
	LL w;
}edge[300 * 300 + 5];

bool cmp(EDGE a, EDGE b) {return a.w < b.w;}

int main()
{
	scanf("%d", &n);
	tot = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) {
			LL x;
			scanf("%lld", &x);
			if(i < j) {edge[++tot].u = i; edge[tot].v = j; edge[tot].w = x;}
		}
	sort(edge + 1, edge + tot + 1, cmp);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(i == j) f[i][j] = 0LL;
			else f[i][j] = 1LL << 60;
	LL ans = 0; bool ok = 1LL;
	for(int i = 1; i <= tot; i++) {
		int u = edge[i].u, v = edge[i].v; LL w = edge[i].w;
		if(f[u][v] < w) {ok = 0; break;}
		else if(f[u][v] > w) {
			ans += edge[i].w; 
			for(int j = 1; j <= n; j++)
				for(int k = 1; k <= n; k++) {
					f[j][k] = min(f[j][k], f[j][u] + f[v][k] + w);
					f[j][k] = min(f[j][k], f[j][v] + f[u][k] + w);
					f[k][j] = min(f[k][j], f[k][u] + f[v][j] + w);
					f[k][j] = min(f[k][j], f[k][v] + f[u][j] + w);
				}
		}
	/*	for(int j = 1; j <= n; j++) {
			for(int k = 1; k <= n; k++) printf("%lld ", f[j][k]);
			printf("\n");
		} */
	}
	if(ok) printf("%lld\n", ans);
	else printf("-1\n");
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define repi(i,n) for(int i=0; i<(n); i++)

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  repi(i,N) cin >> p.at(i);
  //ボール探索
  int routelen=0;
  repi(i,N) {
    if (p.at(i)<K-p.at(i)) routelen += p.at(i);
    else routelen += K-p.at(i);
  }
  cout << routelen*2 << endl;
}

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

ll a, b;
int n;
ll ans = 1000000000000000;

int main(){
    cin >> a >> b >> n;
    for(int i = 1; i <= n; i++){
        if(b%i != 0) continue;
        ll x = b/i;
        for(int j = 1; j <= n; j++){
            ans = min(ans,abs(a-x*j));
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1168
import sys
def input(): return sys.stdin.readline().strip()


def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())

    ans = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                val = 500 * i + 100 * j + 50 * k
                if val == x: ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 65036
#include<bits/stdc++.h>
#define int long long
using namespace std;
int x,y ;
void fun(int p , int q)
{
    int lo=1 , hi=1000000000000 , as;
    while(lo<=hi)
    {
        int md=(lo+hi)/2 ;
        if(p*md>=x && q*md>=y){as=md ; hi=md-1 ; }
        else lo=md+1 ;
    }
    x=p*as ; y=q*as ;
}
int32_t main()
{
    int n ; cin>>n ;
    cin>>x>>y ;
    for(int i = 1 ; i < n ; i++)
    {
        int p,q ; cin>>p>>q ;
        int k=(x+p-1)/p ; if(p*k<x) k++ ; int kk=k ;
        k=(y+q-1)/q ; if(q*k<y) k++ ;
        k=max(k,kk) ;
        p*=k ; q*=k ; x=p ; y=q ;
       // cout<<x<<" kjl "<<y<<endl ;
    }
    cout<<x+y<<endl ;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int mi = 1e9, mx = 0;
	int n, m;
	cin >> n >> m;
	rep(i,m){
		int l, r;
		cin >> l >> r;
		chmin(mi, r);
		chmax(mx, l);
	}
	int ans = max(0, mi - mx + 1);
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll N;
ll A[200005];

ll solve(){
	sort(A, A+N);
	reverse(A, A+N);
	if(N == 1) return 0;
	int n = 2;
	ll res = A[0];
	int i = 0;
	while(n < N){
		i++;
		if(n + 2 <= N){
			res += 2 * A[i];
			n += 2;
		}else{
			res += A[i];
			n++;
		}
	}
	return res;
}

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

	cout<<solve()<<endl;
    return 0;
}






Measured memory_bytes: 5196
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;

typedef long long ll;
ll N ,K,a;
vector<ll> A;

ll roopcounter(ll start,ll stopcnt){
    ll cnt=0;
    while (stopcnt>cnt)
    {
        start = A[start];
        cnt++;        
    }
    return start;
}

int main(int argc, char const *argv[])
{
    cin >> N >> K;
    for (ll i = 0; i < N; i++)
    {
        cin >> a;
        A.push_back(a-1);
    }
    vector<int> finished(N,0);
    ll now = 0,cnt=0;
    ll roopdetectposi;
    while (true)
    {
        finished[now]++;
        if (finished[now]==2)
        {
            roopdetectposi = now;
            break;
        }
        now = A[now];
        cnt++;
    }
    ll roopcnt = 0;
    while (true)
    {
        now = A[now];
        roopcnt++;
        if (now==roopdetectposi)
        {
            break;
        }
    }
    
    ll roopmae = cnt-roopcnt;

    ll posi = 0;
    if (roopmae>=K)
    {
        posi = roopcounter(posi, K);
    }
    else
    {
        ll num = (K-roopmae)%roopcnt;
        posi = roopcounter(roopdetectposi, num);
    }
    
    cout << posi+1;
    
    
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

// pairsをfirstを優先キーとして昇順ソート
bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
// pairsをsecond優先キーとして昇順ソート
bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;
    
    vector<P> p(N);

    REP(i, N){
        cin >> p[i].first;
        p[i].second = i;
        
    }

    sort(p.begin(), p.end(), compare_by_a);

    ll a = p[N/2-1].first;
    ll b = p[N/2].first;

    REP(i, N){
        if(i <=N/2-1){
            p[i].first = b;        
        }
        else{
            p[i].first = a;
        }
    }

    sort(p.begin(), p.end(), compare_by_b);

    REP(i, N){
        cout << p[i].first << endl;
    }
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

//#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


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

    bool ans = false;

    repp(x, 1, 9) repp(y, 1, 9){
        if(x*y == n) ans = true;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
amari = 0
ans = 0
for i in range(N):
    can_kill = Blist[i]
    enemy = Alist[i]
    if can_kill > enemy:
        Alist[i] = 0
        ans += enemy
        amari = Blist[i] - enemy
    else:
        Alist[i] -= can_kill
        ans += can_kill
        amari = 0
    if Alist[i + 1] > amari:
        ans += amari
        Alist[i + 1] -= amari
    else:
        ans += Alist[i + 1]
        Alist[i + 1] = 0
    # print(Alist, ans)
print(ans)


Measured memory_bytes: 18396
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
const int INF = 2147483647;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int n, k, a, b;
	string s;

	cin >> n;

	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		cin >> a >> b;
		cout << a + b << endl;
	}

	return 0;
}


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

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
 
int main()
{
    string outcome = "";
    ll ansAC = 0, ansWA = 0;
    ll N, M, num = 0;
        cin >> N >> M;
    vector<ll> ac(N);
    vector<ll> wa(N);
    
  	rep(i, N){
    	ac[i] = 0;
      	wa[i] = 0;
    }
  	
    rep(i, M){
        cin >> num;
        cin >> outcome;
        
        if(ac[num-1] != 1){
        	if(outcome == "AC"){ 
              ac[num-1] = 1; 
              ansAC++; 
            }else{
              wa[num-1]++;
            }
        }
    }
  
  	rep(i, N){
    	if(ac[i] == 1 && wa[i] > 0) ansWA +=  wa[i];
    }
  
    cout << ansAC << " " << ansWA << endl;
    
 return 0;
}

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

int main() {
    int n;
    long long dp[35];
    dp[0] = 1; //地面：１通り
    dp[1] = 1; //１段目：１通り
    dp[2] = 2; //２段目：２通り

    for (int i = 3; i <= 30; i++) {
        //一回に飛べるのが３段までなので
        dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
    }

    while (cin >> n && n) {
        long long ans = 0;
        ans = dp[n] / 3650;
        if (dp[n] % 3650) ans++;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3004
def selection_Sort(A,N):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
            count += 1
    return (count)

if __name__ == '__main__':
    n = int(input())
    data = [int(i) for i in input().split()]
    result = selection_Sort(data,n)
    print(" ".join(map(str,data)))
    print(result)

Measured memory_bytes: 7748
#include <cstdio>

bool judge_M(int a, int b){
    int c = 10 * a + b;
    if(1 <= c && c <= 12){
        return true;
    }else{
        return false;
    }
}

int main(){
    char s[4+1];
    scanf("%s", s);
    int a[4];
    for(int i = 0; i < 4; i++){
        a[i] = s[i] - '0';
    }

    if(judge_M(a[0], a[1]) && judge_M(a[2], a[3])){
        printf("AMBIGUOUS\n");
    }else if(judge_M(a[2], a[3])){
        printf("YYMM\n");
    }else if(judge_M(a[0], a[1])){
        printf("MMYY\n");
    }else{
        printf("NA\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;


int main(int argc, const char * argv[]) {
  int h, w;
  cin >> h >> w;
  vector<string> vec(h);
  rep(i, h){
    cin >> vec[i];
  }
  vector<vector<int>> dp(h, vector<int>(w, INT_MAX));
  dp[0][0] = (vec[0][0] == '#');
  // repd(j, 1, w){
  //   dp[0][j] = dp[0][j-1];
  //   if(vec[0][j] == '#'){
  //       dp[0][j]++;
  //   }
  // }
  rep(i, h){
    rep(j, w){
      // cout << i << " " << j << endl;
      if (i+1 < h)
        dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (vec[i][j] == '.' && vec[i+1][j] == '#'));
 
      if (j+1 < w)
        dp[i][j+1] = min(dp[i][j+1], dp[i][j] + (vec[i][j] == '.' && vec[i][j+1] == '#'));
    }
  }

  cout << dp[h-1][w-1] << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>

using namespace std;

int n;
int a[500005];
int lf[500005 / 2];
int rt[500005 / 2];
int count = 0;

void merge(int l, int mid, int r) {
    int n1 = mid - l;
    int n2 = r - mid;
    for (int i = 0; i < n1; i++) {
        lf[i] = a[l + i];
        rt[i] = a[mid + i];
    }
    for (int i = 0; i < n2 - n1; i++) {
        rt[n1 + i] = a[mid + n1 + i];
    }
    int i = 0;
    int j = 0;
    for (int k = l; k < r; k++) {
        count++;
        if ((lf[i] <= rt[j] && i != n1) || (j == n2)) {
            a[k] = lf[i];
            i++;
        } else {
            a[k] = rt[j];
            j++;
        }
    }
}

void mergeSort(int l, int r) {
    if (l + 1 < r) {
        int mid = (l + r) / 2;
        mergeSort(l, mid);
        mergeSort(mid, r);
        merge(l, mid, r);
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    mergeSort(0, n);
    for (int i = 0; i < n; i++) {
        if (i) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 7048
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var c = cin.ReadInt;
            var d = cin.ReadInt;
            var e = cin.ReadInt;
            var k = cin.ReadInt;

            if (k >= (e - a)) {
                WriteLine("Yay!");
            } else {
                WriteLine(":(");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 1000010

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

bool vis[Maxn];

int main() {
    int k = read();
    int now = 0, cnt = 0;
    while(true) {
        now = (now * 10 + 7) % k; ++cnt;
        if(!now) {
            cout << cnt << endl;
            return 0;
        }
        if(vis[now]) {
            cout << "-1" << endl;
            return 0;
        }
        vis[now] = 1;
    }
    return 0;
}

Measured memory_bytes: 4524
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;

class RollingHash{
    int N;
    unsigned long long base;
    const unsigned long long MOD0 = 1000000007;
    const unsigned long long MOD1 = 1000000009;
    vector<unsigned long long> pow0, pow1;
    vector<unsigned long long> hash_cum0, hash_cum1;
public:
    RollingHash(unsigned long long base=10007) : base(base) {};
    void set(vector<unsigned long long> v){
        N = v.size();

        pow0.resize(N+1);
        pow1.resize(N+1);
        hash_cum0.resize(N+1);
        hash_cum1.resize(N+1);

        pow0[0] = pow1[0] = 1;
        hash_cum0[0] = hash_cum0[0] = 0;

        for(int i=1; i<=N; i++){
            pow0[i] = (pow0[i-1] * base) % MOD0;
            pow1[i] = (pow1[i-1] * base) % MOD1;
        }

        for(int i=1; i<=N; i++){
            hash_cum0[i] = ((base * hash_cum0[i-1]) % MOD0 + v[i-1]) % MOD0;
            hash_cum1[i] = ((base * hash_cum1[i-1]) % MOD1 + v[i-1]) % MOD1;
        }
    }
    // [l, r) のハッシュ値を取得
    unsigned long long get(int l, int r){
        unsigned long long hash0 = (hash_cum0[r] + MOD0 - (hash_cum0[l] * pow0[r-l]) % MOD0) % MOD0;
        return hash0;
    }
//    pair<unsigned long long, unsigned long long> get(int l, int r){
//        unsigned long long hash0 = (hash_cum0[r] + MOD0 - (hash_cum0[l] * pow0[r-l]) % MOD0) % MOD0;
//        unsigned long long hash1 = (hash_cum1[r] + MOD1 - (hash_cum1[l] * pow1[r-l]) % MOD1) % MOD1;
//        return make_pair(hash0, hash1);
//    }
    // 引数で与えられる v のハッシュ値を取得
    pair<unsigned long long, unsigned long long> get(const vector<unsigned long long> &v){
        unsigned long long hash0 = 0;
        unsigned long long hash1 = 0;
        for(int i=0; i<v.size(); i++){
            hash0 = ((base * hash0) % MOD0 + v[i]) % MOD0;
            hash1 = ((base * hash1) % MOD1 + v[i]) % MOD1;
        }
        return make_pair(hash0, hash1);
    }
    // set されている列 v に対して、v[i,:], v[j,:] の LCP 長さを取得する
    int lcp(int i, int j){
        int l = 0;
        int r = min(N-i, N-j)+1;
        while(r - l > 1){
            int m = (l + r) / 2;
            if(get(i, i + m) == get(j, j + m)) l = m;
            else                               r = m;
        }
        return l;
    }
};

bool C(int N, RollingHash &rh, int x){
    for(int i=0; i<N; i++){
        for(int j=i+x; j<=N-x; j++){
            if(rh.get(i, i+x) == rh.get(j, j+x))
                return true;
        }
    }
    return false;
}

int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<unsigned long long> v(N);
    for(int i=0; i<N; i++)
        v[i] = S[i] - 'a';

    RollingHash rh;
    rh.set(v);

    int lb = 0;
    int ub = N / 2;
    if(C(N, rh, ub)){
        cout << N / 2 << endl;
        return 0;
    }
    while(ub - lb > 1){
        int mid = (ub + lb) / 2;
        if(C(N, rh, mid)) lb = mid;
        else ub = mid;
    }
    cout << lb << endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
int n,f[2005][2005],s[2005],k,P=1e9+7,a;
int main()
{
	scanf("%d%d",&n,&k);f[0][n+1]=1;
	for(int i=1;i<=k;i++)
	{
		s[n+1]=f[i-1][n+1];
		for(int j=n;j;j--) s[j]=(s[j+1]+f[i-1][j])%P;
		for(int j=1;j<=n-i+1;j++) f[i][j]=s[j];
	}
	a=(f[k][1]-f[k-1][1]+P)%P;
	for(int i=1;i<=n-k-1;i++) a=(a+a)%P;
	printf("%d\n",a);
}

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

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

    int win = 0;
    int lose = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == 'o')
        {
            win++;
        }
        else
        {
            lose++;
        }
    }
    if (win + (15 - win - lose) >= 8)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256