akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long max(long long a, long long b)
{
    return (a>b)?a:b;
}
int main()
{
    long long ans=0,n,m,s,c;
    cin>>n>>m;
    
    s=n,c=m;
    
    if(c>2*s)
    {
        c-=2*s;
        ans+=s;
        s=0;
    }
    else{
        s-=c/2;
         ans+=c/2;
        c=c%2;
       
    }
    if(c!=0)ans+=c/4;
    cout<<max(ans,m/4)<<endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]


for i in range(n-m+1):
    for j in range(n-m+1):
        aa = a[i:i + m]
        for k in range(m):
            aa[k] = aa[k][j:j+m]
        if aa == b:
            print('Yes')
            exit()

print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    if (X / D >= K) {
        cout << X - K * D << "\n";
        return 0;
    }
    ll t = X / D;
    if ((K - t) % 2 == 0) {
        cout << X - D * t << "\n";
    } else {
        cout << (t + 1) * D - X << "\n";
    }

    
    return 0;
}

Measured memory_bytes: 3584
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    if(N%2==0) cout << 0.5 << nn;
    else cout << setprecision(7) << (double)(N/2+1)/(double)N << nn;
    return 0;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int a,b ;
    cin >> a >> b;
    cout << (a+b)%24 << endl;

    return 0;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;

int main() {
	double th1, th2, ans;
	cin >> th1 >> th2;
	if (abs(th1 - th2) < 180) {
		ans = (th1 + th2) / 2;
	}
	else {
		ans = (th1 + th2 - 360) / 2;
		if (ans < 0) ans += 360;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3292
solve :: [(Char, Char)] -> Char
solve = foldl f 'A'
  where f c (a, b) | a == c    = b
                   | b == c    = a
                   | otherwise = c

main :: IO ()
main = getContents >>= putStrLn . return . solve . input
  where input = map tup . lines
        tup (a:',':b:_) = (a, b)

Measured memory_bytes: 3504
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const char* dir_s = "RLUD";
int dir(char c) {
  return strchr(dir_s, c) - dir_s;
}

int vxs[] = { 1, -1, 0, 0 },
    vys[] = { 0, 0, 1, -1 };

struct Point {
  i64 x, y, vx, vy;
};

bool cmp_xmin(Point p, Point q) { return p.x < q.x; }
bool cmp_xmax(Point p, Point q) { return p.x > q.x; }
bool cmp_ymin(Point p, Point q) { return p.y < q.y; }
bool cmp_ymax(Point p, Point q) { return p.y > q.y; }

const i64 inf = 1ll << 62;
i64 n;
vector<Point> p_all[4], ps;

int main() {
  cin >> n;
  for (i64 i = 0; i < n; ++i) {
    i64 x, y;
    char d;
    cin >> x >> y >> d;
    i64 di = dir(d);
    p_all[di].push_back({ 2 * x, 2 * y, vxs[di], vys[di] }); 
  }

  decltype(cmp_xmin)* cmps[] = {
    cmp_xmin,
    cmp_xmax,
    cmp_ymin,
    cmp_ymax,
  };
  
  for (i64 d = 0; d < 4; ++d) {
    if (p_all[d].empty()) continue;
    for (i64 k = 0; k < 4; ++k) {
      Point p = p_all[d][0];
      for (size_t i = 1; i < p_all[d].size(); ++i) {
        if (cmps[k](p, p_all[d][i])) p = p_all[d][i];
      }
      ps.push_back(p);
    }
  }

  vector<i64> ts(1, 0);
  for (size_t i = 0; i < ps.size(); ++i) {
    for (size_t j = i + 1; j < ps.size(); ++j) {
      auto p = ps[i], q = ps[j];
      i64 t = 0;
      if (p.vx != q.vx) {
        t = (q.x - p.x) / (p.vx - q.vx);
        if (t >= 0) ts.push_back(t);
      }
      if (p.vy != q.vy) {
        t = (q.y - p.y) / (p.vy - q.vy);
        if (t >= 0) ts.push_back(t);
      }
    }
  }

  i64 ans2 = inf;
  for (i64 t : ts) {
    i64 xmin = inf, xmax = -inf, ymin = inf, ymax = -inf;
    for (auto p : ps) {
      i64 tx = p.x + p.vx * t, ty = p.y + p.vy * t;
      xmin = min(xmin, tx);
      xmax = max(xmax, tx);
      ymin = min(ymin, ty);
      ymax = max(ymax, ty);
    }
    ans2 = min(ans2, (xmax - xmin) * (ymax - ymin));
  }

  printf("%.2lf\n", (double)ans2 / 4);
  return 0;
}


Measured memory_bytes: 3716
# 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K, Q = MAP()
    A = [INT() for i in range(Q)]
    point = [K - Q for i in range(N)]
    for a in A:
        point[a-1] += 1
    ans = []
    for i in range(N):
        if point[i] > 0:
            ans.append("Yes")
        else:
            ans.append("No")
    print(*ans)

if __name__ == "__main__":
    main()




Measured memory_bytes: 16272
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int N = 3009;
double dp[N][N];
int n;
double memo[N][N];
double solve(double a[],int i,int req){
	if(req<=0)
		return 1;
	if(i==n and req>0)
		return 0;
	// if(i==n)
	if(memo[i][req] != -1)
		return memo[i][req];
		// return 0; 
	dp[i][req] = a[i]*solve(a,i+1,req-1) + (1-a[i])*(solve(a,i+1,req));
	memo[i][req] = dp[i][req];
	return dp[i][req];

}

int32_t main()
{	
	Fast_IO
	
	memset(memo,-1,sizeof(memo));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			memo[i][j] = -1;
		}
	}
	// cerr<<memo[0][3];
	cin>>n;
	double a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int req = (n+1)/2;	
	cout<<fixed<<setprecision(9)<<solve(a,0,req);
}

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

