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

using namespace std;

typedef pair<int, int> P;

int main(){
    int N, K;
    cin >> N >> K;
    P p[100000];
    long s = 0;
    int cnt[100001] = {0};
    long ans = 0;
    for(int i = 0; i < N; i++){
        int t, d;
        cin >> t >> d;
        p[i] = P(d, t);
    }
    sort(p, p+N, greater<P>());
    for(int i = 0; i < K; i++){
        if(cnt[p[i].second] == 0) s++;
        cnt[p[i].second]++;
        ans += p[i].first;
    }
    ans += s*s;
    long ans_m = ans;
    int l = K-1;
    int r = K;
    while(l >= 0 && r <= N-1){
        if(/*2*s+1 >= (p[l].first - p[r].first) && */cnt[p[l].second] >= 2 && cnt[p[r].second] == 0){
            ans += 2*s+1 - (p[l].first - p[r].first);
            cnt[p[l].second]--;
            cnt[p[r].second]++;
            l--;
            r++;
            s++;
        }else if(cnt[p[l].second] <= 1){
            l--;
        }else if(cnt[p[r].second] > 0){
            r++;
        }/*else if(2*s+1 < (p[l].first - p[r].first)){
            //l--;
        }*/
        ans_m = max(ans, ans_m);
    }
    cout << ans_m << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <math.h>
 
#define rep(i, n) for(int i = 0; (int)(i) < n; i++)
 
using namespace std;
 
int main() {
  int n;
  long long ans = 0;
  cin >> n;
  for(int i = 1; i <= n; i++){
    if(i % 3 == 0 || i % 5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 3636
/*
 * atcoder/abc117/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * f(X) = (X xor A_1) + (X xor A_2) + ... + (X xor A_n) の最大値を求めよ（X <= K)
 *
 * Kが最大10^12なので2進数40桁を最大とする.
 * X<=Kより同様に2進数40桁.
 * Xの最大値を無視すれば、A_iの各ビットごとに足していくことにすると、f(X)は以下のように書き換えられる.
 * f(X) = 2^0 * max(num1(A, 1), num0(A, 1)) + 2^1 * max(num1(A, 2), num0(A, 2)) + ... + 2^39 * max(num1(A, 40), num0(A, 40))
 * ここでnum1(A, n), num0(A, n)はそれぞれAの各整数の2進数表現右からn番目のビットに1がいくつ、0がいくつ立っているかを返す関数.
 *
 * 次にX<=Kの制約を考慮する.
 * 上位桁(40)から決定していく.
 * 右からn桁目では、
 * i) それより上位の桁でX<Kが確定している場合) 加算する値は2^(n-1) * max(num1(A, n), num0(A, n))となる.
 * それ以後の桁でも常にX<Kが保証される. （一度ある桁で保証されると最後の桁まで保証が続く.）
 * ii) 上位桁でX<Kが決定しておらずKのn桁目が1である場合)
 *   Xのn桁目には0か1の2つ選択肢がある.
 *   1) 0の場合は2^(n-1) * num1(A, n)が加算され、n-1桁目以降でX<Kが保証される.
 *   2) 1の場合は2^(n-1) * num0(A, n)が加算される（X<Kの保証はない）.
 * iii) 上位桁でX<Kが決定しておらずKのn桁目が0である場合)
 *   Xのn桁目は0. 2^(n-1) * num1(A, n)が加算される(X<Kの保証はない).
 */
ll N, K;
vector<ll> A;

// dp[n][b] := (b := 以前の桁でX < Kの保証があるなら1), (n := n桁目まで確認済み) の状態でのf(x)の最大値
ll dp[45][2];

void solve() {
  cin >> N >> K;
  A.resize(N);
  loop(n,0,N) cin >> A[n];

  loop(n,0,41)loop(l,0,2) dp[n][l] = -1;
  dp[40][0] = 0;

  for (int n=39; n>=0; n--) {
    int num1 = 0;
    for (auto&&a: A) num1 += (a>>n)&1;
    int num0 = N-num1;

    ll D = 1LL<<n;

    // i)
    if (dp[n+1][1] >= 0) {
      chmax(dp[n][1], dp[n+1][1] + D * max(num1, num0));
    }

    if (dp[n+1][0] == -1) continue; // その遷移が存在しない.

    if ((K>>n)&1) {
      // ii)
      chmax(dp[n][1], dp[n+1][0] + D * num1);
      chmax(dp[n][0], dp[n+1][0] + D * num0);
    } else {
      // iii)
      chmax(dp[n][0], dp[n+1][0] + D * num1);
    }
  }

  cout << max(dp[0][0], dp[0][1]) << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll x = 1, sum = 0;
  for(; sum < n; x++) sum = x * (x + 1) / 2;
  vl ans;
  x--;
  for(int i = x; i > 0; i--) {
    if(sum - i >= n)
      sum -= i;
    else
      cout << i << '\n';
  }
}

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

int main(){
  int H,W; cin>>H>>W;
  vector<string> M(H);
  vector<int> yok(H,0);
  vector<int> tat(W,0);
  for(int i=0;i<H;i++){
    cin>>M[i];
    for(int j=0;j<W;j++){
      if(M[i][j]=='#'){
        yok[i]++; tat[j]++;
      }
    }
  }
  for(int i=0;i<H;i++){
    if(yok[i]){
      for(int j=0;j<W;j++){
        if(tat[j])
          cout<<M[i][j];
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    double N; cin >> N;

    for (int i = 1; i <= 50000; ++i) {
        double norm = (double) i * 1.08;
        if ((int) norm == N) {
            cout << i << "\n";
            return 0;
        }
    }

    cout << ":(" << "\n";

    return 0;
}


Measured memory_bytes: 256
"""ABC174E diff: 1158
"""

N,K=map(int,input().split())
A=list(map(int, input().split()))

if K == 0:
    print(max(A))
    exit()

def f(x):
    """
    K回以内のカットで全ての丸太の長さをX以下にできるか？
    X: int
    Return: bool
    """
    cnt = 0
    for a in A:
        if a % x == 0:
            cnt += a//x - 1
        else:
            cnt += a//x
    
    if cnt <= K:
        return True
    else:
        return False

left = 0
right = max(A) + 10

while right - left > 1:
    mid = (left+right) // 2
    if f(mid):
        right = mid
    else:
        left = mid
print(right)

Measured memory_bytes: 104112
/*   -------------------------
    | If you see my code,     |
    | You are ............... |
    |   ^___^        ^- -^    |
     -------------------------
*/
#include<bits/stdc++.h>
#include<iomanip>
typedef long long ll;
typedef unsigned long long ul;
#define to_lower(x)  transform(x.begin(), x.end(), x.begin(), ::tolower)
#define to_upper(x)  transform(x.begin(), x.end(), x.begin(), ::toupper)
#define pi acos(-1)
#define ll long long
#define ull unsigned long long
#define vec vector<ll>
#define f1(i,n) for(i=1;i<n;i++)
#define test   ll ttt;cin>>ttt;while(ttt--)
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define faster2 ios_base::sync_with_stdio(0);
#define en '\n'
#define eps 10e9
ll i,j;
using namespace std;

int main()
{
  ll a,b,c,d,x,y;
  cin>>x>>y>>a>>b;
  ll t1,t2,t3,t4;
  t1=x*a; t2=x*b; t3=y*a; t4=y*b;
  cout<<max({t1,t2,t3,t4})<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    while(1){
        string x;cin>>x;
        if(x=="0")return;
        ll ans=0;
        rep(i,x.size())ans+=x[i]-'0';
        cout<<ans<<endl;
    }
}

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



Measured memory_bytes: 3224
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    vector<int> alt;
    int res = 0, mini = INF, maxi = -1;
    for (int i=0; i<n; i++) {
        if (mini < a.at(i)) {
            int bene = a.at(i) - mini;
            if (bene > maxi) {
                maxi = bene;
                res = 1;
            } else if (bene == maxi) {
                res++;
            }
        } else {
            mini = a.at(i);
        }
    }
    cout << res << "\n";
}

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

    solve();

    return 0;
}


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


int main(){
 int r,g,b,n,cnt;
 cnt=0;
 cin>>r>>g>>b>>n;
 
 for(int x=0;x<=n/r;x++)
  { for (int y=0;y<=n/g;y++)
     {  int z=-1;
         if ((n-x*r-y*g)%b==0 && n-x*r-y*g>=0){cnt++;z=(n-r*x-y*g)/b;} 
       }
 }
 cout<<cnt<<endl;
return 0;
    
}

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

int main() {
  int64_t n,a,b;
  cin >> n >> a >> b;
  int64_t ans = n / (a+b) * a;
  if(n%(a+b) <= a) ans += n%(a+b);
  else ans += a;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;
int main(){
	int n,p;
	cin >>n>>p;
	long long ans=0;
	int one=0;
	int zero=0;
	int bef=0;
	long long zeroall=0;
	long long oneall=0;
	long long before=1;

	for(int i=0;i<n;i++){
		cin >>bef;
		bef%=2;
		if(bef==1){
			one++;
		}else{
		}
	}
	//cout<<one <<endl;

	if(one==0){
		if( p==1){
		cout<<0<<endl;
		}else{
			cout<<(long long)(1LL<<n)<<endl;
		}
	}else{
		cout<<(1LL<<(long long)(n-1))<<endl;
	}
	//cout<<oneall<<endl;

}


Measured memory_bytes: 256
r,g,b = list(map(int,input().split()))
k = int(input())

cntgb = 0
x = g / r
while True:
	if x > 1:
		break
	else:
		x *= 2
		cntgb += 1
cntbg = 0
x = b / g / (2 ** cntgb )
while True:
	if x > 1:
		break
	else:
		x *= 2
		cntbg += 1
if cntbg + cntgb > k:
	print('No')
else:
	print('Yes')

Measured memory_bytes: 61724
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define maxn 100002
using namespace std;
ll n,a,b;
ll s[maxn];
bool judge(ll mid)
{
    ll ans=mid;
    for(int i=0;i<n;i++)
    {
      ll temp=s[i]-b*mid;
        if(temp>0)
        {
           ll ss=temp/(a-b)+(temp%(a-b)==0 ? 0:1);
            ans-=ss;
            if(ans<0)
            return false;
        }
    }
    return true;
}
int main()
{
    scanf("%lld%lld%lld",&n,&a,&b);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&s[i]);
    }
    ll l=0,r=INF,ans=0;
    while(l<=r)
    {
         ll mid=(l+r)>>1;
         if(judge(mid)) ans=mid,r=mid-1;
         else
            l=mid+1;

    }
     printf("%lld\n",ans);

}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int X = scan.nextInt();
        int Y = scan.nextInt();

        int ans = (int)1e9;

    for(int i=0;i<2*(X+Y)+1;i++){
        int ABpizza = i;
        int Apizza = X-(i/2)>0 ? X-(i/2):0;
        int Bpizza = Y-(i/2)>0 ? Y-(i/2):0;
        ans = Math.min(ans,Apizza*A+Bpizza*B+ABpizza*C);
    }
    System.out.println(ans);

    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
ll d[300][300];
ll INF = 300 * 1e9;
int main(){
  int N,M;
  cin >> N >> M;
  ll L;
  cin >> L;

  for(int i = 0;i < 300;i++){
    for(int j = 0;j < 300;j++){
      d[i][j] = i == j ? 0 : INF;
    }
  }

  for(int i = 0;i < M;i++){
    int A,B;
    cin >> A >> B;
    --A,--B;
    ll C;
    cin >> C;
    d[A][B] = C;
    d[B][A] = C;
  }

  for(int i = 0;i < 300;i++){
    for(int j = 0;j < 300;j++){
      for(int k = 0;k < 300;k++){
        d[j][k] = min(d[j][k],d[j][i] + d[i][k]);
      }
    }
  }

  for(int i = 0;i < 300;i++){
    for(int j = 0;j < 300;j++){
      if(i != j)d[i][j] = d[i][j] <= L ?  1 : INF;
    }
  }

  for(int i = 0;i < 300;i++){
    for(int j = 0;j < 300;j++){
      for(int k = 0;k < 300;k++){
        d[j][k] = min(d[j][k],d[j][i] + d[i][k]);
      }
    }
  }

  int Q;
  cin >> Q;
  vector<ll> ans;
  for(int i = 0;i < Q;i++){
    int s,t;
    cin >> s >> t;
    --s,--t;
    if(d[s][t] >= INF)ans.push_back(-1);
    else ans.push_back(d[s][t] - (ll)1);
  }

  for(int i = 0;i < Q;i++)cout << ans[i] << endl;
}


Measured memory_bytes: 2040
n=int(input())
a=[int(input()) for i in range(n)]
b=[0]*n
c=0
ans=0
b[0]=1
while True:
    c=a[c]-1
    ans+=1
    
    if c==1:
        print(ans)
        exit()
    if b[c]==1:
        print(-1)
        exit()
    b[c]=1
print(-1)

Measured memory_bytes: 7852
#include<stdio.h>
#include<string.h>
char s[1005];
int main()
{
    int n;
    while(~scanf("%d",&n)){
        scanf("%s",s);
        int a=0,b=0;
        for(int i=0;i<strlen(s);i++){
            if(s[i]=='R')
                a++;
            else
                b++;
        }
        if(a>b)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2]:
        ans += 1
    if p[i] > p[i+1] > p[i+2]:
        ans += 1
print(ans)






Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var e = new int[101];
            for (int i = N; i >= 2; i--)
            {
                var chk = 2;
                var rem = i;
                while (rem > 1)
                {
                    if (rem % chk == 0)
                    {
                        e[chk]++;
                        rem /= chk;
                    }
                    else
                    {
                        chk++;
                    }
                }
            }
            var sortE = new List<int>[5];
            for (int i = 0; i < 5; i++) sortE[i] = new List<int>();
            for (int i = 0; i < e.Length; i++)
            {
                if (e[i] >= 74) sortE[0].Add(i);
                if (e[i] >= 24) sortE[1].Add(i);
                if (e[i] >= 14) sortE[2].Add(i);
                if (e[i] >= 4) sortE[3].Add(i);
                if (e[i] >= 2) sortE[4].Add(i);
            }
            var ans = sortE[0].Count;
            if (sortE[1].Count > 0 && sortE[4].Count > 1) ans += sortE[1].Count * (sortE[4].Count - 1);
            if (sortE[2].Count > 0 && sortE[3].Count > 1) ans += sortE[2].Count * (sortE[3].Count - 1);
            if (sortE[3].Count > 1 && sortE[4].Count > 2) ans += (int)nCr(sortE[3].Count, 2) * (sortE[4].Count - 2);
            
            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static long Factorial(long num) { if (num == 0) return 1L; return num * Factorial(num - 1); }
        static long nCr(long n, long r) { return Factorial(n) / Factorial(r) / Factorial(n - r); }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

#define int long long

#define F first
#define S second
#define all(x) (x).begin(), (x).end()

using namespace std;

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

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    int d[n] = {0}, h[n];
    for(int i = 0; i < n; i++)
        cin >> h[i];
    for(int i = 1; i < n; i++)
        d[i] = min(d[i-1] + abs(h[i] - h[i-1]), (i > 1 ? d[i-2] + abs(h[i] - h[i-2]) : INT_MAX));
    cout << d[n-1];

    return 0;
}


Measured memory_bytes: 5184
#include <iostream>
#include <string>
#include <algorithm>
#include <deque>
using namespace std;

int main() { 
    string S;
    cin >> S;
    deque<char> dq;
    for (int i = 0; i < S.length(); i++) {
        dq.push_back(S[i]);
    }
    int Q;
    cin >> Q;
    bool rev = false;
    for (int q_i = 0; q_i < Q; q_i++) {
        int T;
        cin >> T;
        if (T == 1) {
            // 遅い
            // reverse(S.begin(),S.end());
            rev = !rev;
        } else if (T == 2){
            int F;
            char C;
            cin >> F >> C;
            if (!rev) {
              if (F == 1) {
                dq.push_front(C);
              } else if (F == 2) {
                dq.push_back(C);
              }
            } else {
              if (F == 1) {
                dq.push_back(C);
              } else if (F == 2) {
                dq.push_front(C);
              }
            }
        }
    }

    string ans = "";
    for (int i = 0; i < dq.size(); i++) {
      if (rev) {
          ans += dq[dq.size()-i-1];
      } else {
          ans += dq[i];
      }
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 1412
#include <stdio.h>

int main(void) {
  long long i, j, n, a, b, be, x, ans = 0;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &be);
  for(i = 1; i < n; ++i) {
    scanf("%lld", &x);
    ans += (x - be) * a < b ? (x - be) * a : b;
    be = x;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
let n = Scanf.scanf " %d" @@ (+) 0
let ws = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let ans = ref max_int
let _ =
  for t = 0 to n - 2 do
    let s1 = Array.sub ws 0 (t + 1) |> Array.fold_left (+) 0 in
    let s2 = Array.sub ws (t + 1) (n - (t + 1)) |> Array.fold_left (+) 0 in
    ans := min !ans @@ abs @@ s1 - s2
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int cnt=0;
    bool ans=true;
    string s;
    cin>>s;
    if(s[0]!='A' || !islower(s[1]) || !islower(s[s.size()-1]))
        ans=false;
    else
    {
        for(int i=2;i<=s.size()-2;i++)
        {
            if(s[i]=='C')
                cnt++;
            else if(!islower(s[i]))
            {
                ans=false;
                break;
            }
        }
        if(cnt!=1)
            ans=false;
    }
    if(ans)
        cout<<"AC"<<endl;
    else
        cout<<"WA"<<endl;
    return 0;
}

Measured memory_bytes: 256
def exist_num(target_str, s):
    for i in range(3):
        c = target_str[i]
        try:
            tar_i = s.index(c)
            s = s[tar_i+1:]
        except:
            return False

    return True

n = int(input())
s = input()

count = 0
for i in range(1000):
    target_str = "%03d" % i
    if exist_num(target_str, s):
        #print(target_str)
        count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)2e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

void output(int d){
	static bool used = false;
	if(used)cout << " ";
	cout << d;
	used = true;
}

vvector<ll> dp(12, vector<ll>(bit(12), -1));

int main(){
	int n, m;
	cin >> n >> m;
	vector<ll> much(m);
	vector<ll> keys(m);
	rep(i, m){
		cin >> much[i];
		int d;
		cin >> d;
		rep(j, d){
			int dd;
			cin >> dd;
			keys[i] |= bit(dd-1);
		}
	}
	much.push_back(0);
	keys.push_back(0);
	++m;

	function<ll(int, int)> func = [&](int place, int bought){
		if(place==n){
			if(bought == (bit(n)-1))return 0ll;
			return INFLL;
		}
		if(dp[place][bought]>=0)return dp[place][bought];
		ll res = INFLL;
		rep(i, m){
			if(((bought|keys[i])&bit(place))==0)continue;
			chmin(res, much[i] + func(place+1, bought | keys[i]));
		}
		return dp[place][bought] = res;
	};
	
	ll ans = func(0, 0);
	if(ans>=INFLL){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 640
/**
 * Created by abhishek on 7/29/2016.
 */
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int north= 0,east = 0,west  = 0,south = 0;
        for(int i = 0;i < str.length();i++){
            if(str.charAt(i) == 'N')north++;
            if(str.charAt(i) == 'W')west++;
            if(str.charAt(i) == 'E')east++;
            if(str.charAt(i) == 'S')south++;
        }
        if(north != 0 && south == 0 || south != 0 && north == 0 || east != 0 && west == 0 || west != 0 && east == 0)
            System.out.print("No");
            else System.out.print("Yes");

    }
}


Measured memory_bytes: 8020
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	ans := 0
	for i := a; i <= b; i++ {
		arr := intToArray(i)
		if isEqualAsRevese(arr) {
			ans++
		}
	}
	fmt.Println(ans)
}

func intToArray(num int) []int {
	arr := make([]int, 0)
	for i := 0; num > 0; i++ {
		arr = append(arr, num%10)
		num /= 10
	}
	return arr
}

func isEqualAsRevese(arr []int) bool {
	reverse_i := len(arr) - 1
	for i, e := range arr {
		if e != arr[reverse_i-i] {
			return false
		}
	}
	return true
}


Measured memory_bytes: 5504
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<Long> list = new ArrayList<>();
        for(int i = 0; i < N; i++) {
            list.add((long)sc.nextInt());
        }
        Collections.sort(list, Collections.reverseOrder());

        int num = 0;
        int pi = 0;
        int mi = N-1;
        List<Long> ansList = new ArrayList<>();

        if(list.get(0) < 0 && K % 2 == 1) {
            for(int i = 0; i < K; i++) {
                ansList.add(list.get(i));
            }
            num = K;
        }
        while(num < K) {
            if(K-num == 1) {
                ansList.add(list.get(pi));
                break;
            }
            if((list.get(pi) * list.get(pi+1) < list.get(mi) * list.get(mi-1)) || (pi+2 < N && K % 2 == 1 && list.get(pi+2) < 0)) {
                ansList.add(list.get(mi));
                ansList.add(list.get(mi-1));
                mi -= 2;
            } else {
                ansList.add(list.get(pi));
                ansList.add(list.get(pi+1));
                pi += 2;
            }
            num += 2;
        }
        int MOD = 1000000007;
        long ans = 1;

        for(Long l : ansList) {
            ans = ans * l % MOD;
        }

        if(ans < 0)
            os.println(ans + MOD);
        else
            os.println(ans);

    }


}

Measured memory_bytes: 58132
N, M = map(int, input().split())

#N人の参加者から、M組選ぶ
#これをNセット実施。
#組合わせの距離が重複しなければ、成立


#参加者を半分に分け、
#前半を距離奇数、後半を距離偶数にする

#参加者を半分に分ける
div_point=int((N/2))
#前半グループを奇数にする
if div_point%2==0:
    div_point-=1
#後半グループは更に半分に分ける
re_point=div_point+int((N-div_point)/2)

#組を作る
i=0 #初期化
while 1<div_point-i*2 and i<re_point and i<M:#前半グループ・・・距離が奇数になるように組み分け
    ent1=i+1 #前半グループ：一人目
    ent2=div_point-i #前半グループ：二人目
    print(str(ent1) + ' ' + str(ent2))
    i+=1
for j in range(M-i):#後半グループ
    ent1=re_point-j #後半グループ：一人目
    ent2=re_point+j+1 #後半グループ：二人目
    print(str(ent1) + ' ' + str(ent2))

Measured memory_bytes: 9220
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string ans = "";
    for(int i = 0; i < 2 * n; i++) {
        if(i % 2 == 0) {
            ans += s[i / 2];
        } else {
            ans += t[i / 2];
        }
    }
    cout << ans << endl;
}


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

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

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

	for(int n, k; cin >> n >> k, n | k;) {
		vector<int> c(n);
		for(int i = 0; i < n; ++i)
			cin >> c[i];

		int current = 0;
		for(int i = 0; i + k - 1 < n; ++i) {
			int ck = 1;
			for(int j = 0; j < k; ++j)
				ck *= c[i + j];

			chmax(current, ck);
		}

		int change = 0;
		for(int i = 0; i < n; ++i) {
			for(int j = i + 1; j < n; ++j) {
				vector<int> tmp(c);
				swap(tmp[i], tmp[j]);
				for(int a = 0; a + k - 1 < n; ++a) {
					int ck = 1;
					for(int b = 0; b < k; ++b)
						ck *= tmp[a + b];

					chmax(change, ck);
				}
			}
		}

		if(current > change)
			cout << "NO GAME" << endl;
		else
			cout << change - current << endl;
	}
	

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 998244353
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = INT_MAX/4;
const int N=2e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int read(){
    int x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}
struct rrr{
	int x,y,z;
}a[N];
int t[N],flg,lst,lstu,lstr,lstd;
int ans=INF,n;
bool cmp1(rrr i,rrr j){
	
	if(i.x==j.x) return i.y<j.y; 
	return i.x<j.x;
}
bool cmp2(rrr i,rrr j){
//	if()
	if(i.y==j.y) return i.x<j.x; 
	return i.y<j.y;
}
bool cmp3(rrr i,rrr j){
	
	if(i.x+i.y==j.x+j.y) return i.x<j.x; 
	return i.x+i.y<j.x+j.y;
}
bool cmp4(rrr i,rrr j){
	
	if(i.x-i.y==j.x-j.y) return i.x<j.x; 
	return i.x-i.y<j.x-j.y;
}

int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif	
	n=read();
	for(int i=1,x,y,z;i<=n;i++){
		char s[10];
		x=read(),y=read();cin>>s;
		if(s[0]=='U') z=1;
		if(s[0]=='D') z=2;
		if(s[0]=='L') z=3;
		if(s[0]=='R') z=4;
//		rrr
		a[i]=rrr{x,y,z};
//		a[x].pb(rrr{x,y,z}),d[y].pb(rrr{x,y,z});
//		c[x+y].pb(rrr{x,y,z}),d[x-y+M].pb(rrr{x,y,z})
//		a[i]=rrr{x,y,z};
		
	}
	sort(a+1,a+n+1,cmp1);
//	sort(a+1,a+n+1,cmp1);
	
	for(int i=1;i<=n;i++){
		if(i==1||a[i].x!=a[i-1].x){
			flg++;
		}
		if(a[i].z==3||a[i].z==4) continue;
		if(a[i].z==1){
			lst=i,t[lst]=flg;
		}
		if(a[i].z==2){
			if(t[lst]!=flg) continue; 
			ans=min(ans,(a[i].y-a[lst].y)*5);
		}
	}
	
	sort(a+1,a+n+1,cmp2);
	for(int i=1;i<=n;i++){
		if(i==1||a[i].y!=a[i-1].y){
			flg++;
		}
		if(a[i].z==1||a[i].z==2) continue;
		if(a[i].z==4){
			lst=i,t[lst]=flg;
		}
		if(a[i].z==3){
			if(t[lst]!=flg) continue; 
			ans=min(ans,(a[i].x-a[lst].x)*5);
		}
	}
	
	sort(a+1,a+n+1,cmp3);
	for(int i=1;i<=n;i++){
		if(i==1||a[i].y+a[i].x!=a[i-1].y+a[i-1].x){
			flg++;
		}
//		if(a[i].z==3||a[i].z==4) continue;
		if(a[i].z==2){
			lstd=i,t[lstd]=flg;
		}
		if(a[i].z==4){
			lstr=i,t[lstr]=flg;
		}
		if(a[i].z==1){
			if(t[lstr]!=flg) continue; 
			ans=min(ans,(a[i].x-a[lstr].x)*10);
		}
		if(a[i].z==3){
			if(t[lstd]!=flg) continue; 
			ans=min(ans,(a[i].x-a[lstd].x)*10);
		}
	}
	
	
	sort(a+1,a+n+1,cmp4);
	for(int i=1;i<=n;i++){
		if(i==1||a[i].y-a[i].x!=a[i-1].y-a[i-1].x){
			flg++;
		}
//		if(a[i].z==3||a[i].z==4) continue;
		if(a[i].z==1){
			lstu=i,t[lstu]=flg;
		}
		if(a[i].z==4){
			lstr=i,t[lstr]=flg;
		}
		if(a[i].z==3){
			if(t[lstu]!=flg) continue; 
			ans=min(ans,(a[i].x-a[lstu].x)*10);
		}
		if(a[i].z==2){
			if(t[lstr]!=flg) continue; 
			ans=min((a[i].x-a[lstr].x)*10,ans);
		}
	}
	if(ans!=INF) cout<<ans<<endl;
	else puts("SAFE");
	return 0;
}


