akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>

using namespace std;

int r,c;
short stat[10000];

int cnt0(short a)
{
	int cnt=0;
	for(int i=0;i<r;i++)	if(~a&(1<<i))	cnt++;
	return cnt;
}

int main()
{
	for(;scanf("%d%d",&r,&c),r;){
		for(int j=0;j<c;j++)	stat[j]=0;
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				int t;	scanf("%d",&t);
				stat[j]|=t<<i;
			}
		}

		int zmax=0;
		for(int i=0;i<(1<<r);i++){
			int zero=0;
			for(int j=0;j<c;j++){
				zero+=max(cnt0(stat[j]^i),cnt0(~(stat[j]^i)));
			}
			zmax=max(zmax,zero);
		}

		printf("%d\n",zmax);
	}

	return 0;
}

Measured memory_bytes: 780
# https://atcoder.jp/contests/abc168/tasks/abc168_d
from collections import deque

N, M = map(int, input().split(' '))

A = []
B = []

# 隣接リスト
route2 = [[] for n in range(N)]

for i in range(M):
    a, b = map(int, input().split(' '))
    A.append(a)
    B.append(b)

for a, b in zip(A, B):
    route2[a - 1].append(b - 1)
    route2[b - 1].append(a - 1)

room_sign = [None] * N

queue = deque([])
visited = set()

queue.append(0)
visited.add(0)

while len(queue) > 0:
    now = queue.popleft()
    for i in route2[now]:
        if i not in visited:
            queue.append(i)
            visited.add(i)

            room_sign[i] = now + 1

print('Yes')
for s in room_sign[1:]:
    print(s)


Measured memory_bytes: 57780
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
A = A[A%2==0].tolist()
bool = True
for a in A:
    if a%3 != 0 and a%5 != 0:
        bool = False

print('APPROVED' if bool else 'DENIED')


Measured memory_bytes: 21396
#include<stdio.h>
#include<stdlib.h>
int comp(const void *a,const void *b)
{
    return *(int *)a-*(int *)b;
}
int main()
{
	int T;
	scanf("%d",&T);
	int n[100];
	int sum=0;
	int i;
	for(i=0;i<T;i++)
	{
		scanf("%d",&n[i]);
		sum+=n[i];
	}
	qsort(n,T,sizeof(n[0]),comp);
	if(sum%10==0)
	{
		int j;
		for(i=0;i<T;i++)
		{
			for(j=i;j<T;j++)
			{
				sum-=n[j];
				if(sum%10!=0)
				{
					printf("%d\n",sum);
					return 0;	
				}	
				else
				{
					sum=sum+n[j];
				}
			}
			sum=sum-n[i];
		}
		printf("%d\n",sum);
	}
	else 
		printf("%d\n",sum);
	return 0;
}

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

int main(){
    int K,X;
    cin >> K >> X;
    for(int i=X-K+1;i<=X+K-1;i++){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import product

N, M = map(int, input().split())
KS = []
for _ in range(M):
    kss = list(map(int, input().split()))
    KS.append(kss)

P = list(map(int, input().split()))

count = 0
for sw in product((0, 1), repeat=N):
    judge = True
    for i in range(M):
        on = 0
        for s in KS[i][1:]:
            on += sw[s-1]
        if on % 2 != P[i]:
            judge = False
            break
    if judge:
        count += 1

print(count)


Measured memory_bytes: 3064
// ABC161 C

#include <iostream>
#include <complex>

using namespace std;

int main(){
    long long int n, k;
    cin >> n >> k;
    long long int count = n/k;
    long long int buf_0, buf_1;
    buf_0 = abs(n - k*count);
    buf_1 = abs(n - k*(count+1));   
    if(buf_0 < buf_1) cout << buf_0 << endl;
    else cout << buf_1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
// const int MOD = 1000000007;

template <typename T>
void __print__(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void __print__(std::ostream &os, const char *del, const char *tail, const Fst &fst,
               const Rst &... rst) {
    os << fst << del;
    __print__(os, del, tail, rst...);
}

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __print__(os, ", ", "\n", __VA_ARGS__);           \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#endif

template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, " ", "\n", fst, rst...);
}

template <typename iter>
void println_(iter bgn, iter end) {
    while (bgn != end) println(*bgn++);
}

template <typename iter>
void print_(iter bgn, iter end) {
    while (bgn != end) {
        std::cout << *bgn++;
        std::cout << (bgn == end ? "\n" : " ");
    }
}

int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
         std::ios::sync_with_stdio(0), 0);

template <typename T>
std::vector<T> ndarray(int n, T v) {
    return std::vector<T>(n, v);
}
template <typename... Args>
auto ndarray(int n, Args... args) {
    auto val = ndarray(args...);
    return std::vector<decltype(val)>(n, move(val));
}

template <typename T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, true : false;
}

