akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  if(S.size() == 2){
    cout << (S.at(0) == S.at(1)? "1 2":"-1 -1") << endl;
    return 0;
  }
  vector<int> data(26);
  for(int i = 0; i < 3; i++)data.at(S.at(i) - 'a')++;
  int flag = 0;
  for(int i = 2; i < S.size(); i++){
    if(i >= 3){
      data.at(S.at(i - 3) - 'a')--;
      data.at(S.at(i) - 'a')++;
    }
    for(int j = 0; j < 26; j++){
      if(data.at(j) >= 2)flag = 1;
    }
    if(flag == 1){
      cout << i - 1 << ' ' << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define yes "YES"
#define no "NO"
#define rsort(a) sort(a.rbegin(),a.rend())
const int mod=1000000007;
//void dfs(int i);
long long modular_expo(long long x,long long y);

bool cmp(pair<double,int>p1,pair<double,int>p2)
{
    if(p1.first>p2.first)
        return true;
    else
    {
        if(p1.first<p2.first)
            return false;
        else if(p1.first==p2.first)
        {
            if(p1.second<p2.second)
                return true;
            else
                return false;
        }
    }
}
/*bool cmp1(map<int,int>a,map<int,int>b)
{
    if(a.first<b.first)
        return true;
    else
        return false;
}*/
//ll m;


/*
void bsf(int t)
{
    queue<int>q;
    visited[t]=true;
    q.push(t);
    while(!q.empty())
    {
        int temp=q.front();
        //cout<<temp<<" ";
        if(temp==n)
            {
                vector<int>ans;
    ans.pb(n);
        int tttt=n;
    for(int i=0;i<tttt;i++)
    {
        ans.pb(parent[n]);
        n=parent[n];
        if(n==1)
            break;
    }
    if(n!=1)
    {
        break;
    }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--)
        cout<<ans[i]<<" ";
        f=1;

            }
        q.pop();
        //cout<<temp<<" ";
        for(auto i=l[temp].begin();i!=l[temp].end();i++)
        {
            if(!visited[*i])
            {
                q.push(*i);
                parent[*i]=temp;
                visited[*i]=true;
            }
        }
    }
}
*/
long long modular_expo(long long x,long long y)
{

    if(y==0)
        return 1;
    if(y%2==0)
        return (modular_expo((x*x),y/2));
    if(y%2==1)
        return ((x)*modular_expo((x*x),(y-1)/2));


}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int n,i;
    cin>>n;
    ll sum=0;
    vector<ll>a(n,0);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll maxi=a[0];
    for(i=1;i<n;i++)
    {
        if(a[i]<maxi)
            sum+=(maxi-a[i]);
        maxi=max(maxi,a[i]);
    }
    cout<<sum;
}




Measured memory_bytes: 4732
#include <stdio.h>
#include <limits.h>

int n;
int h[100000];
int dp[100000];

int abs(int x){return x>0?x:-x;}
int min(int a,int b){return a<b?a:b;}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&h[i]);

    for(int i=1;i<n;i++) dp[i]=INT_MAX;
    dp[0]=0;
    for(int i=0;i<n-1;i++)
    {
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        if(i!=n-2)
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    printf("%d\n",dp[n-1]);
}

Measured memory_bytes: 896
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
cnt = [0] * N
flag = 1
for i in range(N):
  cnt[A[i]] += 1
if(N % 2 == 1):
  if(cnt[0] != 1):
    flag = 0
  for i in range(1, N):
    if(i%2 == 1 and cnt[i] != 0):
      flag = 0
    elif(i%2 == 0 and cnt[i] != 2):
      flag = 0
else:
  for i in range(N):
    if(i%2 == 1 and cnt[i] != 2):
      flag = 0
    elif(i%2 == 0 and cnt[i] != 0):
      flag = 0