int main(){
    int s;
    int h,m;
    cin >> s;
    m = s/60;
    h = m/60;
    m = m%60;
    s = s%60;
    cout << h << ":" << m << ":" << s << endl; 
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<int,int>;

int main(){
   int x;
   cin >> x;
   auto ans = 1;
   for (int i = 2; i*i<= x; i++)
   {  
      int p = 0;
      if(x<=3){
         break;
      }

      int j = i;
      while(j<=x){
         p++;
         j*=i;
      }
      
      ans = max(ans,j/i);
   }
   
   cout << ans;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    int sum = 0;
    rep(i,n) sum += s[i];

    VVI dp(n+1, VI(sum+1, -1));
    dp[0][0] = 1;
    rep(i,n){
        rep(j, sum+1){
            if (dp[i][j] == -1) continue;
            chmax(dp[i+1][j], dp[i][j]);
            if (j + s[i] <= sum){
                dp[i+1][j+s[i]] = 1;
            }
        }
    }
    int ans = 0;
    rep(i, sum+1){
        if (dp[n][i] == 1 && i % 10 != 0) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7212
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

#define double long double
#define int long long
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << '\n';
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; };
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; };

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}

const int N = 101;
int a[N];

signed main() {
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 0; i < m; i++) {
		if (sum > a[i] * 4 * m) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class CBase2Number {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n;
    cin >> n;
    vector<short> ans;

    while (n != 1 and n != 0){
        ans.emplace_back(abs(n % 2));
        n = (n - abs(n % 2)) / -2;
    }
    if (n == 1)
        ans.emplace_back(1);

    for (auto itr = ans.rbegin(); itr != ans.rend(); itr++)
        cout << *itr;

    if (ans.size() == 0)
        cout << 0;
    cout << endl;
}
};