template <typename T>
bool umin(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        vector<int> cnt(100001);
        rep(i, n) {
            int x;
            cin >> x;
            cnt[x]++;
        }

        int ans = 0;
        for (int i = 0; i + 2 < 100001; ++i) {
            int k = cnt[i] + cnt[i + 1] + cnt[i + 2];
            ans = max(ans, k);
        }
        print(ans);
    }
}


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

int main() {
  string A,B;
  cin>>A>>B;
  if (A.size()>B.size()){
    cout<<"GREATER"<<endl;
    return 0;
  } else if(A.size()==B.size()){
    for (int i(0);i<A.size();i++){
      if ((int)A[i]>(int)B[i]){
        cout<<"GREATER"<<endl;
        return 0;
      }else if((int)A[i]==(int)B[i]){
        continue;
      }else{
        cout << "LESS"<<endl;
        return 0;
      }
    }
    cout<<"EQUAL"<<endl;
    return 0;
  }else{
    cout << "LESS"<<endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
long n,s,e,i,j;
cin>>n;
for(j=0;j<n;j++){
cin>>s>>e;
if(s<6){
if(e<6){
if(s<e){cout<<s;for(i=s+1;i<=e;i++)cout<<" "<<i;cout<<endl;}
else{cout<<s;for(i=s-1;i>=e;i--)cout<<" "<<i;cout<<endl;}
}else{
cout<<s;for(i=s+1;i<=e;i++)cout<<" "<<i;cout<<endl;
}
}else{
if(e<6){
cout<<s;
for(i=s+1;i<=9;i++)cout<<" "<<i;
for(i=5;i>=e;i--)cout<<" "<<i;cout<<endl;
}else{
if(s<e){cout<<s;for(i=s+1;i<=e;i++)cout<<" "<<i;cout<<endl;}
else{
cout<<s;
for(i=s+1;i<=9;i++)cout<<" "<<i;
for(i=5;i>=0;i--)cout<<" "<<i;
for(i=1;i<=e;i++)cout<<" "<<i;cout<<endl;
}
}
}
}
return 0;
}

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

struct tree{int p,l,r,s,dg,dp,h;};

tree t[30];

void walk(int n,int f){
  if(n==-1)return;
  if(f==1)cout<<" "<<n;
  walk(t[n].l,f);
  if(f==2)cout<<" "<<n;
  walk(t[n].r,f);
  if(f==3)cout<<" "<<n;
}


void depth(int n,int d){
  if(n==-1)return;
  t[n].dp=d;
  depth(t[n].l,d+1),depth(t[n].r,d+1);
}

void height(int n,int h){
  if(n==-1)return;
  t[n].h=max(t[n].h,h);
  height(t[n].p,h+1);
}

int main(){
  int n,id,l,r,cnt=0;
  cin>>n;
  for(int i=0;i<n;i++)t[i].h=t[i].s=t[i].p=-1;
  for(int i=0;i<n;i++){
    cin>>id>>l>>r;
    t[id].r=r;
    t[id].l=l;
    cnt=0;
    if(l!=-1)t[l].p=id,cnt++;
    if(r!=-1)t[r].p=id,cnt++;
    if(cnt==2)t[r].s=l,t[l].s=r;
    t[id].dg=cnt;
  }
  for(int i=0;i<n;i++){
    height(i,0);
    if(t[i].p==-1)depth(i,0);
  }
  int flag;
  for(int i=0;i<n;i++)if(t[i].p==-1)flag=i;
  printf("Preorder\n");
  walk(flag,1);
  cout<<endl;
  printf("Inorder\n");
  walk(flag,2);
  cout<<endl;
  printf("Postorder\n");
  walk(flag,3);
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define int ll
#define Endl endl

signed main(){
    //AA型
    //AB型
    //この２つに大別される
    string S;
    cin >> S;
    int N=S.size();
    int J=N;
    if(S[0]==S[N-1]){
        //消せる文字はN-3文字
        J+=1;
    }
    if(J%2==1){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    return 0;
}

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

int main(){
  long long int x;
  cin>>x;
  for(long long int i=-120;i<=120;i++){
  	for(long long int j=-120;j<=120;j++){
    long long int val1 = i*i*i*i*i;
    long long int val2 = j*j*j*j*j;
    //cout<<val1 <<" "<<val2<<endl;
    if(val1-val2==x){
      cout<<i<<" "<<j<<endl;
       return 0;
  }
  	}
  }
  }
  


Measured memory_bytes: 3604
N=int(input())
tyoutensuu=N*(N+1)*(N+1)//2-N*(N+1)*(2*N+1)//6
hen=0
for i in range(N-1):
    u,v=map(int,input().split())
    if u>v:
        u,v=v,u
    hen+=u*(N-v+1)
print(tyoutensuu-hen)


Measured memory_bytes: 9172
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>
#define FOR(arg, ini, end) for(int arg = ini; arg < end; arg++)


using namespace std;
int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    vector<long> a(n,0);

    long s = 0, se = 0;
    FOR(i, 0, n){
        cin >> a[i];
        s+=a[i];
        if (i%2==1){
            se+=a[i];
        }
    }

    vector<long> x(n,0);
    x[0] = s - 2*se;

    FOR(i, 1, n) {
        x[i] = 2*a[i-1] - x[i-1];
    }


    FOR(i, 0, n) {
        cout << x[i] << " ";
    }
    cout << endl;



    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n,m,a[333][333];
  cin>>n>>m;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
	 cin>>a[i][j];
	 a[i][j]--;
    }
  }

  int ans=n;
  int cnt=0;
  int used[333]={};
  
  for(int i=0;i<m;i++){
    if(cnt==m)break;
    
    int sum[333]={};
    for(int j=0;j<n;j++){
	 for(int k=0;k<m;k++){
	   if(used[a[j][k]])continue;
	   sum[a[j][k]]++;
	   break;
	 }
    }

    int ma=0;
    for(int j=0;j<m;j++){
	 ma=max(ma,sum[j]);
    }
    ans=min(ma,ans);

    for(int j=0;j<m;j++){
	 if(sum[j]<ma)continue;
	 used[j]=1;
	 cnt++;
    }
  }

  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a;
	cin >> b;
	if (a <= 5) {
		cout << 0;
	}
	else if (a <= 12) {
		cout << b / 2;
	}
	else {
		cout << b;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//ノート　isupperで大文字の判定　islowerで小文字の判定
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int n;
    std::cin >> n;
    if(n<1000)std::cout << "ABC" << std::endl;
    else std::cout << "ABD" << std::endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
  long long a,b,x;
  long long ans;
  
  scanf("%lld %lld %lld",&a,&b,&x);
  
  if(a>=1)
  {
    ans=b/x-( (a-1) / x );
  }
  else if(a==0)
  {
    ans=b/x+1;
  }
  
  printf("%lld\n",ans);
  
  return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll h,w;
  cin>>h>>w;
  char oi[h][w];
  char ei[2*h][w];
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>oi[i][j];
    }
    for(int j=0;j<w;j++){
      ll ni=2*i;
      ei[ni][j]=oi[i][j];
      ei[ni+1][j]=oi[i][j];
    }
  }
  
  for(int i=0;i<2*h;i++){
    for(int j=0;j<w;j++){
      cout<<ei[i][j];
    }
    cout<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3672
fn main() {
    let v = read_vec::<u64>();
    let n = v[0];
    let a = v[1];
    let b = v[2];

    if a == 0 {
        println!("0");
        return
    }

    if n % (a+b) == 0 {
        let d = n / (a+b);
        println!("{}", d * a);
    } else {
        let d = n / (a+b);
        let base = d * a;
        let m = n % (a+b);
        if a < m {
            println!("{}", base + a);
        } else {
            println!("{}", base + m);
        }

    }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
import sys
import collections
import itertools


def resolve(in_):
    one = ord(b'1')
    two = ord(b'2')
    # print(f'{one=} {two=}')

    S = in_.readline().strip()
    q = collections.deque(S)
    # print(f'{S=} {q=}')

    reverse_flag = False
    Q = int(in_.readline())
    for query in itertools.islice(in_, Q):
        T = query[0]
        if T == one:
            reverse_flag ^= True 
            # q.reverse()
        elif T == two:
            F = query[2]
            C = query[4]
            if (F == one) ^ reverse_flag:
                q.appendleft(C)
            else:
                q.append(C)
    else:
        if reverse_flag:
            q.reverse()
            reverse_flag = 0

    return bytes(q)


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer.decode('ascii'))


if __name__ == '__main__':
    main()


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    int ans = 0;
    rep(i, 0, N) rep(j, 0, M) {
        if(A[i][j] != B[i][j]) ans++;
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 11132
import java.util.*;
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int H = sc.nextInt(), W = sc.nextInt();
        for (int i=0; i<W+2; i++)
	    	System.out.print('#');
        System.out.println();
	    for (int i=0; i<H; i++) {
	        String word = sc.next();
	        System.out.println('#'+word+'#');
	    }
	    for (int i=0; i<W+2; i++)
	    	System.out.print('#');
	}
}

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