print(flag*pow(2, N//2, mod))

Measured memory_bytes: 14008
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint h(n);
    REP(i,n)cin >> h[i];
    int now=h[0];
    int ans = 0;
    int tmp = 0;
    for(int i=1;i<n;i++){
        if(h[i]<=now){
            tmp++;
            now=h[i];
        }else{
            ans=max(ans,tmp);
            tmp=0;
            now=h[i];
        }
    }
    cout << max(tmp,ans) << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> A(3 * n);
    for (int i = 0; i < 3 * n; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int64_t sum = 0;
    int cnt = 0;
    for (int i = 3 * n - 2; cnt < n; i -= 2, cnt += 1) {
        sum += A[i];
    }
    cout << sum << '\n';
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define int         int64_t
#define ii          pair<int,int>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;
int mod = 1e9 + 7, inf = 4e18;

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr); cout << fixed << setprecision(0);
    int n; string s; cin >> n >> s;
    int c = 0, mini, cnt = 0;
    for(auto &v:s) c += (v == '#');
    mini = min(c,n-c);
    for(int i=0;i<n;i++)
    {
        cnt += (s[i] == '#');
        mini = min(mini, cnt + n-c-(i + 1 - cnt));
    }
    cout<<mini;
    return cout<<endl, 0;
}


Measured memory_bytes: 720
#include<stdio.h>
#define MAX 100
int main(){
  int G[MAX][MAX];
  int id;
  int n;
  int num;
  int i,j;
  int hand;
  
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
      G[i][j]=0;
    }
  }
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&num);//頂点番号　agree　隣の点のid
    
    for(j=0;j<num;j++){
      scanf("%d",&hand);
      G[id-1][hand-1]=1;//グラフつくる//頂点番号は１オリジンなので-1して０オリジンで０の行列作る
    }
  }
  
  for(i=0;i<n;i++){//OUTPUT
    for(j=0;j<n;j++){
      if(j)printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2080
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 10
#define MAX_M 10
#define MAX_G 9

int sx, sy;
int n;
int scx[MAX_N], scy[MAX_N];

bool
b_survival()
{
	bool field[MAX_M][MAX_M];
	int px[MAX_G], py[MAX_G];
	static const int dx2[12] = {-1, 0, 1, 2, 2, 2,-1, 0, 1,-2,-2,-2};
	static const int dy2[12] = {-2,-2,-2,-1, 0, 1, 2, 2, 2,-1, 0, 1};

	int ix = 0;
	px[ix] = sx, py[ix] = sy;
	ix++;

	for (int u = 0; u < n; ++u)
	{
		for (int dy = -1; dy <= 1; ++dy)
		{
			for (int dx = -1; dx <= 1; ++dx)
			{
				int nx = scx[u] + dx, ny = scy[u] + dy;
				if (0 <= nx && nx < MAX_M && 0 <= ny && ny < MAX_M)
					field[ny][nx] = false;
			}
		}

		for (int i = 0; i < ix; ++i)
		{
			for (int j = 0; j < 12; ++j)
			{
				int nx = px[i] + dx2[j], ny = py[i] + dy2[j];
				if (0 <= nx && nx < MAX_M && 0 <= ny && ny < MAX_M)
					field[ny][nx] = true;
			}
		}

		ix = 0;
		for (int dy = -1; dy <= 1; ++dy)
		{
			for (int dx = -1; dx <= 1; ++dx)
			{
				int nx = scx[u] + dx, ny = scy[u] + dy;
				if (0 <= nx && nx < MAX_M && 0 <= ny && ny < MAX_M && field[ny][nx])
				{
					px[ix] = nx;
					py[ix] = ny;
					ix++;
				}
			}
		}

		if (ix == 0)
			return false;
	}

	return true;
}

int
main(int argc, char **argv)
{
	int lineno = 0;
	while (true)
	{
		lineno++;
		scanf("%d%d", &sx, &sy);
		if (sx == 0 && sy == 0)
			break;

		lineno++;
		scanf("%d", &n);

		lineno++;
		for (int i = 0; i < n; ++i)
			scanf("%d%d", &scx[i], &scy[i]);

		printf("%s\n", b_survival() ? "OK" : "NA");
	}

	return 0;
}

Measured memory_bytes: 1696
N, *a = map(int, open(0).read().split())
fours = 0
even = 0
odd = 0
for x in a:
  if x%2 == 1:
    odd += 1
  elif x%4 == 0:
    fours += 1
  else:
    even += 1
ans = (odd <= fours) or (odd == fours + 1 and even == 0)
print('Yes' if ans else 'No')

Measured memory_bytes: 14052
import java.util.*;
import java.util.Arrays;
public class Main {
	private static Scanner sc;

	public static void main(String[] args) {
	   sc = new Scanner(System.in);
	   int a=sc.nextInt();
	   int []b=new int[a];
	   long d=0;
	   for(int i=0;i<a;i++){
		   b[i]=sc.nextInt();
	   }
	   Arrays.sort(b);
	   for(int i=0;i<a;i++){
		  d+=b[i]; 
	   }
	   System.out.println(b[0]+" "+b[a-1]+" "+d);
	}

	

}

Measured memory_bytes: 33776
import math
N=int(input())
s=input().split()
s_l=[]
i=0
count=0
while i<N:
       p=0
       q=0
       if int(s[i])<0:
              p=int(s[i])*(-1)
              s_l.append(p)
              count+=1
       else:
              q=int(s[i])
              s_l.append(q) 
       i+=1
ans1=sum(s_l)
ans2=sum(s_l)-min(s_l)*2

if count%2==0:
       print(ans1)
else:
       print(ans2)       
      

Measured memory_bytes: 14412
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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

int dp[100005];
vector<int> bank;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int H,W,D;cin >> H >> W >> D;
    //keyはマスの数字,value.first,secondでその数字が書かれたますの座標
    map<int,P> retu;
    for(int i = 0;i<H;i++){
        for(int j = 0;j<W;j++){
            int a;cin >> a;
            retu[a].first = i+1;
            retu[a].second = j+1;
        }
    }
    //1,2,3,,,D-1であるL_iからスタートしてR_iまでかかるコスト
    //Dで割ったあまりの道筋はそれぞれ排反なので独立して累積和ができる
    vector<int> rui(90005);
    for(int i = D+1;i<=H*W;i++){
        rui.at(i) += rui.at(i-D)+abs(retu[i-D].first-retu[i].first)+abs(retu[i-D].second-retu[i].second);
    }
  	//for(int i = 1;i<10;i++)cout << rui.at(i) << " ";
  	//cout << endl;
    int Q;cin >> Q;
    long long ans = 0;
    for(int i = 0;i<Q;i++){
        int from,to;cin >> from >> to;
        //累積和をすることで下のループがいらない
        /*for(int j = 0;j<(to-from)/D;j++){
            int x = abs(retu[now].first - retu[next].first);
            int y = abs(retu[now].second - retu[next].second);
            ans += x + y;
            now += D;
            next += D;
        }*/
        ans = rui.at(to)-rui.at(from);
        cout << ans << endl;
        ans = 0;
    }
}


Measured memory_bytes: 9204
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//





int n, k;
bool h[10];

bool nohate(int v){
        while(v){
                if(h[v%10]) return false;
                v /= 10;
        }
        return true;
}


int main(){
        cin >> n >> k;
        for(int i = 0; i < 10; i++) h[i] = false;
        for(int i = 0; i < k; i++){
                int d;
                cin >> d;
                h[d] = true;
        }

        for(;;){
                if(nohate(n)){
                        cout << n << endl;
                        break;
                }
                n++;
        }
        return 0;
}


























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

N,Q = (int(i) for i in input().split())
S = input()
acl = [0 for i in range(N)]
cnt = 0
for j in range(1,N):
  if S[j-1] == 'A' and S[j] == 'C':
    cnt += 1
  acl[j] = cnt
      
for k in range(Q):
  x,y = map(int, input().split())
  print(acl[y-1]-acl[x-1])

Measured memory_bytes: 6416
N, M, K = list(map(int, input().split()))

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 998244353
_N = N + 100 # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, _N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

Mpower = [1, M]
lpower = [1, M-1]
for i in range(2, _N + 1):
    Mpower.append((Mpower[-1] * M) % p)
    lpower.append((lpower[-1] * (M-1)) % p)

ans = Mpower[N]
for i in range(K+2, N+1):
    ans = ans - (cmb(N-1, i-1,p)*M *lpower[N-i]) % p
    ans = ans % p

print(ans)

Measured memory_bytes: 48484
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;

const int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 

int main()
{
	int m, d;
	cin>>m>>d;
	cout<<(a[m]==d?1:0)<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().rstrip()

    x = 0
    ans = 0
    for i in range(N):
        x = x + 1 if S[i] == "I" else x - 1
        if x > ans:
            ans = x
    print(ans)


if __name__ == "__main__":
    main()


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int ans[] = new int[n+1];
		int data[] = new int[m*2];
		for(int i= 0;i < m*2;i++) {
			data[i] = sc.nextInt();
		}
		for(int i = 1;i <= n;i++) {
			for(int k = 0;k < m*2;k++) {
				if(data[k] == i)ans[i]++;
			}
		System.out.println(ans[i]);
		}
	}

}


