akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();


    void Solve()
    {
        int n_ = cin.Nextint;
        int q = cin.Nextint;

        int n = 1;
        while (n < n_) n <<= 1;

        var S = new RUQ(n, int.MaxValue);
        var T = new RUQ(n, -1);

        for (int i = 0; i < q; i++)
        {
            if (cin.Nextint == 0)
            {
                int a = cin.Nextint, b = cin.Nextint, x = cin.Nextint;
                S.Update(a, b + 1, x, 0, 0, n);
                T.Update(a, b + 1, i, 0, 0, n);
            }
            else
            {
                int k = T.Find(cin.Nextint);
                Console.WriteLine(S.Get(k));
            }
        }

    }

}

class RUQ
{
    int n;
    int[] dat;

    public RUQ(int t, int s)
    {
        n = t;
        dat = Enumerable.Repeat(s, 2 * n - 1).ToArray();
    }

    //[a, b) update
    public void Update(int a, int b, int x, int k, int l, int r) // ue-kara
    {
        if (r <= a || b <= l) return;
        if (a <= l && r <= b) dat[k] = x;
        else
        {
            Update(a, b, x, k * 2 + 1, l, (l + r) / 2);
            Update(a, b, x, k * 2 + 2, (l + r) / 2, r);
        }

    }
    public int Get(int k)
    {
        return dat[k];
    }
    
    public int Find(int k) // shita-kara
    {
        k += n - 1;
        int max = dat[k];
        int res = k;
        while (k > 0)
        {
            k = (k - 1) / 2;
            if (max < dat[k])
            {
                max = dat[k];
                res = k;
            }
        }
        return res;
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return Console.ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 14072
//カルノー図っぽいものをメモっていたら分かった
#include<iostream>
using namespace std;

int pointer = 0;
int Re[10000],I[10000],J[10000],K[10000];

int main(){
	int n;
	int x1,y1,z1,w1,x2,y2,z2,w2;
	
	while( cin >> n ){
		if(n == 0)
			break;
		for( int i = 0;i < n;i++ ){
			cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
			Re[ pointer ] = x1*x2 - y1*y2 -z1*z2 - w1*w2;
			I[ pointer ] = x1*y2 + x2*y1 + z1*w2 - z2*w1;
			J[ pointer ] = x1*z2 + x2*z1 -y1*w2 + y2*w1;
			K[ pointer ] = x1*w2 + y1*z2 - y2*z1 + x2*w1;
			cout << Re[pointer] << " "<< I[pointer] << " "<< J[pointer]<< " " << K[pointer] << endl;
			pointer++;
		}
	}
	return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int n,a,b,c,ans=99999999;
    cin>>n>>a>>b>>c;
    int l[10];
    for(int i=0;i<n;i++){
        cin>>l[i];
    }

    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<(1<<n);j++){
            for(int k=0;k<(1<<n);k++){
                if((i&j)+(j&k)+(k&i)==0&&i>0&&j>0&&k>0){
                    int s=-30;
                  int x=0,y=0,z=0;
                    for(int t=0;t<n;t++){

                        if(((1<<t)&i)>0){
                            s+=10;
                          x+=l[t];
                        }
                        if(((1<<t)&j)>0){
                          y+=l[t];
                            s+=10;
                        }
                        if(((1<<t)&k)>0){
                          z+=l[t];
                            s+=10;
                        }
                    }
                  s+=abs(x-a)+abs(y-b)+abs(z-c);
                    if(s<ans){
                      //cout<<i<<" "<<j<<" "<<k<<endl;
                      ans=s;
                    }
                }
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
const int INF = 1000000007;
using namespace std;
void solve() {
   int n, k;
   cin >> n >> k;
   int a[n][k];
   for(int i=0;i<n;i++) {
       for(int j=0;j<k;j++) {
           cin >> a[i][j];
       }
   }
   int ans, count = 0;
   for(int i=0;i<n;i++) {
       for(int j=n-1;j>i;j--) {
           ans = 0;
           for(int p=0;p<k;p++) {
               //cout << a[i][p] << " " << a[j][p] << endl;
               ans += (a[i][p] - a[j][p])*(a[i][p] - a[j][p]);
           }
           //cout << ans << '\n';
           if(ans == 0)
                continue;
           int z = sqrt(ans);
           if(z*z == ans)
                count++;
       }
   }
   cout << count << '\n';
   return ;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, p, ans;

int main() {
	cin >> n >> p;
	ans = min(n, p/2);
	n -= ans, p -= ans*2;
	ans += p/4;
	cout << ans << ln;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long c = scanner.nextLong();
        long [] x = new long[n];
        long [] v = new long[n];
        for (int i = 0; i < n; ++i) {
            x[i] = scanner.nextLong();
            v[i] = scanner.nextLong();
        }
        long [][] dist1 = new long[n][2];
        long [][] f1 = new long[n][2];
        f1[0][0] = 0;
        f1[0][1] = v[0] - x[0];
        dist1[0][0] = 0;
        dist1[0][1] = x[0];
        for (int i = 1; i < n; ++i) {
            f1[i][0] = Math.max(f1[i - 1][0], f1[i - 1][1]);
            f1[i][1] = f1[i - 1][1] + v[i] - (x[i] - x[i - 1]);
            dist1[i][0] = f1[i - 1][0] >= f1[i - 1][1]
                    ? dist1[i - 1][0]
                    : x[i - 1];
            dist1[i][1] = x[i];

        }
        long [][] dist2 = new long[n][2];
        long [][] f2 = new long[n][2];
        f2[n - 1][0] = 0;
        f2[n - 1][1] = v[n - 1] - (c - x[n - 1]);
        dist2[n - 1][0] = 0;
        dist2[n - 1][1] = c - x[n - 1];
        for (int i = n - 2; i >= 0; --i) {
            f2[i][0] = Math.max(f2[i + 1][0], f2[i + 1][1]);
            f2[i][1] = f2[i + 1][1] + v[i] - (x[i + 1] - x[i]);
            dist2[i][0] = f2[i + 1][0] >= f2[i + 1][1]
                    ? dist2[i + 1][0]
                    : c - x[i + 1];
            dist2[i][1] = c - x[i];
        }

        long result = 0;
        for (int i = 0; i < n; ++i) {
            long onlyLeft = Math.max(f1[i][0], f1[i][1]);
            long onlyRight = i + 1 < n
                    ? Math.max(f2[i + 1][0], f2[i + 1][1])
                    : 0;
            result = Math.max(result, Math.max(onlyLeft, onlyRight));
            long leftBack = Math.max(f1[i][0] - dist1[i][0], f1[i][1] - dist1[i][1]);
            long rightBack = i + 1 < n
                    ? Math.max(f2[i + 1][0] - dist2[i + 1][0], f2[i + 1][1] - dist2[i + 1][1])
                    : 0;
            long leftRight = leftBack + onlyRight;
            long rightLeft = rightBack + onlyLeft;
            result = Math.max(result, Math.max(leftRight, rightLeft));
        }
        // all counter clockwise
        result = Math.max(result, Math.max(f2[0][0], f2[0][1]));

        System.out.println(result);

    }
}


Measured memory_bytes: 97076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

int cal_score(vector<int> t){
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
    }
    return satis;
}

int ch_sch(vector<int> t, int d, int q, int score){
    // change t[d - 1] -> q
    // calculate the score
    int old = t[d - 1];
    score -= s[d - 1][old - 1];
    score += s[d - 1][q - 1];

    int last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old ) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score += c[old - 1] * (i - last_old + 1);
        score += c[q - 1] * (i - last_new + 1);
    }

    t[d - 1] = q;

    last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score -= c[old - 1] * (i - last_old + 1);
        score -= c[q - 1] * (i - last_new + 1);
    }
    return score;
}