int main() {
    int n, m, a[101];
    cin >> n >> m;
    int votes = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        votes += a[i];
    }

    int cnt = 0;
    double limit = (double) votes / (4 * m);
    for (int i = 0; i < n; i++) {
        if (a[i] >= limit) cnt++;
    }
    if (cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n);
    for(int i=0; i<n+1; i++) {
        cin >> a[i];
    }

    for(int i=0; i<n; i++) {
        cin >> b[i];
    }

    ll ans = 0;
    ll tmp = min(b[n-1], a[n]);
    b[n-1] -= tmp;
    ans += tmp;

    for(int i=n-1; i>=1; i--) {
        ll tmp1 = b[i];
        ll tmp2 = min(a[i], b[i-1]+tmp1);
        ans += tmp2;
        if(a[i] > b[i]) {
            b[i-1] = max(ll(0), b[i-1] - max(ll(0), a[i] - b[i]));
        } else {
            b[i] -= a[i];
        }
    }

    tmp = min(b[0], a[0]);
    ans += tmp;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920
import numpy as np

h, w = list(map(int, input().split()))

aaa = [list(map(int, input().split())) for _ in range(h)]
bbb = [list(map(int, input().split())) for _ in range(h)]
aaa = np.array(aaa, dtype=np.int8)
bbb = np.array(bbb, dtype=np.int8)
diff = abs(aaa - bbb)