Measured memory_bytes: 22736
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        	double v = sc.nextDouble();
        	System.out.println((int)Math.ceil((v*v/(9.8*2) + 5)/5));
        }
    }
}

Measured memory_bytes: 27644
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid M1;
    int sz;
    vector<Monoid> dat;
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) {
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, M1);
    }
    void set(int k, const Monoid &x) { dat[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            dat[k] = f(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x) {
        dat[k += sz] = x;
        while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
    }
    Monoid get(int a, int b) {  // [a, b)
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, dat[a++]);
            if (b & 1) R = f(dat[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const { return dat[k + sz]; }
    friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) {
        for (int i = 0; i < seg.sz; i++) os << seg[i] << " ";
        return os;
    }
};

const int INF = (int)1e9 + 7;
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
int main() {
    int n, m; cin >> n >> m;
    string s; cin >> s;
    SegmentTree<int> seg(n + 1, [](int a, int b) { return min(a, b); }, INF);
    seg.update(n, 0);
    for (int i = n - 1; i >= 0; i--) if (s[i] == '0') {
        seg.update(i, min(INF, seg.get(i + 1, min(n + 1, i + 1 + m)) + 1));
    }
    if (seg[0] == INF) return !(cout << -1 << endl);
    vector<int> res;
    res.emplace_back(0);
    int cur = seg[0];
    for (int i = 0; i <= n; i++) if (seg[i] == cur - 1) {
        res.emplace_back(i);
        cur--;
    }
    vector<int> diff;
    for (int i = 0; i < seg[0]; i++) diff.emplace_back(res[i + 1] - res[i]);
    cout << diff << endl;
    return 0;
}

Measured memory_bytes: 2616
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<chrono>
#include<random>
#include<cstdio>
#include<set>
#include<map>
#include<numeric>
#include<cfenv>
#include<cmath>
#define MAX_N pow(10,6)
#define MAX_M pow(10,6)
#define INF pow(10,6)
#define REP(i,n) for(long long i=0;i<n;i++)
typedef long long ll;
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    cout<<6-a-b;
}

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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans;
  if(2*c <= a && 2*c <= b){
    ans = max(x, y)*2*c;
  }else if(2*c <= a){
    ans = 2*c*x + b*max(0, y-x);
  }else if(2*c <= b){
    ans = a*max(0, x-y) + 2*c*y;
  }else if(a+b >= 2*c){
    ans = 2*c*min(x, y) + a*max(x-y, 0) + b*max(y-x, 0);
  }else{
    ans = a*x + b*y;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int main() {
  rep (i, 9) rep (j, 9) cout << i + 1 << "x" << j + 1 << "=" << (i + 1) * (j + 1) << endl;
  return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <list>
using namespace std;

typedef long long int ll;


int main () {
    string s;
    cin >> s;
    list<char> l;
    int flip = 0;
    for (int i=0; i<(int)s.size(); i++) {
        l.push_back(s[i]);
    }
    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int op; cin >> op;
        if (op == 1) {
            flip ^= 1;
            continue;
        }
        int f; cin >> f;
        char c; cin >> c;

        if (flip == 0) {
            if (f == 1) {
                l.push_front(c);
            } else {
                l.push_back(c);
            }
        } else {
            if (f == 1) {
                l.push_back(c);
            } else {
                l.push_front(c);
            }
        }

    }
    string ans = "";
    if (flip == 0) {
        for_each(l.cbegin(), l.cend(), [&](char c){
            ans += c;
        });
    } else {
        for_each(l.crbegin(), l.crend(), [&](char c){
            ans += c;
        });
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10500
/* Bismillahir Rahmanir Rahim. */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


int main() {
	ios_base::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ll r,h;
	cin>>r>>h;
	if(r==1 || h==1)
		cout<<1<<endl;
	else
		cout<<(r*h+1)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
d=input().split()
d=list(map(int,d))
s1=[]
s2=0
difn=10000000000000000000
dif=0
i=0
while i<=n:
    s1.append(d[0])
    d.remove(d[0])
    s2=sum(d)
    if sum(s1)>=s2:
        dif=sum(s1)-s2
    elif s2>sum(s1):
        dif=s2-sum(s1)
    if dif<=difn:
        difn=dif
    else:
        break
    i+=1
print(difn)


Measured memory_bytes: 3064
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

vector<int> edge[100005];
int arr[100005];
int visit[100005][2];
int comp = 1;

void dfs(int r)
{
	visit[r][0] = comp;
	visit[arr[r]][1] = comp;

	for (auto& e : edge[r])
	{
		if (visit[e][0] != 0)
			continue;

		dfs(e);
	}
}

int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= n; i++)
		scanf("%d", &arr[i]);

	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);

		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	for (int i = 1; i <= n; i++)
	{
		if (visit[i][0] != 0)
			continue;

		dfs(i);
		comp++;
	}

	int ans = 0;

	for (int i = 1; i <= n; i++)
		if (visit[i][0] == visit[i][1])
			ans++;

	printf("%d", ans);

	return 0;
}

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

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  int h,w;
  cin>>h>>w;
  vector<vector<int>> table(h+1,vector<int>(w+1,INF));
  REP(i,h){
  	string str;
  	cin>>str;
  	REP(j,w){
			table[i+1][j+1]=str[j]-'0';
			if(i||j)
				table[i+1][j+1] += min(table[i][j+1],table[i+1][j]);
  	}
  }
  cout<<table[h][w]<<endl;
  return 0;
}

Measured memory_bytes: 1240
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",b+min(a+b+1,c));
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...







int Main(){


ll x,k,d;
cin>>x>>k>>d;


ll temp = abs(x) % d;

ll ti = abs(x)/d;

ll tmp = d -temp;

if( ti >= k){
	
	cout<<abs( x) - d*k<<endl;
	return 0;
}

ll left = k - ti ;

if(left %2==0){
 cout<<temp;
 	
}
else
cout<<tmp;







return 0;

}

















int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;


}