int main() {
	CBase2Number solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
require 'pp'

n = gets.chomp!.to_i

def f(n)
    if n == 1 || n == 0
        1
    else
        n * f(n-2)
    end
end

if n % 2 != 0
    puts 0
    exit 0
end

count = 0

# 10 の倍数の数
tmp = 5
while n >= tmp
    count += (n / tmp) /2
    tmp *= 5
end

puts count




Measured memory_bytes: 2172
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, m =f()
    con = [0] * n
    for i in range(m):
        x, y = f()
        con[x-1] += 1
        con[y-1] += 1

    for i in range(n):
        print(con[i])

solve()


Measured memory_bytes: 2940
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	int negC=0;ll sum = 0;int mi = INT_MAX;
	while(n--) {
		int val;
		cin>>val;
		if(val<0)negC++;
		mi = min(mi,abs(val));
		sum+=abs(val);
	}
	if(negC&1)sum-=2*mi;
	cout<<sum;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3660
/*
  C - Sugar Water
  http://arc083.contest.atcoder.jp/tasks/arc083_a
*/

int main(int argc, char const *argv[]) {

  int A,B,C,D,E,F;
  int a,b,c,d;
  int suger,water,max_suger,max_water;
  double concentration,max_concentration;
  scanf("%d %d %d %d %d %d\n", &A, &B, &C, &D, &E, &F );

  max_suger = 0;
  max_water = 0;
  max_concentration = -1.0;

  for( a=0; 100*A*a<=F; a++ ){
    for( b=0; 100*A*a+100*B*b<=F; b++ ){
      for( c=0; 100*A*a+100*B*b+C*c<=F; c++ ){
        for( d=0; 100*A*a+100*B*b+C*c+D*d<=F; d++ ){
          water = 100*A*a+100*B*b;
          suger = C*c+D*d;
          if( water+suger == 0) break;
          concentration = (double)suger/(double)(water+suger);
          if( concentration <= (double)(E)/(double)(100+E) ){
            if( concentration > max_concentration ){
              max_water = water;
              max_suger = suger;
              max_concentration = concentration;
            }
          }
        }
      }
    }
  }

  printf("%d %d\n", max_suger+max_water, max_suger);
  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e6+5;
const int mod=998244353;
int n,m,inv[N],jc[N],jcn[N],foo,bar;
int C(int n,int m){
	if(n<0||m<0||n<m)return 0;
	return 1ll*jc[n]*jcn[m]%mod*jcn[n-m]%mod;
}
int cal(int n,int m){
	return C(n+m-1,n);
}
int main(){
	scanf("%d%d",&n,&m);inv[1]=jc[0]=jcn[0]=1;
	for(int i=2;i<N;++i)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	for(int i=1;i<N;++i)jc[i]=1ll*jc[i-1]*i%mod,jcn[i]=1ll*jcn[i-1]*inv[i]%mod;
	for(int i=0;i<=m&&i<=n;++i)if(~(m+m+m-i)&1)foo=(foo+1ll*C(n,i)*cal(m+m+m-i>>1,n))%mod;
	for(int i=0;i<m;++i)bar=(bar+cal(i,n-1))%mod;
	printf("%lld\n",(foo+1ll*(mod-n)*bar)%mod);return 0;
}

Measured memory_bytes: 23552
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int K,N;
    cin>>K>>N;
    
    vector<int> ans;
    
    if(K%2){
        rep(i,N) ans.push_back((K+1)/2);
        rep(i,N/2){
            if(ans.back()==1){
                ans.pop_back();
            }else{
                ans.back()--;
                while(ans.size()<N) ans.push_back(K);
            }
        }
    }else{
        ans.push_back(K/2);
        rep(i,N-1) ans.push_back(K);
    }
    
    rep(i,ans.size()){
        if(i)cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;

long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

long long int N, K;
string getans(long long int place, const int from) {
	string st = to_string(place);
	st = st.substr(from, st.size() - from);
	while (st.size() < K) {
		place++;
		st += to_string(place);
	}
	st.resize(K);
	return st;
}

int main() {
	while (1) {
		 cin >> N >> K;
		 if (!N)break;
		 N--;
		int num = 1;
		while (1) {
			if (N < 9*num*powint(10, num-1)) {
				const long long int place = powint(10,num-1)+N / num;
				const int from = N%num;
				string st(getans(place, from));
				cout << st << endl;
				break;
			}
			else {
				N -= 9 * num*powint(10, num - 1);
			}
			num++;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

int h, w;
vector<string> ss;

LL revhash(LL x){
	LL z = 0;
	for(int i = 0; i < w; ++i){
		z |= (x & 31) << ((w - i - 1) * 5);
		x >>= 5;
	}
	return z;
}

void check(const vector<int> &idx){
	vector<LL> v;
	for(cauto s : ss){
		LL z = 0;
		for(int k : idx){
			z = z << 5 | (s[k] - 'a');
		}
		v.push_back(z);
	}

	bool flag = (h % 2 != 0);
	while(!v.empty()){
		LL r1 = v.back();
		v.pop_back();
		LL r2 = revhash(r1);

		auto it = find(ALL(v), r2);
		if(it != v.end()){
			v.erase(it);
		}
		else if(flag && r1 == r2){
			flag = false;
		}
		else{
			return;
		}
	}
	puts("YES");
	throw 0;
}

void dfs(int i, vector<int> &idx, vector<int> rest){
	rest.erase(remove(ALL(rest), -1), rest.end());
	if(rest.empty()){
		check(idx);
	}
	else{
		int a = rest.back();
		rest.pop_back();
		if(idx.size() & 1){
			int &cent = idx[idx.size() / 2];
			if(cent == -1){
				cent = a;
				dfs(i, idx, rest);
				cent = -1;
			}
		}

		idx[i] = a;
		for(int &x : rest){
			int &rt = idx[idx.size() - i - 1];
			int y = x;
			x = -1;
			rt = y;
			dfs(i + 1, idx, rest);
			rt = -1;
			x = y;
		}
		idx[i] = -1;
	}
}

void mainmain(){
	cin >> h >> w;
	ss.resize(h);
	for(int i = 0; i < h; ++i){
		cin >> ss[i];
	}

	vector<int> idx(w, -1);
	vector<int> rest(w);
	iota(ALL(rest), 0);
	dfs(0, idx, rest);
	puts("NO");
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 256
from copy import deepcopy
from collections import deque
h,w = map(int,input().split())
s = [['#']*(w+2) for i in range(h+2)]
for i in range(h):
    x = input()
    for j in range(w):
        s[i+1][j+1] = x[j]
ans = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] != '#':
            maze = deepcopy(s)
            maze[i][j] = 0
            queue = deque([[i,j]])
            while queue:
                x,y = queue.popleft()
                for a,b in([0,-1],[0,1],[1,0],[-1,0]):
                    nh,nw = x+a,y+b
                    if maze[nh][nw] == '.':
                        maze[nh][nw] = maze[x][y] + 1
                        queue.append([nh,nw])
            l = 0
            for x in range(1,h+1):
                for y in range(1,w+1):
                    if maze[x][y] != '#':
                        l = max(l,maze[x][y])
            ans = max(ans,l)
print(ans)

Measured memory_bytes: 9640
import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))

c = np.array([0] * 8)

a //= 400

for i in range(8):
    num = np.sum(a == i)
    c[i] = num
red = np.sum(a >= 8)


mincol = np.sum(c != 0)
maxcol = mincol + red
if mincol == 0:
    mincol = 1

print(mincol, maxcol)



    


Measured memory_bytes: 12508
#include <iostream>
#include<math.h>
#include<vector>
# include<string.h>
#include <queue>
#include <cstdio>
using namespace std;
const int maxn=2010;
const int INF=10000;
typedef long long LL;
int dp[maxn][maxn];
LL way[maxn][maxn];
int n;
LL k;
char s[maxn];

void dfs(int L,int R){
    if(L>=R) {dp[L][R]=0;way[L][R]=1;return;}
    if(dp[L][R]!=-1){
        return;
    }

    dp[L][R]=INF;way[L][R]=0;
    if(s[L]==s[R]){
        dfs(L+1,R-1);
        dp[L][R]=dp[L+1][R-1];
        way[L][R]+=way[L+1][R-1];return;
    }

    dfs(L+1,R);dp[L][R]=min(dp[L][R],dp[L+1][R]+1);
    dfs(L,R-1);dp[L][R]=min(dp[L][R],dp[L][R-1]+1);


    if(dp[L][R]==dp[L+1][R]+1) way[L][R]+=way[L+1][R];
    if(dp[L][R]==dp[L][R-1]+1) way[L][R]+=way[L][R-1];
    if(way[L][R]>k) way[L][R]=k+1;

    //printf("L:%d R:%d dp:%d way:%d\n",L,R,dp[L][R],way[L][R]);
    return;
}

char ans[maxn<<1];
int ql,qr;

void print(int L,int R,LL k){
    if(L>R){
        return;
    }
    if(L==R) {ans[ql]=s[L];return;}
    if(s[L]==s[R]){
        ans[ql++]=s[L];ans[qr--]=s[R];
        print(L+1,R-1,k);return;
    }

    if(dp[L+1][R]+1==dp[L][R]&&dp[L][R]!=dp[L][R-1]+1){
        ans[qr--]=s[L];ans[ql++]=s[L];print(L+1,R,k);return;
    }
    else if(dp[L][R]==dp[L][R-1]+1&&dp[L+1][R]+1!=dp[L][R]){
        ans[ql++]=s[R];ans[qr--]=s[R];print(L,R-1,k);return;
    }
    else{
        if(s[L]<s[R]){
            if(way[L+1][R]>=k){
                ans[qr--]=s[L];ans[ql++]=s[L];print(L+1,R,k);return;
            }
            else{
                ans[ql++]=s[R];ans[qr--]=s[R];print(L,R-1,k-way[L+1][R]);return;
            }
        }
        else{
            if(way[L][R-1]>=k){
                ans[ql++]=s[R];ans[qr--]=s[R];print(L,R-1,k);return;
            }
            else{
                ans[qr--]=s[L];ans[ql++]=s[L];print(L+1,R,k-way[L][R-1]);return;
            }
        }
    }
}

int main()
{

    //freopen("C.in","r",stdin);
    scanf("%s",s);n=strlen(s);
    scanf("%lld",&k);

    memset(dp,-1,sizeof(dp));
    dfs(0,n-1);

    ql=0;qr=dp[0][n-1]-1+n;
    if(k>way[0][n-1]) {puts("NONE");return 0;}
    print(0,n-1,k);
    ans[dp[0][n-1]+n]='\0';
    puts(ans);
	return 0;
}

Measured memory_bytes: 48440
def main():
    """
    2 <=  N <= 10^3
    2 <= ai <= 10^5

    非負整数 m に対して
    f(m) = (m mod a1) + (m mod a2) + (m mod aN)
    f_max

    mの制約は問題文中には直接記述されていない
    """
    N = int(input())
    *A, = map(int, input().split())

    ans = editorial(N, A)
    print(ans)


def f(N, A):
    """
    直感: 最小公倍数,最大公約数
        最小公倍数のm ならすべてのaで割り切れる
        つまり最小公倍数-1 ならすべてのaについて m mod ai = ai - 1

    m=a_MAX-1, (m mod a_MAX) が最大
    ただし他のa=a_MAX-1 の場合、f(m)は小さくなってしまう
    aiに対して1 <= m <= a_Max-1 をすべて試す: 10^5 * 3 * 10^3 => TLE
    """
    try:
        # py3.5
        from math import gcd
    except:
        from fractions import gcd

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

    m1 = lcm(A[0], A[1])
    for a in A[2:]:
        m1 = lcm(m1, a)

    m = m1 - 1
    ans = sum(m % a for a in A)

    return ans


def editorial(N, A):
    """
    lcm を求めなくても、ai - 1 であることはわかるので
    lcm を計算しなくてよい
    """
    return sum(a - 1 for a in A)


def WA(N, A):
    ans = 0
    m_max = max(A) * 2 - 1
    for m in range(1, m_max):
        mods = [m % a for a in A]
        tmp = sum(mods)
        print(*(mods + [tmp]), sep="\t")
        ans = max(ans, tmp)

    return ans


if __name__ == '__main__':
    main()


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  rep(i,N)  cin >> A.at(i);
  rep(i,N)  cin >> B.at(i);

  vector<vector<int>> dp((1<<N),vector<int>(N,1e9));
  rep(i,N)  dp.at((1<<i)).at(i)=0;
  REP(bit,1,(1<<N)){
    int cnt=0;
    rep(i,N)  if(bit&(1<<i))  cnt++;

    rep(i,N){
      int c;
      if(abs(cnt-1-i)%2==0) c=A.at(i);
      else  c=B.at(i);

      rep(j,N){
        if(bit&(1<<j))  continue;
        int nc;
        if(abs(cnt-j)%2==0) nc=A.at(j);
        else  nc=B.at(j);
        if(c>nc)  continue;

        int calc=0;
        REP(k,j,N)  if(bit&(1<<k))  calc++;
        chmin(dp.at(bit | (1<<j)).at(j),dp.at(bit).at(i) + calc);
      }
    }
  }
  int ans=1e9;
  rep(i,N)  chmin(ans,dp.at((1<<N)-1).at(i));
  if(ans==1e9)  ans=-1;
  cout << ans << endl;

  return 0;
}

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

typedef long long ll;

int main() {
    //freopen("in.txt", "r",stdin);
    int N, K;
    cin>>N>>K;
    const int modulo = 1e9 + 7;

    int M = max(K, N-K);
    vector<vector<ll> > C(N+1, vector<ll>(M+1));

    for (int i=0;i<=N;++i){
        for (int j=0;j<=min(M, i); ++j){

            if (i==j || j==0) C[i][j] = 1;
            else if (j==1) C[i][j] = (ll)i;
            else {
                C[i][j] = C[i-1][j-1] + C[i-1][j];
                C[i][j] %= modulo;
            }
        }
    }

    int B = K, R = N-K;
    for (int i=1;i<=K;++i){
        ll ans = C[B-1][i-1]*C[R+1][i];
        ans %= modulo;
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 31616
#include<cmath>
#include<cstdio>
using namespace std;
#define PI 3.1415926535898
int main(){
	double x = 0,y = 0,dis,ang,angnow = 90;
	for(;;){
		scanf("%lf,%lf",&dis,&ang);
		if(dis == 0 && ang == 0){break;}
		x+=dis*cos(angnow*PI/180);
		y+=dis*sin(angnow*PI/180);
		angnow-=ang;
	}
	x = (int)x/1;
	y = (int)y/1;
	printf("%.0lf\n%.0lf\n",x,y);
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main ()
{
	int n, sum = 0;
	cin >> n;
	int a[n+5], b[n+5], c[n+5];
	for (int i=0; i<n; i++){
		cin >> a[i];
	}
	for (int i=0; i<n; i++){
		cin >> b[i];
	}
	for (int i=0; i<n-1; i++){
		cin >> c[i];
	}
	for (int i=0; i<n; i++){
		sum += b[a[i]-1];
	}
	for (int i=0; i<n-1; i++){
		if (a[i] == a[i+1] - 1){
			sum += c[a[i]-1];
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
from collections import Counter
h, w, n = map(int, input().split())
d = Counter()
for _ in range(n):
    a, b = map(int, input().split())
    for i in range(3):
        for j in range(3):
            if w > b+j-1 > 1 < a+i-1 < h:
                d[(a+i,b+j)] += 1
ans = Counter()
for i in d.values():
    ans[i] += 1
print((h-2)*(w-2) - sum(ans.values()))
for i in range(1,10):
    print(ans[i])

Measured memory_bytes: 166892
#include <string.h>
#include <iostream>
using namespace std;

int main() {
  char A,B,C;
  std::cin>>A>>B>>C;
  if(A!='7' && B!='7' && C!='7'){
        std::cout <<"No"<<endl;
  }
  else{
    std::cout<< "Yes"<<endl;
  }
}
    
  

    
  


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int H, W;
    cin >> H >> W;
    string S[320];
    for(int i = 1; i <= H; i++){
        cin >> S[i];
        S[i] = "a" + S[i];
    }
    vector<int> points[605];
    vector<int> points2[605];
    for(int h = 1; h <= H; h++){
        for(int w = 1; w <= W; w++){
            if(S[h][w] == '#'){
                points[h + w].push_back(h - w);
                points2[h - w + 300].push_back(h + w);
            }
        }
    }
    for(int i = 0; i <= 600; i++){
        sort(points[i].begin(), points[i].end());
        sort(points2[i].begin(), points2[i].end());
    }
    int ans = 0;
    for(int X = 0; X <= 600; X++){
        int number = points[X].size();
        for(int j = 0; j < number; j++){
            for(int k = j + 1; k < number; k++){
                int dY = points[X][k] - points[X][j];
                if(X - dY >= 0){
                    ans += distance(lower_bound(points[X - dY].begin(), points[X - dY].end(), points[X][j]), upper_bound(points[X - dY].begin(), points[X - dY].end(), points[X][k]));
                }
                if(X + dY <= 600){
                    ans += distance(lower_bound(points[X + dY].begin(), points[X + dY].end(), points[X][j]), upper_bound(points[X + dY].begin(), points[X + dY].end(), points[X][k]));
                }
            }
        }
    }
    for(int X = 0; X <= 600; X++){
        int number = points2[X].size();
        for(int j = 0; j < number; j++){
            for(int k = j + 1; k < number; k++){
                int dY = points2[X][k] - points2[X][j];
                if(X - dY >= 0){
                    ans += distance(upper_bound(points2[X - dY].begin(), points2[X - dY].end(), points2[X][j]), lower_bound(points2[X - dY].begin(), points2[X - dY].end(), points2[X][k]));
                }
                if(X + dY <= 600){
                    ans += distance(upper_bound(points2[X + dY].begin(), points2[X + dY].end(), points2[X][j]), lower_bound(points2[X + dY].begin(), points2[X + dY].end(), points2[X][k]));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
# Problem B - Sumo

# input process
S = input()

# initilization
win_num = 0
rest_num = 15 - len(S)

# count process
for s in S:
    if s=='o':
        win_num+=1

if win_num+rest_num>=8:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 38256
N, Y = map(int, input().split())

result = "-1 -1 -1"

for i in range(N+1):
    if result != "-1 -1 -1":
        break
    if i * 10000 > Y:
        break
    for j in range(N-i+1):
        k = N-i-j
        if i * 10000 + j * 5000 + k * 1000 == Y:
            result = "{} {} {}".format(i, j, k)
            break
        elif i * 10000 + j * 5000 + k * 1000 > Y:
            break

print(result)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, w;
    cin >> n >> w;
    vector<int> we(n), v(n);
    for (int i = 0; i < n; ++i) cin >> we[i] >> v[i];
    int sum = 0;
    for (int s: v) sum += s;
    const long long inf = (long long) 1e9 * 100 + 5;
    vector<long long> dp(sum + 1, inf);
    dp[0] = 0;
    for (int i = 0; i < n; ++i)
        for (int s = sum - v[i]; s >= 0; --s)
            dp[s + v[i]] = min(dp[s + v[i]], dp[s] + we[i]);
    int ans = 0;
    for (int i = 0; i <= sum; ++i) if (dp[i] <= w) ans = max(ans, i);
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>

long long s[1010000], a[1001000];

int main()
{
	int n, k; scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	int tot = 0;
	for(int l = 1; l <= n; l++)
	{
		long long sum = 0;
		for(int r = l; r <= n; r++)
		{
			sum += a[r];
			s[++tot] = sum;
		}
	}
	int o = tot;
	for(int j = 40; j >= 0; j--)
	{
		int t = 0;
		for(int i = 1; i <= o; i++)
		{
			if((s[i] >> j) & 1) t++;
		}
		if(t >= k)
		{
			int k = 0;
			for(int i = 1; i <= o; i++)
			{
				if((s[i] >> j) & 1) s[++k] = s[i];
			}
			o = k;
		}
	}
	long long ans = s[1];
	for(int i = 2; i <= k; i++) ans &= s[i];
	printf("%lld\n", ans);
}

Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int N;
vector<int> a;
vector<pair<int,int>> ans;

int main(){
    cin >> N;
    a=vector<int>(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }

    auto minmax=std::minmax_element(a.begin(),a.end());
    int min_i=minmax.first-a.begin();
    int max_i=minmax.second-a.begin();

    if(std::abs(a[min_i]) < std::abs(a[max_i]) ){
        for(int i=0;i<N;i++){
            if(a[i]<0){
                a[i]+=a[max_i];
                ans.push_back(pair<int,int>(max_i+1,i+1));
            }
        }
        for(int i=1;i<N;i++){
            a[i]+=a[i-1];
            ans.push_back(pair<int,int>(i,i+1));
        }
    }
    else{
        for(int i=0;i<N;i++){
            if(a[i]>0){
                a[i]+=a[min_i];
                ans.push_back(pair<int,int>(min_i+1,i+1));
            }
        }
        for(int i=N-2;i>=0;i--){
            a[i]+=a[i+1];
            ans.push_back(pair<int,int>(i+2,i+1));
        }
    }


    cout << ans.size() << endl;
    for(pair<int,int> p : ans){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
     
    public class Main{
          public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                String str = sc.next();
                String[] str2 = str.split("");
                if(str2[0].equals(str2[1]) || str2[1].equals(str2[2]) || str2[2].equals(str2[3])){
                  System.out.println("Bad");
                } else {
                  System.out.println("Good");
                }
          }
    }

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int n,arr[3009];
long long dp[3009][3009];
long long bt(int l,int r){
	if(l == r) return arr[l];
	long long &ret = dp[l][r];
	if(ret != -1000000000000009ll) return ret;
	ret = max(arr[l]-bt(l+1,r),arr[r]-bt(l,r-1));
	return ret;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>arr[i];
	for(int i=0;i<3001;i++){
		for(int j=0;j<3001;j++) dp[i][j] = -1000000000000009ll;
	}
	cout<<bt(0,n-1)<<endl;
}


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

typedef long long ll;

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

    ll n,m,a;
    cin >> n >> m;
    vector<bool> broken(100100,false);
    for(ll i=0;i<m;i++){
        cin >> a;
        broken[a] = true;
    }
    ll dp[100100];
    dp[0] = 1LL;
    for(ll i=1;i<=n;i++) dp[i] = 0LL;
    const ll MOD = 1e9+7;
    for(ll i=1;i<=n;i++){
        if(broken[i]) continue;
        if(i==1) dp[i] = dp[i-1]%MOD;
        else dp[i] = dp[i-1]%MOD + dp[i-2]%MOD;
        dp[i] %= MOD;
    }
    cout << dp[n] << endl;
    return 0;
}

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

typedef long long LL;

LL x;

int main() {
	scanf("%lld", &x);
	for (int i = 1; i <= 4000; i++) {
		LL s = 100;
		for (int j = 0; j < i; j++) s += (LL)(s * 0.01);
		if (s >= x) {
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	int K;
	cin >> K;
	int now=7, ans=1;
	while(ans<=K+10){
		if(now%K==0){
			cout << ans << endl;
			return 0;
		}
		now=(now*10+7)%K;
		++ans;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void){
	int n, k, c, idx;
	char str[200000];

	scanf("%d%d%d%s", &n, &k, &c, str);

	int fwd[n], bck[n];
	for(int i=0, idx = 0; i < n || idx < k; i++) {
		if(str[i] == 'o') {
			fwd[idx++] = i+1;
			i += c;
		}
	}

	for(int i=n-1, idx = 0; i >= 0 || idx < k; i--) {
		if(str[i] == 'o') {
			bck[k-1-idx++] = i+1;
			i -= c;
		}
	}

	for(idx=0; idx < k; idx++) {
		if(fwd[idx] == bck[idx])
			printf("%d\n", fwd[idx]);
	}

	return 0;
}


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

int main() {
  int N,k;
  int x = 1;
  cin >> N >> k;
  
  for (int i = 0; i < N; i++) {
    if(x < k){
      x *= 2;
    }
    else {
      x += k;
    }
  }
  cout << x << endl;

}


Measured memory_bytes: 256
import Data.List
import Data.Function
import Control.Monad
main = do
    (n,m) <- inputPair
    as <- replicateM n inputPair
    cs <- replicateM m inputPair
    sequence .(map print) $  ( as >>= (\x -> return (solve cs x)))

inputPair :: IO (Int,Int)
inputPair = (\[x,y] -> (x,y)).(map read).words <$> getLine

manDist :: (Int ,Int) -> (Int,Int) -> Int
manDist (a,b) (c,d) = abs (a-c) + abs (b -d)

solve :: [(Int,Int)] -> (Int,Int) -> Int
solve xs a=fst $ minimumBy (compare `on` ((manDist a).snd))
                  (zip [1..] xs)

Measured memory_bytes: 1020
using System;
class Mainclass 
{
    static void Main()
    {
        var input = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
        int a = Math.Abs(input[0] - input[1]), b = Math.Abs(input[0]-input[2]);
        Console.WriteLine(a<b?"A":"B");
    }
}

Measured memory_bytes: 27004
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

ll a[200001];
int main(){
	int n; cin>>n;
	int f1=true;
	FOR(i,0,n){
		cin>>a[i];
		if(i)if(a[i]<=a[i-1]) f1=false;
	}
	if(f1){
		co(1);
		return 0;
	}
	int st=1,en=200001;
	while(st+1<en){
		int mid=(st+en)/2;
		bool f=true;
		int k[100]={};
		FOR(i,1,n){
			int t=a[i]-1;
			if(t>=100) continue;
			if(a[i]>a[i-1]){
				continue;
			}
			while(1){
				k[t]++;
				if(k[t]>=mid){
					if(t>0){
						k[t]=0;
						t--;
					}else{
						f=false;
						break;
					}
				}else{
					break;
				}
			}
			FOR(j,a[i],100) k[j]=0;
			if(!f) break;
		}
		if(f) en=mid;
		else st=mid;
	}
	co(st+1);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define COUT cout<<fixed<<setprecision(12)
#define CIN getline(cin,s)
ll MOD=1000000007;

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll p[n+1];
	for(ll i=0;i<n;i++)
	{
		cin>>p[i];
		p[i]--;
	}
	
	ll c[n+1];
	for(ll i=0;i<n;i++)
	cin>>c[i];
	
	ll ans=INT_MIN;
	for(ll i=0;i<n;i++)
	{
		
		ll b[n+2]={0};
		ll j=p[i];
		vector<ll>v;
		v.push_back(0);
		while(b[j]==0)
		{
			v.push_back(c[j]);
			b[j]=1;
			j=p[j];
			
		}
		ll m=v.size()-1;
		
		for(ll j=1;j<=m;j++)
		v[j]=v[j]+v[j-1];
		
		ll val=INT_MIN;
		
		if(k>(m) && v[m]>0)
		{
			ll a=k/(m);
			ll d=k%(m);
			ll x=a*(v[m]);
			ll y=(a-1)*(v[m]);
			ll p=0;
			for(ll j=1;j<=d;j++)
			p=max(v[j],p);
			ll q=0;
			for(ll j=1;j<=m;j++)
			q=max(v[j],q);
			
			x=x+p;
			y=y+q;
			val=max(x,y);
		}
		else if(v[m]<0 && k>m)
		{
			for(ll j=1;j<=m;j++)
			val=max(val,v[j]);
		}
		else if(k<=m)
		{
			for(ll j=1;j<=k;j++)
			val=max(val,v[j]);
		}
		
		ans=max(ans,val);
	}
	cout<<ans;
}
int main()
{
	ll t=1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    vector<ll> sum;
    ll temp = 0;
    REP(i,N) {
        if (A[i] == 0) {
            sum.pb(temp);
            temp = 0;
        }
        else {
            temp += A[i];
        }
    } 
    if (temp != 0) sum.pb(temp);

    ll ans = 0;
    REP(i,sum.size()) {
        ans += sum[i] / 2;
    }

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

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    vector<vector<int>> g(n, vector<int>());
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    int good = 0;
    for (int i = 0; i < n; i++)
    {
        if (g[i].size() > 0)
        {
            bool f = 0;
            for (int j = 0; j != g[i].size(); j++)
            {
                if (h[g[i][j]] >= h[i])
                {
                    f = 1;
                    break;
                }
            }
            if (!f)
                good++;
        }
        else
            good++;
    }
    cout << good << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  int n; cin >> n;
  stack<P<int,int>> st;
  {
    int a=0,b=0;
    int k = 1;
    for(int i = 0; i < 32; ++i){
      int&c = (i%2==0?a:b);
      st.emplace(k,c);
      c += k;
      k*=-2;
    }
  }
  string s;
  bool f = false;
  while(!st.empty()){
    P<int,int> p = st.top();
    st.pop();
    if(p.first > 0){
      if(n > p.second){
	f = true;
	s.push_back('1');
	n -= p.first;
      } else {
	if(f)s.push_back('0');
      }
    } else {
      if(n < p.second){
	f = true;
	s.push_back('1');
	n -= p.first;
      } else {
	if(f)s.push_back('0');
      }
    }
  }
  if(s.empty())s = "0";
  cout << s << endl;
}


Measured memory_bytes: 3616
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = [0] * n
for i,x in enumerate(a):
    res[x-1] = i+1
print(*res)


Measured memory_bytes: 21544
#include<iostream>
#include<vector>
#include<climits>
using namespace std;

int recur(int n,vector<int>op,vector<int>&dp)
{
    if(n==0||dp[n]!=-1)
    {
        return dp[n];
    }
    else
    {
        int min=INT_MAX;
        for(int i=0;i<op.size();i++){
            if(op[i]<=n){
                int result=recur(n-op[i],op,dp)+1;
                if(min>result){
                    min=result;
                }
            }
        }
        dp[n]=min;
        return dp[n];
    }
}


int main(){
    int n;
    cin>>n;
    vector<int>op;
    vector<int>dp(n+1,-1);
    dp[0]=0;
    op.push_back(1);
    int element=6;
    while(element<=n)
    {
        op.push_back(element);
        element*=6;
    }
    element=9;
    while(element<=n)
    {
        op.push_back(element);
        element*=9;
    }
    recur(n,op,dp);
    cout<<dp[n];
}

Measured memory_bytes: 22260