akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())
a = [input() for _ in range(h)]

cnt = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            cnt += 1
if cnt == h+w-1:
    print('Possible')
else:
    print('Impossible')


Measured memory_bytes: 9060
package main

import "fmt"

func myPow(a, n int) (b int) {
	b = 1
	for n > 0 {
		b *= a
		n--
	}
	return
}

func isPal(n int) (res bool) {
	var ls []int
	var cp = n
	var pal int
	for cp > 0 {
		ls = append(ls, cp%10)
		cp /= 10
	}
	for i := 0; i < len(ls); i++ {
		pal += ls[i] * myPow(10, len(ls)-1-i)
	}
	if n == pal {
		res = true
	} else {
		res = false
	}
	return
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	cnt := 0
	for i := a; i <= b; i++ {
		if isPal(i) {
			cnt++
		}
	}
	fmt.Println(cnt)
}


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

using namespace std;

int main()
{
    int n,m,x;
    cin>>n>>m>>x;
    vector<long long> possible;
    vector<vector<int>> v(n,vector<int>(m+1));
    for(int i = 0;i<n;i++)
    {
        for(int j = 0;j<=m;j++)
        {
            cin>>v[i][j];
        }
    }
    // Applying bitmasking to get work done

    for(int mask = 0;mask <(1<<n);mask++)
    {
        vector<int> maskindices;
        for(int i = 0;i<n;i++)
        {
            if(mask & (1<<i))
            {
                maskindices.push_back(i);
            }
        }

        vector<int> ans;
        for(int k = 1;k<=m;k++)
        {
            int sum = 0;
            for(int j = 0;j<maskindices.size();j++)
            {
                sum += v[maskindices[j]][k];
            }
            ans.push_back(sum);
        }
        int flag = 1;
        for(int h = 0;h<ans.size();h++)
        {
            if(ans[h] >= x)
            {
                flag *= 1;
            }
            else
            {
                flag *= 0;
            }
            
        }

        if(flag)
        {
            long long sum = 0;
            for(int j = 0;j<maskindices.size();j++)
            {
                sum += v[maskindices[j]][0];
            }
            possible.push_back(sum);
        }

    }

    if(!possible.empty())
    {
        long long mi = possible[0];
        for(long long c:possible)
        {
            mi = min(mi,c);
        }

        cout<<mi;
    }
    else
    {
        cout<<-1;
    }
    


    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s = "";
  long long k = 0;
  cin >> s;
  cin >> k;
  int n = (int)s.size();
  for (int i=0; i<n; i++) {
    if (i == n-1) {
      k %= 26;
      for (int j=0; j<(int)k; j++) {
        if (s.at(i) == 'z') {
          s.at(i) = 'a';
        } else {
          s.at(i)++;
        }
      }
    } else if (s.at(i) != 'a') {
      long long dif = (long long)('z' - s.at(i) + 1);
      if (dif <= k) {
        k -= dif;
        s.at(i) = 'a';
      }
    }
  }
  cout << s << endl;
  return 0;
}


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

int main() {
	string s;
	cin >> s;
	int arr[125] = {};
	for(int i = 0; i < 4; i++) {
		arr[(s[i]-'A')]++;
	}
	int temp = 0;
	for(int i = 0; i < 125; i++) {
		if(arr[i]%2==1) {
			cout << "No" << endl;
			return 0;
		}
		if(arr[i]==2) temp++;
	}
	if(temp!=2) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}


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

int main(){
	string s,t;
	cin >> s >> t;
	map<char,char> mp1;
	map<char,char> mp2;
	for (char c = 'a'; c <= 'z'; ++c) {
		mp1[c] = 'A';
		mp2[c] = 'A';
	}
	bool ok = true;
	rep(i,s.size()){
		if(mp1[s[i]] != 'A' && mp1[s[i]] != t[i]) ok = false;
		if(mp2[t[i]] != 'A' && mp2[t[i]] != s[i]) ok = false;
		if(mp1[s[i]] == 'A'){
			mp1[s[i]] = t[i];
		}
		if(mp2[t[i]] == 'A'){
			mp2[t[i]] = s[i];
		}
	}
	
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
    return 0;
}