Measured memory_bytes: 3652
module Factwithmod
  implicit none
  integer(16),allocatable,dimension(:)::Kaijo
  contains
subroutine initiationFactorial(maxnum,mo)
  implicit none
  integer(16)::maxnum
  integer(16)::mo
  integer(16)::i

  allocate(Kaijo(0:maxnum))
  Kaijo(0)=1
  do i=1,maxnum
    Kaijo(i)=mod(Kaijo(i-1)*i,mo)
  end do
end subroutine

function combination(n,k,l)
implicit none
integer(16),intent(in)::n,k,l
integer combination

combination=mod(Kaijo(N)*inv(Kaijo(K),l)*inv(Kaijo(N-K),l),l)

end function

function inv(K,L)
integer(16),intent(in)::k,l
integer(16) l2,y
integer(16) inv
inv=1
l2=l-2
y=k
do
  if(mod(l2,2)==1)inv=mod(inv*y,l)
  y=mod(y*y,l)
  l2=l2/2
  if(l2==0)exit
end do
end function

function permutation(n,k,mo)
implicit none
  integer(16)::n,k
  integer(16)::mo,permutation
  permutation=mod(Kaijo(N)*inv(Kaijo(N-K),mo),mo)
end function
end module
program speedrun
   use Factwithmod
   implicit none
   integer(16)::N,M
   integer(16)::mo=10**9+7
   integer(16)::ANS=1,CNT
   integer(16)::i,j
   read*,N,M
   do i=2,int(sqrt(real(M+1)))
      CNT=0
      if(M==1)exit
      if(mod(M,i)/=0)cycle
      do while(mod(M,i)==0)
         CNT=CNT+1
         M=M/i
      end do
      do j=1,CNT
         ANS=mod(ANS*(CNT+N-j)*inv(j,mo),mo)
      end do
      ANS=mod(ANS,mo)
   end do
   if(M/=1)ANS=ANS*N
   ANS=mod(ANS,mo)
   print"(I0)",ANS