Measured memory_bytes: 6648
//It is made by Awson on 2018.2.2
    #include <bits/stdc++.h>
    #define LL long long
    #define dob complex<double>
    #define Abs(a) ((a) < 0 ? (-(a)) : (a))
    #define Max(a, b) ((a) > (b) ? (a) : (b))
    #define Min(a, b) ((a) < (b) ? (a) : (b))
    #define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
    #define writeln(x) (write(x), putchar('\n'))
    #define lowbit(x) ((x)&(-(x)))
    using namespace std;
    const int N = 100000;
    const int yzd = 1e9+7;
    void read(int &x) {
        char ch; bool flag = 0;
        for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
        for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
        x *= 1-2*flag;
    }
    void print(int x) {if (x > 9) print(x/10); putchar(x%10+48); }
    void write(int x) {if (x < 0) putchar('-'); print(Abs(x)); }
     
    int n, m, s, t, u, v, c;
    struct tt {int to, next, cost; }edge[(N<<2)+5];
    int path[N+5], top;
    int ans1[N+5], ans2[N+5], vis[N+5], in[N+5];
    LL dist1[N+5], dist2[N+5];
    queue<int>Q;
    vector<int>to[N+5];
     
    void add(int u, int v, int c) {
        edge[++top].to = v, edge[top].cost = c, edge[top].next = path[u], path[u] = top;
    }
    void SPFA(int s, LL *dist) {
        dist[s] = 0; Q.push(s); vis[s] = 1;
        while (!Q.empty()) {
    	int u = Q.front(); Q.pop(); vis[u] = 0;
    	for (int i = path[u]; i; i = edge[i].next)
    	    if (dist[edge[i].to] > dist[u]+edge[i].cost) {
    		dist[edge[i].to] = dist[u]+edge[i].cost;
    		if (!vis[edge[i].to]) {
    		    vis[edge[i].to] = 1; Q.push(edge[i].to);
    		}
    	    }
        }
    }
    void topsort(int s, LL *dist, int *ans) {
        for (int u = 1; u <= n; u++) {
    	to[u].clear();
    	for (int i = path[u]; i; i = edge[i].next)
    	    if (dist[edge[i].to] == dist[u]+edge[i].cost) to[u].push_back(edge[i].to), ++in[edge[i].to];
        }
        ans[s] = 1; Q.push(s);
        while (!Q.empty()) {
    	int u = Q.front(), size = to[u].size(); Q.pop();
    	for (int i = 0; i < size; i++) {
    	    if (--in[to[u][i]] == 0) Q.push(to[u][i]); (ans[to[u][i]] += ans[u]) %= yzd;
    	}
        }
    }
    void work() {
        read(n), read(m), read(s), read(t);
        for (int i = 1; i <= m; i++) {
    	read(u), read(v), read(c); add(u, v, c); add(v, u, c);
        }
        memset(dist1, 127/3, sizeof(dist1));
        SPFA(s, dist1); topsort(s, dist1, ans1);
        memset(dist2, 127/3, sizeof(dist2));
        SPFA(t, dist2); topsort(t, dist2, ans2);
        int ans = 1ll*ans1[t]*ans1[t]%yzd;
        for (int u = 1; u <= n; u++) {
    	if (dist1[u] == dist2[u] && dist2[u]*2 == dist1[t]) (ans -= 1ll*ans1[u]*ans1[u]%yzd*ans2[u]%yzd*ans2[u]%yzd) %= yzd;
    	for (int i = path[u]; i; i = edge[i].next)
    	    if (dist1[u]+edge[i].cost+dist2[edge[i].to] == dist1[t] && dist1[u]*2 < dist1[t] && dist2[edge[i].to]*2 < dist1[t])
    		(ans -= 1ll*ans1[u]*ans1[u]%yzd*ans2[edge[i].to]%yzd*ans2[edge[i].to]%yzd) %= yzd;
        }
        writeln((ans+yzd)%yzd);
    }
    int main() {
        work();
        return 0;
    }

