akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		long[] a = new long[n];
		long[] b = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();
		}
		
		long[] minDist = new long[n];
		int[] asm = new int[n];
		Arrays.fill(minDist, 1000000000);
		for (int i = 1; i <= m; i++) {
			long c = sc.nextLong();
			long d = sc.nextLong();
			for (int j = 0; j < n; j++) {
				long dist = Math.abs(a[j] - c) + Math.abs(b[j] - d);
				if (dist < minDist[j]) {
					minDist[j] = dist;
					asm[j] = i;
				}
			}
		}
		
		Arrays.stream(asm).forEach(System.out::println);
	}
}


Measured memory_bytes: 27092
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cassert>
using namespace std;
 
//??¨????
int calc(vector<string> vec){
    vector<int> stack;
     
    for(int i =0; i < vec.size(); i++){
    //   cout << "i="<< i << "::" << vec[i] << endl;
         
        int res = 0;
        int sw = vec[i][0];
        switch(sw){
            case '+':{
               int num1 = stack.back();
               stack.pop_back();
               int num2 = stack.back();
               stack.pop_back();
               res  = num1 + num2;
               stack.push_back(res);
//   cout << num1 << "+"<< num2 << "=" << res << endl; 
               break;
            }
            case '-':{
               int num1 = stack.back();
               stack.pop_back();
               int num2 = stack.back();
               stack.pop_back();
    //   cout << "num1="<< num1 << endl;
    //   cout << "num2="<< num2 << endl;
               res  = num2 - num1;
               stack.push_back(res);
               break;
            }
            case '*':{
               int num1 = stack.back();
               stack.pop_back();
               int num2 = stack.back();
               stack.pop_back();
               res  = num1 * num2;
               stack.push_back(res);
               break;
            }
            case '/':{
               int num1 = stack.back();
               stack.pop_back();
               int num2 = stack.back();
               stack.pop_back();
               //0??????
               assert(num1 != 0);
                res  = num2 / num1;
               stack.push_back(res);
               break;
            }
            default: {
               stack.push_back(stoi(vec[i]));
               //res =  stoi(stack[i]);
            }
        }
        // cout <<"when i=" <<i << ";switch res::" << res << endl;
    }
    int ans = 0 ;
    ans = stack[0];
    return ans;
}
 
int main(){
    //input
    vector<string> vec;
    while(1){
        string str ;
        cin >> str ;
        if(cin.eof()){
            break;
        }else{
            vec.push_back(str);

        }
    }
     
    //calc
    int result = 0;
    result = calc(vec);
     
    //output
    cout << result << endl;
     
    return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, i, j, k, ans=0;
  cin>>n;
  int arr[n];
  for(i=0; i<n; i++)
    cin>>arr[i];

  sort(arr, arr+n);
  for(i=0; i<n; i++){
    for(j=i+1; j<n; j++){
      for(k=j+1; k<n; k++){
        if(arr[i]+arr[j]<=arr[k])
          break;
        else if(arr[i]+arr[j]>arr[k] && arr[i]+arr[k]>arr[j] && arr[k]+arr[j]>arr[i])
          ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int h, n;
int a[1005], b[1005];
int dp[10005];

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

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

    dp[0] = 0;
    for (int i = 1; i <= h; i++) {
        dp[i] = inf;
    }

    for (int i = 0; i < h; i++) {
        if (dp[i] == inf) continue;
        for (int j = 0; j < n; j++) {
            int nxt = min(i+a[j], h);
            dp[nxt] = min(dp[nxt], dp[i] + b[j]);
        }
    }

    cout << dp[h];




    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long num=1;
        long max=1000000000000000000L;
        boolean flag=true;
        long[] nums = new long[N];
        for(int i=0; i<N; i++) {
            long enter = sc.nextLong();
            if(enter==0) {
                flag=false;
                break;
            }else {
                nums[i]=enter;
            }
        }
        if(flag) {
            int count=0;
            while(count<N && num<=(long)(max/nums[count]) ){
                num*=nums[count];
                count++;
            }
            if(count!=N) {
                System.out.println(-1);
            }else {
                System.out.println(num);
            }
        }else {
            System.out.println(0);
        }
	}

}


Measured memory_bytes: 61344
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<' '<<b<<' '<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int H, W;

	while (1) {

		cin >> H >> W;
	
		if (H == 0 && W == 0)break;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i % 2 == 1) {
					if (j % 2 == 1) {
						cout << "#";
					}
					else {
						cout << ".";
					}
				}
				else {
					if (j % 2 == 1) {
						cout << ".";
					}
					else {
						cout << "#";
					}
				}
			}
			cout << endl;
		}

		cout << endl;
	}

	return 0;
}


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