def merge_new_can(d, can, prev_can):
    if d == 0:
        can |= prev_can
    else:
        can[d:] |= prev_can[:-d]
        can[:-d] |= prev_can[d:]


prev_row = [None] * w

can = np.zeros(25601, dtype=np.int8)
can[diff[0][0] + 12800] = 1
prev_row[0] = can

for j in range(1, w):
    d = diff[0][j]
    can = np.zeros(25601, dtype=np.int8)
    prev_can = prev_row[j - 1]
    merge_new_can(d, can, prev_can)
    prev_row[j] = can

for i in range(1, h):
    curr_row = [None] * w

    d = diff[i][0]
    prev_can = prev_row[0]
    can = np.zeros(25601, dtype=np.int8)
    merge_new_can(d, can, prev_can)
    curr_row[0] = can

    for j in range(1, w):
        d = diff[i][j]
        can = np.zeros(25601, dtype=np.int8)
        prev_can1 = prev_row[j]
        prev_can2 = curr_row[j - 1]
        merge_new_can(d, can, prev_can1)
        merge_new_can(d, can, prev_can2)
        curr_row[j] = can

    prev_row = curr_row

goal = prev_row[-1]
goal[12801:] |= goal[:12800][::-1]
goal = goal[12800:]
print(np.argmax(goal))


Measured memory_bytes: 17132
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>

using namespace std;
#define ll long long
#define ve vector
#define umap unordered_map

const int MxN=105;
char a[MxN];

int main() {
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++) {
            cin>>a[j];
            cout<<a[j];
        }
        cout<<endl;
        for(int j=0;j<w;j++) {
            cout<<a[j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,n,min,flag=0;
  char tmp,cardA[36][2],cardB[36][2];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%c",&cardA[i][0],&cardA[i][1]);
    cardB[i][0]=cardA[i][0];
    cardB[i][1]=cardA[i][1];
  }

  for(i=0;i<n;i++){
    for(j=n-1;i+1<=j;j--){
      if(cardA[j][1]<cardA[j-1][1]){
	tmp=cardA[j][1];
	cardA[j][1]=cardA[j-1][1];
	cardA[j-1][1]=tmp;
	tmp=cardA[j][0];
	cardA[j][0]=cardA[j-1][0];
	cardA[j-1][0]=tmp;
      }
    }
  }
  for(i=0;i<n-1;i++) printf("%c%c ",cardA[i][0],cardA[i][1]);
  printf("%c%c\n",cardA[i][0],cardA[i][1]);
  printf("Stable\n");

  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(cardB[j][1]<cardB[min][1]) min=j;
    }
    
    tmp=cardB[i][1];
    cardB[i][1]=cardB[min][1];
    cardB[min][1]=tmp;
    tmp=cardB[i][0];
    cardB[i][0]=cardB[min][0];
    cardB[min][0]=tmp;
  }

  for(i=0;i<n;i++){
    if(cardA[i][0]!=cardB[i][0] || cardA[i][1]!=cardB[i][1]) flag=1;
  }

  for(i=0;i<n-1;i++) printf("%c%c ",cardB[i][0],cardB[i][1]);
  printf("%c%c\n",cardB[i][0],cardB[i][1]);
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");
    
  return 0;
}