Measured memory_bytes: 14208
#include <stdio.h>

int main(void){

    int n, m, x=0, i, a[10000];

    scanf("%d%d", &n, &m);

    for(i=0;i<m;i++){
    scanf("%d", &a[i]);
    x = x + a[i];
    }
    if(x>n)
        printf("-1\n");
    else 
        printf("%d\n", n-x);

    return 0;

}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
#define N 30
using namespace std;
bool exist[N];
string s,e="zyxwvutsrqponmlkjihgfedcba";
int n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    if(s==e){
        cout<<-1;
        return 0;
    }
    n=s.size();
    for(int i=0;i<n;i++)
        exist[s[i]-'a']=true;
    for(int i=0;i<26;i++){
        if(!exist[i]){
            cout<<s<<(char)(i+'a');
            return 0;
        }
    }
    for(int i=n-1;i>=0;i--){
        for(int j=s[i]-'a'+1;j<26;j++){
            if(!exist[j]){
                for(int k=0;k<i;k++)
                    cout<<s[k];
                cout<<(char)(j+'a');
                return 0;
            }
        }
        exist[s[i]-'a']=false;
    }
    return 0;
}


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

int main() {
    int a, b, c , d; cin >> a >> b >> c >> d;
    int ao = (c + b - 1) / b;
    int ta = (a + d - 1) / d;

    cout << (ao <= ta ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fit(x) for(auto it=x.begin();it!=x.end();++it)
#define se second
#define mp make_pair
#define ALP "abcdefghijklmnopqrstuvwxyz"
#define nline cout<<"\n"
#define rep(i,x) for(i=0;i<x;++i)
#define repr(i,a,b) for(i=a;i<=b;++i)
#define mi2 500000004
#define mi3 333333336
#define MOD 1000000007
#define N 1000005
#define pll pair<ll,ll>
#define Vll vector<ll>
#define W(t) while(t--)
#define modsum(a,b,M) (a%M + b%M)%M
#define modsub(a,b,M) (a%M - b%M + M)%M
#define modmul(a,b,M) (a%M * b%M)%M
#define moddiv(a,b,M) (a%M * modinv(b,M)%M)%M
using namespace std;
ll powermod(ll x,ll n,ll M)
{
	ll result=1;
	while(n>0)
	{
	  if(n % 2 ==1)
	    result=(result * x)%M;
	  x=(x*x)%M;
	  n=n/2;
	}
	return result;
}
vector<ll> readll() {
	cin>>ws;
	vector<ll> v;
	string input;
	getline(cin, input);
	cout<<input;
	istringstream is(input);
	ll num;
	while(is>>num) v.pb(num);
	return v;
}
ll modinv(ll n,ll p) {
	return powermod(n,p-2,p);
}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[1000005],invf[1000005];
void facmod(ll n,ll M) {
	ll i;
	fact[0]=fact[1]=1;
	for(i=2;i<=n;++i) {
		fact[i]=((fact[i-1])%M * (i%M))%M;
	}
	invf[n]=modinv(fact[n],M);
	for (i=n-1;i>=0;--i){
		invf[i]=invf[i+1]*(i+1);
		invf[i]%=M;
	}
}
/*****
ll T=0;
ll p[200005], d[200005];
ll tin[200005], tout[200005];
vector<ll> g[200005];

void dfs(ll v, ll par = 1, ll dep = 0) {
	p[v] = par;
	d[v] = dep;
	tin[v] = T++;
	for (auto to : g[v]) {
		if (to == par) continue;
		dfs(to, v, dep + 1);
	}
	tout[v] = T++;
}
****/
void solve() {
	ll n,m,i,sm=0,x=0;
	cin>>n>>m;
	ll a[n+4];
	rep(i,n) {
		cin>>a[i];
		sm+=a[i];
	}
	//sort(a,a+n,greater<ll>());
	rep(i,n) {
		if(a[i]*4*m>=sm) {
			x++;
		}
	}
	if(x>=m) cout<<"Yes";
	else cout<<"No";
}
int main() {
  	fastio;
	ll t=1;
	//cin>>t;
	W(t) {
		solve();
	}
	
  	return 0;
}

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

int main(){
    string s;
    cin>>s;
    bool ok=false;
    for(int i=0;i<s.size();i++){
        if(s[i]=='7')ok=true;
    }
    if(ok)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll x2 = 0;
    rep(i, n) {
        if (i%2) x2 -= a[i];
        else x2 += a[i];
    }
    vector<int> ans(n);
    ans[0] = x2/2;
    rep(i, n-1) {
        ans[i+1] = a[i]-ans[i];
    }
    rep(i, n) ans[i] *= 2;
    rep(i, n) printf("%d%c", ans[i], i==n-1?'\n':' ');
    return 0;
}

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

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

	int arr[n][2];
	int check[m][2];

	for(int i=0;i<n;i++) for(int j=0;j<2;j++) cin>>arr[i][j];
	for(int i=0;i<m;i++) for(int j=0;j<2;j++) cin>>check[i][j];

	for(int i=0;i<n;i++){
		int idx = 1e9;
		int res = INT_MAX;
		for(int j=0;j<m;j++){
		int tmp = abs(arr[i][0]-check[j][0])+abs(arr[i][1]-check[j][1]);
		//cout<<arr[i][0]<<" "<<arr[i][1]<<" "<<check[j][0]<<" "<<check[j][1]<<" "<<tmp<<endl;
			if(tmp<res){
				idx = j;
				res = tmp;
			}
		}
		cout<<idx+1<<"\n";
	}
}

Measured memory_bytes: 256
/*
D棰橈細
缁欏畾n鍒楃殑鏂瑰潡
绗琲鍒楅珮搴i
鐜板湪瑕佹妸瀹冩煋鎴愮孩钃濅袱鑹?
瑕佹眰婊¤冻锛?
瀵逛簬浠绘剰涓€涓?*2鐨勫尯鍩燂紝鎭版湁2涓摑鑹诧紝2涓孩鑹?
闂柟妗堟暟
n<=100,h<=10^9
*/
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int maxn = 105;
const int MOD = 1000000007;
int bin[maxn], h[maxn], f[maxn][3];
int n, mx, res, base = 1;

inline int power(int x, int p) {
	int res = 1;
	while (p) {
		if (p & 1) res = 1LL * res * x % MOD;
		x = 1LL * x * x % MOD; p >>= 1;
	}
	return res;
}

pii solve(int l, int r, int base) {
	// printf("%d %d %d\n", l, r, base);
	int mn = MOD, cnt = 0;
	pii res = make_pair(0, 0), sub;
	rep (i, l, r)
		if (h[i] < mn) mn = h[i], cnt = 1;
		else if (h[i] == mn) cnt++;
	if (cnt == r - l + 1) {
		res.first = (power(2, r - l + 1) + MOD - 2) % MOD;
		res.second = power(2, mn - base - 1);
		//printf("%d %d %d  %d %d\n", l, r, base, res.fi, res.se);
		return res;
	}
	int remain = r - l + 1, last = 0, tmp = 1;
	int res0 = 1, res1 = 1;
	rep (i, l, r + 1)
		if (!last && h[i] > mn) last = i;
		else if (last && (i > r || h[i] == mn)) {
			remain -= i - last;
			sub = solve(last, i - 1, mn);
			res0 = 1LL * res0 * (sub.fi + 4LL * sub.se) % MOD;
			res1 = 2LL * res1 * sub.se % MOD;
			last = 0;
		}
	res0 = (res0 + MOD - res1) % MOD;
	res.fi = 1LL * res0 * power(2, remain) % MOD;
	res.fi = (res.fi + 1LL * res1 * (power(2, remain) + MOD - 2)) % MOD;
	res.se = 1LL * res1 * power(2, mn - base - 1) % MOD;
	//printf("%d %d %d  %d %d\n", l, r, base, res.fi, res.se);
	return res;
}

int main() {
	scanf("%d", &n);
	rep (i, 1, n) scanf("%d", &h[i]);
	if (n == 1) {
		printf("%d\n", power(2, h[1]));
		return 0;
	}
	rep (i, 1, n)
		if (h[i] > h[i-1] && h[i] > h[i+1]) {
			base = 1LL * base * power(2, h[i] - max(h[i-1], h[i+1])) % MOD;
			h[i] = max(h[i-1], h[i+1]);
		}
	pii tmp = solve(1, n, 0);
	res = 1LL * base * (tmp.fi + 2LL * tmp.se) % MOD;
	printf("%d\n", res);
	return 0;
}

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

using namespace std;

#define ll long long
#define MOD 1000000007
#define ii pair<ll, ll>
#define fi first
#define se second

string s;
ll f[200000][20];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> s;
    s = " " + s;
    f[0][0] = 1;
    for (int i = 1; i < s.size(); i++){
        if (s[i] != '?'){
            int x = s[i] - '0';
            for (int j = 0; j < 13; j++){
                f[i][(j*10 + x) % 13] += f[i - 1][j];
                f[i][(j*10 + x) % 13] %= MOD;
            }
        }
        else{
            for (int x = 0; x <= 9; x++){
                for (int j = 0; j < 13; j++){
                    f[i][(j*10 + x) % 13] += f[i - 1][j];
                    f[i][(j*10 + x) % 13] %= MOD;
                }
            }
        }
    }
    cout << f[(int)s.size() - 1][5] % MOD;
    return 0;
}