const int inf = 1e9;

struct MaxFlow {
	struct edge {
		int u; int v; int c; int f;
		edge(int u=0, int v=0, int c=0, int f=0): u(u), v(v), c(c), f(f) {}
	};

	int n, s, t; // nNode, source, sink
	vector< vector<int> > G;
	vector<edge> e;
	MaxFlow(int n=0, int s=0, int t=0): n(n), s(s), t(t) {
		G.assign(n + 1, vector<int>());
	}
	void add(int u, int v, int c) {
		G[u].push_back(e.size()); e.push_back(edge(u, v, c, 0));
		G[v].push_back(e.size()); e.push_back(edge(v, u, 0, 0));
	}

	vector<int> d; // dist
	vector<int> ptr; // pointer
	bool bfs() {
		d.assign(n + 1, -1); ptr.assign(n + 1, 0);
		queue <int> q; q.push(s); d[s] = 0;
		while(!q.empty()) {
			int u = q.front(); q.pop();
			for (int id : G[u]) if (d[e[id].v] == -1 && e[id].c > e[id].f) {
				d[e[id].v] = d[u] + 1;
				q.push(e[id].v);
			}
		}
		return d[t] != -1;
	}
	int dfs(int u, int fl) {
		if (!fl || u == t) return fl;
		for (int &i = ptr[u]; i < G[u].size(); ++i) {
			int id = G[u][i];
			if (e[id].f >= e[id].c || d[e[id].v] != d[u] + 1) continue;
			int nxt = dfs(e[id].v, min(fl, e[id].c - e[id].f));
			if (nxt) {
				e[id].f += nxt; e[id ^ 1].f -= nxt; return nxt;
			}
		}
		return 0;
	}
	int maxFlow() {
		int ans = 0;
		while(bfs()) {
			while(int cur = dfs(s, inf)) ans += cur;
		}
		return ans;
	}
} mf;

const int N = 105;
int H, W;
int st, en;
char a[N][N];
vector < pair<int,int> > cells;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> H >> W;
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			cin >> a[i][j];
			if (a[i][j] != '.') cells.push_back(make_pair(i,j));
		}
	}
	for (int i = 0; i < cells.size(); ++i) {
		int x = cells[i].first, y = cells[i].second;
		if (a[x][y] == 'S') st = i;
		else if (a[x][y] == 'T') en = i;
	}

	// create Max Flow
	mf = MaxFlow(cells.size() * 2 + 10, 2 * st + 1, 2 * en);
	for (int i = 0; i < cells.size(); ++i) {
		int x = cells[i].first, y = cells[i].second;
		mf.add(2 * i, 2 * i + 1, 1);
		for (int j = 0; j < cells.size(); ++j) if (j != i) {
			if (cells[i].first == cells[j].first || cells[i].second == cells[j].second) {
				mf.add(2 * i + 1, 2 * j, inf);
			}
		}
	}

	// find mincut 
	int ans = mf.maxFlow();
	if (ans >= inf) printf("-1\n");
	else printf("%d\n", ans);
}

Measured memory_bytes: 85696
N = int(input())
A = list(map(int, input().split()))
cnt = 0
ans = 0
for i in range(N):
  if(A[i] < 0):
    cnt += 1
if(cnt % 2 == 0):
  for i in range(N):
    ans += abs(A[i])
  print(ans)
else:
  minabs = 10**9
  for i in range(N):
    minabs = min(minabs, abs(A[i]))
  for i in range(N):
    ans += abs(A[i])
  print(ans - 2*minabs)

Measured memory_bytes: 14412
using System;

class Program
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int a = inp[0] + inp[1];
        int b = inp[0] - inp[1];
        int c = inp[0] * inp[1];
        int ans = (int)Math.Max(a, b);
        Console.WriteLine((int)Math.Max(ans, c));
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,m,q,x,y,X,Y,v,r,d;
    in>>n>>m>>q;
    vector<string> s(n);
    for(auto&c:s) in>>c;
    vector<vector<int>> sv(n+1,vector<int>(m+1));
    vector<vector<int>> sr(n+1,vector<int>(m));
    vector<vector<int>> sd(n,vector<int>(m+1));
    fr(i,n) fr(j,m) sv[i+1][j+1]=sv[i+1][j]+s[i][j]-'0';
    fr(i,n) fr(j,m) sv[i+1][j+1]+=sv[i][j+1];
    fr(i,n) fr(j,m-1) sr[i+1][j+1]=sr[i+1][j]+(s[i][j]&s[i][j+1])-'0';
    fr(i,n) fr(j,m-1) sr[i+1][j+1]+=sr[i][j+1];
    fr(i,n-1) fr(j,m) sd[i+1][j+1]=sd[i+1][j]+(s[i][j]&s[i+1][j])-'0';
    fr(i,n-1) fr(j,m) sd[i+1][j+1]+=sd[i][j+1];
    fr(i,q){
        in>>x>>y>>X>>Y;
        --x,--y;
        v=sv[X][Y]-sv[x][Y]-sv[X][y]+sv[x][y];
        r=sr[X][Y-1]-sr[x][Y-1]-sr[X][y]+sr[x][y];
        d=sd[X-1][Y]-sd[x][Y]-sd[X-1][y]+sd[x][y];
        cout<<v-r-d<<'\n';
    }
}