end program speedrun

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n, t, a; cin >> n >> t >> a; t--; a--;
    vector<vector<int>> G(n);
    rep(i, n-1) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<int> td(n, -1), ad(n, -1);
    queue<int> q;
    q.push(a);
    ad[a] = 0;
        while(!q.empty()) {
        int v = q.front(); q.pop();
        for(const auto& nv: G[v]) {
            if (ad[nv]!=-1) continue;
            ad[nv] = ad[v]+1;
            q.push(nv);
        }
    }
    q.push(t);
    td[t] = 0;
    while(!q.empty()) {
        int v = q.front(); q.pop();
        for(const auto& nv: G[v]) {
            if (td[nv]!=-1) continue;
            if (nv==a) continue;
            if (td[v]+1>=ad[nv]) continue;
            td[nv] = td[v]+1;
            q.push(nv);
        }
    }

    debug(td, ad);
    int ans = 0;
    rep(i, n) {
        if (td[i]!=-1) chmax(ans, ad[i]);
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 7920
S = input()

d1 = S[0]
d2 = S[1]
d3 = S[2]
d4 = S[3]

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
    ans = "Bad"
else:
    ans = "Good"
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int main() {
    int h, w; cin >> h >> w;
    vector<vector<char>> a(h + 1, vector<char>(w + 1));
    vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (a[i][j] == '.') {
                dp[i][j] += dp[i - 1][j]; //上
                dp[i][j] += dp[i][j - 1]; //左
                dp[i][j] %= MOD;
            }
        }
    }

    cout << dp[h][w] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;