Measured memory_bytes: 2048
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,k;cin>>n>>k;
  cout<<n-k+1<<endl;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,x,y,sum=0;
	cin>>n>>k>>x>>y;
	if(n<=k)
	sum=n*x;
	else{
		sum+=k*x;
		sum+=(n-k)*y;
	}
	cout<<sum;
	
	
	
	return 0;
}

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

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var s = new string[N];
        var ans = 0;
        for (int i = 0; i < s.Length; i++)
        {
            s[i] = ReadLine();
            for (int j = 1; j < s[i].Length; j++)
            {
                if (s[i][j - 1] == 'A' && s[i][j] == 'B') ans++;
            }
        }

        var c = 0;
        var a = 0;
        var b = 0;
        var ab = 0;
        for (int i = 0; i < s.Length; i++)
        {
            var l = s[i][0];
            var r = s[i][s[i].Length - 1];
            if (l == 'B' && r == 'A') c++;
            else
            {
                if (l == 'B')
                {
                    b++;
                }
                if (r == 'A')
                {
                    a++;
                }
            }
            if (l == 'A' && r == 'B') ab++;

        }


        if (c == 0)
        {
            ans += Min(a, b);
        }
        else
        {
            ans += c - 1;
            if (a > 0) ans++;
            if (b > 0) ans++;
            ans += Max(Min(a - 1, b - 1), 0);
        }
        WriteLine(ans);

    }
}

Measured memory_bytes: 13232
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var w = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var s1 = new int[n];
        s1[0] = w[0];
        for (int i = 1; i < n; i++)
            s1[i] = s1[i - 1] + w[i];

        var s2 = new int[n];
        s2[n - 1] = w[n - 1];
        for (int i = n - 2; 0 <= i; i--)
            s2[i] = s2[i + 1] + w[i];

        var min = int.MaxValue;
        for (int i = 0; i + 1 < n; i++)
        {
            min = Math.Min(min, Math.Abs(s1[i] - s2[i + 1]));
        }

        Console.WriteLine(min);
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
 