Measured memory_bytes: 776
#include <stdio.h>
#include <math.h>
int main() {
	int a,b,c,count;
	scanf("%d %d %d\n%d",&a,&b,&c,&count);
	if (a > b) {
		if (a > c) a *= pow(2,count);
		if (a <= c) c *= pow(2,count);
	}
	if (a <= b) {
		if (b > c) b *= pow(2,count);
		if (b <= c) c *= pow(2,count);
	}
	printf("%d\n",a + b + c);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define FF(i,a,b) for (int i=a;i<=b;i++)
#define F(i,b,a)  for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
typedef long long ll;
const int N = 10;

int G[N][N], vis[N], cnt, ans, n, m;
void dfs(int u)
{
    cnt++, vis[u]=1;
    if(cnt==n)  ans++;
    FF(i,1,n) {
        if(vis[i]==0 && G[u][i]==1) dfs(i);
    }
    vis[u]=0, cnt--;
}
int main()
{
    cin>>n>>m;
    int u, v;
    FF(i,1,m) cin>>u>>v, G[u][v]=G[v][u]=1;
    dfs(1);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define F first
#define S second
#define s(x) #x<<" "<<x<<" | "<<
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define all(A)  A.begin(),A.end()  
#define has(m,x)   (m.find(x)!=m.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
#define endl "\n"
const int MSIZE = 1e5+5;
const int MOD = 1e9+7 ;


int arr[MSIZE];

int main(){

    FIO
    int n; cin>>n;
    map<int,int> mp;
    ll sum = 0;
    f(i,0,n-1)   {
        cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
    } 
    int m; cin>>m;
    while(m--) {
        int a,b; cin>>a>>b;
        sum = sum + (b-a)*(ll)mp[a];
        mp[b] += mp[a]; mp[a] = 0;
        cout<<sum<<endl;
    }
    
    
    
    return 0;
}
    


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

int main(){
 	double n, m, d;
	cin >> n >> m >> d;

	if(d == 0) cout << (m - 1) / n << endl;
	else cout << fixed << setprecision(15) << 2 * (n - d) * (m - 1) / pow(n, 2) << endl;

	return 0;
}


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

using namespace std;
using ll = long long;

int main(){
  int N;
  string S;
  cin >> N >> S;
  int cnt = 0;
  for(int i=0; i<(N-2); i++){
    if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') cnt++;
  }
  
  cout << cnt << endl;
   
  
  return 0;
}

Measured memory_bytes: 3628
#確率は(p_i+1)/2
N, K=(int(i) for i in input().split())
P=[int(i) for i in input().split()]

Q=[(P[i]+1)/2 for i in range(len(P))]
R=[0]*(len(Q)+1)
for i in range(1,len(R)):
    R[i] = R[i-1] + Q[i-1]
maxp=0
for i in range(N-K+1):
        maxp=max((R[i+K]-R[i]), maxp)
print(maxp)


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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int cnt = 0;
  for (int i = max(a, b); i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      cnt++;
      if (cnt == k) {
        cout << i << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define dame {cout<< "NO" <<"\n"; return;}
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    char cm[N][N];
    rep(i,N) rep(j,N) cin>>cm[i][j];
    ll ans=0;
    rep(i,N){ //横移動
        bool ok=true;
        rep(j,N){
            rep(k,N){ //各マス判定
                if(cm[j][(k+i)%N]!=cm[k][(j+i)%N]) ok=false;
            }
        }
        if(ok) ans++;
    }
    cout<< ans*N <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
int int_compare(const void*a,const void*b){return *(int*)a-*(int*)b;}
int main(void)
{
    int n;
    int s[100];
    int ans=0,tmp;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s[i]);
        ans+=s[i];
    }
    qsort(s,n,sizeof(int),int_compare);
    if(ans%10==0){
        for(int i=0;i<n;i++){
            if(s[i]%10!=0){
                printf("%d\n",ans-s[i]);
                return 0;
            }
        }
    }
    else{
        printf("%d\n",ans);
        return 0;
    }
    printf("0\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
 
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define R(i,n) for(int i=0;i<(n);++i)
#define fill(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
 
const LL INF = 1e10 + 7;
 
int n,tot;
map<LL,int> cnt;
map<LL,LL> cp;
LL p[4][3000];
 
void init()
{
	tot = 0;
	for(int i=2;;++i)
	{
		if(1LL*i*i*i >= INF) break;
		if(p[0][i]) continue;
		p[1][tot] = i;
		p[2][tot] = i*i;
		p[3][tot++] = 1LL*i*i*i;
		for(int j=i;;j+=i)
		{
			if(1LL*j*j*j >= INF) break;
			p[0][j] = 1;
		}
	}
}
 
int main()
{
	//freopen("test.txt","r",stdin);
	init();
	scanf("%d",&n);	
	int ans = 0,fi = 1;
	R(i,n)
	{
		LL s,x,y;
		scanf("%lld",&s);
 
		x = y = 1;
		R(j,tot)
		{
			while(s%p[3][j] == 0)
			{
				s /= p[3][j];
			}
			if(s%p[2][j] == 0)
			{
				x *= p[2][j];
				y *= p[1][j];
				if(y > INF) y = INF;
			}
			else if(s%p[1][j] == 0)
			{
				x *= p[1][j];
				y *= p[2][j];
				if(y > INF) y = INF;
			}
		}
		s /= x;
		if(s != 1)
		{
			int t = sqrt(s),r = -1;
			F(j,max(1,t-10),t+10)
				if(1LL*j*j == s)
				{
					r = j;
					break;
				}
			if(r != -1)
			{
				if(y < INF) y *= r;
			}
			else
			{
				if(INF/s/s < y) y = INF;
				else y *= 1LL*s*s;
			}
		}
		if(y >= INF)
		{
			++ans;
			continue;
		}
 
		s *= x;
 
		if(s == 1)
		{
			if(fi)
			{
				fi = 0;
				++ans;
			}
			continue;
		}
 
		cnt[s]++;
		cp[s] = y;
	}
	for(auto it = cnt.begin();it != cnt.end(); ++it)
	{
		LL gf = cp[it->fi];
		if(it->fi < gf || cnt.find(gf) == cnt.end()) ans += max(it -> se,cnt[gf]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 20864
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

N,M = inputIL()

print((100*(N-M)+1900*M)*2**M)



Measured memory_bytes: 38384
use std::collections::*;

fn main() {
    let l = read::<f64>();
    let l = l / 3.0;
    println!("{}", l * l * l);
}

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include <stdio.h>
 
void find3(int n);
  
int main(void) {
    int n;
      
    scanf("%d",&n);
    find3(n);
     
    printf("\n");
    return 0;
}
 
void find3(int n){
    int i;
     
    for(i=1;i<=n;i++){
        if(i % 3 == 0)
            printf(" %d",i);
        else if (i % 10 == 3)
            printf(" %d",i);
        else if (i % 100 == 3)
            printf(" %d",i);
        else if (i % 1000 == 3)
            printf(" %d",i);
        else if (i / 10 == 3)
            printf(" %d",i);
        else if (i / 100 == 3)
            printf(" %d",i);
        else if (i / 1000 == 3)
            printf(" %d",i);
        else if (i % 1000 / 100 == 3)
            printf(" %d",i);
        else if (i % 100 / 10 == 3)
            printf(" %d",i);
        else{}
         
    }
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main() {
  int l,r,d,x,y;
  cin>>l>>r>>d;
  if(l%d==0){
    x=l/d;
  }
  else{
    x=l/d+1;
  }
  if(r%d==0){
    y=r/d;
  }
  else{
    y=r/d;
  }
  cout<<y-x+1<<endl;
  
}

Measured memory_bytes: 3632
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let mut split = buf.split(" ");
    let n: u32 = split.next().unwrap().parse().unwrap();
    let m: u32 = split.next().unwrap().parse().unwrap();
    if n == m {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
#include<stdio.h>
#define min(x,y) ((x) < (y) ? (x) : (y))

int main(){
  int a, b, c, d, e;
  scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
  printf("%d\n", min(a, min(b, c)) + min(d, e) - 50);
  return 0;
}

Measured memory_bytes: 592
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    s = input().rstrip()
    res = 0
    for k,v in groupby(list(s)):
        res += 1
    print(res)

if __name__ == '__main__':
    main()

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

using namespace std;

int main () {
	int n, x;
	cin >> n >> x;
	if (x == 1 || x == n + n - 1) {
		cout << "No";
		return 0;
	}
	cout << "Yes\n";
	if (n == x) {
		for (int i = 1;i < n + n - 2;i ++) {
			cout << i << endl ;
		}
		cout << n + n - 1 << endl << n + n - 2;
		return 0;
	}
	if (x < n) {                    
		for (int i = 1;i <= n;i ++) {
			if (i != x && i != x - 1) cout << i << endl;
		}
		cout << x - 1 << endl << x << endl ;
		for (int i = n + 1;i <= n + n - 1;i ++) cout << i << endl;
	}
	else {
		for (int i = 1;i < n;i ++) cout << i << endl;
		cout << x << endl << x + 1 << endl ;
		for (int i = n;i <= n + n - 1;i ++) {
			if (i != x && i != x + 1) cout << i << endl;
		} 
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include<queue>

using namespace std;

int n;
int u[10010], k[10010],  v[10010][10010];
int answer[10010][10010];

int D[10010];
void bfs(int src){
	//cerr << "bfs root = " << src << endl;
	queue<int> Q;
	Q.push(src);
	D[src] = 0;
	//int cnt = 0;
	while(! Q.empty()){
		int cur = Q.front();
		Q.pop();
		//cerr << "visiting " << cur << " " << D[cur] << endl;
		
		for(int dst = 0; dst < 1001; ++dst){
			if(answer[cur - 1][dst - 1] == 1 && D[dst] > 10000){
				D[dst] = D[cur] + 1; 
				Q.push(dst);
			}
		}

	}
	for(int i = 1; i  < n + 1; ++i ){
		if(D[i] < 10000){
			cout << i << " " <<  D[i] << endl;
		}else{
			cout << i << " " << -1 << endl;
		}
	}

	
}

int main(){
	cin >> n;
	for(int i = 0; i < 1001; ++i){
		for(int j = 0; j < 1001; ++j)
			answer[i][j] = 0;
	}
	for(int i = 0; i < 10010; ++i){
		D[i] = 10010;
	}

	
	
	for(int i = 0; i < n; ++i){
		cin >> u[i] >> k[i];
		for(int j = 0; j < k[i]; ++j){
			cin >> v[i][j];
			answer[u[i] - 1][v[i][j] - 1] = 1;
		} 
	}
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			//cout << answer[i][j] << " ";
		} 
		//cout << endl;
	}
	bfs(1);
}


Measured memory_bytes: 11468
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(min(K,41)):
    l=[0]*(N+1)
    c=0
    for j in range(N):
        if j-A[j]>0:
            l[j-A[j]]+=1
        else:
            c+=1
        if A[j]+j<N:
            l[A[j]+j+1]-=1 
    for j in range(N):
        c+=l[j]
        A[j]=c
print(*A)

Measured memory_bytes: 152792
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, K) = Slice2<long>();
            var Ai = Sarray();
            var cdt = 0L;
            for (long b = 1L << 41; 0 < b; b >>= 1)
            {
                if (K < cdt + b) continue;
                var oNum = 0L;
                foreach (var a in Ai)
                    if (0 != ((a ^ b) & b)) ++oNum;
                if (N / 2 < oNum)
                    cdt += b;
            }
            var ans = 0L;
            foreach (var a in Ai)
                ans += a ^ cdt;
            WriteLine(ans);
        }


        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

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

int main(){
  int T;
  cin>>T;
  while(T--){
  int h,m;
  scanf("%d:%d",&h,&m);
  double A=360*(h/12.0)+30*(m/60.0);
  double B=360*(m/60.0);
  

  double r=min(abs(A-B),360-abs(A-B));
  
  if(r<30)cout<<"alert"<<endl;
  else if(r<90)cout<<"warning"<<endl;
  else cout<<"safe"<<endl;
  
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int k,a,b;
    cin >> k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n, m;
  cin >> n >> m;

  priority_queue<ll> a;

  REP(i, n) {
    ll a_in;
    cin >> a_in;
    a.push(a_in);
  }

  REP(i, m) {
    ll target = a.top();
    a.pop();
    a.push(target / 2);
  }

  ll count = 0;
  while(!a.empty()) {
    count += a.top();
    a.pop();
  }
  COUT(count);

}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*

3 2
*/


Measured memory_bytes: 4220
fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    handle.read_line(&mut buf).unwrap();
    let mut s: String = buf.trim().to_string();
    loop {
        s.pop();
        s.pop();
        if is_even_str(&s) {
            println!("{}", s.len());
            break;
        }
        if s.len() < 2 {
            break;
        }
    }
}

fn is_even_str(s: &str) -> bool {
    let length = s.len();
    let left = s[0..length/2].to_string();
    let right = s[length/2..].to_string();
    if left == right {
        true
    } else {
        false
    }
}

Measured memory_bytes: 4352
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
using namespace std;


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

int main(){
	long long x, y;
	cin >> x >> y;

	long long tmp;
	if (x < y){
		tmp = x;
		x = y;
		y = tmp;
	}

	cout << gcd(x, y) << endl;


	return 0;
}



Measured memory_bytes: 3116
input = open(0).read

N, *Sn = map(str, input().split())
N = int(N)


def main():
    M = {j for j in Sn if j[0] in "M"}
    A = {j for j in Sn if j[0] in "A"}
    R = {j for j in Sn if j[0] in "R"}
    C = {j for j in Sn if j[0] in "C"}
    H = {j for j in Sn if j[0] in "H"}

    m = len(M)
    a = len(A)
    r = len(R)
    c = len(C)
    h = len(H)

    print(
        m * a * r
        + m * a * c
        + m * a * h
        + m * r * c
        + m * r * h
        + m * c * h
        + a * r * c
        + a * r * h
        + a * c * h
        + r * c * h)

    return


main()


Measured memory_bytes: 16572
/*input
5 3
1 3
1 7
2 3
2 1 
2 0
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=505;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    map<int,vector<int>> v;
    REP(i,n){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
    }
    multiset<int> s;
    ll ans=0;
    for(int i=m-1;i>=0;i--){
        for(auto x:v[m-i]){
            s.insert(x);
        }
        if(!s.empty()){
            ans+=*prev(s.end());
            s.erase(prev(s.end()));
        }
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 13172
import sys
from collections import defaultdict

fin = sys.stdin.readline
num = str(fin()).split()[0]

char_list = defaultdict(int)
for each_char in num:
    char_list[each_char] += 1

if len(char_list) == 2 and list(char_list.values())[0] == 2:
    print("Yes")
else:
    print('No')




Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 INF = std::numeric_limits<i64>::max();
constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const i64 MOD = 1000000007;
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    i64 n, m;
    cin >> n >> m;
    vector<i64> k(m);
    vector<vector<i64>> s(10, vector<i64>(10, 0));
    for (int i = 0; i < m; ++i) {
        cin >> k[i];
        for (int j = 0; j < k[i]; ++j) {
            cin >> s[i][j];
            --s[i][j];
        }
    }
    vector<i64> p(m);
    for(int i = 0; i < m; ++i) cin >> p[i];
    i64 ans = 0;
    for (int i = 0; i < 1 << n; ++i) {
        bool flag = true;
        for (int j = 0; j < m; ++j) {
            i64 cnt = 0;
            for (int idx = 0; idx < k[j]; ++idx) {
                if(1<<s[j][idx] & i) ++cnt;
            }
            if(cnt % 2 != p[j]) flag = false;
        }
        if(flag) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long 
#define mod 998244353
using namespace std;
LL f[300005];
LL ans;
LL n,a,b,k;
LL quick_pow(LL a,LL b)
{
	LL ret=1;
	while(b)
	{
		ret=ret*(b&1?a:1)%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
LL C(LL n,LL m)
{
	if(m>n)return 0;
	return f[n]*quick_pow(f[m],mod-2)%mod*quick_pow(f[n-m],mod-2)%mod;
}
void Pre()
{
	f[0]=f[1]=1;
	for(int i=2;i<=300001;++i)
	f[i]=f[i-1]*i%mod;
}
int main()
{
ios::sync_with_stdio(false);
	cin>>n>>a>>b>>k;
	Pre();
for(int i=0;i<=n;++i)
{
	if(i*a>k)break;
	LL bule=(k-i*a)/b;
	if((k-i*a)%b==0&&bule<=n)
	{
		ans+=C(n,i)*C(n,bule)%mod;
		ans%=mod;
	}
}
cout<<ans<<endl;
return 0;
} 

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

    ll sum = 0;
    rep(i,n) sum += a[i];
    int tmp = 0;
    vector<ll> left(n,0), right(n,0);
    left[0] = a[0];
    right[n-1] = a[n-1];
    for (int i = 1; i < n; i++) {
        left[i] = left[i-1] + a[i];
    }
    for (int i = n-1-1; i >= 0; i--) {
        right[i] = right[i+1] + a[i];
    }

    ll minx = INF;
    rep(i,n-1) {
        minx = min(minx, abs(left[i] - right[i+1]));
    }
    cout << minx << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

struct bottle
{
    ll amount, cost;
    double cost_per_litre;
};
bool operator <(const bottle & a, const bottle & b) 
{
    return a.cost_per_litre < b.cost_per_litre;
}

int32_t main()
{
    #ifdef DEBUG
    freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    ll Q,H,S,D;
    cin >> Q >> H >> S >> D;
    ll N;
    cin >> N;
    N *= 4;
    
    vector<bottle> bottles;
    bottles.pb((bottle){1,Q,Q/1.0});
    bottles.pb((bottle){2,H,H/2.0});
    bottles.pb((bottle){4,S,S/4.0});
    bottles.pb((bottle){8,D,D/8.0});
    sort(all(bottles));
    iter(bottles) {
        pr(it->cost_per_litre); 
    } nl
    
    ll ans = 0;
    for (int i=0; i<4; i++) {
        ll take = N / bottles[i].amount;
        pr(i) pr(take) nl
        ans += take * bottles[i].cost;
        N -= take * bottles[i].amount;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
class Pair:
    def __init__(self,x,y):
        self.x=x
        self.y=y
class PPair:
    def __init__(self,xx,yy):
        self.xx=xx
        self.yy=yy

h,w=map(int,input().split())
A = [ list(map(int,input().split())) for i in range(h)]
odd =0
for i in range(h): 
    for j in range(w): 
        if A[i][j]%2==1: odd+=1
num=0;x=0;y=0
res=[]
for i in range(0,w*h):
    if A[x][y]%2==1: num+=1
    nx=x;ny=y;
    if x%2==0:
        if ny == w-1: nx+=1
        else: ny+=1
    else: 
        if ny==0: nx+=1
        else: ny-=1
    if num%2==1:
        if num<odd:
            res.append(PPair(Pair(x,y),Pair(nx,ny)))
    x=nx;y=ny
print (len(res))
for r in res:
    print("%d %d %d %d" %(r.xx.x+1, r.xx.y+1, r.yy.x+1, r.yy.y+1))
            


Measured memory_bytes: 111640
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
#define MAX 200000

int main(){
  int N;
  cin>>N;
  ll A[MAX],B[MAX],count=0;
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
  }
  for(int i=N-1;i>=0;i--){
    if((A[i]+count)%B[i]!=0){
      count+=B[i]-(A[i]+count)%B[i];
    }
  }
  cout<<count<<endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

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

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

	string s, t;
	cin >> s >> t;

	int n = s.size();
	int m = t.size();

	vector<vector<int>> dp(n + 1, vector<int>(m + 1));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			} else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}

	deque<char> dq;
	for (ll i = n, j = m; (i >= 0 || j >= 0) && dp[i][j];) {
		if (i && dp[i][j] == dp[i - 1][j]) {
			i--;
		} else if (dp[i][j] == dp[i][j - 1]) {
			j--;
		} else {
			i--;
			j--;
			dq.push_front(s[i]);
		}
	}

	for (auto v : dq) {
		cout << v;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S;
  cin >> S;

  int ma, mb;

  ma = S / 100;
  mb = S % 100;

  int a=0, b=0;

  if (0<ma && ma < 13) a = 1;
  if (0<mb && mb < 13) b = 1;

  if(a==0 && b==0) cout << "NA" << endl;
  if(a==1 && b==0) cout << "MMYY" << endl;
  if(a==0 && b==1) cout << "YYMM" << endl;
  if(a==1 && b==1) cout << "AMBIGUOUS" << endl;

}

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

namespace Switching_Railroad_Cars
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> nums = new List<int>();
            List<int> ans = new List<int>();


            while(true)
            {
                string input = Console.ReadLine();
                if (input == null)
                {
                    break;
                }

                int temp = int.Parse(input);
                if (temp == 0)
                {
                    Console.WriteLine(nums[nums.Count-1]);
                    nums.RemoveAt(nums.Count - 1);
                }
                else
                {
                    nums.Add(temp);
                }


            }

        }
    }
}



Measured memory_bytes: 13912
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;


int main() {
  int h,w;
  cin >> h >> w;
  int n;
  int grid[w][h];
  rep(x,w)rep(y,h) grid[x][y] = -1;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];

  int px =0, py = 0;
  grid[0][0] = 1;
  a[0]--;
  rep(i,n){
    while(a[i]!=0){
      int isPaint = false;
      //右に進む
      if(px<w-1)
      if(grid[px+1][py] == -1){
        px++;
        grid[px][py] = i+1;
        a[i]--;
        isPaint= true;
      }
      //上
      if(py<h && !isPaint)
      if(grid[px][py+1] == -1){
        py++;
        grid[px][py] = i+1;
        a[i]--;
        isPaint= true;
      }
      //左
      if(px>0 && !isPaint)
      if(grid[px-1][py] == -1){
        px--;
        grid[px][py] = i+1;
        a[i]--;
        isPaint= true;
      }
      //下
      if(py>0 && !isPaint)
      if(grid[px][py-1] == -1){
        py--;
        grid[px][py] = i+1;
        a[i]--;
        isPaint= true;
      }
    }
  }
  rep(y,h){
    rep(x,w)
    {
      cout<< grid[x][y]<<" ";
    }
  cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 384
n = int(input())
a = [int(item) for item in input().split()] + [0]

ans = 0
s = 0
j = 0
for i in range(n):
  while not s & a[j] and j < n:
    s += a[j]
    j += 1
  ans += j - i
  s -= a[i]
    
print(ans)


Measured memory_bytes: 23560
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner scan=new Scanner(System.in);
		BigInteger bi1=new BigInteger(scan.next());
		BigInteger bi2=new BigInteger(scan.next());
		System.out.println(bi1.gcd(bi2));
	}
}

Measured memory_bytes: 17228
#!/usr/bin/env python3

from itertools import product

def calc(s, p):
    assert len(s) == len(p) + 1
    s2 = ""
    for i, c in enumerate(s):
        if i > 0 and p[i - 1]:
            s2 += "+"
        s2 += c
    return eval(s2)

def main():
    s = input()
    n = len(s)
    tf = [True, False]
    ip = list(product(*[tf for i in range(n - 1)]))
    res = 0
    for p in ip:
        res += calc(s, p)
    print(res)

main()


Measured memory_bytes: 3064
#include<stdio.h>

void SortBubble(int array[],int n);

int main(){

	int n,m,X,Y,x[100],y[100],i;

	scanf("%d %d %d %d",&n,&m,&X,&Y);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	for(i=0;i<m;i++){
		scanf("%d",&y[i]);
	}

	SortBubble(x,n);
	SortBubble(y,m);

	if(x[n-1]<y[0] && X<=x[n-1] && y[0]<=Y){
		printf("No War\n");
	}else{
		printf("War\n");
	}

	return 0;
}

void SortBubble(int array[],int n)
{
    int i,j,temp;

    for (i = 0;i < n - 1;i++) {
        for (j = 0;j < n - 1;j++) {
            if (array[j + 1] < array[j]) {
                temp = array[j];array[j] = array[j + 1];array[j + 1] = temp;
            }
        }
    }
}

Measured memory_bytes: 128
#include <stdio.h>
#include <set>
#include <algorithm>
using namespace std;
int siz[524288],mnv[2][524288],mni[2][524288];
pair<int,int> query(int mod2,int id,int il,int ir,int l,int r)
{
	if (il>=l&&ir<=r)
		return make_pair(mnv[mod2][id],mni[mod2][id]);
	if (l>=ir||r<=il)
		return make_pair(1000000000,-1);
	return min(query(mod2,id<<1,il,(il+ir)>>1,l,r),query(mod2^(siz[id<<1]&1),(id<<1)^1,(il+ir)>>1,ir,l,r));
}
void update(int id)
{
	id+=262144;
	siz[id]=0;
	mnv[0][id]=1000000000;
	for (id>>=1;id;id>>=1)
	{
		siz[id]=siz[id<<1]+siz[(id<<1)^1];
		for (int i=0;i<2;++i)
		{
			mnv[i][id]=min(mnv[i][id<<1],mnv[i^(siz[id<<1]&1)][(id<<1)^1]);
			mni[i][id]=mnv[i][id<<1]<=mnv[i^(siz[id<<1]&1)][(id<<1)^1]?mni[i][id<<1]:mni[i^(siz[id<<1]&1)][(id<<1)^1];
		}
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=262144;i<524288;++i)
	{
		mnv[0][i]=mnv[1][i]=1000000000;
		mni[0][i]=mni[1][i]=i-262144;
		siz[i]=1;
	}
	for (int i=0;i<n;++i)
		scanf("%d",&mnv[0][262144+i]);
	for (int i=262143;i;--i)
	{
		siz[i]=siz[i<<1]+siz[(i<<1)^1];
		for (int j=0;j<2;++j)
		{
			mnv[j][i]=min(mnv[j][i<<1],mnv[j^(siz[i<<1]&1)][(i<<1)^1]);
			mni[j][i]=mnv[j][i<<1]<=mnv[j^(siz[i<<1]&1)][(i<<1)^1]?mni[j][i<<1]:mni[j^(siz[i<<1]&1)][(i<<1)^1];
		}
	}
	set<int> st;
	st.insert(n);
	for (int i=0;i<n/2;++i)
	{
		printf("%d ",mnv[0][1]);
		pair<int,int> id=query(1,1,0,262144,mni[0][1],*st.lower_bound(mni[0][1]));
		printf("%d ",id.first);
		st.insert(mni[0][1]);
		st.insert(id.second);
		update(mni[0][1]);
		update(id.second);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 21248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int l = str.length();
		System.out.println("" + str.charAt(0) + (l - 2) + str.charAt(l - 1));
	}
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("03")
#pragma GCC optimization ("unroll-loops")
using namespace std;

const int maxn = 200002;
const int maxe = 20;
int a[maxn],b[maxn],c,k,pa[maxn],x,y,q,sol,d,mod=1000000007;
int m,n;
string s;
int rmq[maxn][maxe];
int st[4*maxn],la[4*maxn],ft[maxn];
char h;
set<int>se;
void build(int n){
    for(int j=1;(1<<j)<=n;j++){
        for(int i=1;i+(1<<j)-1<=n;i++){
            rmq[i][j] = min(rmq[i][j-1], rmq[i+(1<<(j-1))][j-1]);
        }
    }
}

int query(int a, int b){
    int k = 31- __builtin_clz(b-a+1);
    return min(rmq[a][k], rmq[b-(1<<k)+1][k]);
}

int fin(int i)
{
    if(pa[i]==i)return i;
    return pa[i]=fin(pa[i]);
}

int bs(int l,int r)
{

    while(l!=r)
    {
        int mi=(l+r)/2;
        if(a[mi]==x)return mi;
        if(a[mi]>x)r=mi;
        else l=mi+1;
    }
    return l;
}
void crear(int l,int r,int nod){
if(l==r)st[nod]=a[l];
else{
int mi=(l+r)/2;
crear(l,mi,2*nod);
crear(mi+1,r,2*nod+1);
st[nod]=min(st[2*nod],st[2*nod+1]);
}
}

void upd(int l,int r,int nod){
if(l>x || r<x)return;
if(la[nod]!=0){
st[nod]+=la[nod];
la[2*nod]+=la[nod];
la[2*nod+1]+=la[nod];
la[nod]=0;
}
if(l==r)st[nod]+=y;
else{
int mi=(l+r)/2;
upd(l,mi,2*nod);
upd(mi+1,r,2*nod+1);
st[nod]=min(st[2*nod],st[2*nod+1]);
}
}

int qu(int l,int r,int nod){
if(l>y || r<x)return 100001;
if(la[nod]!=0){
st[nod]+=la[nod];
la[2*nod]+=la[nod];
la[2*nod+1]+=la[nod];
la[nod]=0;
}
if(l>=x && r<=y)return st[nod];
else {
int mi=(l+r)/2;
return min(qu(l,mi,2*nod),qu(mi+1,r,2*nod+1));
}
}

void lazy(int l,int r,int nod){
if(l>y || r<x)return;
if(la[nod]!=0){
st[nod]+=la[nod];
la[2*nod]+=la[nod];
la[2*nod+1]+=la[nod];
la[nod]=0;
}
if(l>=x && r<=y){
st[nod]+=q;
if(l!=r){
la[nod*2]+=q;
la[2*nod+1]+=q;
}
}
else {
int mi=(l+r)/2;
lazy(l,mi,2*nod);
lazy(mi+1,r,2*nod+1);
st[nod]=min(st[2*nod],st[2*nod+1]);
}
}

int ftq(int n){
int c=0;
while(n){
c+=ft[n];
n-=(n&-n);
}
return c;
}

void ftupd(int x){
for(int i=x;i<maxn;i+=(i&-i))
ft[i]+=y;
}

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

    cin>>n>>m;
    if(n>9 || m>9)cout<<-1;
    else cout<<n*m;
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int dp[300030];

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  map<int,int> mp;
  rep(i,N) mp[A[i]]++;

  vector<int> v;
  for(int i=0;i<N;i++){
    if(mp[A[i]]>0){
      v.push_back(mp[A[i]]);
      mp[A[i]]=0;
    }
  }
  sort(v.begin(),v.end());

  int n=v.size();
  for(int t=1;t<=N;t++){
    int z=lower_bound(v.begin(),v.end(),t)-v.begin();
    dp[t]=dp[t-1]+(n-z);
  }

  for(int k=1;k<=N;k++){
    ll ok=0,ng=N+1;
    while(ng-ok>1){
      ll mid=(ok+ng)/2;
      if(dp[mid]>=k*mid) ok=mid;
      else ng=mid;
    }
    cout<<ok<<endl;
  }

  return 0;
}


Measured memory_bytes: 17904
import math, sys
inp = int(input())
var = list(map(int,input().split()))
l = []
for i in range(inp-1):
  a = math.fabs(sum(var[0:i+1]) - sum(var[i+1:inp+1]))
  if a==0:
        print(0)
        sys.exit()
  l.append(a)
l.sort()
print(int(l[0]))

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

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

int main(){
    ll N,M;
    cin >> N >> M;

    vector<ll> A(M);
    
    repo(i,M){
        cin >> A[i];
        N -= A[i];
    }
        
    if(N < 0){
        cout << -1 << endl;
    }else{
        cout << N << endl;
    }

    return 0;
}



Measured memory_bytes: 3708