ll f(ll a){
    if (a==-1) return 0;
    if (a%4==3) return 0;
    if (a%4==1) return 1;
    if(a%4==2) return 1^a;
    else return 0^a;
}
int main(){FIN
    
    ll l,r;cin>>l>>r;
    ll ans = f(l-1)^f(r);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().Split();
        var sx = int.Parse(s[0]);
        var sy = int.Parse(s[1]);
        var tx = int.Parse(s[2]);
        var ty = int.Parse(s[3]);

        var dx = new[] { tx, tx, sx, sx, tx + 1, tx + 1, tx, tx, sx - 1, sx - 1, sx };
        var dy = new[] { sy, ty, ty, sy - 1, sy - 1, ty, ty, ty + 1, ty + 1, sy, sy };

        var x = sx;
        var y = sy;
        for (int i = 0; i < 11; i++)
        {
            if (x < dx[i])
            {
                Console.Write(new string('R', dx[i] - x));
            }
            else
            {
                Console.Write(new string('L', x - dx[i]));
            }

            if (y < dy[i])
            {
                Console.Write(new string('U', dy[i] - y));
            }
            else
            {
                Console.Write(new string('D', y - dy[i]));
            }

            x = dx[i];
            y = dy[i];
        }

        Console.WriteLine();
    }
}


Measured memory_bytes: 11092
N = int(input())
s = list([str(input()) for _ in range(N)])
M = int(input())
t = list([str(input()) for _ in range(M)])
l = list(set(s) | set(t))

s_count, t_count = [0]*len(l), [0]*len(l)
for i in range(N):
    s_count[l.index(s[i])] += 1
for i in range(M):
    t_count[l.index(t[i])] += 1

ans_l = [0]
for i in range(len(l)):
    ans_l.append(s_count[i] - t_count[i])

print(max(ans_l))

Measured memory_bytes: 3064
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cmath>
#include<list>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 8;
#define MOD 1046527
int n;
char H[maxn][15];
 