int main(void)
{   int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        else if(op=='-')
        {printf("%d\n",a-b);
        }
        else if(op=='*')
        {printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }else if(op=='?') {
            break;
        }
    }
    return 0;
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repe(i, n) for (ll i = 0; i <= (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_VAR_Scan(T &t)
{
    std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &... rest)
{
    std::cin >> first;
    MACRO_VAR_Scan(rest...);
}

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

double ans = 0;
bool check = 0;
bool boo = 0;
string s, t;
int N = 3;
vector<int> v(N);
double a, b, c, d, n, m, k = 0;
int x = 0, y = 0;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;
    cin >> n;
    rep(i, n)
    {
        cin >> a;
        sum += a;
        m = max(m, a);
    }
    pr(sum - m / 2);

    return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <bitset>
#include <cassert>
#include <queue>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
const int SZ = 2e5 + 4;
const double EPS = 1e-7;
const int mod = 998244353;
const int hashpow = 2;
const int inf = 2e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int n;
string s;

void read() {
    cin >> n >> s;
}

void solve() {
    map<char, vector<int>> m;
    for (int i = 0; i < n; ++i) {
        m[s[i]].push_back(i);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (s[i] == s[j]) continue;
            char c = 'R' + 'G' + 'B' - s[i] - s[j];
            if (m[c].empty()) continue;
            int lo = -1, hi = m[c].size() - 1;
            while (hi - lo > 1) {
                int x = lo + ((hi - lo) >> 1);
                if (m[c][x] > j) {
                    hi = x;
                } else {
                    lo = x;
                }
            }
            if (m[c][hi] > j) {
                ans += m[c].size() - hi;

                if (j + j - i < n && s[j + j - i] == c) --ans;
            }
        }
    }
    cout << ans;
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
        read();
        solve();
//    }

    return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    int a, b, c, n=0;
    cin >> a >> b >> c;
    for (int i = a; i < b + 1;i++) {
        if (c % i == 0) n++;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3096
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

R,C = map(int,input().split())
N = int(input())
RCA = [tuple(int(x) for x in input().split()) for _ in range(N)]

# 二部グラフ
graph = [[] for _ in range(R+C)]
for r,c,a in RCA:
    graph[r-1].append((R+c-1,a))
    graph[R+c-1].append((r-1,a))

graph

# グラフの頂点に値を割り当てて、頂点の重みの和が辺の重みになるようにする。
wt_temp = [None] * (R+C)
wt = [None] * (R+C)
for x in range(R+C):
    if wt_temp[x] is not None:
        continue
    wt_temp[x] = 0
    min_wt_row = 0
    q = [x]
    while q:
        y = q.pop()
        for z,a in graph[y]:
            if wt_temp[z] is not None:
                continue
            wt_temp[z] = a - wt_temp[y]
            q.append(z)
            if z<R and min_wt_row > wt_temp[z]:
                min_wt_row = wt_temp[z]
    wt[x] = -min_wt_row
    q = [x]
    while q:
        y = q.pop()
        for z,a in graph[y]:
            if wt[z] is not None:
                continue
            wt[z] = a - wt[y]
            q.append(z)

bl = True
if any(x<0 for x in wt):
    bl = False
for r,c,a in RCA:
    if wt[r-1] + wt[R+c-1] != a:
        bl = False

answer = 'Yes' if bl else 'No'
print(answer)

Measured memory_bytes: 72544
#include<stdio.h>

int main(){
    int N, A[100];
    int sum=0;

    scanf("%d", &N);
    for(int i=0; i<N; i++){
        scanf("%d", &A[i]);
        if(A[i]!=i+1){
            sum++;
        }
    }
    if(sum<=2){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}

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

int main(){
  int N,M;
  long long ans=0;
  cin >> N >> M;
  priority_queue<int> q;
  for(int i=0;i<N;i++){
    int A;
    cin >> A;
    q.push(A);
  }
  for(int i=0;i<M;i++){
    int A=q.top();
    q.pop();
    q.push(A/2);
  }
  for(int i=0;i<N;i++){
    ans+=q.top();
    q.pop();
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3896
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    long long h;cin>>h;

    long long level = 0;
    while (true){
        if (h == 1){
            break;
        } else {
            h /= 2;
            level++;
        }
    }
    cout << fixed << long(pow(2.0, level + 1) - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define MAXN 2000
using namespace std;
priority_queue<int> que;
vector<int> G[MAXN+5];
vector<int> ans;
int n,a[MAXN+5],d[MAXN+5];
int M[MAXN+5][MAXN+5];
bool vis[MAXN+5];
int gcd(int x,int y)
{
	if(y==0)
		return x;
	return gcd(y,x%y);
}
void DFS(int u)
{
	vis[u]=true;
	for(int v=1;v<=n;v++)
		if(vis[v]==false&&M[u][v])
		{
			d[v]++;
			G[u].push_back(v);
			DFS(v);
		}
}
int main()
{
//	freopen("newgame.in","r",stdin);
//	freopen("newgame.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(gcd(a[i],a[j])!=1)
				M[i][j]=M[j][i]=1;
	for(int i=1;i<=n;i++)
		if(vis[i]==false)
			DFS(i);
	for(int i=1;i<=n;i++)
		if(d[i]==0)
			vis[i]=true,que.push(i);
	memset(vis,0,sizeof(vis));
	while(que.empty()==false)
	{
		int u=que.top();
		que.pop();
		ans.push_back(u);
		for(int i=0;i<(int)G[u].size();i++)
		{
			int v=G[u][i];
			if(vis[v]==false)
			{
				vis[v]=true;
				que.push(v);
			}
		}
	}
	for(int i=0;i<(int)ans.size();i++)
		if(i==0)
			printf("%d",a[ans[i]]);
		else
			printf(" %d",a[ans[i]]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 16128
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int n,m,s,c;
	cin>>n>>m;
	int a[5],b[5],flag=0;
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	for(int i=0;i<m;i++)
	{
		cin>>s>>c;
		s--;
		if(!b[s])
		{
			a[s]=c;
			b[s]=1;
		}
		else
		{
			if(a[s]!=c)
			  flag=1;
		}
	}
	if(!b[0]&&n>1)
	  a[0]=1;
	if(a[0]==0&&n>1)
	  flag=1;
	if(flag==1)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<n;i++)
	  cout<<a[i];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int dp[n][n];
	memset(dp,0,sizeof(dp));
	int max_cnt=INT_MIN;
	for(int i=1;i<n;i++)
	{
		if(s[0]==s[i])
			dp[0][i]=1;
		max_cnt=max(max_cnt,dp[0][i]);
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(s[i]==s[j]&&(j-i)>dp[i-1][j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			max_cnt=max(max_cnt,dp[i][j]);
		}
	}
	/*for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			cout<<dp[i][j]<<" ";
		cout<<'\n';
	}*/
	cout<<max_cnt<<'\n';
	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vi a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
    a[i]--;
  }
  vector<bool> sel(n);
  int now = 0;
  int cnt = 0;
  bool ok = true;
  while(1) {
    if(sel[now]) {
      ok = false;
      break;
    }
    if(now == 1) {
      break;
    }
    cnt++;
    sel[now] = true;
    now = a[now];
  }
  cout << (ok ? cnt : -1) << endl;
}


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

double dp[1001][1001];

double d(int n,int m){
  if(n<=1||m<0||n<=m)return 0;
  if(dp[n][m]!=-1)return dp[n][m];
  double res=0;
  double a=0;

  if(n-m>0&&n-m-2>0)res+=(d(n-2,m+2)+1)*(n-m)/n*(n-m-2)/(n-1),a+=1.0*(n-m)/n*(n-m-2)/(n-1);
  
  res+=(d(n-2,m)+1)*(n-m)/n*m/(n-1),a+=1.0*(n-m)/n*m/(n-1);  

  res+=d(n-1,m-1)*m/n,a+=1.0*m/n;

  if(n-m>0)res+=d(n-2,m)*(n-m)/n/(n-1),a+=1.0*(n-m)/n/(n-1);

  return dp[n][m]=res;
}

int main(){
  for(int i=0;i<1001;i++)
    for(int j=0;j<1001;j++){
      dp[i][j]=-1;
    }
  int n;
  while(cin>>n,n){
    printf("%.8lf\n",d(n,0));
  }
  
  return 0;
}



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

using ll = long long;
template< typename T >
struct Edge {
  int from, to;
  T cost;
  Edge() {}
  Edge(int f, int t) : from(f), to(t), cost(1) {}
  Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

template< typename T >
using Edges = std::vector< Edge< T > >;
template< typename T >
using Graph = std::vector< Edges< T > >;

using graph = Graph<int>;

vector<ll> counter(200000);
graph g(200000);
vector<bool> visit(200000, false);

void dfs(int s) { 
  // cerr << s << " " << counter[s] << endl;
  visit[s] = true;
  for (auto e: g[s]) { 
    if (visit[e.to]) continue;
    counter[e.to] += counter[s];
    dfs(e.to);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n-1; ++i) {
    int a, b; cin >> a >> b;
    --a; --b;
    g[a].emplace_back(a, b);
    g[b].emplace_back(b, a);
  }
  for (int i = 0; i < q; ++i) {
    int p, x; cin >> p >> x;
    --p;
    counter[p] += x;
  }
  dfs(0);
  for (int i = 0; i < n; ++i) {
    cout << counter[i] << endl;
  }
}


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

#define rep(i, n) for (Int i = 0; i < (Int)(n); i++)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n, k;
    cin >> n >> k;
    Int a[51][51] = {};
    rep(i, n) rep(j, n) cin >> a[i][j];
    Int b[51][51] = {};
    rep(i, n) b[i][i] = 1;
    while (k > 0) {
        Int tmp[51][51] = {};      
        if (k % 2 == 1) {
            rep(i, n) {
                rep(j, n) {
                    Int x = 0;
                    rep(k, n) {
                        x = (x + b[i][k] * a[k][j]) % mod;
                    }
                    tmp[i][j] = x;
                    //cout << x << " ";
                }
                //cout << endl;
            }
            rep(i, n) rep(j, n) b[i][j] = tmp[i][j];
        }
        rep(i, n) {
            rep(j, n) {
                Int x = 0;
                rep(k, n) {
                    x = (x + a[i][k] * a[k][j]) % mod;
                }
                tmp[i][j] = x;
            }
        }
        rep(i, n) rep(j, n) a[i][j] = tmp[i][j];
        k /= 2;
    }
    Int res = 0;
    rep(i, n) rep(j, n) res = (res + b[i][j]) % mod;
    dump(res);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;

int main() {
	int q = 0;
	while (1) {
		double n;
		double date[1000];
		double sum = 0;
		double var = 0;
		string haki;
		cin >> n;
		getline(cin, haki);
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> date[i];
			sum += date[i];
		}
		double ave = sum / n;
		for (int i = 0; i < n; i++) {
			var += pow(date[i] - ave, 2);
		}
		cout << fixed << pow(var / n,0.5) << endl;
		q++;
		if (q > 10)break;

	}
	return 0;
}


Measured memory_bytes: 3448
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String u = s;
        for(int i = 0; i < s.length(); i++){
            u = s.substring(0,s.length() - i - 1);
            String copy1 = u;
            String copy2 = u;
            String copy3 = u; 
            if(u.length()%2 == 0){
                if(copy3.substring(0,(copy3.length()/2 - 1)).equals(copy1.substring(copy1.length()/2,copy1.length()-1))){
                    System.out.println(copy2.length());
                    break;
                }
            }
     }
    }
}

Measured memory_bytes: 22996
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

# lcm & gcd not math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

from functools import reduce
def lcm_multi(num_list):
    return reduce(lcm, num_list, 1)

div_num = 10 ** 9 + 7
lcm_num = lcm_multi(tuple(A_list))
ans = 0
for i in range(N):
    ans += (lcm_num // A_list[i])
print(ans % div_num)

Measured memory_bytes: 4208
h,w,d = map(int,input().split())

pos_x = [None]*(h*w)
pos_y = [None]*(h*w)
for i in range(h):
    a_list = list(map(int,input().split()))
    for j,a in enumerate(a_list):
        pos_x[a-1] = j
        pos_y[a-1] = i

power = [0]*(h*w)
for i in range(h*w):
    if i<d:
        continue
    else:
        use = abs(pos_x[i]-pos_x[i-d]) + abs(pos_y[i]-pos_y[i-d])
        power[i] = power[i-d] + use

q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    print(power[r-1]-power[l-1])
    
        

Measured memory_bytes: 9272
<?php
$a = fgets(STDIN);
$b = fgets(STDIN);
$c = fgets(STDIN);
$x = fgets(STDIN);

$r = 0;
$tmp = 0;
for($ia = 0; $ia <= $a; $ia++){
	for($ib = 0; $ib <= $b; $ib++){
		for($ic = 0; $ic <= $c; $ic++){
			$tmp = $ia * 500 + $ib * 100 + $ic * 50;
			if($tmp == $x){
				$r++;
				continue 2;
			}elseif($tmp > $x){
				continue 2;
			}
		}
	}
}
echo $r;
?>


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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif

    int h,n;
    cin>>h>>n;
    int sum=0;
    f1(i,0,n)
    {
    	cin>>temp;
    	sum+=temp;
    }
    if(sum>=h)
    {
    	cout<<"Yes"<<endl;
    }
    else
    	cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
//20190622
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int a,b,k;

    cin >> a >> b >> k;

    if(k>b-a){
        for(int i=a;i<=b;i++){
            cout << i << endl;
        }
    }
    else{
        for(int i=a;i<a+k;i++){
            cout << i << endl;
        }
        if(a+k>b-k+1){
            for(int j=a+k;j<=b;j++){
                cout<<j<<endl;
            }
        }
        else{
            for(int j=b-k+1;j<=b;j++){
                cout << j << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <vector>
#include <unordered_set>
#include <unordered_map>

typedef long long ll;

using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> v;

  while (n) {
    if (abs(n) % 2 == 1) {
      v.push_back(1);
      n--;
    } else {
      v.push_back(0);
    }
    n /= (-2);
  }

  if (v.empty())
    v.push_back(0);

  for (int i = v.size() - 1; i >= 0; i--)
    cout << v[i];
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	int rez=0;
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= n ; j ++){
			int gcdij=__gcd(i,j);
			for(int k = 1 ; k <= n ; k ++){
				int gcd=__gcd(gcdij,k);
				rez+=gcd;
			}
		}
	}
	cout<<rez;
}

Measured memory_bytes: 3640
def abc():
    n = int(input())
    s = input().rstrip()
    x = 0
    ans = 0
    for i in range(n):
        if s[i] == 'I':
            x += 1
        if s[i] == 'D':
            x -= 1
        ans = max(ans, x)
    print(ans)


abc()


Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

#define endl '\n'
#define ll long long
const ll mod = 1000000007;

using namespace std;

ll sigma(ll n)
{
	return (n * (n + 1) / 2);
}

ll rsigma(ll n, ll k)
{
	return (sigma(n) - sigma(n - k));
}

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

	ll n, k;
	cin >> n >> k;

	ll cnt = 1;
	for (ll i = k; i < n + 1; i++)
	{
		ll mn = sigma(i - 1);
		ll mx = rsigma(n, i);
		cnt += (mx - mn + 1) % mod;
	}

	cout << cnt % mod << endl;

	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
using namespace std;
int a[2002020];
int read(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main()
{
	int n=read(),k=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=k+1;i<=n;i++){
		if(a[i-k]>=a[i])puts("No");
		else puts("Yes");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int ans = max(2 * a - 1, 2 * b - 1);
    cout << max(ans, a + b) << '\n';
    return 0;
}


Measured memory_bytes: 256
l,r = map(int,input().split())
'''
for h in range(0,2):
	for i in range(l,r+1):
		if i % (2019+h) == 0:
			print(h)
			exit()
		elif i % (673+h) == 0 and (r-l)>=2:
			print(h)
			exit()
		elif i % (2019-h) == 0:
			print(h)
			exit()
		elif i % (673-h) == 0 and (r-l)>=2:
			print(h)
			exit()
'''
			
lst = []

for i in range(l,r):
	for j in range(l+1,r+1):
		if (i*j)%2019 == 0:
			print(0)
			exit()
		lst.append((i*j)%2019)

print(min(lst))


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int A, B;
    cin >> A >> B;
    int p = 1;
    int ans = 0;
    while (p < B){
        p += A-1;
        ans ++;
    }
    cout << ans << endl;
}

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


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

int main() {
	ll A, V, B, W, T;
	cin >> A >> V;
	cin >> B >> W;
	cin >> T;

	ll afterA, afterB;
	bool ans = false;
	if(A >= B) {
		afterA = A - V * T;
		afterB = B - W * T;
		if(afterA <= afterB) ans = true;
	} else {
		afterA = A + V * T;
		afterB = B + W * T;
		if(afterA >= afterB) ans = true;
	}

	if(ans)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 3632