Measured memory_bytes: 53760
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX_Y = 10000;
const int MAX_X = 10;
int a[MAX_X][MAX_Y] = {0};
int n, m;

void solve(){
	while(cin >> n >> m && n && m){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				cin >> a[i][j];
			}
		}
		int d = 0, r = 0;
		// 1 << n &#31181;情况 
		for(int i = 0; i < (1 << n - 1); i++){
			//&#27599;&#31181;情况&#32479;&#35745;&#27599;一列&#35813;不&#35813;反面 
			int s = 0;
			for(int j = 0; j < m; j++){
				int c = 0;
				for(int k = 0; k < n; k++){
					d = (i >> k) & 1;
					c += a[k][j] ^ d;
				}
				s += max(c, n - c);
			}
			r = max(r, s);
		}
		cout << r << endl;
	}
}
int main(){
	solve();
}

Measured memory_bytes: 3464
#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN=200111;

int N;
int Ans=0;

int A[MAXN];

struct Node{
	int v, c;
} T[MAXN];

int Tc;

inline int lowbit(int a){
	return a&(-a);
}

bool Norm(int v){
	return lowbit(v)==v;
}

int Val(int v){
	int r=1;
	while(r<=v)	r<<=1;
	return r;
}

bool Find(int v, int l, int r){
	if(l>r || T[l].v>v)	return false;
	int m;
	while(l<r){
		m=(l+r)>>1;
		if(T[m+1].v>v)	r=m;
		else	l=m+1;
	}
	m=(l+r)>>1;
	if(T[m].v!=v)	return false;
	if(!T[m].c)	return false;
	--T[m].c;++Ans;
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	
	cin >> N;
	
	for(int i=1;i<=N;++i)	cin >> A[i];
	
	sort(A+1, A+N+1);
	
	for(int i=1, c=0;i<=N;++i){
		++c;
		if(i==N || A[i]!=A[i+1]){
			++Tc;
			T[Tc].v=A[i];T[Tc].c=c;
			c=0;
		}
	}
	
	for(int i=N;i>=1;--i){
		if(Norm(T[i].v)){
			Ans+=T[i].c>>1;
			T[i].c&=1;
		}
		for(int k=1;k<=T[i].c;++k){
			if(!Find(Val(T[i].v)-T[i].v, 1, i-1))	break;
		}
	}
	
	cout << Ans << endl;
	
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;
import java.math.*;
class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        int[] b = new int[n];
        int max = 0;
        int sec = 0;
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        }
        
        Arrays.sort(b);
        max = b[n-1];
        sec = b[n-2];
        for(int i = 0;i < n;i++){
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        }
    }
}

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

