akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations
import copy

H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]
ans = 0

w = list(range(W))
h = list(range(H))
for i in range(W+1):
    for comi in combinations(w, i):
        for j in range(H+1):
            for comj in combinations(h, j):
                tmpC = copy.deepcopy(C)
                for ci in comi:
                    for hj in range(H):
                        tmpC[hj][ci] = '.'
                for cj in comj:
                    for wi in range(W):
                        tmpC[cj][wi] = '.'
                tmp = 0
                for tc in tmpC:
                    tmp += tc.count('#')
                if tmp == K:
                    ans += 1

print(ans)

Measured memory_bytes: 9368
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e16;
typedef array<int, 3>arr3;
void die(string s) { cout << s << endl; exit(0); }
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
void solve() {
	int N, K; cin >> N >> K;
	ll ans = K;
	FOR(i, 1, N)ans *= (K - 1);
	print(ans);
}


signed main() {
	solve();
}



Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.StringTokenizer;


public class Main {

  class A {
    int c;
    int t;

    public A(int c, int t) {
      this.c = c;
      this.t = t;
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      A a = (A) o;
      return c == a.c &&
              t == a.t;
    }

    @Override
    public int hashCode() {
      return Objects.hash(c, t);
    }
  }

  private void solve(InputReader in, PrintWriter out) {
    int n = in.nextInt();
    int T = in.nextInt();
    A[] arr = new A[n];
    for (int i = 0; i < n; i++) {
      arr[i] = new A(in.nextInt(), in.nextInt());
    }
    Arrays.sort(arr, Comparator.comparingInt(a -> a.c));
    for (int i = 0; i < n; i++) {
      if (arr[i].t <= T) {
        out.println(arr[i].c);
        return;
      }
    }
    out.println("TLE");

  }

  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try (
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
      solve(in, out);
    }
  }


  static class InputReader implements AutoCloseable {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }


    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    @Override
    public void close() {

    }
  }

}


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

static const int INF = 1e9;

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

int main(){
    int H,W,ans;
    cin>>H>>W;
    char board[50][50];
    int dis[50][50];

    ans = 0;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin>>board[i][j];
            if(board[i][j] == '.') ans++;
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            dis[i][j] = INF;
        }
    }

    queue<pair<int,int>> q;

    q.push({0,0});
    dis[0][0] = 0;

    while(!q.empty()){
        pair<int,int> cur = q.front();
        q.pop();
        int vx,vy;
        vx = cur.second;
        vy = cur.first;

        for(int i=0; i<4; i++){
            int nx,ny;
            nx = vx,ny = vy;
            nx += dx[i];
            ny += dy[i];
            if(vx >= 0 && vx < W && vy >= 0 && vy < H){
                if(dis[ny][nx] == INF && board[ny][nx] == '.'){
                    dis[ny][nx] = dis[vy][vx]+ 1;
                    q.push({ny,nx});
                }           
            }
        }
    }

    if(dis[H-1][W-1] == INF) ans = -1;
    else ans =  ans - (dis[H-1][W-1]+1);

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
for o in range((2*N)-1):
  a=0
  if o<N:
    i=0
    j=o
    omomi=N-j
  else:
    j=0
    i=o-N+1
    omomi=N-i
  for t in range(N):
    for q in range(t):
      if L[i+t][j+q]!=L[i+q][j+t]:
        a=1
        break
    if a==1:
      break
  if a==0:
    ans+=omomi
print(ans)