Measured memory_bytes: 16876
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] a = new int[n];
		for(int i=0; i<a.length; i++){
			a[i] = scn.nextInt();
		}
      	int gra = 0;
      	int bro = 0;
      	int gre = 0;
      	int ligh = 0;
      	int blu = 0;
      	int yel = 0;
      	int ora = 0;
      	int red = 0;
      	int xxx = 0;
      	int count = 0;
      	for(int i=0; i<a.length; i++){
          if(a[i]>0 && a[i]<400){
            gra++;
            if(gra==1) count++;
          }
          if(a[i]>=400 && a[i]<800){
            bro++;
            if(bro==1) count++;
          }
          if(a[i]>=800 && a[i]<1200){
            gre++;
            if(gre==1) count++;
          }
          if(a[i]>=1200 && a[i]<1600){
            ligh++;
            if(ligh==1) count++;
          }
          if(a[i]>=1600 && a[i]<2000){
            blu++;
            if(blu==1) count++;
          }
          if(a[i]>=2000 && a[i]<2400){
            yel++;
            if(yel==1) count++;
          }
          if(a[i]>=2400 && a[i]<2800){
            ora++;
            if(ora==1) count++;
          }
          if(a[i]>=2800 && a[i]<3200){
            red++;
            if(red==1) count++;
          }
          if(a[i]>=3200) xxx++;
        }
      	int max = count+xxx;
      	if(count==0) count++;
      	int min = count;
      	System.out.println(min + " "+ max);
	}
}