int main(){

    int a,b;
    cin >> a >> b;
    int ans;
    ans=max({a+b,a-b,a*b});
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
author:lingling
date:2017.06.01
description: ??°??????????????????????¢???????????????\??????
*/
#include<iostream> 
using namespace std;
void InsertSort(int a[],int n);
void PRINT(int a[],int n);
#define MAX 100
int main() {
    int N;
    int data[MAX];
    while(cin>>N) {
        for(int i=0;i<N;i++) cin>>data[i];
        InsertSort(data,N);
    }
    return 0;
}
void InsertSort(int a[],int n) {
    int key;
    int j;
    PRINT(a,n);
    cout<<endl;
    for(int i=1;i<n;i++) {
        key=a[i];//?????????????´?
        j=i-1;
        while(j>=0&&a[j]>key) {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=key;
        PRINT(a,n);
       // if(i<n-1) cout<<endl;
       cout<<endl;
    }
}
void PRINT(int a[],int n) {
    for(int i=0;i<n;i++) {
        cout<<a[i];
        if(i<n-1) cout<<' ';
    }
 //  cout<<endl;
}

Measured memory_bytes: 3100
#include <stdio.h>

int main(){
  int a, b;
  char c;

  scanf("%d %c %d", &a, &c, &b);
  if(c == '+'){
    printf("%d\n", a+b);
  }
  else{
    printf("%d\n", a-b);
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main(){
	int m, l, a, mins, lins, sta;
	string eq;
	cin >> eq;
	eq += "+";
	cin >> a;
	sta = 0;
	m = 0;
	l = 0;
	for(int i=0;i<eq.size();i++){
		if(i%2==0){
			if(!sta){
				m += eq[i]-'0';
				lins = eq[i]-'0';
			}
			else{
				m = m * (eq[i]-'0');
				lins *= eq[i]-'0';
			}
		}
		else{
			if(eq[i]=='+'){
				sta = 0;
				l += lins;
			}
			else {
				sta = 1;
			}
		}
		//cout << m << " " << l << endl;
	}
	if(a==l&&a==m)cout << "U" << endl;
	else if(a==l)cout << "M" << endl;
	else if(a==m)cout << "L" << endl;
	else cout << "I" << endl;
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <sstream>
#include <algorithm>
#define endl '\n'
#define all(var) var.begin(), var.end()
typedef long long ll;
using namespace std;

int main(){
    int n; cin >> n;
    vector <int> arr(n);
    bool duple = false;
    vector < bool > table(1000000000+7, false);

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

        if(table[arr[i]]) duple = true;
        table[arr[i]] = true;
    }
    if(duple) cout << "NO" << endl;
    else
        cout <<  "YES" << endl;


}


Measured memory_bytes: 123136
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

signed main() {
    //input
    int s,w;cin>>s>>w;
    check_input();


    //solve
    cout << (w>=s ? "unsafe" : "safe") << endl;

    return 0; 
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, T;
    cin >> N >> T;
    VI a(N);
    int ama = 0;
    int mxid;
    REP(i, N) {
        scanf("%d", &a[i]);
        if (ama < a[i]) {
            ama = a[i];
            mxid = i;
        }
    }
    int ami = INF;
    REP(i, mxid) {
        ami = min(ami, a[i]);
    }
    int sa = ama - ami;
    int cnt = 1;
    while (mxid < N) {
        ama = 0; ami = INF;
        int idbuf = N;;
        FOR(i, mxid + 1, N) {
            if (ama < a[i]) {
                ama = a[i];
                idbuf = i;
            }
        }
        FOR(i, mxid + 1, idbuf) {
            ami = min(ami, a[i]);
        }
        if (sa == ama - ami) {
            cnt++;
        } else if (sa < ama - ami) {
            sa = ama - ami;
        }
        mxid = idbuf;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
s = input()
x, y = map(int, input().split())
cnt = 0
xm = []
ym = []
flag = True

for i in range(len(s)):
    if s[i]=='F':
        cnt += 1
    else:
        if flag:
            xm.append(cnt)
            flag = False
        else:
            ym.append(cnt)
            flag = True
        
        cnt = 0

if flag:
    xm.append(cnt)
else:
    ym.append(cnt)
    
s = {0}

for i in range(len(xm)):
    ns = set()
    
    if i==0:
        for si in s:
            ns.add(si+xm[i])
    else:
        for si in s:
            ns.add(si-xm[i])
            ns.add(si+xm[i])
    
    s = ns

if x not in ns:
    print('No')
    exit()

s = {0}

for i in range(len(ym)):
    ns = set()
    
    for si in s:
        ns.add(si-ym[i])
        ns.add(si+ym[i])
    
    s = ns
    
if y not in s:
    print('No')
    exit()

print('Yes')

Measured memory_bytes: 48604
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N_MAX = 200001;
int main()
{
  int n,qq,a,b,i,j,k;
  long long x;
  bool chk[N_MAX];
  long long c[N_MAX];
  vector<int> v[N_MAX];
  queue<int> q;
  cin >> n >> qq;
  fill(c+1,c+n+1,0);
  fill(chk+1,chk+n+1,true);
  for(i=0;i<n-1;i++){
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for(i=0;i<qq;i++){
    cin >> a >> x;
    c[a]+=x;
  }
  q.push(1);
  while(q.size()){
    j=q.front(); q.pop();
    for(k=0;k<v[j].size();k++)
      if(chk[v[j][k]]){
        q.push(v[j][k]);
        c[v[j][k]]+=c[j];
      }
    chk[j]=false;
  }
  for(i=1;i<n;i++)
    cout << c[i] << " ";
  cout << c[n] << endl;
  return 0;
}

Measured memory_bytes: 16500
import sys

l = []
for i in sys.stdin:
    l.append(i.split())

for i in range(0,len(l)-1):
    count = 0
    for a in range(1,int(l[i][0])+1):
        for b in range(a+1,int(l[i][0])+1):
            for c in range(b+1,int(l[i][0])+1):
                if a + b + c == int(l[i][1]):
                    count += 1
    print(count)


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/03  Problem: ABC 046 D / Link: http://abc046.contest.atcoder.jp/tasks/abc046_d  ----- */


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

	string s; cin >> s;
	LL ans = SZ(s) - 2*count(ALL(s), 'p');


	cout << (ans / 2) << "\n";

	return 0;
}


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

vector<bool> passed(vector<bool>& isPassed,string s, int a, int b)
{
    int i = 0;
    int num = 0;
    int overseas = 0;
    while (i < s.length()){
        if (s[i] == 'a' && num < (a + b)){
            isPassed[i] = true;
            num++;
        }
        if (s[i] == 'b'){
            overseas++;
            if (overseas <= b && num < (a + b)){
                isPassed[i] = true;
                num++;
            }
        }
        i++;
    }
    return isPassed;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    vector<bool> isPassed(n,false);
    isPassed = passed(isPassed, s, a, b);
    for (int i = 0; i < isPassed.size(); i++){
        if (isPassed[i] == true)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 1140
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

n = raw_input()
n = int(n)
f = np.zeros([n,10],int)
for i in range(n):
    line = raw_input()
    line = line.split()
    line = map(int,line)
    f[i] = line
p = np.zeros([n,11],int)
for i in range(n):
    line = raw_input()
    line = line.split()
    line = map(int,line)
    p[i] = line

for i in range(2**10):
    kaburi = np.zeros([n],int)
    num = i
    for j in range(10):
        shutten = num % 2
        num = num / 2
        if shutten == 1:
            for k in range(n):
                if f[k,j] == 1:
                    kaburi[k] += 1
    rieki = 0
    for k in range(n):
        rieki += p[k][kaburi[k]]
    if i <= 1:
        saidai = rieki
    else:
        saidai = max(rieki,saidai)

print saidai


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

#define all(x) x.begin(),x.end()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;
int ctoi(char c) {return c-'0';}

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

int N,K;
cin>>N>>K;
vi a(N);
vi dp(N+K+5,1e9);
for(auto& x: a)
  cin>>x;

dp[0]=0;
forn(i,N) {
  forn(d,K) {
    dp[i+d+1]=min(dp[i+d+1],dp[i]+abs(a[i]-a[i+d+1]));
  }
}
cout<<dp[N-1]<<endl;
return 0;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= 9; ++i)
        for (int j = 1; j <= 9; ++j)
            if (i * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>

using namespace std;

int main(){
    int n, a, b;
    int a_score, b_score;
    while(true){
        a_score = b_score = 0;
        scanf("%d", &n);
        if(n == 0) break;
        for(int i = 0; i < n; i++){
            scanf("%d %d", &a, &b);
            if( a > b ){
                a_score += ( a + b);
            } else if( a < b ){
                b_score += ( a + b);
            } else {
                a_score += a;
                b_score += b;
            }
        }
        printf("%d %d\n", a_score, b_score);


    }
    return 0;

}

Measured memory_bytes: 1028
N=int(input())
AB = [[int(i) for i in input().split()] for j in range(N)]
ABDeadStart = [[A,B,B-A] for A,B in AB]#所要時間、初めてないと駄目な時間
MaxShoyou = sum([a for a,b,kaisi in ABDeadStart])
ABDeadStart.sort(key = lambda x:x[2]-MaxShoyou+x[0])
curtime = 0
NO =0
for a,b,ds in ABDeadStart:
    if curtime <= ds:
        curtime += a
    else:
        NO =True
        break
if NO :print("No")
else:print("Yes")

Measured memory_bytes: 74200
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define inf 1000000005
#define MOD 1000000007 
#define N 100005
#define M 1000000
#define LOG 20
#define KOK 300
#define EPS 0.0000001
using namespace std;

int mx,dia,n;
int sub[N],dad[N];
vector<int> v[N];

void dfs(int node,int ata,int dst) {

	dad[node]=ata;
	sub[node]=1;

	if(dst>mx) {

		mx=dst;
		dia=node;

	}

	for(auto x:v[node]) {

		if(x==ata) continue ;

		dfs(x,node,dst+1);

		sub[node]+=sub[x];

	}

}

vector<int> ans;
vector<int> cur;
int val;

void dfs2(int node,int ata) {

	int leaf=0;
	int non=0;

	for(int x:v[node]) {

		if(x==ata) continue ;

		leaf+=(sub[x]==1);
		non+=!(sub[x]==1);

	}

	if(non>1) return ;

	if(non) {

		int tut=++val;

		for(int i=1;i<=leaf;i++) {

			cur.pb(++val);

		}

		cur.pb(tut);

		for(int x:v[node]) {

			if(x==ata || sub[x]==1) continue ;

			dfs2(x,node);

		}
	
	}
	else {

		int tut=++val;

		for(int i=1;i<leaf;i++) {

			cur.pb(++val);

		}

		cur.pb(tut);
		cur.pb(++val);

		if(!sz(ans)) ans=cur;
		else umin(ans,cur);

	}

}

void solve(int node) {

	cur.clear();
	val=0;

	dfs(node,0,0);

	dfs2(node,0);

}

int main() {

	int root=1;

	scanf("%d",&n);

	for(int i=1;i<n;i++) {

		int x,y;

		scanf("%d %d",&x,&y);

		v[x].pb(y);
		v[y].pb(x);

		if(sz(v[x])>1) root=x;
		if(sz(v[y])>1) root=y;

	}

	vector<int> cd;

	mx=0;
	dfs(root,0,0);

	cd.pb(dia);

	mx=0;
	dfs(dia,0,0);

	cd.pb(dia);

	solve(cd[0]);
	solve(cd[1]);

	if(ans.empty()) printf("-1");
	else for(auto x:ans) printf("%d ",x);

}	

Measured memory_bytes: 15736
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <numeric>
#include <cmath>
#include <memory.h>
#include <sstream>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef pair<ll, int> pli;
typedef vector<vector<int>> vvi;

#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-8

unordered_set<char> foo;

int solve(string s, char ch) {
    if (s.length() == 1) return 0;
    bool flag = true;
    string next;
    for (int i = 0; i < s.length() - 1; ++i) {
        if (s[i] == ch || s[i + 1] == ch) {
            next.push_back(ch);
        } else {
            flag = false;
            next.push_back(s[i]);
        }
    }
    if (flag) {
        return 1;
    } else {
        return 1 + solve(next, ch);
    }
}

int main() {
    string s;
    cin >> s;
    for (char ch : s) {
        foo.insert(ch);
    }
    if (foo.size() == 1) {
        cout << 0;
        return 0;
    }
    int res = s.length();
    for (char ch : foo) {
        res = min(res, solve(s, ch));
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, K = map(int, readline().split())
    P = [0] + list(map(int, readline().split()))

    cur = sum(P[:K])
    s_max = 0

    for i in range(N - K + 1):
        cur += P[K + i]
        cur -= P[i]
        s_max = max(s_max, cur)

    print((s_max + K) / 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 99496
#include <stdio.h>

int main(){
    int p, q, r;
    scanf("%d %d %d", &p, &q, &r);
    if(p>=q && p>=r)  
        printf("%d", q+r);
    else if(q>=p && q>=r)
        printf("%d", r+p);
    else if(r>=p &&r>=q)
        printf("%d", p+q);

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int selectionSort(int A[], int N){
	int temp = 0;
	int i = 0, j = 0;
	int minj = 0;
	int times = 0;
	for( i = 0; i < N; i++ ){
		minj = i;
		for( j = i; j < N; j++ ){
			if( A[minj] > A[j] ){
				minj = j;
			}
		}
		if( minj != i ){
			temp = A[i];
			A[i] = A[minj];
			A[minj] = temp;
			times++;
		}
	}
	return times;
}

int main(){
	int N = 0;;
	int A[100];
	int i = 0;
	int re = 0;
	scanf("%d", &N);
	for( i = 0; i < N; i++ ){ scanf("%d", &A[i]); }
	re = selectionSort(A, N);
	printf("%d", A[0]);
	for( i = 1; i < N; i++ ){
		printf(" %d", A[i]);
	}
	printf("\n");
	printf("%d\n", re);
	return 0;
}

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

typedef long long ll;

const ll MAX_N = 1e5 + 5, inf = 1000000LL * 1000000LL * 1000000LL;
ll n, E, T;
ll x[MAX_N];
ll dp[MAX_N];
ll seg[MAX_N << 2];
ll lazy[MAX_N << 2];

void shift (ll id) {
	seg[id << 1] += lazy[id];
	lazy[id << 1] += lazy[id];

	seg[id << 1 | 1] += lazy[id];
	lazy[id << 1 | 1] += lazy[id];
	lazy[id] = 0;
}

void add (ll l, ll r, ll val, ll s = 0, ll e = n, ll id = 1) {
	if (l <= s && e <= r) {
		seg[id] += val;
		lazy[id] += val;
		return ;
	}

	if (r <= s || e <= l)
		return ;

	shift(id);

	ll mid = e + s >> 1;
	add(l, r, val, s, mid, id << 1);
	add(l, r, val, mid, e, id << 1 | 1);
	seg[id] = min(seg[id << 1], seg[id << 1 | 1]);
}

ll get (ll l, ll r, ll s = 0, ll e = n, ll id = 1) {
	if (l <= s && e <= r)
		return seg[id];

	if (r <= s || e <= l)
		return inf;

	shift(id);
	ll mid = e + s >> 1;
	return min(get(l, r, s, mid, id << 1), get(l, r, mid, e, id << 1 | 1));
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> E >> T;
	for (ll i = 0; i < n; i++)
		cin >> x[i];

	dp[n - 1] = T;
	for (ll i = n - 2; ~i; i--) {
		add(i + 1, n, 2 * (x[i + 1] - x[i]));
		add(i, i + 1, dp[i + 1]);
		ll ind = lower_bound(x, x + n, x[i] + (T + 1) / 2) - x;
		ind--;

		dp[i] = T + dp[ind + 1];
		if (ind + 1 < n)
			dp[i] = min(dp[i], get(ind + 1, n));
	}

	cout << dp[0] + E << "\n";
	return 0;
}

Measured memory_bytes: 7936
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
vector<pair<int, int>> v;
vector<int>sol;
void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		v.pb(MP(b, a));
	}
	sort(v.begin(), v.end());
	sol.pb(0);
	bool ans = true;
	for (int i = 0; i < n; i++)
	{
		sol.pb(v[i].second + sol.back());
		if (sol[i + 1] > v[i].first)
			ans = false;
	}
	if (ans)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}
int main()
{
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi ans(n);
    rep(i, n-1) {
        int a;
        cin >> a;
        a--;
        ans[a]++;
    }
    rep(i, n) cout << ans[i] << endl;
}

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

int main()
{
    int n, k; cin>>n>>k;
    vector<int> w(n); for(auto& e: w) cin>>e;

    int a=1<<28;
    int P=2*a-1;
    for(; a>0; a>>=1) {
        int c=1;
        int t=P-a;
        for(int i=0, s=0; i<n; ++i) {
            if (w[i]>t) { c=k+1; break; }
            if (s+w[i]>t) {
                ++c;
                s=w[i];
            }
            else {
                s+=w[i];
            }
        }
        if (c<=k) P=t;
    }
    cout<<P<<endl;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,l,m,n,o,p,q,r,s,t,x,a[500],tt=0;
    cin>>n>>m;
    p=(n%m);
    q=m%n;
    r=m-p;
    s=n-q;
    cout<<min({p,r})<<endl;
    return 0;
}
    

Measured memory_bytes: 256
using System.Linq;
using System;
using System.IO;

class Program
{
  static void Main(string[] args) => new Program().solve();

  void solve()
  {
    var n = int.Parse(Console.ReadLine());
    var seq = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var ans = seq.Aggregate(0, (acc, ai) => acc + shiftCount(cnt:0, n:ai));
    Console.WriteLine(ans);
  }

  int shiftCount(int cnt, int n)
  {
    if((n & 1) == 1) return cnt;
    return shiftCount(++cnt, n >> 1);
  }
}

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

int main(){
  int N;
  int A[210];
  int count = 0;
  
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  
  while(true){
    bool all_even = true;
    for(int i=0; i<N; i++){
      if(A[i] % 2 != 0) all_even = false;
    }
    if(all_even == false) break;
    else {
      for(int i=0; i<N; i++){
        A[i] /= 2;
      }
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
using PanasonicProgrammingContest2020.Questions;
using PanasonicProgrammingContest2020.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace PanasonicProgrammingContest2020.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var hw = inputStream.ReadIntArray();
            long h = hw[0];
            long w = hw[1];

            if (h == 1 || w == 1)
            {
                yield return 1;
            }
            else
            {
                yield return (h * w + 1) / 2;
            }
        }
    }
}


namespace PanasonicProgrammingContest2020
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace PanasonicProgrammingContest2020.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace PanasonicProgrammingContest2020.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

int main(void) {
	double a, b, x;
	double ans = 0;
	scanf("%lf %lf %lf", &a, &b, &x);
	double h = x / a / a;

	if (2 * h - b > 0) {
		ans = M_PI / 2. - atan(a / (2 * (b - h)));
	} else {
		ans = atan(b * b / (2 * a * h));
	}
	ans = ans * 180. / M_PI;
	printf("%lf", ans);

	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())
ans = 0
for i in range(N - M + 1):
    for j in range(N - M + 1):
        ans = 1
        for mi in range(M):
            for mj in range(M):
                if B[mi][mj] != A[i+mi][j+mj]:
                    ans = 0
                    break
            if ans == 0:
                break
        if ans == 1:
            break
    if ans == 1:
        break
if ans == 1:
    print('Yes')
else:
    print('No')
        

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

int mod = 998244353;
struct Mint {
    int val;
    Mint inv() const {
        int tmp, a = val, b = mod, x = 1, y = 0;
        while(b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
        return Mint(x);
    }
public:
    Mint() :val(0) {}
    Mint(ll x) :val(x >= 0 ? x % mod : x % mod + mod) {}
    int mtoi() { return this->val; }
    Mint pow(ll t) { Mint res = 1,b = *this; while(t){if(t&1)res *= b;b *= b;t >>= 1;}return res; }
    Mint& operator+=(const Mint& x) { if ((val += x.val) >= mod) val -= mod; return *this; }
    Mint& operator-=(const Mint& x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; }
    Mint& operator*=(const Mint& x) { val = (ll)val * x.val % mod; return *this; }
    Mint& operator/=(const Mint& x) { return *this *= x.inv(); }
    bool operator==(const Mint& x) const { return val == x.val; }
    bool operator!=(const Mint& x) const { return val != x.val; }
    bool operator<(const Mint& x) const { return val < x.val; }
    bool operator<=(const Mint& x) const { return val <= x.val; }
    bool operator>(const Mint& x) const { return val > x.val; }
    bool operator>=(const Mint& x) const { return val >= x.val; }
    Mint operator+(const Mint& x) const { return Mint(*this) += x; }
    Mint operator-(const Mint& x) const { return Mint(*this) -= x; }
    Mint operator*(const Mint& x) const { return Mint(*this) *= x; }
    Mint operator/(const Mint& x) const { return Mint(*this) /= x; }
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx) {
        Fact.resize(maxx+1,Mint(1)),Finv.resize(maxx+1); rep(i,0,maxx)Fact[i+1]=Fact[i]*Mint(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*Mint(i);
    }
    Mint fact(int n,bool inv) { if(inv) return Finv[n]; else return Fact[n]; }
    Mint nPr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[n-r]; }
    Mint nCr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};

int main(){
    int n; scanf("%d",&n);
    char c[300010]; scanf("%s",c); string s=c;
    int cnt[3]={}; Mint ans=1;
    rep(i,1,n+1)ans*=Mint(i);
    rep(i,0,3*n){
        int idx=-1;
        if(s[i]=='R')idx=0;
        if(s[i]=='G')idx=1;
        if(s[i]=='B')idx=2;
        int minn=inf;
        rep(j,0,3){
            if(j!=idx&&cnt[j]>cnt[idx])chmin(minn,cnt[j]);
        }
        if(minn<=n)ans*=Mint(minn-cnt[idx]);
        cnt[idx]++;
    }
    printf("%d\n",ans.mtoi());
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x <<": "<<x<<"\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T = int> T in(){T x; cin>>x;return(x);}
template <class T > void print(T& x){cout<<x<<"\n";}
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N=in<int>();
  int count=0;
  REPS(i,N){
      int dig = ceil(log10(i+1));
      if (dig %2==1)count++;
  }
  cout <<count<<endl;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))
dict = {}
for i in range(n):
    dict.setdefault(a[i],i+1)

for i in range(1,n+1):
    if i != n+1:
        print('{} '.format(dict[i]),end="")
    else:
        print(dict[i])


Measured memory_bytes: 20704
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

bool pal(string s)
{
        rep(i, 0, len(s)) {
                if (s[i] != s[len(s)-1-i]) return false;
        }
        return true;
}

int main()
{
        string S;
        cin >> S;
        bool f1 = pal(S);
        ll last = (len(S)-1) / 2;
        string SS(S.begin(), S.begin()+last);
        // cout << SS << endl;
        bool f2 = pal(SS);
        string SSS(S.begin()+(len(S)+3)/2-1, S.end());
        // cout << SSS << endl;
        bool f3 = pal(SSS);

        if (f1 and f2 and f3) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}

Measured memory_bytes: 3588
h, w = gets.split.map(&:to_i)
n = gets.to_i
a = gets.split.map(&:to_i)
m = Array.new(h){Array.new(w, 0)}
y, x, lr = 0, 0, 1
a.each_with_index do |n, v|
  n.times do |i|
    m[y][x] = v + 1
    x += lr
    if x == w
      y += 1
      x = w - 1
      lr = -1
    elsif x < 0
      y += 1
      x = 0
      lr = 1
    end
  end
end
h.times do |i|
  puts m[i].join(' ')
end

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

typedef long long LL;

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

    sort(A, A + N);
    LL colors = N;
    for (LL i = 0 ; i  < N - 1; i++)
    {
        if (A[i + 1] > 2*A[i])
            colors = N - i - 1;

        A[i + 1] += A[i];
    }

    cout << colors;

    return 0;
}

Measured memory_bytes: 1024