Measured memory_bytes: 78344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<ll> ab(m*2);
  rep(i, m){
    cin >> ab[i*2] >> ab[i*2+1];
    ab[i*2]--;
    ab[i*2+1]--;
  }
  
  vector<ll> good(n, 1);
  rep(i, m){
    if (h[ab[i*2]] <= h[ab[i*2+1]])
      good[ab[i*2]] = 0;
    if (h[ab[i*2]] >= h[ab[i*2+1]])
      good[ab[i*2+1]] = 0;
  }
  
  ll ans = 0;
  rep(i, n){
    if (good[i] == 1)
      ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 6360
#include <cstdint>
#include <vector>

using namespace std;

#define GRAPH_SIZE 100
#define WEIGHT_MAX (1 << 21)

enum state_t {
  WHITE,
  GRAY,
  BLACK,
};

static uint32_t graph[GRAPH_SIZE][GRAPH_SIZE];
static state_t state[GRAPH_SIZE];
static uint32_t dist[GRAPH_SIZE];

size_t single_source_shotest_path(size_t num)
{
  size_t cost = 0;

  for (uint32_t i = 0; i < num; i++) {
    state[i] = WHITE;
    dist[i] = WEIGHT_MAX;
  }

  state[0] = GRAY;
  dist[0] = 0;

  while (true) {
    size_t minimum_cost = WEIGHT_MAX;
    uint32_t to = 0;
    for (uint32_t i = 0; i < num; i++) {
      if ((dist[i] < minimum_cost) && (state[i] != BLACK)) {
        minimum_cost = dist[i];
        to = i;
      }
    }

    if (minimum_cost == WEIGHT_MAX) break;

    cost += minimum_cost;
    state[to] = BLACK;

    for (uint32_t i = 0; i < num; i++) {
      if (((dist[to] + graph[to][i]) < dist[i]) && state[i] != BLACK) {
        state[i] = GRAY;
        dist[i] = dist[to] + graph[to][i];
      }
    }
  }

  return cost;
}

#include <iostream>

int32_t main()
{
  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    for (uint32_t j = 0; j < num; j++) {
      graph[i][j] = WEIGHT_MAX;
    }
  }

  for (uint32_t i = 0; i < num; i++) {
    uint32_t index, len;
    cin >> index >> len;
    for (uint32_t j = 0; j < len; j++) {
      uint32_t v, c;
      cin >> v >> c;
      graph[index][v] = c;
    }
  }

  single_source_shotest_path(num);

  for (uint32_t i = 0; i < num; i++) {
    cout << i << " " << dist[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
        using namespace std;
         int main(){
           int N; 	
           cin >> N;
           int x;
           int counter=0; 
           for(int i=1 ; i<=N; i++ ){
             cin >> x;
             if(x!=i) counter++; 
           }
           if(counter==2||counter==0){
             cout<< "YES" <<endl;
           }else{
             cout<< "NO" <<endl;
           }
         }

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, p;
    cin >> n >> p;
    vector<long long> w(n), b(n);
    for(int i=0; i<n; ++i)
        cin >> w[i] >> b[i];

    long long sum = 0;
    vector<long long> v(n);
    for(int i=0; i<n; ++i){
        sum -= p * b[i];
        v[i] = (100 - p) * w[i] + p * b[i];
    }
    sort(v.rbegin(), v.rend());

    for(int i=0; ; ++i){
        if(sum >= 0){
            cout << i << endl;
            return 0;
        }
        sum += v[i];
    }
}


Measured memory_bytes: 2560
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

N = int(input())
ans_list = []
for prime in primes(55555):
    if prime%10 == 1:
        ans_list.append(prime)
        N -= 1
        if N == 0:
            break
print(" ".join(list(map(str, ans_list))))


Measured memory_bytes: 3572
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector<int> a(86400);
		while (n--) {
			int h1, m1, s1, h2, m2, s2;
			scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
			a[h1 * 3600 + m1 * 60 + s1]++;
			a[h2 * 3600 + m2 * 60 + s2]--;
		}
		int x = 0, maxi = 0;
		for (int t = 0; t < 86400; t++) {
			x += a[t];
			maxi = max(maxi, x);
		}
		cout << maxi << endl;
	}
}