Measured memory_bytes: 38852
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    REP(i, 5){
        int t;
        cin >> t;
        if (t == 0) {
            cout << i+1 << endl;
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3652
let a, b = Scanf.scanf " %d %d" @@ fun a b -> a, b
let f n = let s = string_of_int n in s.[0] = s.[4] && s.[1] = s.[3]
let ans = ref 0
let _ = for i = a to b do if f i then incr ans done; Printf.printf "%d\n" !ans

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

bool JYM(int a){
    if ( a >= 1 && a <= 12) return true;
    return false;
}

int main(){
    int s; cin >> s;
    int a = s/100, b = s%100;

    if ( JYM(a) && JYM(b)) cout << "AMBIGUOUS" << endl;
    else if ( JYM(a) && !JYM(b) ) cout << "MMYY" << endl;
    else if ( !JYM(a) && JYM(b) ) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 200005;

ll tree_arr[4 * MAXN], n, a[MAXN], h[MAXN], ans, dp[MAXN];

ll combine(ll a, ll b)
{
	return max(a, b); 
}

void build(ll node, ll curr_l, ll curr_r)
{
	if(curr_l == curr_r)
		tree_arr[node] = dp[curr_r];
	else
	{
		ll curr_mid = (curr_l + curr_r) >> 1;
		build(2 * node + 1, curr_l, curr_mid);
		build(2 * node + 2, curr_mid + 1, curr_r);
		tree_arr[node] = combine(tree_arr[2 * node + 1], tree_arr[2 * node + 2]);
	}
}

ll query(ll node, ll curr_l, ll curr_r, ll query_l, ll query_r)
{
	if(query_l > query_r || curr_l > curr_r || curr_l > query_r || curr_r < query_l) return 0;
	if(curr_l >= query_l && curr_r <= query_r) return tree_arr[node];
	else
	{
		ll curr_mid = (curr_l + curr_r) >> 1;
		ll left_value = query(2 * node + 1, curr_l, curr_mid, query_l, min(query_r, curr_r)); 
		ll right_value = query(2 * node + 2, curr_mid + 1, curr_r, max(query_l, curr_l), query_r);
		return combine(left_value, right_value);
	}
}

void point_update(ll node, ll curr_l, ll curr_r, ll pos)
{
	if(curr_l == curr_r)
		tree_arr[node] = dp[curr_r];
	else
	{
		ll curr_mid = (curr_l + curr_r) >> 1;
		if(curr_mid >= pos)
			point_update(2 * node + 1, curr_l, curr_mid, pos);
		else
			point_update(2 * node + 2, curr_mid + 1, curr_r, pos);
		tree_arr[node] = combine(tree_arr[2 * node + 1],tree_arr[2 * node + 2]);
	}
}

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

 	cin >> n;
 	for(int i=0;i<n;i++) cin >> h[i];
 	for(int i=0;i<n;i++) cin >> a[i];
 	build(0, 0, n-1);
 	for(int i=0;i<n;i++)
 	{
 		dp[h[i]] = a[i] + query(0, 0, n-1, 0, h[i] - 1);
 		point_update(0, 0, n-1, h[i]);
 		ans = max(ans, dp[h[i]]);
 	}
 	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10496