int main(){
    srand((unsigned)time(NULL));

    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    // greedy
    vector<int> last(26, 0);
    vector<int> res(D);

    rep(d, D){
        int max_plus = -10000;
        int use = -1;
        rep(i, 26){
            int tmp = s[d][i] + c[i] * (d - last[i] + 1);
            if(max_plus < tmp){
                max_plus = tmp;
                use = i;
            }
        }
        last[use] = d + 1;
        res[d] = use + 1;
    }

    int cur_score = cal_score(res);
    //int ch_d = 1;
    //int cnt = 0;

    while((clock() / (double)CLOCKS_PER_SEC) <= 1.98){
        // cnt++;
        int ch_d = rand() % D + 1;
        int ch_c = rand() % 26 + 1;
        // int ifch = rand() % 100;
        int new_score = ch_sch(res, ch_d, ch_c, cur_score);
        if(cur_score < new_score){
            cur_score = new_score;
            res[ch_d - 1] = ch_c;
            // ch_d--;
            // if(ch_d == 0) ch_d = D;
        }
    }

    rep(i, D){
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int result(vector<char> &f){
  int res=f[0]-'0';
    for(int i=1;i<7;i+=2){
      if(f[i]=='+')res+=f[i+1]-'0';
      else res-=f[i+1]-'0';
    }
  return res;
}
int main(){
  int i,tmp;
  string N;cin>>N;
  for(tmp=0;tmp<(1<<3);tmp++){
    bitset<3> s(tmp);
    vector<char> f;
    f.push_back(N[0]);
    for(i=0;i<3;i++){
      if(s[i])f.push_back('+');
      else f.push_back('-');
      f.push_back(N[i+1]);
    }
    //reverse(f.begin(),f.end());
    if(result(f)==7){
      for(i=0;i<7;i++)cout<<f[i];
      cout<<"=7"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
import java.util.*;
 class Main{

    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String a = sc.next();
      String b = sc.next();
      StringBuilder sb = new StringBuilder("");
      for(int i=0,j=0; i<a.length() && j<b.length();i++,j++){
        sb.append((char)a.charAt(i)+"").append((char)b.charAt(j)+"");
      }
      System.out.println(sb);
    }
}


Measured memory_bytes: 22612
import java.util.*;
public class Main {
    static void solve(){
        Scanner sc = new Scanner(System.in);
        int NOC = sc.nextInt();
        int count = 1; int no = 0;
        while(NOC-->0){
             if(((sc.nextInt()&1)==1) && ((count&1)==1)) no++;
             count++;
        }
        System.out.println(no);
        sc.close();
    }
    
    public static void main(String args[]) {
        solve();
    }
}


Measured memory_bytes: 35852
def gcd(x, y):
    if y == 0:
        return x
    if x < y:
        return gcd(y, x)
    return gcd(y, x%y)

def fai(n, x, y):
    g = gcd(x, y)
    l = x * (y//g)
    return n - (n//x) - (n//y) + (n//l)

a, b, c, d = map(int, input().split())

alpha = 0
if a%c != 0 and a%d != 0:
    alpha = 1

print(fai(b, c, d) - fai(a, c, d) + alpha)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

int main( void ) {
    int N;
    std::vector< int > a;   // Point: 長さが自由な配列です

    std::cin >> N;
    for( size_t i = 0; i < N; ++i ) {
        // i番目の値を順次読み込んで配列に格納していく
        int ai;
        std::cin >> ai;
        a.push_back( ai );  // 配列の一番後ろにデータを入れる操作
    }

    // - 通りに並んでいる(一直線上にならんでいる)
    // - 自由な順序で歩いて良い
    // ... ということは、
    // 一番左の家から一番右の家まで、順番に移動しながらプレゼントを置くのが一番安くなります
    // というのも、右に行っている途中で、左に戻るということは、戻った分だけ余計に移動してるからです。
    // (手元で一直線に丸をいくつか並べて、左から右に行きながら、途中で戻ってみてください)
    // そのため、「一番小さな座標の家から、一番大きな座標の家までの距離」を求めれば解答になります
    // つまりただの引き算です

    // std::vector の中で最大の要素と、最小の要素を探すコードはこうかけます(便利)
    const int min = *std::min_element( a.begin(), a.end() );
    const int max = *std::max_element( a.begin(), a.end() );

    // もちろん以下のように書いてもOKです。
    /*
    int min = 0;
    int max = 100;
    for( size_t i = 0; i < N; ++i ){
        min = std::min( min, a[ i ] );
        max = std::max( max, a[ i ] );
    }
    */

    // 引き算して距離を求める
    std::cout << max - min << std::endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
  int K;
  string S;
  cin >> K >> S;
  
  string ret;
  if(S.size() <= K) ret = S;
  else  ret = S.substr(0,K) + "...";
  
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    vint a(5);
    rep(i, 5) cin >> a[i];

    rep(i, 5)
    {
        if (a[i] == 0)
        {
            cout << i + 1 << endl;
        }
    }

    return 0;
}

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

int main() {
  int D;
  cin >> D;
  
  if (D == 25) cout << "Christmas" << endl;
  if (D == 24) cout << "Christmas Eve" << endl;
  if (D == 23) cout << "Christmas Eve Eve" << endl;
  if (D == 22) cout << "Christmas Eve Eve Eve" << endl; 
}

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

public class Main {


  private void solve(InputReader in, PrintWriter out) {
    int n = in.nextInt();
    int sum = 0;
    int[] arr = new int[n];
    for (int i = 0; i < n; i++) {
      arr[i] = in.nextInt();
      sum += arr[i];
    }
    int x = sum / n;
    int ans1 = 0;
    int ans2 = 0;
    for (int i = 0; i < n; i++) {
      int t1 = x - arr[i];
      int t2 = x + 1 - arr[i];
      ans1 += t1 * t1;
      ans2 += t2 * t2;
    }
    out.println(Math.min(ans1, ans2));
  }


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

  private void run() {

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


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

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

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

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

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

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

    @Override
    public void close() {
    }
  }

}


Measured memory_bytes: 22996
import copy
S = input()
#print(S)
S2 = S.replace("BC", "D")
#print(S2)
count = 0
Acount = 0
Dcount = 0
for i in range(len(S2)):
    if S2[i] == 'A' or S2[i] == 'D':
        if S2[i] == 'A':
            Acount += 1
        else:
            count += Acount
    else:
        Acount = 0
    #print(count, Acount, S2[i])
print(count)


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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N;
  cin >> N;
  ll H[N];
  rep(i, N) cin >> H[i];

  ll cnt = 0, ans = 0;
  rep(i, N-1){
    if(H[i] >= H[i+1]) cnt++;
    else cnt = 0;
    if(cnt > ans) ans = cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, k;
    cin >> n >> k;
    ll ans = k;
    for (int i = 0; i < n-1; i++) ans *= k-1;
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
)

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	run()
}

func run() {
	var str string
	fmt.Fscan(reader, &str)
	var count int

	for _, r := range str {
		if r == '1' {
			count++
		}
	}

	fmt.Fprintln(writer, count)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> a(N);
  for (int i = 0; i < N; ++i)
    std::cin >> a[i];

  int mod = 1000000007;
  std::vector<std::vector<long long>> dp(N + 3,
                                         std::vector<long long>(K + 3, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    std::vector<long long> s(K + 3, 0);
    for (int k = 0; k <= K; ++k)
      s[k + 1] = (s[k] + dp[i][k]) % mod;
    for (int k = 0; k <= K; ++k) {
      int l = std::max(k - a[i], 0);
      int r = k + 1;
      dp[i + 1][k] = s[r] - s[l];
      if (dp[i + 1][k] < 0)
        dp[i + 1][k] += mod;
    }
  }
  std::cout << dp[N][K] << std::endl;
}


Measured memory_bytes: 81792
#include<bits/stdc++.h>
using namespace std;
int main()
{

     int k,l,b,c=0,x,ans=0;
    cin>>k;
     int a[k+10];
    for(int i = 0; i < k; i++)
    {
        cin>>a[i];
    }
    for(int i = 1; i < k; i++)
    {

        if (a[i] > a[i-1]) c = i;
		ans = max(ans, i-c);
    }


    cout<<ans<<endl;
}





Measured memory_bytes: 640
def main():
    bingo = []
    for i in range(3):
        a,b,c = [int(n) for n in input().split()]
        bingo.append([a,b,c])
    N = int(input())
    for i in range(N):
        a = int(input())
        for i, row in enumerate(bingo):
            for j in range(3):
                if bingo[i][j] == a:
                    bingo[i][j] = -1
    flag = False
    for i in range(3):
        if bingo[i][0] == bingo[i][1] == bingo[i][2]:
            flag = True
        if bingo[0][i] == bingo[1][i] == bingo[2][i]:
            flag = True
    if bingo[0][0] == bingo[1][1] == bingo[2][2]:
        flag = True
    if bingo[2][0] == bingo[1][1] == bingo[0][2]:
        flag = True
    print("Yes" if flag else "No")
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

vector<int> prime(int N) {
  vector<bool> a(N, true);
  for(int i=1; i<sqrt(N); i++) {
    if(a[i]) for(int k=2; (i+1)*k-1<N; k++) a[(i+1)*k-1] = false;
  }
  vector<int> p;
  rep(i, N) if(a[i]) p.push_back(i+1);
  p.erase(p.begin());
  return p;
}

signed main() {
  int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
  vector<int> p(A), q(B), r(C);
  rep(i, A) cin >> p[i];
  rep(i, B) cin >> q[i];
  rep(i, C) cin >> r[i];
  
  sort(all(p));
  reverse(all(p));
  sort(all(q));
  reverse(all(q));
  sort(all(r));
  reverse(all(r));
  
  priority_queue<int, vector<int>, greater<int>> ab;
  
  int ans = 0;
  rep(i, X) {
    ans += p[i];
    ab.push(p[i]);
  }
  rep(i, Y) {
    ans += q[i];
    ab.push(q[i]);
  }
  
  rep(i, C) {
    if(r[i] > ab.top()) {
      ans += r[i] - ab.top();
      ab.pop();
    } else break;
  }
  
  cout << ans << endl;

  

}

Measured memory_bytes: 7592
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    map<int,int> mp;
    vector<int> bn(n);
    int a;
    rep(i,n) {
        cin >> a;
        mp[a]++;
        bn[i] = a;
    }
    int sum = 0;
    for (auto p : mp) {
        sum += p.second*(p.second-1)/2;
    }
    rep(i,n) {
        int k = mp.at(bn[i]) - 1;
        cout << sum - k << "\n";
    }
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
int n,m,a[100001],b[100001],indeg[100001],dmax[100001],ans[100001],rt;
vector<int> graph[100001];
int dfs(int p)
{
	if (dmax[p]!=-1) return dmax[p];
	dmax[p]=0;
	for (int q: graph[p]) dmax[p]=max(dmax[p],dfs(q)+1);
	return dmax[p];
}
void dfs2(int p,int rt)
{
	if (ans[p]!=-1) return ;
	ans[p]=rt+1;
	vector<pair<int,int> > ch;
	for (int q: graph[p]) ch.pb(mp(dmax[q],q));
	sort(ch.begin(),ch.end());
	reverse(ch.begin(),ch.end());
	for (auto a: ch) dfs2(a.second,p);
}
int main()
{
	cin>>n>>m;
	for (int i=0;i<n+m-1;i++)
	{
		scanf("%d%d",a+i,b+i);
		a[i]--; b[i]--;
		graph[a[i]].pb(b[i]);
		indeg[b[i]]++;
	}
	int ori=-1;
	for (int i=0;i<n;i++) if (indeg[i]==0) ori=i;
	for (int i=0;i<n;i++) dmax[i]=ans[i]=-1;
	dfs(ori);
	dfs2(ori,-1);
	for (int i=0;i<n;i++) cout<<ans[i]<<endl;
	return 0;
}

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

typedef long long ll;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0);
//#define cerr if(false)cerr
#define PRINT(x) cerr<<"\n" << (#x) << " is " << (x) << endl;
//Erase duplicates in vector
#define REMOVE_DUP(x) x.erase(unique(x.begin(), x.end()), x.end());
#define UP toupper // lowercase to uppercase;
#define DOWN tolower
#define SZ(a) (int)a.size()
#define EB emplace_back
#define PB push_back
#define REP(i, a, b) for(int i=a; i<b; i++)
#define PER(i, a, b) for(int i=a; i>=b; i--)
ostream_iterator<int> output(cout, " ");
#define MOD 1e9+7
#define INF 10008

void solve(){
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " "<< b << " " << c << endl;
}

int32_t main(){
	FAST_IO;
	int t1 = 1; //cin >> t1;
	while(t1--)
		solve();
}


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

int main() {

	double l;	cin >> l;

	double ans = (l * l * l) / 27;

	cout << fixed<< setprecision(7) << ans << endl;


	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q;
string S;

int main() {
    cin >> S;
    bool flag = true;
    if (S[0] != 'A') flag = false;
    int cnt = 0;
    for (int i = 1; i < (int)S.size(); i++) {
        if (i >= 2 && i < (int)S.size() - 1 && S[i] == 'C') {
            cnt++;
        } else if (!('a' <= S[i] && S[i] <= 'z')) {
            flag = false;
        }
    }

    if (cnt != 1) flag = false;

    if (flag) {
        cout << "AC" << endl;
    } else {
        cout << "WA" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int a,b,A,B;
	while(cin>>A>>B){
		a=A,b=B;

		if(a<b)swap(a,b);
		for(int r;(r=a%b)!=0;)a=b,b=r;

		int L=b,G=A*(B/L);
		cout<<L<<" "<<G<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;


int main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=1000;
  rep(i,0,n-2){
    int cur=100*(s[i]-'0')+10*(s[i+1]-'0')+(s[i+2]-'0');
    ans=min(ans,abs(cur-753));
  }
  cout<<ans<<endl;
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    vector<int> a(26,0);
    REP(i,s.length()){
        a[s[i]-97]++;
    }
    string ans = "yes";
    REP(i,s.length()){
        if(a[i]>=2) ans = "no";
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main() {
  int a, b;
  cin >> a >> b;
  if ((a * b) % 2==0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

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


void solve(std::string S){
    for(char i = 'a'; i <= 'z'; ++i){
        if(count(S.begin(), S.end(), i) == 0){
            cout << i << endl;
            exit(0);
        }
    }
    cout << "None" << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

using namespace std;
 
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
 
int main(){
    int mN,mE,mS,mW,N,n,d,x[200],y[200];
 
    while(1){
 
	mN = mE = mS = mW = 0;
 
	cin >> N;
	if( N == 0 ) break;
 
	for( int i = 0 ; i < 200 ; i++ ){
	    x[i] = 0;
	    y[i] = 0;
	}
 
	for( int i = 1 ; i < N ; i++ ){
	    cin >> n >> d;
 
	    x[i] = x[n] + dx[d];
	    y[i] = y[n] + dy[d];
 
	    mN = max( y[i] , mN );
	    mS = min( y[i] , mS );
	    mW = max( x[i] , mW );
	    mE = min( x[i] , mE );
	}
	cout << mW - mE + 1 << " " << mN - mS + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp;
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

#define range_with(index, beg, end) for (ll index = beg; index < N; ++index)
#define range(N) for (ll i = 0; i < N; i++)
#define rev_range(N) for (ll i = N-1; i >= 0; i--)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n";

ll powMod(ll a, ll n, ll mod){
    if(n == 0) return 1;
    if(n%2 == 0)
        return powMod(a, n/2, mod) * powMod(a, n/2, mod) % mod;
    else
        return a * powMod(a, n-1, mod)% mod;
}

ll ncrMod(ll n, ll r, ll mod){
    ll x=1, y=1;
    for(ll i = 1; i <= r; ++i){
        x *= n-i+1;
        x %= mod;
        y *= i;
        y %= mod;
    }
    return x * powMod(y, mod-2, mod) % mod;
}

int main() {
    string S;
    int N, P;

    cin >> N >> P;
    cin >> S;

    ll ans = 0;

    if (P == 2 || P == 5) {
        range(N) {
            int n = S[i] - '0';
            if (n % P == 0) ans += i+1;
        }

        cout << ans;
    } else {
        vector<ll> cnt_of_remain(P, 0);
        cnt_of_remain[0] = 1;

        int now = 0;
        int ten = 1;

        rev_range(N) {
            int n = S[i] - '0';
            now = (now + ten * n) % P;

            ans += cnt_of_remain[now];

            cnt_of_remain[now]++;
            ten = (ten * 10) % P;
        }

        cout << ans;
    }


    return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
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 (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
signed main()
{
    int x, y;
    cin >> x >> y;
    int diff = abs(abs(x) - abs(y));

    if (x > 0)
    {
        if (y > 0)
        {
            if (x < y)
            {
                //0 x y
                cout << diff << endl;
            }
            else
            {
                //0 y x
                cout << diff + 2 << endl;
            }
        }
        else if (y < 0)
        {
            //y 0 x
            if (-x < y)
            {
                //-x y 0 x
                cout << diff + 1 << endl;
            }
            else
            {
                //y -x 0 x
                cout << diff + 1 << endl;
            }
        }
        else
        {
            cout << diff + 1 << endl;
        }
    }
    else if (x < 0)
    {
        if (y > 0)
        {
            //x 0 y
            if (-x < y)
            {
                //x 0 -x y
                cout << 1 + diff << endl;
            }
            else
            {
                //x 0 y -x
                cout << 1 + diff << endl;
            }
        }
        else if (y < 0)
        {
            if (x < y)
            {
                //x y 0
                cout << diff << endl;
            }
            else
            {
                //y x 0
                cout << diff + 2 << endl;
            }
        }
        else
        {
            cout << diff << endl;
        }
    }
    else {
        if(y>0){
            cout << diff << endl;
        }
        else {
            cout << diff + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3584
ls = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(ls[k-1])

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

#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

#define FOR(i,n) for(ll i=0;i<n;i++)


int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   ull N;
   cin>>N;
   map<ull,ull>count;
   FOR(i,N){
      ull a;
      cin>>a;
      count[a]++;
      count[a-1]++;
      count[a+1]++;
   }
   vector<pair<ull,ull> >c;
   FOR(i,100002)c.push_back(make_pair(count[i],i));
   sort(c.rbegin(),c.rend());
   cout<<c[0].first<<endl;
   return 0;
}


Measured memory_bytes: 8436
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;

int main(){
    int N; cin>>N;
    P a[100000];
    for(int i=0;i<N;i++){
        int A,B; cin>>A>>B;
        a[i]=P(A,B);
    }
    sort(a,a+N);
    int ans = a[N-1].first + a[N-1].second;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include<string>
#include<sstream>
using namespace std;
typedef complex<double> P;

const double eps = 1e-8;

namespace std {
  bool operator <(const P &a, const P &b) {
    if(a.real() != b.real()) return a.real() < b.real();
    return a.imag() < b.imag();
  }
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

int ccw(P p, P a, P b) {
  a -= p;
  b -= p;
  if(cross(a,b) > eps) return 1;
  if(cross(a,b) < -eps) return -1;
  if(dot(a,b) < -eps) return 2;
  if(norm(b)-norm(a) > eps) return -2;
  return 0;
}

vector<P> convex_hull(vector<P> ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<P> ch(2*n);
  for(int i = 0; i < n; ch[k++] = ps[i++])
    while(k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for(int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--])
    while(k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

int main() {
  int n;
  while(scanf("%d", &n) != EOF && n) {
    vector<P> g(n);
    for(int i = 0; i < n; ++i) {
      P &p = g[i];
      scanf("%lf,%lf", &p.real(), &p.imag());
    }
    printf("%d\n", g.size() - convex_hull(g).size());
  }
  return 0;
}

Measured memory_bytes: 3208
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100 + 5;
const int M = 100;

int a, b;
char c[N][N];

void solve()
{
    cin >> a >> b;
    for(int i = 0; i < M; ++ i) {
        c[0][i] = '.';
        c[M - 1][i] = '#';
        for(int j = 1; j < M - 1; ++ j) {
            if (i & 1) {
                c[j][i] = '#';
            } else {
                c[j][i] = '.';
            }
        }
    }
    for(int j = 0; a > 1; j += 2) {
        for(int i = M - 3; a > 1 && i > 1; i -= 2) {
            a--;
            c[i][j] = '#';
        }
    }

    for(int j = M - 1; b > 1; j -= 2) {
        for(int i = 2; b > 1 && i < M - 2; i += 2) {
            --b;
            c[i][j] = '.';
        }
    }
    cout << M << ' ' << M << endl;
    for(int i = 0; i < M; ++ i) {
        puts(c[i]);
    }
}

int main()
{
    solve();
    return 0;
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

int h,w,memo[50][50],cicada[50][50];

int DFS(int y,int x){
	int &res=memo[y][x];
	if(res!=INF) return res;
	if(y==h-1&&x==w-1) return res=0;

	if(y!=h-1) res=min(res,DFS(y+1,x)+cicada[y+1][x]);
	if(x!=w-1) res=min(res,DFS(y,x+1)+cicada[y][x+1]);

	return res;
}

void Solve(){
	fill_n((int*)memo,50*50,INF);
	cin >> h >> w;
	rep(y,0,h) rep(x,0,w){
		char c; cin >> c;
		cicada[y][x]=c-'0';
	}
	cout << DFS(0,0) << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 1216
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = sc.nextInt();
        
        int s = 0;
        int t = 0;
        long ans = 0;
        int tmp;
        long sum = 0;
        long xor_sum = 0; 
        while(t <= n-1){
            if((xor_sum |+ a[t]) == sum + a[t]){
                ans += t - s + 1;
                xor_sum = xor_sum ^ a[t];
                sum += a[t];
                t++;
            }else{
                xor_sum = xor_sum ^ a[s];
                sum -= a[s];
                s++;
            }
        }
          System.out.println(ans);   
    }
}

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


int main() {
	
	int N;
	int x = 0;
	cin >> N;
	int m = N;
	for(int i=0; i<9; i++){
		x += N % 10;
		N = N/10;
	}
	if(m % x) cout << "No" << endl;
	else cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<cstring>
#include<iostream>
#define _PI acos(-1.0)
#define INF 0x3f3f3f3f
#define esp 1e-9
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define FRE freopen("abc.in", "r", stdin)
#define MEM(X,Y) memset(X,Y,sizeof(X))
typedef long long LL;
typedef unsigned long long ULL;
long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; }
using namespace std;
/*===========================================*/

int dis[200005];

int main(void)
{
	int n,k;
	scanf("%d%d", &k, &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &dis[i]);
	sort(dis, dis + n);
	int mx = (k - dis[n - 1]) + dis[0];
	for (int i = 1; i < n; ++i)
		mx = max(mx, dis[i] - dis[i - 1]);
	printf("%d", k - mx);
}

Measured memory_bytes: 1024
n = int(input().strip())
btc2jpy = 380000
jpy_total = 0
btc_total = 0.0
for _ in range(n):
    line = input().strip().split()
    if line[1] == 'JPY':
        jpy_total += int(line[0])
    else:
        btc_total += float(line[0])
print(jpy_total + btc2jpy * btc_total)


Measured memory_bytes: 2940
N = int(input())
X = []
Y = []
P = []
for _ in range(N):
    x,y,p = map(int,input().split())
    X.append(x)
    Y.append(y)
    P.append(p)
DX = [[0]*N for _ in range(1<<N)]
DY = [[0]*N for _ in range(1<<N)]

for i,x in enumerate(X):
    for k in range(1<<N):
        d = abs(x)
        for j,xx in enumerate(X):
            if k & (1<<j):
                d = min(d,abs(xx-x))
        DX[k][i] = d*P[i]
for i,y in enumerate(Y):
    for k in range(1<<N):
        d = abs(y)
        for j,yy in enumerate(Y):
            if k & (1<<j):
                d = min(d,abs(yy-y))
        DY[k][i] = d*P[i]

ANS = [1<<100]*(N+1)
PC = [0]*(1<<N)
for i in range(1,1<<N):
    PC[i] = PC[i^1] + 1 if i%2 else PC[i//2] 
RA = []
for i in range(1<<N):
    t = []
    for j in range(N):
        if i&(1<<j):
            t.append(j)
    RA.append(t)

mm = (1 << N) - 1
for i in range(1 << N):
    m = i ^ mm
    j = m
    dxi = DX[i]
    pci = PC[i]
    while 1:
        dyj = DY[j]
        ans = 0
        for k in RA[i^j^mm]:
            ans += min(dxi[k], dyj[k])
        
        pc = pci + PC[j]
        ANS[pc] = min(ANS[pc], ans)
        
        if not j:
            break
        j = m & (j - 1)
print(*ANS ,sep="\n")


Measured memory_bytes: 94532
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

int main(void){
  int a, b, count = 0;
  cin >> a >> b;
  for(int i = a; i <= b; i++){
    if((i/10000)%10 == (i/1)%10 && (i/1000)%10 == (i/10)%10) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
 int i,j,n,a[2000],q,num,m[2000];

 a[0]=1;

 scanf("%d",&n);

 for(i=0;i<n;i++){
  scanf("%d",&num);
  for(j=2000-num;j>=0;j--){
   if(a[j]){
    a[j+num]=1;
   }
  }
 }

 scanf("%d",&q);

 for(i=0;i<q;i++){
  scanf("%d",&m[i]);
 }

 for(i=0;i<q;i++){
  if(a[m[i]]){
   printf("yes\n");
  }else{
   printf("no\n");
  }
 }

 return 0;

}
  

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

int main(){
	int L,R;cin>>L>>R;
	if(L%2019==0 or R%2019==0 or L/2019!=R/2019){puts("0");return 0;}
	int ans=2019;
	for(int i=L;i<=R;i++)
		for(int j=i+1;j<=R;j++)
			ans=min(1ll*ans,1ll*i*j%2019);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a[100010]={0},t=0,s;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=0)
		{
		    s=0;
		    if(a[i]<=n)
			{
				for(int j=1;j<=n;j++)
				{
					if(a[j]!=0&&a[j]==a[i]&&j!=i)
					{
						a[j]=0;
						s++;
					}
				}
				s++;
				if(s!=a[i])
				{
					if(s>a[i]) t+=s-a[i];
					else t+=s;
				}
			}
			else t++;
		}
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i,n,m,h,g;
  cin >> n;
  vector<int> x;
  for(i=0;i<n;i++){
    cin >> h >> g;
    x.push_back(h*60+g);
  }
  cin >> m;
  for(i=0;i<m;i++){
    cin >> h >> g;
    x.push_back(h*60+g);
  }
  sort(x.begin(),x.end());
  for(i=0;i<n+m;i++){
    if(i!=0 && x[i-1]==x[i]){
      continue;
    }
    if(i!=0){
      printf(" ");
    }
    printf("%d:",x[i]/60);
    printf("%02d",x[i]%60);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  int n,m,x;
  int min = 0;
  int max = 0;
  cin >> n >> m >> x;
  int count = m;
  int a[m];
  for (size_t i = 0; i < count; i++) {
    cin >> a[i];
  }
  for (size_t i = 0; i < count; i++) {
    if (a[i] < x) {
      min++;
    } else if (a[i] > x) {
      max++;
    }
  }
  if (min > max) cout << max << endl;
  else cout << min << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int N;

		N = scanner.nextInt();

		int[] min_dist = new int[N];
		Node[] nodes = new Node[N];
		for(int i = 0; i < N; i++)nodes[i] = new Node();

		int node_id,num,to,dist;

		for(int loop = 0; loop < N; loop++){
			node_id = scanner.nextInt();
			num = scanner.nextInt();

			for(int i = 0; i < num; i++){
				to = scanner.nextInt();
				dist = scanner.nextInt();
				nodes[node_id].ADJ.add(new Edge(to,dist));
			}
		}

		min_dist[0] = 0;
		for(int i = 1; i < N; i++)min_dist[i] = BIG_NUM;

		PriorityQueue<Info> Q = new PriorityQueue<Info>();
		int next_node,next_dist;

		Q.add(new Info(0,0));

		while(!Q.isEmpty()){

			if(Q.peek().sum_dist > min_dist[Q.peek().node_id]){
				Q.remove();
			}else{

				for(int i = 0; i < nodes[Q.peek().node_id].ADJ.size(); i++){
					next_node = nodes[Q.peek().node_id].ADJ.get(i).to;
					next_dist = Q.peek().sum_dist+nodes[Q.peek().node_id].ADJ.get(i).dist;

					if(min_dist[next_node] > next_dist){
						min_dist[next_node] = next_dist;
						Q.add(new Info(next_node,next_dist));
					}
				}
				Q.remove();
			}
		}

		StringBuilder ans = new StringBuilder();
		for(int i = 0; i < N; i++){
			System.out.println(i + " " + min_dist[i]);
		}

		System.out.print(ans.toString());
	}
}

class Node{
	public ArrayList<Edge> ADJ;

	Node(){
		ADJ = new ArrayList<Edge>();
	}
}

class Edge{
	public int to;
	public int dist;

	Edge(int arg_to,int arg_dist){
		to = arg_to;
		dist = arg_dist;
	}
}

class Info implements Comparable<Info>{
	public int node_id;
	public int sum_dist;

	Info(int arg_node_id,int arg_sum_dist){
		this.node_id = arg_node_id;
		this.sum_dist = arg_sum_dist;
	}

	public int compareTo(Info arg){
		if(this.sum_dist < arg.sum_dist)return -1;
		if(this.sum_dist > arg.sum_dist)return 1;
		return 0;
	}
}




Measured memory_bytes: 275980
fun main(args: Array<String>) {
    val (n, a, b) = readLine()?.split(" ")?.map(String::toInt) ?: return
    var pass = 0
    var bPass = 0
    buildString {
        readLine()?.forEachIndexed { i, s ->
            when (s) {
                'a' -> {
                    if (a + b > pass) {
                        pass++
                        appendln("Yes")
                    } else {
                        appendln("No")
                    }
                }
                'b' -> {
                    if (a + b > pass && bPass + 1 <= b) {
                        pass++
                        bPass++
                        appendln("Yes")
                    } else {
                        appendln("No")
                    }
                }
                'c' -> {
                    appendln("No")
                }
            }
        }
    }.let {
        println(it)
    }
}

Measured memory_bytes: 40388