Measured memory_bytes: 1576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i,n,a[200010];
  vector<int> x;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
    x.push_back(a[i]);
  }
  sort(x.begin(),x.end());
  for(i=0;i<n;i++){
    if(a[i]<=x[(n-1)/2]){
      cout << x[n/2] << endl;
    }
    else{
      cout << x[(n-1)/2] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4820
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int mod=1000000007 ;

void solve(){
	
	int n ;
	cin>>n ;

	vector<int> v(n+1) ;
	unordered_map<int,int> mp ;

	for(int i=2;i<=n;i++)
	{
		cin>>v[i] ;
		mp[v[i]]++ ;
	}

	for(int i=1;i<=n;i++){
		cout<<mp[i]<<"\n" ; 
	}

}


int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    rep(i, n) cin >> a[i];
    map<ll, int> mp;
    rep(i, n) mp[a[i]] = 0;
    {
        int cnt = 0;
        for (auto& p : mp) p.se = cnt++;
    }
    vector<vector<int>> v(mp.size());
    rep(i, n) v[mp[a[i]]].pb(i);
    vector<int> nxt_id(n);
    rep(i, n) {
        auto& u = v[mp[a[i]]];
        auto it = lower_bound(all(u), i);
        ++it;
        if (it == u.end()) nxt_id[i] = *u.begin();
        else nxt_id[i] = *it;
    }

    int prv = -1;
    int cyc = 1;
    int cur = 0;
    while (1) {
        int nxt = nxt_id[cur];
        if (nxt <= cur) cyc++;
        // //
        // cout << " " << cur << " " << nxt << " " << cyc << endl;
        // prv = cur;
        cur = nxt + 1;
        if (cur == n) break;
    }

    // //
    // cout << cyc << endl;


    k %= cyc;

    cur = 0;
    int kk = 1;
    while(kk < k) {
        int nxt = nxt_id[cur];
        if (nxt <= cur) kk++;
        // //
        // cout << " " << cur << " " << nxt << " " << cyc << endl;
        prv = cur;
        cur = nxt + 1;
    }
    // //
    // cout << cur << endl;


    deque<int> d;
    vector<int> used(mp.size());
    REP(i, cur, n) {
        if(used[mp[a[i]]]) {
            while(d.back() != a[i]) {
                used[mp[d.back()]] = 0;
                d.pop_back();
            }
            d.pop_back();
            used[mp[a[i]]] = 0;
        }
        else {
            d.push_back(a[i]);
            used[mp[a[i]]] = 1;
        }
    }
    rep(i, d.size()) {
        cout << d[i] << (i+1 == d.size() ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 28928
import java.util.Scanner;

public class Main {

	static int[] v={-1,0,1};
	static int N;
	static int[][] a;
	static int[][][] field;
	static int cnt=0;
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		for(;;){
			N=cin.nextInt();
			if(N==0)break;
			if(cnt!=0){
				System.out.println();
			}
			field=new int[5][5][5];
			a=new int[27][2];
			for(int i=0;i<27;i++){
				a[i][0]=a[i][1]=-1;
			}
			for(int i=0;i<5;i++){
				for(int j=0;j<5;j++){
					char[] s=cin.next().toCharArray();
					for(int k=0;k<5;k++){
						field[i][j][k]=s[k]-'0';
					}
				}
			}
			// 居ない時
			int m1=cin.nextInt();
			for(int i=0;i<m1;i++){
				a[i][0]=cin.nextInt();
			}
			// 居る時
			int m2=cin.nextInt();
			for(int i=0;i<m2;i++){
				a[i][1]=cin.nextInt();
			}
			for(int n=0;n<N;n++){
				boolean[][][] change=new boolean[5][5][5];
				for(int i=0;i<5;i++){
					for(int j=0;j<5;j++){
						int sum=0,ind=0;
						for(int k=0;k<5;k++){
							sum=check(i,j,k);
							// inai
							ind=field[i][j][k];
							if(ind==0){
								for(int l=0;l<27;l++){
									if(a[l][ind]==-1)break;
									if(sum==a[l][ind]){
										change[i][j][k]=true;
										break;
									}
								}
							}
							else{
								boolean f=false;
								change[i][j][k]=true;
								for(int l=0;l<27;l++){
									if(a[l][ind]==-1)break;
									if(sum==a[l][ind]){
										change[i][j][k]=false;
										break;
									}
								}
							}
						}
					}
				}
				for(int i=0;i<5;i++){
					for(int j=0;j<5;j++){
						for(int k=0;k<5;k++){
							if(change[i][j][k]){
								field[i][j][k]=1-field[i][j][k];
							}
						}
					}
				}
			}
			output();
		}
	}
	static void output(){
		System.out.println("Case "+(++cnt)+":");
//		System.out.print("Case");
//		System.out.printf("%2d",(++cnt));
//		System.out.println(":");
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++){
				int sum=0,ind=0;
				for(int k=0;k<5;k++){
					System.out.print(field[i][j][k]);
				}
				System.out.println();
			}
			if(i!=4)
				System.out.println();
		}
	}
	static int check(int x,int y,int z){
		int re=0;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<3;k++){
					if(i==1&&j==1&&k==1)continue;
					int xx=x+v[i];
					int yy=y+v[j];
					int zz=z+v[k];
					if(xx<0||yy<0||zz<0||xx>=5||yy>=5||zz>=5){
						continue;
					}
					re+=field[xx][yy][zz];
				}
			}
		}
		return re;
	}
}