int getChar(char ch)
{
    return ch -'A' + 1;
}
int getValue(char t[])
{
    int len = strlen(t);
    int p = 1;
    int sum = 0;
    for(int i = 0; i < len;  ++i){
        sum += p * getChar(t[i]);
        p *= 7;
    }
    return sum;
}
int h1(int k)
{
    return k % MOD;
}
int h2(int k)
{
    return 1 + (k % (MOD - 1));
}
int solve_insert(char c[])
{
    int key = getValue(c);
    int i = 0;
    while(true)
    {
        int h = (h1(key) + i * h2(key)) % MOD;
        if(strcmp(H[h],c) == 0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h],c);
            return 0;
        }
        i++;
    }
}
int solve_find(char c[])
{
    int key = getValue(c);
    int i = 0;
    while(true)
    {
        int h = (h1(key) + i * h2(key)) % MOD;
        if(strcmp(H[h],c) == 0) return 1;
        else if(strlen(H[h]) == 0){
            return 0;
        }
        i++;
    }
}
int main()
{
    scanf("%d",&n);
    char s[15],t[15];
    for(int i = 0; i < n; ++i){
        scanf("%s%s",s,t);
        if(s[0] == 'i'){
            solve_insert(t);
        }else{
            if(solve_find(t))printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}

Measured memory_bytes: 18472
#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>>;

// 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 );
}

int main()
{
    vector<string> W(7);
    W[0] = "SUN";
    W[1] = "MON";
    W[2] = "TUE";
    W[3] = "WED";
    W[4] = "THU";
    W[5] = "FRI";
    W[6] = "SAT";

    string S;
    cin >> S;

    REP(i,7){
        if(S == W[i]){
            cout << 7-i<< endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
s = input()
def solve(s):
    head = s[0]
    tail = s[-1]
    len_s = len(s)
    res = len_s -2
    if head == tail:
        res -= 1
    for c in s[1:-1]:
        if c != head and c != tail:
            return res%2 == 1 
    return False
print('First' if solve(s) else 'Second')

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int memb[201];
long long memo[201][31];
int n;

long long func(int index, int sum){
	if(sum < 0 || sum > 20)return 0;
	if(memo[index][sum] != -1){
		return memo[index][sum];
	}
	if(index == n-1){
		return (sum == memb[n-1]);
	}
	return (memo[index][sum] = func(index+1, sum + memb[index]) + func(index+1, sum - memb[index]));
}


int main(void){
	cin >> n;
	rep(i,n){
		cin >> memb[i];
	}
	fill_n(*memo, 101*31, -1);
	cout << func(1, memb[0]) << endl;

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
int N,K;

int main() {
	cin >> N >> K;
	long long ans = 0;
	vector<pair<int, int>> sushi(N);
	for (int i = 0; i < N; i++) {
		int t, d;
		cin >> t >> d;
		sushi[i] = make_pair(d, t);
	}
	sort(sushi.rbegin(), sushi.rend());
	priority_queue<int, vector<int>,greater<int>> pq;
	set<int> set;
	for (int i = 0; i < K; i++) {
		if (set.count(sushi[i].second))pq.push(sushi[i].first);
		else set.insert(sushi[i].second);
		ans += sushi[i].first;
	}
	long long sum = ans;
	ans += set.size()*set.size();
	for (int i = K; i < N; i++) {
		if (pq.empty())break;
		if (set.count(sushi[i].second))continue;
		set.insert(sushi[i].second);
		sum -= pq.top();pq.pop();
		sum += sushi[i].first;
		ans = max(ans, sum + (long long)(set.size()*set.size()));
	}
	cout << ans << endl;
}


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

int main()
{
  string A;
  int N;
  cin >> A;
  N=A.size();
  for(int i=0; i<N; i++)
  {
    A.at(i)='x';
  }
  for(int i=0; i<N; i++)
  {
    cout << A.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;
typedef pair<long,long> P;

int main()
{
  long N,K;
  cin >> N >> K;

  vector<P> v;
  REP(i,0,N) {
    long a,b;
    cin >> a >> b;
    v.push_back(P(a,b));
  }
  sort(v.begin(),v.end());

  long s = 0;
  int i = 0;
  while (1) {
    s += v[i].second;
    if (s >= K) break;
    ++i;
  }
  long res = v[i].first;
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 2420
from math import floor
s = list(input())
l = floor(len(s)/2)
ans = 0
if not len(s)%2 == 0:
    a = s[:l]
    b = s[l+1:]
else:
    a = s[:l]
    b = s[l:]
b.reverse()
for _a, _b in zip(a, b):
    if _a == _b:
        continue
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << " ";
    os << *it;
  }
  return os;
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

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 chmin(T &a, const U &b) { if(b<a){ a=b; return 1; } return 0; }


int main() {
  int n, m; cin>>n>>m;
  string s; cin>>s;
  reverse(s.begin(), s.end());
  vector<int> ans;
  int cur = 0;
  while (cur != n) {
    bool flag = false;
    RREP(i, m+1, 1) {
      if (cur+i >= n+1) i = n-cur;
      if (s[cur+i] == '0') {
        ans.emplace_back(i);
        cur += i;
        flag = true;
        i = 0;
      }
    }
    if (flag == false) {
      print(-1);
      return 0;
    }
  }
  reverse(ans.begin(), ans.end());
  print(ans);

  return 0;
}

Measured memory_bytes: 1096
/*
  Official House
*/
#include<iostream>
using namespace std;
int main(){
	
	int n; //件数
	int x[4][3][10] = { { {} } };//記録

	cin >> n;

	//ここから入力、データインプットループに入る
	for (int i = 0; i < n; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d; //入力
		x[a - 1][b - 1][c - 1] += d;//データインプット
		if (x[a - 1][b - 1][c - 1] > 9){
			x[a - 1][b - 1][c - 1] = 9;
		}
		if (x[a - 1][b - 1][c - 1] < 0){
			x[a - 1][b - 1][c - 1] = 0;
		}
	}

	//ここから出力ループに入る  iは棟　kはタテ　jはヨコ
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 10; k++){
				cout << " " << x[i][j][k];
			}
			cout << endl;
		}
		if (i == 0 || i == 1 || i == 2){
			cout << "####################" << endl;
		}
	}
	//ここでラストォ
	return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

Int H,W;
Int dp[1001][1001];

int main(void) {
    cin>>H>>W;
    bool flag1 = true;
    bool flag2 = true;
    for(int i = 1;i <= H;i++) {
        for(int j = 1;j <= W;j++) {
            char a;
            cin>>a;
            if(i == 1) {
                if(a == '.') {
                    if(flag1)
                        dp[i][j] = 1;
                    else
                        dp[i][j] = 0;
                } else {
                    dp[i][j] = 0;
                    flag1 = false;
                }
            } else if(j == 1) {
                if(a == '.') {
                    if(flag2)
                        dp[i][j] = 1;
                    else
                        dp[i][j] = 0;
                } else {
                    dp[i][j] = 0;
                    flag2 = false;
                }
            } else {
                if(a == '.')
                    dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
                else
                    dp[i][j] = 0;
            }
        }
    }

    cout<<dp[H][W]<<endl;

    return 0;
}




Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

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

  for (int i = 0; i < n; i++) {
    long long int tmp;
    cin >> tmp;
    h.push_back(tmp);
  }

  bool res = true;
  for (int i = n - 1; i > 0; i--) {
    if (h[i] - h[i - 1] >= 0) {
      
    } else if (h[i] - h[i - 1] == -1) {
      h[i - 1]--;
    } else {
      res = false;
      break;
    }
  }
  printf("%s\n", res ? "Yes" : "No");
}


Measured memory_bytes: 1400
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
	SpeedForce;
	cin >> n >> m;
	cout << n * m << '\n';

	return Accepted;
}

// B...a

Measured memory_bytes: 17736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;


int main(){
  int n;
  cin >> n;
  int d[50];
  ll ans = 0;
  rep(i, n) cin >> d[i];
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      ans += d[i] * d[j];
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'


int main() {
	#ifndef ONLINE_JUDGE
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int h, w, m; cin >> h >> w >> m;
	vi row(h+1), col(w+1);
	set<ii> s;
	for_(i, 0, m) {
		int x, y; cin >> x >> y;
		s.insert({x, y});
		row[x] += 1;
		col[y] += 1;
	}
	
	int mxRow = -1, mxCol = -1;
	vi bestRows, bestCols;
	for_(i, 1, h+1) mxRow = max(mxRow, row[i]);
	for_(i, 1, w+1) mxCol = max(mxCol, col[i]);
	
	for_(i, 1, h+1) if (mxRow == row[i]) bestRows.push_back(i);
	for_(i, 1, w+1) if (mxCol == col[i]) bestCols.push_back(i);
	
	int ans = 0, tt = mxRow+mxCol;
	for (auto i: bestRows) {
		if (ans == tt) break;
		for (auto j: bestCols) {
			int v = mxRow+mxCol;
			if (s.count({i, j})) {
				ans = v-1;
			} else {
				ans = v;
				break;
			}
		}
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 23784
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;

static const int N = 1e5 + 10;
int n;
int a[N], b[N], c[N], cnt1[N], cnt2[N];

int main ()
{
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf ("%d", &a[i]);
	for (int i = 1; i <= n; ++i)
		scanf ("%d", &b[i]);
	for (int i = 1; i <= n; ++i)
		scanf ("%d", &c[i]);
	sort (a + 1, a + n + 1);
	sort (b + 1, b + n + 1);
	sort (c + 1, c + n + 1);
	int k = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (; c[k] <= b[i] && k <= n ;)
			++k;
		cnt1[i] = n - k + 1;
	}
	k = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (; a[k] < b[i] && k <= n ;)
			++k;
		cnt2[i] = k - 1;
	}
	long long ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += (long long)cnt1[i] * cnt2[i];
	printf ("%lld", ans);
}

Measured memory_bytes: 2176