akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    vvc masu(H,vc(W));
    int countb=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> masu[i][j];
            if(masu[i][j]=='#') countb++;
        }
    }
    //cout << countb << endl;
    int ans=0;
    for(int i=0;i<(1<<H);i++){
        int count=countb;
        vvc tmasu=masu;
        for(int j=0;j<H;j++){
            if(i>>j&1){
                for(int k=0;k<W;k++){
                    if(tmasu[j][k]=='#') count--;
                    tmasu[j][k]='r';
                }
            }
        }
        for(int j=0;j<(1<<W);j++){
            int count2=count;
            //cout << count2 << endl;
            vvc tmasu2=tmasu;
            for(int k=0;k<W;k++){
                if(j>>k&1){
                    for(int l=0;l<H;l++){
                        if(tmasu2[l][k]=='#') count2--;
                    }
                }
            }
            //cout << count2 << endl;
            //cout << endl;
            if(count2==K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n,d,x;
	cin >> n;cin >> d >>x;
	int sum=0;
	for (int i=0;i<n;++i) {
		int t;cin >> t;
		sum += 1+(d-1)/t;
	}
	cout << x+sum << endl;  
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a[3],z[10],sum,i,n;
	double p;
	char d;

	while(scanf("%d%c%d%c%d",a,&d,a+1,&d,a+2)!=EOF)
	{
		sum=0;
		n=0;
		for(i=0;i<10;i++)
			z[i]=1;
		for(i=0;i<3;i++)
		{
			sum+=a[i];
			--z[a[i]-1];
		}
		sum-=a[2];
		for(i=0;i<10;i++)
		{
			if(z[i])
			{
				if((sum+i+1)>20)
					n++;
			}
		}
		
		p=(double)n/7.0;
		if(p>0.5)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
using namespace std;
int main(){
  int n,m,p;
  while(cin>>n>>m>>p,n||m||p){
    int s=0,w;
    for(int i=1;i<=n;++i){
      int x; cin >> x;
      s+=100*x;
      if(i==m) w=x;
    }
    s-=s*p/100;
    cout << (w?(s/w):0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
// #733568 Solution for 0017: Caesar Cipher by rabbit_TR
//reason I want to see test case.

#include <iostream>
#include <string>
using namespace std;

int main() {

  string input;

  while(true) {
    if ( cin.eof() ) break;

    getline( cin, input );

    char c;
    for ( int i = 0; i < 26; i++ ) {

      string ans = "";
      for ( int j = 0; j < input.size(); j++ ) {

        c = input[j];
        if ( c >= 'a' && c <= 'z' ) {
          c = 'a' + ( c - 'a' + i )%26 ;
        }
        ans += c;

      }

      if ( ans.find( "the", 0 ) == string::npos && ans.find( "this", 0 ) == string::npos && ans.find( "that", 0 ) == string::npos ) continue;

      cout << ans << endl;

      break;

    }

  }

  return 0;

}

Measured memory_bytes: 3144
//package solution;

import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;

    public static void main(String[] args) throws Exception {
        new Main().run();
    }
    
    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    void run() throws Exception {
        int n = ni(), m = ni();
        HashSet<Integer>[] g = new HashSet[n];
        for(int i=0; i<n; i++) g[i] = new HashSet<>();
        for(int i=0; i<m; i++) {
            int a = ni()-1, b = ni()-1;
            g[a].add(b);
        }
        int[] sorted = topSort(g);
        
        int[] cost = new int[n];
        Arrays.fill(cost, 1);
        for(int i=0; i<n; i++) {
            int cur = sorted[i];
            for(int adj : g[cur]) {
                if(cost[adj] < cost[cur] + 1) cost[adj] = cost[cur] + 1;
            }
        }
        
        int max = 1;
        for(int i=0; i<n; i++) max = Math.max(max, cost[i]);
        pl(max - 1);
    }
    
    int[] topSort(HashSet<Integer>[] g) {
        int n = g.length;
        int[] in = new int[n];
        for(int i=0; i<n; i++) {
            for(int adj : g[i]) in[adj]++;
        }
        Queue<Integer> queue = new LinkedList<>();
        for(int i=0; i<n; i++) if(in[i] == 0) queue.add(i);
        int visited = 0, sorted[] = new int[n];
        while(!queue.isEmpty()) {
            int cur = queue.remove();
            for(int adj : g[cur]) {
                in[adj]--; if(in[adj] == 0) queue.add(adj);
            }
            sorted[visited++] = cur;
            if(visited > n) return null;
        }
        return sorted;
    }
    
    //Reader & Writer
    String nextToken() throws Exception {
        if (stk == null || !stk.hasMoreTokens()) {
            stk = new StringTokenizer(br.readLine(), " ");
        }
        return stk.nextToken();
    }

    String nt() throws Exception {
        return nextToken();
    }

    String ns() throws Exception {
        return br.readLine();
    }

    int ni() throws Exception {
        return Integer.parseInt(nextToken());
    }

    long nl() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nd() throws Exception {
        return Double.parseDouble(nextToken());
    }

    void p(Object o) {
        System.out.print(o);
    }

    void pl(Object o) {
        System.out.println(o);
    }
    
    void selector() {
        Random rd = new Random();
        String[] s = new String[] {"Strings", "Sorting", "Search"
                , "Graph theory", "Greedy", "Dynamic programming"
                , "Constructive algos", "Bit manipulation", "Recursion"};
        pl(s[rd.nextInt(s.length)] + " " + (rd.nextInt(5)+1));
    }
}

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

int ans = 0;
void dfs(string s, string n){
	if(s.size() >= 3 && count(s.begin(), s.end(), '3') && count(s.begin(), s.end(), '7') && count(s.begin(), s.end(), '5'))
		++ans;

	for(auto c : "357"s){
		if((s+c).size() <= 9 && stoi(s + c) <= stoi(n)) dfs(s+c, n);
	}
}

int main(){
	int N; cin >> N;

	dfs(""s, to_string(N));

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
vector<vector<ll>> arr;

ll bfs(ll start, ll goal) {
  vector<ll> dist(2010, -1);
  queue<ll> que;
  que.push(start);  // start
  dist[start] = 0;
  while (!que.empty()) {
    const ll current = que.front();
    que.pop();
    if (current == goal) {
      break;
    }
    for (const auto& next : arr[current]) {
      if (dist[next] == -1) {
        que.push(next);
        dist[next] = dist[current] + 1;
      }
    }
  }
  return dist[goal];
}

int main() {
  // init
  ll N, X, Y;
  cin >> N >> X >> Y;
  // 0-index;
  X--;
  Y--;

  // 距離を計算する
  map<ll, ll> dist;
  for (ll i = 0; i < N - 1; i++) {
    for (ll j = i + 1; j < N; j++) {
      const ll guchoku = j - i;
      const ll start_X = abs(X - i);
      const ll goal_Y = abs(Y - j);
      ll dis = min(guchoku, (start_X+goal_Y + 1));
      dist[dis]++;
    }
  }

  for (ll i = 1; i < N; i++) {
    // 順番に出力。
    try {
      ll count = dist.at(i);
      cout << count << endl;
    } catch (...) {
      cout << 0 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define register rg
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
typedef long long ll;
main() {
	//file("a");
	int maxx=0,a=0,n,ans=0;
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a;
		maxx=max(maxx,a);
		if(a==maxx)
			ans++;
	}
	printf("%lld\n",ans); 
	return 0;
}


Measured memory_bytes: 256
// AOJ 3114 Min Element
// 2020.1.14 bal4u

#include <stdio.h>

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int main()
{
	int i, N, a, mi, ans;
	
	N = in(), mi = 1000000009;
	for (i = 1; i <= N; ++i) {
		a = in();
		if (a < mi) mi = a, ans = i;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 2112
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,1);
  if(input >= 100 && input <= 105 ||
    input >= 200 && input <= 210 ||
     input >= 300 && input <= 315 ||
     input >= 400 && input <= 420 ||
     input >= 500 && input <= 525 ||
     input >= 600 && input <= 630 ||
     input >= 700 && input <= 735 ||
     input >= 800 && input <= 840 ||
     input >= 900 && input <= 945 ||
     input >= 1000 && input <= 1050 ||
    input >= 1100 && input <= 1155 ||
    input >= 1200 && input <= 1260 ||
     input >= 1300 && input <= 1365 ||
     input >= 1400 && input <= 1470 ||
     input >= 1500 && input <= 1575 ||
     input >= 1600 && input <= 1680 ||
     input >= 1700 && input <= 1785 ||
     input >= 1800 && input <= 1890 ||
     input >= 1900 && input <= 1995
    ){
     myout(1);
     }else{
       if(input >= 2000){
     	 myout(1);
     	}else{
         myout(0);  
        }
     }
}
Main(myin());


Measured memory_bytes: 7372
def com(x,y,mod):
    bunb = 1
    buns = 1
    for i in range(y):
        buns = buns * (x-i) % mod
        bunb = bunb * (i+1) % mod
 
    bunb_inv = pow(bunb,mod-2,mod)
    d = (buns * bunb_inv) % mod
    return (buns*pow(bunb,mod-2,mod))%mod

x,y = map(int,input().split())
setcou = 0
katacou = 0
while True:
    if x * 2 == y or y * 2 == x:
        katacou = min(x,y)
        break
    elif x < 3 or y < 3:
        print(0)
        exit()
    elif x >= 3 and y >= 3:
        setcou += 1
        x -= 3
        y -= 3

print(com(setcou*2+katacou,setcou,10**9+7))

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

int main()
{
    string s, before, after;
    cin >> s;

    before = s[0];
    before += s[1];
    after = s[2];
    after += s[3];

    int beforeNum = stoi(before);
    int afterNum = stoi(after);

    bool beforeIsMM, afterIsMM;

    if (1 <= beforeNum && beforeNum <= 12)
        beforeIsMM = true;
    else
        beforeIsMM = false;

    if (1 <= afterNum && afterNum <= 12)
        afterIsMM = true;
    else
        afterIsMM = false;

    if (!beforeIsMM && afterIsMM)
        cout << "YYMM";
    else if (beforeIsMM && !afterIsMM)
        cout << "MMYY";
    else if (beforeIsMM && afterIsMM)
        cout << "AMBIGUOUS";
    else
        cout << "NA";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n;
    double s=0,a;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%lf",&a);
        s+=(1/a);
    }
    printf("%lf\n",1/s);
    return 0;
}


Measured memory_bytes: 128
n, m = gets.chomp.split(' ').map(&:to_i)
arys = gets.chomp.split(' ').map(&:to_i)
sums = arys.inject(:+)
min_base_point = sums / (4*m).to_f

plus_ary = arys.select { |num| num >= min_base_point }.size
puts plus_ary >= m ? 'Yes' : 'No'

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> k;
    vector<ll> a(k);
    for(i = 0; i < k; i++) {
        cin >> a[i];
    }
    ll down = 2, up = 2;
    reverse(a.begin(), a.end());
    for(ll x : a) {
        ll now_d, now_u;
        now_d = down / x;
        if(down % x != 0) {
            now_d++;
        }
        // 現時点のnow_d := 作られたグループの最小
        now_d *= x;
        if(now_d > up) {
            cout << -1 << endl;
            return 0;
        }
        now_u = up/x;
        now_u= (now_u+1)*x-1;
        down = now_d;
        up = now_u;
        //cout << down << " " << up << endl;
    }
    cout << down << " " << up << endl;
    return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
light_sw = []
for _ in range(m):
  k, *sw = map(int, input().split())
  light_sw.append(sw)
p = list(map(int, input().split()))

cnt = 0
for i in range(2 ** n):
  sw = [1 if ((i >> j) & 1) else 0 for j in range(n)]
  
  flg = True
  for k, light in enumerate(light_sw):
    sum_sw = 0
    for ls in light:
      sum_sw += sw[ls-1]
    if sum_sw % 2 != p[k]:
      flg = False
      break
  
  if flg:
    cnt += 1

print(cnt)


Measured memory_bytes: 3064
n, m = map(int, input().split())
solved = {}
penalty = {}
for case in range(m):
    p, s = input().split()
    p = int(p)

    if s=='AC':
        solved[p] = True
    else: ## s is WA
        if p in solved:
            continue ## ignore
        else:
            penalty[p] = penalty.get(p, 0) + 1

total_penalty = 0
for key in solved:
    total_penalty += penalty.get(key, 0)

print(len(solved), total_penalty)


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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define delete

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;
    if (S[S.size() - 1] == 's') cout << S << "es" << endl;
    else cout << S << "s" << endl;
    
    return 0;
}

Measured memory_bytes: 3656
a_list = list(list(map(int, input().split())) for _ in range(3))
# print(a_list)
li = []
n = int(input())
nums = list(int(input()) for _ in range(n))

for i in range(0,3):
    dum = []
    for j in range(0,3):
        if a_list[i][j] in nums:
            dum.append(1)
        else:
            dum.append(0)
    li.append(dum)
ans = 'No'
for i in range(0,3):
    if li[i][0] and li[i][1] and li[i][2]:
        ans = 'Yes'

for i in range(0,3):
    if li[0][i] and li[1][i] and li[2][i]:
        ans = 'Yes'

if li[0][0] and li[1][1] and li[2][2]:
    ans = 'Yes'
    
if li[0][2] and li[1][1] and li[2][0]:
    ans = 'Yes'

# print(li)
    

print(ans)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define sd(t)       scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii         cout << "hii" << endl
#define okay        cout << "okay" << endl
#define hey         cout << "hey" << endl
const int INF = 1e12;
const int MOD = 998244353;
const int mod = 1e9+7;


template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.x << ' ' << v.y; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.x << "=>" << i.y << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("jjj.txt", "w", stdout);
    #endif
} 

inline int mul(int a, int b, int m = mod) { return (a * b) % m; }
inline int add(int a, int b, int m = mod) { return (a + b) % m; }
inline int sub(int a, int b, int m = mod) { return (a - b + m) % m; }

const int N = 2e6+5;

void solve(){
    string s;
    cin >> s;

    int n = s.size();

    if(s[n-1]=='s'){
        s += "es";
    }
    else{
        s += 's';
    }

    cout << s << endl;
}                            

int32_t main(){
    fast();
    int t = 1;
    // cin>> t;
    for(int i=1; i<=t; i++){
        // cout << "Case #" << i << ": ";
        solve();
    }
    starboy1299();
}

Measured memory_bytes: 3848
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){
    while(true){
        int w,d;
        cin >> w >> d;
        if(w == 0) break;
        vector<int> MEMO(21);
        int cnt = 0;
        for(int i=0;i<w;i++){
            int x;
            cin >> x;
            cnt += x;
            MEMO[x]++;
        }
        for(int i=0;i<d;i++){
            int x;
            cin >> x;
            if(MEMO[x] == 0){
                cnt += x;
            }else{
                MEMO[x]--;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m,k,i,j,a,b;
	cin >> n >> m;
	ll arr[n+2];
	a=0;
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
		a+=arr[i];
	}
	b=a/(4*m);
	j=0;
	if(a%(4*m)==0)
	{
		for(i=0;i<n;i++)
		{
			if(arr[i]>=b)
				j++;
		}
	}
	else
	{
		for(i=0;i<n;i++)
		{
			if(arr[i]>b)
				j++;
		}
	}
	if(j>=m)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

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

int find_sum_of_digit(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}


int main(){
    int N,A,B;
    cin >> N >> A >> B;
    int total = 0;
    for(int i = 0; i <= N; ++i){
        int sum = find_sum_of_digit(i);
        if(sum >= A && sum <= B){
            total += i;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char ma[55][55];
  int h,w;
  fill_n(*ma,55*55,'.');
  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>ma[i][j];
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(ma[i][j]=='#')cout<<ma[i][j];
      else{
	int sum=0;
	for(int x=-1;x<=1;x++)
	  for(int y=-1;y<=1;y++)
	    sum+=ma[i+x][j+y]=='#';
	cout<<sum;
      }
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
from collections import deque

def shortestpath(y0, x0):
    step_cnt = [[-1] * (w+2) for _ in range(h+2)]
    step_cnt[y0][x0] = 0
    q.append((y0, x0))
    while q:
        y, x = q.popleft()
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if maze[y_next][x_next] == '.'\
            and step_cnt[y_next][x_next] == -1:
                q.append((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1

    
    return step_cnt[y][x]

h, w = map(int, input().split())
maze = [['#'] * (w+2)]
maze += [['#']+[x for x in input()]+['#'] for _ in range(h)]
maze += [['#'] * (w+2)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = deque()

max_steps = -1
for y0 in range(1, h+1):
    for x0 in range(1, w+1):
        if maze[y0][x0] != '#':
            max_steps = max(max_steps, shortestpath(y0, x0))

print(max_steps)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int n;
int a[114514];
int ans;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	cout << a[n / 2] - a[n / 2 - 1] << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long a = sc.nextLong();
		long b = 0;
		if( a % 2 == 1){
			System.out.println(0);
		}else{
			a = a / 10;
			b += a;
			while(a > 4){
				a = a / 5;
				b += a;
			}
			System.out.println(b);
		}
		
		
		
	}
}

Measured memory_bytes: 35476
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b=scan.nextInt();
	int sa=b-a;
	int s=0;
	for(int i=0;i<=999;i++) {
		s+=i;
		if(i==sa) {
			System.out.println(s-b);
			return;
		}
	}
	scan.close();
}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vi a(n), b(n), diff(n);
    ll sum_a = 0, sum_b = 0;

    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n){
        sum_a += a[i], sum_b += b[i];
        diff[i] = a[i]-b[i];
        if(diff[i] < 0) diff[i] = (1LL<<50);
    }
    sort(all(diff));

    // 総和は変えられないので、元々の準備度が必要な準備度の合計を超えていない場合は達成不可能
    if(sum_a < sum_b){
        cout << -1 << endl;
        return 0;
    }

    // 許される超過量
    ll excess = sum_a - sum_b;
    ll cnt = 0, pos = 0;
    for(; pos<n; pos++){
        if(cnt + diff[pos] > excess) break;
        else cnt += diff[pos];
    }
    cout << n-pos << endl;
}

Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e5+5;
ll mod=1e9+7;
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
vector<int> graph[205];
int color[205];
bool bipartite_jugding(int v, int c){
    color[v] = c;
    for(int i = 0; i < graph[v].size(); ++i){
        if(color[graph[v][i]] == c) return false;
        if(color[graph[v][i]] == 0 && !bipartite_jugding(graph[v][i], -c)){
            return false;
        }
    }
    return true;
}

bool compare(const pair<pair<ll,ll>,pair<ll,ll> >  &a,const pair<pair<ll,ll>,pair<ll,ll> >  &b){
        if(a.fi.fi<b.fi.fi)
            return true;
        if(a.fi.fi==b.fi.fi && a.fi.se<b.fi.se)
            return true;
        if(a.fi.fi==b.fi.fi && a.fi.se==b.fi.se && a.se.fi<b.se.fi)
            return true;
            return false;
        }
long long expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%mod,n/2,mod);
    else                             //n is odd
        return (x*expo((x*x)%mod,(n-1)/2,mod))%mod;

}

void solve(){

}

void input()
{
   /*int n;
   cin>>n;
   set<int> sth[n];
   set<int> stu[n];
   for(int  i=0;i<n;i++)
   {
       int ai;
       cin>>ai;
       for(int  j=0;j<ai;j++)
       {
           int x,y;
           cin>>x>>y;
           if(y==1)
           {
               sth[i].insert(x);
           }
           else
           {
               stu[i].insert(x);
           }
       }
   }
   set<int> honest;
   set<int> unkind;*/
   string s;
   cin>>s;
   int n=s.length();
   int ans=0;
   for(int  i=0;i<=((n-1)/2);i++)
   {
       if(s[i]!=s[n-1-i])
        ans++;

   }
   cout<<ans<<endl;
}

int main(){
boost;
  input();
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    static long mod = (long) (1e9 + 7);

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int b = in.nextInt();
        int ans = Math.max(0, (n-2*b));
        out.println(ans);
        out.close();
    }

    static long[][] powMat(long[][] a, long pow) {
        if (pow == 1) {
            return a;
        } else {
            if (pow % 2 == 0) {
                return powMat(mul(a, a), pow / 2);
            } else {
                return mul(a, powMat(mul(a, a), pow / 2));
            }
        }
    }

    static long[][] mul(long[][] a, long[][] b) {
        int n = a.length;
        long[][] c = new long[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    c[i][k] = (c[i][k] + (a[i][j] * b[j][k]) % mod) % mod;
                }
            }
        }
        return c;
    }

    static class InputReader {
        public BufferedReader reader;
        public 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 double nextDouble() {
            return Double.parseDouble(next());
        }

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

    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
using pii = pair<int, int>;
#define fst first
#define snd second

using Edge  = tuple<int, double>;
using State = tuple<double, int>;

constexpr double inf = 1e20;
constexpr double ub  = 1e6;

int main(void){
    int n, m; cin >> n >> m;

    vector<pii> pos(n);
    for(auto & e : pos) cin >> e.fst >> e.snd;

    vector<vector<Edge>> edge(n);
    double res = 0.0;
    rep(_, m){
        int a, b; cin >> a >> b;
        a--, b--;
        double dist = sqrt(pow(pos[a].snd - pos[b].snd, 2) + pow(pos[a].fst - pos[b].fst, 2));
        res += dist;

        edge[a].push_back(Edge(b, ub - dist));
        edge[b].push_back(Edge(a, ub - dist));
    }

    int start = 0;
    vector<bool> used(n);
    while(1){
        while(start < n and (edge[start].size() == 0 or used[start])) start++;
        if(start == n) break;

        priority_queue<State, vector<State>, greater<State>> q;
        q.push(State(ub, start));

        while(q.size()){
            double d; int v;
            tie(d, v) = q.top(); q.pop();

            if(used[v]) continue;
            used[v] = true;

            res -= (ub - d);

            for(auto & e : edge[v]){
                int nv; double nd;
                tie(nv, nd) = e;

                if(used[nv]) continue;
                q.push(State(nd, nv));
            }
        }
    }

    cout.precision(12);
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5036
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=1e9+7;
const ll maxn=2*1e5+5;
const ll inf=99999999999;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<int> uid(l, r); return uid(rng); }
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.F << ", " << a.S << ")"; }
template <class A> ostream& operator << (ostream& out, const vector<A> &v) { 
out << "["; for (int i=0;i<v.size();i++) { if(i) out << ", "; out << v[i]; } return out << "]"; } 


void solve(){


	ll x,n;
	cin>>x>>n;
	vector<ll> v(n);
	for (int i=0;i<n;i++) cin>>v[i];
	sort(v.begin(), v.end());
	for (int i=0;i<=400;i++){
		ll ans1=x+i;
		ll ans2=x-i;
		if (!(binary_search(v.begin(), v.end(), ans2))){
			cout<<ans2<<endl;
			return;	
		}
		else if (!(binary_search(v.begin(), v.end(), ans1))){
			cout<<ans1<<endl;
			return;
		}
		
	}
	
	
	return;
}

int main(){ 
    
    #ifndef ONLINE_JUDGE
	//	freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
 
	
	//T{ solve(); }
	solve();
	
	
	return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+5;
char ans[maxn];
string s[maxn];
int n,a,b,c;
void dfs(int step,int a,int b,int c)
{
	if(a<0||b<0||c<0)return ;//剪枝
	if(step==n+1){
		cout<<"Yes"<<endl;
		for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
		exit(0);
	} 
	else
	{
		if(s[step]=="AB")
		  {
		  	   ans[step]='A';dfs(step+1,a+1,b-1,c);
		  	   ans[step]='B';dfs(step+1,a-1,b+1,c);
		  }
		else
		  	if(s[step]=="AC")
		  {
		  	   ans[step]='A';dfs(step+1,a+1,b,c-1);
		  	   ans[step]='C';dfs(step+1,a-1,b,c+1);
		  }
		  else
		  { ans[step]='B';dfs(step+1,a,b+1,c-1);
		  	   ans[step]='C';dfs(step+1,a,b-1,c+1);
		  }
	}
}
int main()
{

   cin>>n>>a>>b>>c;
   for(int i=1;i<=n;i++)
     cin>>s[i];
    dfs(1,a,b,c); 
    cout<<"No";

return 0;
}


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

int main() {
  
  char X;
  cin >> X;
  
  if (X >= 'A' && X <= 'Z') {
    cout << "A";
  }
  else if (X >= 'a' && X <= 'z') {
    cout << "a";
  }
  
}

Measured memory_bytes: 3616
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)

def ruiseki_lr(array):
    """左右からの畳み込みをそれぞれ計算する
    left[p]  := 区間[0, p)の畳み込み
    right[p] := 区間[p, n)の畳み込み
    """
    op = lambda a, b: gcd(a, b)
    e = 0

    n = len(array)
    left = [e] * (n + 1)
    right = [e] * (n + 1)

    for i in range(n):
        left[i + 1] = op(left[i], array[i])
    for i in reversed(range(n)):
        right[i] = op(right[i + 1], array[i])

    return left, right



n = int(input())
a = list(map(int, input().split()))

left, right = ruiseki_lr(a)
ans = 0
for i in range(n):
    ans = max(gcd(left[i], right[i + 1]), ans)
print(ans)

Measured memory_bytes: 63984
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main(){
  while(1){
    int n,m; cin >> n >> m; 
    if(n == 0 && m == 0) break;
    vector<vector<int> > friend_list(n+1);
    for(int i=0; i<m; i++){
      int a,b; cin >> a >> b;
      friend_list[a].push_back(b);
      friend_list[b].push_back(a);
    }
    set<int> fri;
    for(int i=0; i<friend_list[1].size(); i++){
      fri.insert( friend_list[1][i] );
    }
    set<int> frifri;
    for(auto f : fri){
      for(int i=0; i<friend_list[f].size(); i++)
	frifri.insert( friend_list[f][i] );
    }
    for(auto f : fri){
      frifri.insert(f);
    }    
    if(frifri.find(1) != frifri.end()) frifri.erase(1);
    cout << frifri.size() << "\n";

    
  }
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define putc putchar
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
using namespace std;

const int L = 128, lim = 62;
int res, len, cnt[lim + 5];

char get(int k) {
	if (k < 26) return 'a' + k;
	else if (k < 52) return 'A' + k - 26;
	else return '0' + k - 52;
}

bool query(vector<char> X, int pos, char ch) {
	X.insert(X.begin() + pos, ch);
	putc('?'), putc(' ');
	rep(i, 0, X.size() - 1) putc(X[i]);
	puts(""), fflush(stdout);
	scanf("%d", &res);
	return res == len - X.size();
}

vector<char> solve(int l, int r) {
	if (l == r) return vector<char>(cnt[l], get(l));
	int mid = (l + r) >> 1;
	vector<char> L = solve(l, mid);
	vector<char> R = solve(mid + 1, r);
	int p = 0;
	rep(i, 0, L.size()) while (p < R.size() && query(L, i, R[p])) L.insert(L.begin() + i, R[p]), i++, p++;
	return L;
}

int main() {
	rep(i, 0, lim - 1) {
		putc('?'), putc(' ');
		rep(j, 0, L - 1) putc(get(i));
		puts(""), fflush(stdout);
		scanf("%d", &res);
		cnt[i] = L - res, len += cnt[i];
	}
	vector<char> X = solve(0, lim - 1);
	putc('!'), putc(' ');
	rep(i, 0, X.size() - 1) putc(X[i]);
	puts("");
	return 0;
}

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

#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define mem(dp,a) memset(dp,a,sizeof dp);
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long

const ll mod=1e9+7;

int main()
{
    int n,w;
    sfi(n)
    sfi(w)

    ll weight[n+1];
    ll value[n+1];

    f(i,1,n+1)
    {
        sfl(weight[i])
        sfl(value[i])
    }

    ll dp[n+1][w+1];

    f(i,0,n+1)
        dp[i][0]=0;
    f(i,0,w+1)
        dp[0][i]=0;

    f(i,1,n+1)
    {
        f(j,1,w+1)
        {
            if(j-weight[i]>=0)
            {
                dp[i][j]=max((dp[i-1][j-weight[i]]+value[i]),(dp[i-1][j]));
            }
            else
                dp[i][j]=(dp[i-1][j]);
        }
    }

    // f(i,0,n+1)
    // {
    //     f(j,0,w+1)
    //         pfls(dp[i][j])
    //     printf("\n");
    // }

    pfln(dp[n][w])

    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define repl(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll x;
    cin >> x;
    ll have = 100;
    ll res = 0;
    while(have < x){
        res ++;
        have = floor(have * 1.01);
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll fib(ll n){
    vll a(n+1);
    a[0] = 1;
    a[1]  = 1;

    REP(i,2,n+1){
        a[i] = a[i-1] + a[i-2];
        a[i] %= mod;
    }

    return a[n-1];
}

int main()
{
    string s;
    cin >> s;
    if(SIZE(s) == 4){
        ll cnt = 0;
        rep(i,4){
            rep(j,4){
                if(s[i] == s[j] && i != j)cnt++;
            }
        }
        if(cnt == 4)cout << "Yes" << endl;
        else cout << "No" << endl;

        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

class alphabet: #Trueなら大文字
    def __init__(self, capitalize):
        self.num = dict() #アルファベットを数字に変換
        self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"\
            ,"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
        if capitalize: 
            for i in range(26): self.abc[i] = self.abc[i].upper()
        for i, a in enumerate(self.abc): self.num[a] = i


def solve():
    input = sys.stdin.readline
    N = int(input())
    AB = alphabet(False)
    Ans = ""
    while N > 0:
        N -= 1
        Ans = AB.abc[N % 26] + Ans
        N //= 26
        
    
    print(Ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9232
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007
#define pi atan(1) * 4

int main()
{
	int h, w;
	cin >> h >> w;
	int cnt[26] = {};
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			char a;
			cin >> a;
			cnt[a - 'a']++;
		}
	}
	int need4 = (w / 2) * (h / 2);
	int need2 = (h / 2) * (w % 2) + (w / 2) * (h % 2);
	int need1 = (w % 2) * (h % 2);
	for(int i = 0; i < 26; i++){
		// cout << i << " " << cnt[i] << endl;
		if(cnt[i] >= 4 && need4 > 0){
			need4--;
			cnt[i] -= 4;
			i--;
		} else if(cnt[i] >= 2 && need2 > 0){
			need2--;
			cnt[i] -= 2;
			i--;
		} else if(cnt[i] > 0 && need1 > 0){
			need1--;
			cnt[i]--;
			i--;
		} else if(cnt[i] > 0){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep0(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int s[m],c[m],ans[n]={1};
	if(n==1) ans[0]=0;
	rep0(i,0,m) {
	    cin>>s[i]>>c[i];
	    if(ans[s[i]-1]==0||ans[s[i]-1]==c[i]) {
	      ans[s[i]-1]=c[i];
	    }
		else if(ans[0]==1&&s[i]==1){
			ans[s[i]-1]=c[i];
		}
		else {
			cout<<"-1";
			re 0;
		}
	}
	if(ans[0]==0&&n>1) {
		cout << "-1";
		re 0;
	}
	rep0(i,0,n) cout<<ans[i];
	re 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i]; A[i]--;
	}

	vector<int> cnt(N);
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		ans += cnt[A[i]]++;
	}
	for (int i = 0; i < N; i++) {
		cout << ans - (cnt[A[i]]-1) << '\n';
	}

	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	ll n, m, k;
	cin >> n >> m >> k;
	int ans = 0;
	vector<VI> grid(n + 1,VI(m + 1));
	rep(i, 1, n + 1) {
		string s;
		cin >> s;
		rep(j, 1, m + 1)grid[i][j] = s[j-1];
	}
	for (int row = 0; row < (1 << n); row++) {
		for (int col = 0; col < (1 << m); col++) {
			VI rows, cols;
			int r = row, c = col;
			int p = 1;
			while (r) {
				if (r & 1)rows.push_back(p);
				r >>= 1;
				p++;
			}
			p = 1;
			while (c) {
				if (c & 1)cols.push_back(p);
				c >>= 1;
				p++;
			}
			vector<VI> copy = grid;
			for (int i = 0; i < rows.size(); i++) {
				for (int j = 1; j <= m; j++)copy[rows[i]][j] = '*';
			}
			for (int i = 0; i < cols.size(); i++) {
				for (int j = 1; j <= n; j++)copy[j][cols[i]] = '*';
			}
			int cnt1 = 0;
			rep(i, 1, n + 1)rep(j, 1, m + 1)if (copy[i][j] == '#')cnt1++;
			if (cnt1 == k)ans++;
		}
	}
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 3640
S = list(raw_input())

if S[0]=='o' and S[1]=='o' and S[2]=='o':
    print '1000'
elif (S[0]=='o' and S[1]=='o') or (S[0]=='o' and S[2]=='o') or(S[1]=='o' and S[2]=='o'):
    print '900'
elif S[0]=='o' or S[1]=='o' or S[2]=='o':
    print '800'
else:
    print '700'


Measured memory_bytes: 2568
n, m = map(int, input().split())
A = {}
for i in range(n):
  a, b = map(int, input().split())
  if not a in A:
    A[a] = b
  else:
    A[a] += b
ans = 0
num = 0
A = sorted(A.items())
for k, v in A:
  if num < m and m <= num+v:
    ans += (m-num)*k
    break
  else:
    ans += v*k
    num += v
print(ans)

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y;
	cin>>x>>y;
	if(x%y==0){
		cout<<-1<<endl;
		return 0;
	}
	for(ll i=x;i<=1e18;i+=x){
		if(i%y!=0){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1000,W_I=10000,S_I=10000;
int n;
struct object{int w,s,v;}obj[N+1];
bool operator<(object x,object y){return y.s-x.w>x.s-y.w;}
int dp[N+1][W_I+S_I+1];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>obj[i].w>>obj[i].s>>obj[i].v;
	sort(obj+1,obj+n+1);
	for(int i=1;i<=n;i++)for(int j=0;j<=W_I+S_I;j++){
		dp[i][j]=dp[i-1][j];
		if(j>=obj[i].w)dp[i][j]=max(dp[i][j],dp[i-1][min(j-obj[i].w,obj[i].s)]+obj[i].v);
	}
	cout<<dp[n][W_I+S_I];
	return 0;
}

Measured memory_bytes: 156544
#include<iostream>
#include<algorithm>
#include<cstdio>
#define int long long
using namespace std;
void wk();
main(){int test=1;//scanf("%d",&test);
while(test--)wk();}
int a[10000050];int n,k;
int jl(int x,int y){
	if(x==1&&y==n)return a[x]+(k-a[y]);
	return a[x]-a[y];
}
void wk(){
	cin>>k>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	int maxx=-1;
	for(int i=1;i<=n;++i){
		maxx=max(maxx,jl(i,((i-2)%n+n)%n+1));
	}cout<<k-maxx<<endl;
}

Measured memory_bytes: 1792
#coding:utf-8

if __name__ == "__main__":
    N, T = map(int, raw_input().split(" "))
    t_list = map(int, raw_input().split(" "))

    total = 0
    for i in range(1, N):
        sub = t_list[i] - t_list[i - 1]

        if sub > T:
            total += T
        else:
            total += sub

    total += T
    print total


Measured memory_bytes: 20036