Measured memory_bytes: 32880
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)
vector<pair<int, int>> A;

int main() {
    int N;
    cin >> N;
    A.resize(N);
    REP(i, 0, N){//firstが〆切までの時間, secondが必要な時間
        cin >> A[i].second >> A[i].first; 
    }
    sort(A.begin(), A.end());
    long sum = 0;
    REP(i, 0, N){
        sum += A[i].second; 
        if(sum > A[i].first){
            cout<< "No" <<endl;
            return 0;
        }
    }
    cout<< "Yes" <<endl;
    return 0;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    if (s[0] == s[n - 1]) {
        if (n & 1) {
            cout << "Second";
        } else {
            cout << "First";
        }
    } else {
        if (n & 1) {
            cout << "First";
        } else {
            cout << "Second";
        }
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n;
  while(cin >> n ,n){
    vector<P> mas;
    mas.clear();
    for(int i=1;i<=n;i++){
      int c; cin >> c;
      int back = mas.size() - 1;
      if(i % 2 == 1){
	if(mas.empty() || c != mas[back].first) mas.push_back(P(c,1));
	else mas[back].second++;
      }
      else {
	if(c != mas[back].first){
	  if(back == 0) {
	    mas[back].first = c;
	    mas[back].second++;
	  }
	  else {
	    int cnt = mas[back].second + 1;
	    mas.pop_back(); back--;
	    mas[back].second += cnt;
	  }
	}
	else mas[back].second++;
      }
    }
    int ans = 0;
    for(int i=0;i<mas.size();i++){
      if(mas[i].first == 0){
	ans += mas[i].second;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1192
#include<iostream>
#include<utility>
#include<algorithm>
#define N 100
#define M 50
#define Pair pair<int, int>
#define x first
#define y second

using namespace std;

int n, m;
int data[N][N], data_[4][M][M];
Pair p[4];

void spin(int k){
  for(int i=0; i<m; ++i){
    for(int j=0; j<m; ++j){
      data_[k][m-j-1][i] = data_[k-1][i][j];
    }
  }
}

void top_point(){
  for(int k=0; k<4; ++k){
    for(int i=0; i<m; ++i){
      if(data_[k][0][i] != -1){
	p[k].x=0; p[k].y=i; break;
      }
    }
  }
}

bool check(int u, int v, int k, int i, int j){
  if(data_[k][i][j] == -1) return true;
  return data[u][v] == data_[k][i][j];
}

bool solve2(int u, int v, int k){
  for(int i=0; i<m; ++i){
    for(int j=0; j<m; ++j){
      if(!check(u+i, v+j, k, i, j)) return false;
    }
  }
  return true;
}

bool solve(Pair* pair){
  for(int u=0; u<=n-m; ++u){
    for(int v=0; v<=n-m; ++v){
      for(int k=0; k<4; ++k){
	if(solve2(u, v, k)){
	  pair->x = u + p[k].x;
	  pair->y = v + p[k].y;
	  return true;
	}
      }
    }
  }
  return false;
}

int main(){
  while(1){
    cin >> n >> m;
    if(!n && !m) break;
    for(int i=0; i<n; ++i){
      for(int j=0; j<n; ++j){
	cin >> data[i][j];
      }
    }
    for(int i=0; i<m; ++i){
      for(int j=0; j<m; ++j){
	cin >> data_[0][i][j];
      }
    }
    spin(1);
    spin(2);
    spin(3);
    top_point();
    Pair pair;
    if(solve(&pair)) cout << pair.y+1 << " " << pair.x+1 << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
  
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int s = a * b;
        int l = 2 * (a + b);
        
        System.out.println(s + " " + l);
    }

}


Measured memory_bytes: 26416
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] k = new int[n];
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            k[i] = Integer.parseInt(sc.next());
            int[] a = new int[k[i]];
            for (int j = 0; j < k[i]; j++) {
                a[j] = Integer.parseInt(sc.next());
            }
            list.add(a);
        }

        // 主処理
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int[] target = list.get(i);
            for (int j = 0; j < k[i]; j++) {
                if (map.containsKey(target[j])) {
                    map.put(target[j], map.get(target[j]) + 1);
                } else {
                    map.put(target[j], 1);
                }
            }
        }

        int result = 0;
        for (int i = 1; i <= m; i++) {
            if (map.containsKey(i) && map.get(i) == n) {
                result++;
            }
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 21588
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


N = int(input())
count = [0] * N
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            m = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if m > N:
                continue
            count[m - 1] += 1

print('\n'.join(map(str, count)))

Measured memory_bytes: 9356
N,M = list(map(int, input().split(' ')))


bridge=[]

for i in range(M):
    C = list(map(int,input().split(' ')))
    bridge.append(C)

#print(bridge)

bridge.sort(key=lambda x:x[0])
bridge.sort(key=lambda x:x[1])

#print(bridge)

temp = 0
ans = 0

for i in range(M):
    if(temp<=bridge[i][0]):
        temp = bridge[i][1]
        ans+=1

print(ans)
    

Measured memory_bytes: 31080
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int x;
	cin>>x;
	if(x>=30){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
int main(){
  int N,min,max;
  std::cin >> N >> min >> max;
  
  
  auto sumdigit = [](int n){
    int sum=0;
  	int digits = std::log10(n)+ 1;
    for(int i=0;i<digits;++i){
      auto d = (int)std::pow(10,i);
      sum += (n / d ) % 10;
    }
    
    return sum;
  };
  
  int sum = 0;
  for(int i=1;i<=N;++i){
    auto n = sumdigit(i);
    if(n >= min && n<=max){
      sum += i;
    }
  }
  std::cout << sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
int main()
{
	int m,n,i,j,t,k,s1,s2;
	cin>>n>>m;
	if(n==0||n==1) s1=0;
	else {
		s1=n*(n-1)/2;
	} 
	if(m==0||m==1) s2=0;
	else {
		s2=m*(m-1)/2;
	} 
	cout<<s1+s2;
 } 

Measured memory_bytes: 888
#include<iostream>
#include<cstring>

using namespace std  ;


int main()

{
    string str ;

    getline(cin, str) ;

    if(str=="Sunny")
    {
        cout<<"Cloudy"<<endl ;
    }

    else if(str=="Cloudy")
    {
        cout<<"Rainy"<<endl ;
    }

    if(str=="Rainy")
    {
        cout<<"Sunny"<<endl ;
    }

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<string,pair<ll,ll>>p[110];
int main() {
	char s[5];
	cin>>s;
	sort(s,s+4);
	cout<<((s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    deque<int> deq;
    for(int i = 0; i < n; i++)
    {
        int q, x, d;
        cin >> q;
        if(q == 0)
        {
            cin >> d >> x;
            if(d == 0) deq.push_front(x);
            else if(d == 1) deq.push_back(x);
        }
        else if(q == 1)
        {
            cin >> d;
            cout << deq[d] << "\n";
        }
        else if(q == 2)
        {
            cin >> d;
            if(d == 0) deq.pop_front();
            else if(d == 1) deq.pop_back();
        }
    }
    return 0;
}




Measured memory_bytes: 4624
import scala.io.StdIn.{readInt,readLine}

object Main extends App {
  println {
    Iterator.continually(readInt).takeWhile(_!=0).map { n =>
      { for(i<-1 to n) yield {
          val t = readLine.split(" ")
          (t(0),t(1).toInt*3 + t(3).toInt*1)
        }
      }.sortWith( _._2 > _._2).map{ e => e._1 + "," + e._2 }.mkString("\n")
    }.mkString("\n\n")
  }
}

Measured memory_bytes: 43824
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val (T, A) = readLine()!!.split(" ").map { it.toInt() }
    val xs = readLine()!!.split(" ").map { it.toInt() }

    var ans = 0
    var diff = Double.MAX_VALUE
    for ((index, p) in xs.withIndex()) {
        var t = T - p * 0.006
        if (Math.abs(A - t) < diff) {
            diff = Math.abs(A - t)
            ans = index + 1
        }
    }
    println(ans)
}

Measured memory_bytes: 37900
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 100000000
#define MOD 100000007
#define SIZE 100005
#define pi 	3.14159265358979323846

int main(){
	string s,p;
	cin >> s >> p;
	s = s + s;
	//cout << s << endl;
	REP(i,1+(s.size()/2)){
		ll roop = 0;
		while(1){
			//cout << i << ":" <<s[roop+i] << endl;
			if(p[roop]==s[roop+i]){
				//cout << roop << ":" << p.size()/4 << endl;
				if(roop==p.size()-1){
					cout << "Yes" << endl;
					return 0;
				}
				roop++;
			}else{
				break;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3176
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

q = int(input())
mod = 10**6+3
f = {}
f[0] = 1
for i in range(1,mod):
	f[i] = f[i-1] * i % mod

for i in range(q):
	x,d,n = m()
	if d == 0:
		ans = pow(x,n,mod)
	else:
		x = x * pow(d,mod-2,mod)%mod
		if mod <= x + n - 1:
			ans = 0
		else:
			ans = pow(d,n,mod) * f[x+n-1] * pow(f[x-1],mod-2,mod) % mod
	print(ans)

Measured memory_bytes: 129656
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
      
      ll n;cin>>n;
      ll x=n%1000;
      if(x)
      {
        x=1000-x;
      }
      cout<<x;
      
    }    
} 

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  while (true) {
    int n, r;
    cin >> n >> r;
    if (n == 0) return 0;
    vi a(n);
    rep (i, n) {
      a[i] = n - i;
    }
    rep (i, r) {
      int p, c;
      cin >> p >> c;
      p--;
      vi temp;
      for (int j = p; j < p + c; j++) {
        temp.push_back(a[p]);
        a.erase(a.begin() + p);
      }
      temp.insert(temp.end(), a.begin(), a.end());
      a = temp;
    }
    cout << a[0] << endl;
  }
}



Measured memory_bytes: 3056
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0

for i in range(n):
    if a[i] >= b[i]:
        s += b[i]
    else:
        s += a[i]
        b[i] -= a[i]
        if a[i + 1] >= b[i]:
            s += b[i]
            a[i + 1] -= b[i]
        else:
            s += a[i + 1]
            a[i + 1] = 0
print(s)

Measured memory_bytes: 19116
#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 = 1e9;
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;
int a[SZ];
int ans[SZ];

void read() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ++ans[a[i]];
    }
}

void solve() {
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << "\n";
    }
}

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: 6720
import java.util.Scanner;
import java.util.Stack;

public class Main {

	@SuppressWarnings("null")
	public static void main(String[] args) {
		Stack<Integer> que = new Stack<Integer>();
		Scanner scan = new Scanner(System.in);

		String[] stringArray = new String[100];// = new String[];
		char[] c;
		char[] charArray;

		String str = scan.nextLine();
		stringArray = str.split(" ");
		int a = 0;
		int b = 0;
		for (int i = 0; i < stringArray.length; i++) {
			if(stringArray[i] == " "){
				continue;
			}else
				if (stringArray[i].equals("+")) {
					a = que.pop();
					b = que.pop();
					que.add(b + a);
					continue;
				}else
					if (stringArray[i].equals("-")) {
						a = que.pop();
						b = que.pop();
						que.add(b - a);
						continue;
					}else
						if (stringArray[i].equals("*")) {
							a = que.pop();
							b = que.pop();
							que.add(b * a);
							continue;
						}else
							if (stringArray[i].equals("/")) {
								a = que.pop();
								b = que.pop();
								que.add(b / a);
								continue;
							}else
								// 演算子以外はstackに登録する
								que.push(Integer.parseInt(stringArray[i]));
		}
		System.out.println(que.pop());
	}
}



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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;
    if (s[0] == '0') {
        cout << "Impossible\n";
        return 0;
    }
    vector<bool> z(1 << n);
    vector<pair<int, int>> p;
    p.push_back({0, 0});
    for (int j = 1; j < (1 << n); j++) {
        if (z[j]) {
            if (s[j] == '1') {
                cout << "Impossible\n";
                return 0;
            }
            for (int i = 0; i < n; i++) {
                z[j | (1 << i)] = true;
            }
            continue;
        }
        if (s[j] == '0') {
            vector<pair<int, int>> pp;
            for (int i = 0; i < n; i++) {
                if (j & (1 << i)) {
                    if (pp.size() == 0) {
                        for (int x = 0; x <= i; x++) {
                            pp.push_back({x, 0});
                        }
                        pp.push_back({i, 1});
                        pp.push_back({i + 1, 1});
                        for (int x = i + 1; x >= 0; x--) {
                            pp.push_back({x, 0});
                        }
                    } else {
                        vector<pair<int, int>> ppp = pp;
                        for (int x = 1; x <= i; x++) {
                            ppp.push_back({x, 0});
                        }
                        ppp.push_back({i, 1});
                        ppp.push_back({i + 1, 1});
                        for (int x = i + 1; x >= 1; x--) {
                            ppp.push_back({x, 0});
                        }
                        reverse(pp.begin(), pp.end());
                        ppp.insert(ppp.end(), pp.begin(), pp.end());
                        for (int x = 1; x <= i + 1; x++) {
                            ppp.push_back({x, 0});
                        }
                        ppp.push_back({i + 1, 1});
                        ppp.push_back({i, 1});
                        for (int x = i; x >= 0; x--) {
                            ppp.push_back({x, 0});
                        }
                        pp = ppp;
                    }
                }
            }
            p.insert(p.end(), pp.begin() + 1, pp.end());
            for (int i = 0; i < n; i++) {
                z[j | (1 << i)] = true;
            }
        }
    }
    bool ok = false;
    while (!ok) {
        vector<pair<int, int>> pp;
        ok = true;
        for (int i = 0; i < p.size(); i++) {
            if (i > 0 && i < (int)p.size() - 1 && p[i - 1] == p[i + 1]) {
                ok = false;
                i++;
            } else {
                pp.push_back(p[i]);
            }
        }
        p = pp;
    }
    cout << "Possible\n";
    cout << p.size() - 1 << "\n";
    for (auto x : p) {
        cout << x.first << " " << x.second << "\n";
    }

    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[200000], b[200000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i] >> b[i]; }
	
	bool f = true;
	inc(i, n) { f &= (a[i] == b[i]); }
	if(f) { cout << 0 << endl; return 0; }
	
	LL sum = 0, mi = 1e9;
	inc(i, n) {
		sum += a[i];
		if(a[i] > b[i]) { setmin(mi, b[i]); }
	}
	
	cout << sum - mi << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,d,i,j=0,k=0,l=0,x=0,y;
vector<ll>v,vv;
cin>>a;
    v.push_back(0);
    vv.push_back(0);
 for(i=1;i<=a;i++)
    {
    cin>>b;v.push_back(b+v[i-1]);
    }
    
 for(i=1;i<=a;i++)
    {
    cin>>b;vv.push_back(b+vv[i-1]);
    }
   for(i=1;i<=a;i++)
    {
   j=vv[a]-vv[i-1];
   l=j+v[i];
    x=max(l,x);
   }
cout<<x<<endl;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X; cin >> N >>X;
  vector<int> D(N + 1);
  D.at(0) = 0;
  int ans = 0;
  for(int i = 1; i < N + 1; i++){
    int a; cin >> a;
    D.at(i) = D.at(i - 1) + a;
  }
  for(int i = 0; i < N + 1; i++){
    if(D.at(i) <= X)
      ans++;
  }
  cout << ans << endl;
}

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

int main()
{
	int x;
	std::cin >> x;

	if (x < 600) std::cout << 8;
	else if (x < 800) std::cout << 7;
	else if (x < 1000) std::cout << 6;
	else if (x < 1200) std::cout << 5;
	else if (x < 1400) std::cout << 4;
	else if (x < 1600) std::cout << 3;
	else if (x < 1800) std::cout << 2;
	else if (x < 2000) std::cout << 1;
}

Measured memory_bytes: 3628
x = [[[0 for k in range(10)]for j in range(3)]for i in range(4)]
n = int(input())
for i in range(n):
    [b, f, r, v] = map(int, input().split())
    x[b-1][f-1][r-1] += v

for b in range(4):
    for f in range(3):
        tmp = list(map(str, x[b][f]))
        print(" "+" ".join(tmp))
    if b!=3:
        print("#"*20)

Measured memory_bytes: 7736
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

const long long MOD = (long long)1e9 + 7;

long long mod_pow(long long x_, long long y_){
    if(y_ == 0) return 1;
    long long res = mod_pow(x_ * x_ % MOD, y_ / 2);
    if(y_ & 1) res =  x_ * res % MOD;
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<ll> p(65);
    for(int i = 0; i < 60; i++){
        ll x = 0, y = 0;
        for(int j = 0; j < n; j++){
            if(((a[j] >> i) & 1) == 1){
                x++;
            }else{
                y++;
            }
        }
        p[i] = x * y;
    }
    unsigned long long ans = 0;
    ll q = 0, cnt = 0;
    while(q > 0LL || cnt < 61){
        if(cnt < 61){
            q = p[cnt];
            p[cnt + 1] += (q / 2);
        }
        ans += mod_pow(2, cnt) * (q % 2);
        q /= 2;
        ans %= MOD;
        cnt++;
    }
    cout << ans << endl;
    return 0;
}


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

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

    for(int i = 0; i < n-1; i++){
        if(h[i] > h[i+1]){
            break;
        }
        if(i == n-2){
            cout << "Yes" << endl;
            return 0;
        }
    }

    for(int i = 0; i < n-2; i++){
        if(h[i] < h[i+1]){
            h[i+1]--;
        }
        if(h[i] > h[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }
    if(h[n-2] <= h[n-1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
from sys import stdin

def main():
  input = stdin.readline
  H, W, M = map(int, input().split())
  B = set()
  Hc = {}
  Wc = {}
  for _ in range(M):
    h, w = map(int, input().split())
    B.add((h, w))
    if h not in Hc:
      Hc[h] = 0
    if w not in Wc:
      Wc[w] = 0
    Hc[h] += 1
    Wc[w] += 1
  Hm = max(Hc.values())
  Wm = max(Wc.values())
  Hp = [h for h, c in Hc.items() if c == Hm]
  Wp = [w for w, c in Wc.items() if c == Wm]
  #print(Hm, Wm, Hc, Wc)
  if len(B) < len(Hp) * len(Wp):
    print(Hm + Wm)
    exit()
  else:
    for h in Hp:
      for w in Wp:
        if (h, w) not in B:
          print(Hm + Wm)
          exit()
  #print('aaa')
  print(Hm + Wm - 1)
    
      
  
    
main()

Measured memory_bytes: 179480
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  double T,X;
  cin>>T>>X;
  cout<<T/X<<endl;
  return 0;
}


Measured memory_bytes: 256
m,f,r = [],[],[]
grade = []
while True:
	a,b,c = map(int,input().split())
	if a == -1 and b == -1 and c == -1:
		break
	else:
		m.append(a)
		f.append(b)
		r.append(c)
for i in range(len(m)):
	if m[i] == -1 or f[i] == -1:
		grade.append("F")
	elif m[i] + f[i] >= 80:
		grade.append("A")
	elif m[i] + f[i] >= 65:
		grade.append("B")
	elif m[i] + f[i] >= 50 or r[i] >= 50:
		grade.append("C")
	elif m[i] + f[i] >= 30:
		grade.append("D")
	else:
		grade.append("F")
for k in grade:
	print(k)


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

int d[5005];

void run_case() {
    int k, q;
    cin >> k >> q;
    for(int i = 0; i < k; ++i) cin >> d[i];
    while(q--) {
        int n, x, m;
        cin >> n >> x >> m;
        x %= m;
        LL sum = 0, zero = 0;
        for(int i = 0; i < k; ++i) {
            sum += (d[i] % m);
            zero += (d[i] % m == 0);
        }
        LL large = 1LL*((n-1)/k)*sum;
        zero = zero*((n-1)/k);
        for(int i = 0; i <= n-2-((n-1)/k)*k; ++i) {
            large += (d[i] % m);
            zero += (d[i] % m == 0);
        }
        cout << n-1-(large+x)/m-zero << "\n";
    }

}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 384