akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;

class UnionFind {
  public:
    UnionFind(int n): par(n, -1) { }
    int root(int x) {
      if (par[x] < 0) return x;
      else return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
      x = root(x), y = root(y);
      if (x == y) return;
      if (par[y] < par[x]) swap(x, y);
      par[x] += par[y];
      par[y] = x;
    }
    bool same(int x, int y) {
      return root(x) == root(y);
    }
    int size(int x) {
      return -par[root(x)];
    }

  private:
    vector<int> par;
};

int main()
{
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  REP(i, M) {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X--, Y--;
    uf.unite(X, Y);
  }

  set<int> st;
  REP(i, N) {
    st.insert(uf.root(i));
  }
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 5376
def main():
    import sys
    from math import atan2, hypot, pi
    from bisect import bisect_left
    input = sys.stdin.readline

    eps = 10**-8
    N = int(input())
    P = []
    rad = []
    for _ in range(N):
        x, y = map(int, input().split())
        P.append((atan2(y, x), x, y))
        rad.append(atan2(y, x))
    P.sort(key=lambda p: p[0])
    rad.sort()
    for i in range(N):
        r, x, y = P[i]
        P.append((r+pi*2, x, y))
        rad.append(r+pi*2)

    ans = 0
    for i in range(N):
        rad_op = rad[i] + pi
        j = bisect_left(rad, rad_op)
        xsum = ysum = 0
        for k in range(i, j):
            x, y = P[k][1], P[k][2]
            xsum += x
            ysum += y
        ans = max(ans, hypot(xsum, ysum))
        xsum -= P[i][1]
        ysum -= P[i][2]
        ans = max(ans, hypot(xsum, ysum))
    for i in range(N, N*2):
        rad_op = rad[i] - pi
        j = bisect_left(rad, rad_op)
        xsum = ysum = 0
        for k in range(j, i+1):
            x, y = P[k][1], P[k][2]
            xsum += x
            ysum += y
        ans = max(ans, hypot(xsum, ysum))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39280
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;

    int ans = 0;

    for(int i=0; i<2; i++){
        ans += max(a, b);
        if(a > b){
            a--;
        }else{
            b--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")

#include<bits/stdc++.h>

#define pb push_back
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f(i, a ,b) for(int i = (int)a; i <=(int)(b);i++)
#define endl "\n"
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;

using namespace std;

const int N = 1e3+5,MOD = 1000000007;
const long long int INF = 0xFFFFFFFFFFFFFFFL;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void IOS()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
   	cout.precision(10);
   	cout << fixed;
}

char a[N][N];
int dp[1005][1005];
int h,w;
	
int rec(int i, int j)
{
	if(dp[i][j] != -1)return dp[i][j];
	if(i >= h or j >= w or a[i][j] == '#')return 0;
	else
	{
		return dp[i][j] = (rec(i+1,j)%MOD+rec(i,j+1)%MOD)%MOD;
	}
}

int32_t main()
{
	IOS();
	cin >> h >> w;
	memset(dp,-1,sizeof(dp));
	f(i,0,h-1)f(j,0,w-1)cin >> a[i][j];
	dp[h-1][w-1] = 1;
	cout << rec(0,0)%MOD;	 		
	return 0;
}

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

using namespace std;

int main() {
    int test = 1;
    while (true) {
        int x;
        cin >> x;
        if (x == 0) {
            break;
        }
        cout << "Case " << test << ": " << x << '\n';
        ++test;
    }
    return 0;
}


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

using namespace std;

int n, k, a[200000], f[200000];

bool chk(int qq)
{
    int cnt = 0;
    for (int i = 0; i < n; i++)
        if (a[i] * f[i] > qq)
            cnt += max(0LL, (a[i] * f[i] - qq) / f[i] + !!((a[i] * f[i] - qq) % f[i]));

    if (cnt > k)
        return true;
    else
        return false;
}

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

    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> f[i];
    sort(a, a + n);
    sort(f, f + n, greater<int>());

    int l = 0, r = 1000000000001;
    while (l != r)
    {
        int m = (l + r) / 2;
        if (chk(m))
            l = m + 1;
        else
            r = m;
    }
    cout << l << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***
//     *****  *****  *****
//    *      *   *  *
//   *      *****  *
//  *      *  *   *
//  ***** *   *   *****


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, c;
	cin >> a >> c;
	cout << max(0, a - c - c);
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;

    int cnt = 0;
    while (n > 0) {
        if (n % 10 == 2)
            cnt++;
        n /= 10;
    }
    cout << cnt << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int n;
ll pos[MAX_N];
multiset<ll> st;

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

    cin >> n;
    for (int i=1; i<=n; i++) {
        int a; cin >> a;
        pos[a] = i;
    }
    st.insert(0);
    st.insert(0);
    st.insert(n+1);
    st.insert(n+1);

    ll ans = 0LL;
    for (int i=n; i>=1; i--) {
        ll ind = pos[i];
        ll a, b, x, y;
        auto it = st.upper_bound(ind);
        x = *it;
        it++;
        y = *it;
        it = st.lower_bound(ind);
        it--;
        a = *it;
        it--;
        b = *it;
        st.insert(ind);
        //cout << "D: " << ind << "  " << a << "  " << b << "  " << x << "  " << y << "\n";
        if (a == 0 && x == n+1) continue;
        ll tmp = (a-b)*(x-ind) + (y-x)*(ind-a);
        ans += i*tmp;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 5760
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

using namespace std;

typedef long long ll;
inline int in(){int x;scanf("%d",&x);return x;}

const int INF = 1 << 28;

int main()
{
  int N, M, S, G1, G2;
  while (N = in(), M = in(), S = in() - 1, G1 = in() - 1, G2 = in() - 1, N){
    int way[111][111];
    for (int i = 0; i < N; i++) fill_n(way[i], N, INF), way[i][i] = 0;

    for (int i = 0; i < M; i++){
      int b1 = in() - 1, b2 = in() - 1, c = in();
      way[b1][b2] = c;
    }
    for (int k = 0; k < N; k++){
      for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++){
          way[i][j] = min(way[i][j], way[i][k] + way[k][j]);
        }
      }
    }
    int mini = INF;
    for (int i = 0; i < N; i++){
      mini = min(mini, way[S][i] + way[i][G1] + way[i][G2]);
    }
    printf("%d\n", mini);
  }

  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);
  
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  int ans = 0;
  rep(k, n + 1) {
    bool f = true;
    rep(i, n) {
      rep(j, n) {
        if (s[(i + k) % n][j] != s[(j + k) % n][i]) {
          f = false;
        }
      }
    }
    if (f) ans += n - k;
  }
  FOR(k, 1, n + 1) {
    bool f = true;
    rep(i, n) {
      rep(j, n) {
        if (s[i][(j + k) % n] != s[j][(i + k) % n]) {
          f = false;
        }
      }
    }
    if (f) ans += n - k;
  }
  cout << ans << '\n';






  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

set<int> G[10];

int main(){
    int N,M; cin >> N >> M;
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].insert(b);
        G[b].insert(a);
    }

    vector<int> v(N);
    iota(all(v),0);

    int ans = 0;
    do{
        bool ok = true;
        if(v[0]!=0) continue;
        for(int i=0;i<N-1;i++){
            int s = v[i];
            int t = v[i+1];
            if(!G[s].count(t)){
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }while(next_permutation(all(v)));

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

main() {
	int H[1000], W[1000],i,kkn=0,j,k;
	for (i = 0;i < 10000;i++) {
		scanf("%d %d", &H[i], &W[i]);
		if (H[i] == 0 && W[i] == 0) break;
		kkn++;

	}
	for (i = 0;i < kkn;i++) {
		for (j = 0;j < H[i];j++) {
			for (k = 0;k < W[i];k++) {
				putchar('#');
			}

				putchar('\n');
			}
		
		
		printf("\n");
		
	}
}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define pr pair<int,int>
signed main()
{
    SPEED;
    int a,b;
    cin>>a>>b;
    cout<<a*b;
}

Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Program{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        Console.WriteLine(string.Join(" ",
            Console.ReadLine().Split(' ').Select(s => int.Parse(s)).Distinct().ToArray()));
    }
}



Measured memory_bytes: 34312
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.map!(to!int), a = rd[0], b = rd[1], c = rd[2];
  auto r = iota(a, b+1).count!(i => c % i == 0);
  writeln(r);
}

Measured memory_bytes: 2492
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int R = sc.nextInt();
			int N = sc.nextInt();
			if (R == 0) break;
			int[] H = new int[41];
			for (int i = 0; i < N; ++i) {
				int l = sc.nextInt();
				int r = sc.nextInt();
				int h = sc.nextInt();
				for (int j = l; j < r; ++j) {
					H[j + 20] = Math.max(H[j + 20], h);
				}
			}
			double ans = 1e9;
			for (int i = -R; i < R; ++i) {
				int h = H[i + 20];
				int w = i < 0 ? -i - 1 : i;
				double y = Math.sqrt(R * R - w * w);
				ans = Math.min(ans, R + h - y);
			}
			System.out.printf("%.6f\n", ans);
		}
	}

}

Measured memory_bytes: 26548
/*There's a possibility*/
/*but stop sucking first*/
#define dbg(...) ; 
#define db(...) ; 
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define tst cout<<'*';
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define pf push_front
using namespace std;
 
ll dp[105][100005];
 
int main()
{
    fast;
    ll n,W,i,j,mx=0;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    f(i,1,n+1)
        cin>>w[i]>>v[i];
 
    memset(dp,1e9+7,sizeof(dp));
 
    f(i,1,n+1)
        f(j,1,1e5+5)
        {
            if(j<v[i])
                dp[i][j]=dp[i-1][j];
            else if(j==v[i])
                dp[i][j]=min(w[i],dp[i-1][j]);
            else dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            
            if(dp[i][j]<=W)
                mx=max(mx,j);
            // dbg(i,mx);
        }
    cout<<mx;
}

Measured memory_bytes: 85688
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.server.UnicastRemoteObject;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int d = (n+m)/2;
        if(abs(d-n)==abs(d-m))
            out.println(d);
        else out.println("IMPOSSIBLE");
        
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x, y;
	P(int  x, int y) {
	  this.x=x;
	  this.y=y;
	}
}


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return b-p.b;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21332
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int Q = scanner.nextInt();
    int[] numEnds = new int[N + 1];
    int[] numStarts = new int[N + 1];
    int[][] rails = new int[M][2];
    for (int i = 0; i < M; i++) {
      rails[i][0] = scanner.nextInt();
      rails[i][1] = scanner.nextInt();
    }
    Arrays.sort(rails, Comparator.comparingInt(o -> o[1]));
    int[][] count = new int[N + 1][N + 1];
    for (int i = 0; i < M; i++) {
      int left = rails[i][0];
      int right = rails[i][1];
      for (int j = right; j <= N; j++) numEnds[j]++;
      for (int j = left + 1; j <= N; j++) numStarts[j]++;
      if (N + 1 >= 0) System.arraycopy(numStarts, 0, count[right], 0, N + 1);
    }
    for (int i = 0; i < Q; i++) {
      int p = scanner.nextInt();
      int q = scanner.nextInt();
      System.out.println(numEnds[q] - count[q][p]);
    }
  }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] ab = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long n = ab[0] + ab[1];
            Console.WriteLine(n%2 == 0 ? (n/2).ToString() : "IMPOSSIBLE");
        }
    }
}


Measured memory_bytes: 11348
import sys
input = sys.stdin.readline
from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
gh, gw = map(int, input().split())

s = []
for i in range(h):
   s.append(input().rstrip('\n'))

INF = 10 ** 10
d = [INF] * (h*w)

stack = deque([(ch-1, cw-1, 0)])

nex = []
for i in range(-2, 3):
    for j in range(-2, 3):
        if (i, j) in [(-1,0),(1,0),(0,-1),(0,1),(0,0)]:
            continue
        else:
            nex.append((i,j))

while stack:
    curh, curw, cnt = stack.popleft()
    if d[curh * w + curw] <= cnt:
        continue
    else:
        d[curh * w + curw] = cnt
    for dh, dw in ((-1,0), (1,0), (0,1), (0,-1)):
        nh = curh + dh
        nw = curw + dw
        if nh >= 0 and nh < h and nw >= 0 and nw < w and s[nh][nw] == '.' and d[nh * w + nw] > cnt:
            stack.appendleft((nh, nw, cnt))
    for dh, dw in nex:
        nh = curh + dh
        nw = curw + dw
        if nh >= 0 and nh < h and nw >= 0 and nw < w and s[nh][nw] == '.' and  d[nh * w + nw] > cnt:
            stack.append((nh, nw, cnt+1))

# for item in d:
#     print(item)
gh -= 1
gw -= 1

if d[gh*w + gw] == INF:
    print(-1)
else:
    print(d[gh*w + gw])


Measured memory_bytes: 173772
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

bool comp(str a, str b){
  if(a.size()<b.size()) return true;
  if(a.size()>b.size()) return false;
  int l = a.size();
  REP(i,l){
    if(a[i]<b[i]) return true;
    if(a[i]>b[i]) return false;
  }
  return false;
}

int main(){
  ll cnt[10] = {0,2,5,5,4,5,6,3,7,6};
  ll n,m;
  cin >> n >> m;
  string dp[n+1]; //i本使ってできる整数の最大数
  fill(dp,dp+n+1,"0");
  ll a[m];
  REP(i,m) cin >> a[i];
  dp[0] = "";
  REP(i,n+1){
    REP(j,m){
      if(i-cnt[a[j]]>=0&&dp[i-cnt[a[j]]]!="0") dp[i] = max(dp[i],dp[i-cnt[a[j]]]+char(a[j]+'0'),comp);
    }
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 41728
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
//#define MOD (ll)(998244353)
#define MOD (ll)(1e9+7)
#define INF (1e17)
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
pii exgcd(int a,int b){
    if(a%b==0) return pii(0,1);
    pii p=exgcd(b,a%b);
    return pii(p.S,p.F-a/b*p.S);
}
int fpow(int b,int p){
	b%=MOD;
	int ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}
int MODinv(int n){
    int x=exgcd(n,MOD).F;
    return (x+MOD)%MOD;
}
int modinvP(int n){
	return fpow(n,MOD-2);
}
int fac(int n){
	int ans=1;
	For(i,1,n) ans=(ans*i)%MOD;
	return ans;
}
int nCr(int x,int y){
	int ans=1;
	For(i,1,y) ans=ans*(x-i+1)/i;
	return ans;
}
int nCrM(int x,int y){
	int y1=fac(y);
	int y2=fac(x-y);
	x=fac(x);
	return (x*modinvP(y1)%MOD*modinvP(y2)%MOD);
}

int32_t main() {
#ifdef LOCAL_TEST
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\input.in","r",stdin);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\output.out","w",stdout);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	//code...
	int x,y; cin>>x>>y;
	int a=(x*2-y)/3;
	int b=(y*2-x)/3;
	if((x+y)%3 || a<0 || b<0){
		cout<<0<<"\n";
		return 0;
	}
	cout<<(nCrM(a+b,a))<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)

int selectionSort(int A[], int N){
    int sw = 0;
    rep(i, N - 1){
        int minj = i;
        for(int j = i; j < N; ++j){
            if(A[j] < A[minj]) 
                minj = j;
        }
        if(i != minj){
            swap(A[i], A[minj]);
            ++sw;
        }
    }
    return sw;
}

int main(void){
    int N;    cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    
    int sw = selectionSort(A, N);
    
    rep(i, N - 1) cout << A[i] << " ";
    cout << A[N - 1] << endl;
    cout << sw << endl;
    
    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &p[i]);
    }

    vector<double> k(N);
    for (int i = 0; i < N; i++) {
        k[i] = (p[i] + 1) / 2.0;
    }

    vector<double> S(N);
    S[0] = k[0];
    for (int i = 1; i < N; i++) {
        S[i] = S[i - 1] + k[i];
    }

    double MAX = S[K - 1];
    for (int j = 0; j < N; j++) {
        if (j + K >= N) {
            break;
        }
        double x = S[j + K] - S[j];
        MAX = max(MAX, x);
    }

    printf("%.10lf\n", MAX);

    return 0;
}

Measured memory_bytes: 4096
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-10 16:51:59
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=10000010,mod=998244353;
i64 f[N],F[N],ans;
int n,a,b;
i64 power(i64 a,i64 b,i64 p)
{
	i64 r=1;
	for(;b;b>>=1,a=a*a%p) if(b&1) r=r*a%p;
	return r;
}
i64 C(i64 a,i64 b){ return b>=0&&a>=b?f[a]*F[b]%mod*F[a-b]%mod:0; }
int main()
{
	n=read(); a=read(); b=read(); f[0]=1; a=b-a;
	fr(i,1,n) f[i]=f[i-1]*i%mod;
	F[n]=power(f[n],mod-2,mod);
	fd(i,n,1) F[i-1]=F[i]*i%mod;
	if(!b){ printf("1\n"); return 0; }
	if(b>n){ printf("0\n"); return 0; }
	fr(i,0,b-1) if(i+b<=n)
	{
		if(i+b==n&&b-i==a) ans=(ans+C(b+i-1,b-1)-C(b+i-1,b)+mod)%mod;
		else ans=(ans+(C(b+i-1,b-1)-C(b+i-1,b)+mod)*C(n-b-i-1+(b-a-i+1)-1,n-b-i-1))%mod;
//		printf("%d %d %d %d  %d %d\n",i,int(ans),int(C(b+i-1,b-1)),int(C(b+i-1,b)),n-b-i-1,b-a-i+1);
	}
	// put n-b-i-1 in b-i-a+1
	printf("%d\n",int(ans));
	return 0;
}

Measured memory_bytes: 156416
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,k;
Vi v[2001];
int tot,cnt;
void dfs(int N,int p,int d)
{
	if(d<=k/2)tot++;
	if(d==k/2+1)cnt++;
	if(d>=k/2+1)return;
	for(int next:v[N])
	{
		if(next==p)continue;
		dfs(next,N,d+1);
	}
}
int res(int x)
{
	tot=1;
	int tmp=0;
	for(int next:v[x])
	{
		cnt=0;
		dfs(next,x,1);
		tmp=max(tmp,cnt);
	}
	if(k&1)tot+=tmp;
	return n-tot;
}
int main() {
	scanf("%d%d",&n,&k);
	fup(i,1,n-1,1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	int ans=INF;
	fup(i,1,n,1)ans=min(ans,res(i));
	printf("%d",ans);
}


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{

    class Program
    {
        public static (long m, long s)[,] dp;
        public static long mod;


        static void Main(string[] args)
        {
            checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                var vals = Console.ReadLine().Split(' ')
                    .Select(x => int.Parse(x)).ToList();


                var N = vals[0];


                string ans = "";
                for (int i = 0; i < N; i++)
                {
                    ans += "ACL";
                }

                
                

                Console.WriteLine(ans);

                Console.Out.Flush();
            }//cheked

        }
        
    }

}




Measured memory_bytes: 28148
#include<iostream>
#define ll long long
#define MOD 1000000007

using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    ll int *arr=new ll int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    ll int *dp=new ll int[n+1]();
    for(int i=1;i<=n;i++)
        dp[i]=INT_MAX;
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        for(int j=i-1;j>=max(1,i-k);j--)
        {
            dp[i]=min(dp[i],abs(arr[i-1]-arr[j-1])+dp[j]);
        }
        
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 4616
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main(){
    int a;
    cin >> a;
    string b[a];
    for(int i=0;i<a;i++){
        cin >> b[i];
    }
    for(int i=1;i<a;i++){
        if(b[i-1][b[i-1].size()-1]!=b[i][0]){
            cout << "No" << endl;
            return 0;
        }
        for(int j=0;j<a;j++){
            if(b[i]==b[j] && i != j){
                cout << "No" << endl;
                return 0;
            }
        }

    }
        cout << "Yes" << endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      w: usize,
      wvs: [(usize, usize); n],
    }

    const INF: usize = 1 << 50;
    let max_v = 1_000_00;
    let mut dp = vec![vec![INF; max_v+1]; n+1];
    dp[0][0] = 0;
    for i in 0..n {
        let (iw, iv) = wvs[i];
        for cv in 0..max_v+1 {
            dp[i+1][cv] = min(dp[i+1][cv], dp[i][cv]);
            let nv = cv + iv;
            let nw = dp[i][cv] + iw;
            if nv <= max_v {
                dp[i+1][nv] = min(nw, dp[i+1][nv]);
            }
        }
    }

    for i in (0..max_v+1).rev() {
        if dp[n][i] <= w {
            return puts!("{}\n", i);
        }
    }
    unreachable!()
}


Measured memory_bytes: 106748
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;
 
int main() {
	int n;
    cin >> n;
    vector<string> s(10);
    s[0] = "pon";
    s[1] = "pon";
    s[2] = "hon";
    s[3] = "bon";
    s[4] = "hon";
    s[5] = "hon";
    s[6] = "pon";
    s[7] = "hon";
    s[8] = "pon";
    s[9] = "hon";
    cout << s[n%10] << "\n";
    return 0;
}

Measured memory_bytes: 3632
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ n, k ] <- readInts
	as <- concat <$> replicateM k ( getLine >> readInts )
	let
		m = length $ group $ sort as
	print $ n - m

Measured memory_bytes: 6016
#!/usr/bin/env pypy3

#import numpy as np
#import scipy, scipy.special

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5
from fractions import gcd

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return map(conv, inp().split(sep = sep))

################################################################################

A, P = input_ints()

P += 3 * A
print(P // 2)


Measured memory_bytes: 5508
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e9;
//const ll mod = 1000000007;
ll A[201000];
ll N;

ll f(string S) {
    int idx = -1;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '.') idx = i;
    }
    if(idx == -1) {
        ll tmp = stoll(S);
        tmp *= INF;
        return tmp;
    }
    ll num = S.size() - idx - 1;
    string T = S.substr(0, idx);
    string Q = S.substr(idx+1, num);
    ll tmp = stoll(T);
    for(int i = 0; i < num; i++) tmp *= 10;
    tmp += stoll(Q);
    for(int i = num; i < 9; i++) tmp *= 10;
    return tmp;
}

vector<ll> Div;
ll num[20][20];
ll five[201000], two[201000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) {
        string S;
        cin >> S;
        A[i] = f(S);
        while(A[i] % 2 == 0) {
            A[i] /= 2;
            two[i]++;
        }
        while(A[i] % 5 == 0) {
            A[i] /= 5;
            five[i]++;
        }
        chmin(two[i], 18LL);
        chmin(five[i], 18LL);
        num[two[i]][five[i]]++;
        //cerr << A[i] << " ";
    }
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 20; j++) {
            for(int k = 0; k < 20; k++) {
                if(two[i] + j >= 18 and five[i] + k >= 18) {
                    ans += num[j][k];
                }
            }
        }
        if(2*two[i] >= 18 and 2 * five[i] >= 18) {
            ans -= 1;
        }
    }
    ans /= 2;
    cout << ans << endl;
    //cerr << endl;
    return 0;
}


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

int H, W, K;

int count(std::vector<std::vector<int>>& color) {
    int cnt = 0;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (color[y][x] == 1) {
                cnt++;
            }
        }
    }
    return cnt;
}


int search(int num, std::vector<std::vector<int>> color) {
    if (num == H + W) {
        if (count(color) == K) {
            return 1;
        }
        return 0;
    }
    int cnt = 0;
    cnt += search(num + 1, color);
    if (num < H) {
        for (int x = 0; x < W; x++) {
            color[num][x] = 0;
        }
    } else {
        for (int y = 0; y < H; y++) {
            color[y][num - H] = 0;
        }
    }
    if (count(color) >= K) {
        cnt += search(num + 1, color);
    }
    return cnt;
}


int main() {
    std::cin >> H >> W >> K;

    std::vector<std::vector<int>> c(H, std::vector<int>(W, 0));
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            char val;
            std::cin >> val;
            if (val == '#') {
                c[y][x] = 1;
            }
        }
    }

    int cnt = search(0, c);
    std::cout << cnt << std::endl;
}


Measured memory_bytes: 3628
#n:shinamono no kazu
#m:waribiki maisuu
import heapq

n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
#print(temp)
heapq.heapify(a)
for _ in range(m):
  minA=heapq.heappop(a)
  #print(minA)
  heapq.heappush(a,minA/2.0)
  #print(a)
#print(a)
result=0
for item in a:
  result+=item*(-1)//1
  
print(int(result))


Measured memory_bytes: 92312
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		sc.close();

		int end = b - a;
		int west = (1 + end - 1) * (end - 1) / 2;
		int east = (1 + end) / 2;

		System.out.println(west - a);
	}

}

Measured memory_bytes: 23124
package main

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

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var h, w int
	fmt.Fscanf(in, "%d%d", &h, &w)

	a := make([][]int, h)

	for i := range a {
		a[i] = make([]int, w)
		for j := range a[i] {
			fmt.Fscanf(in, "%d", &a[i][j])
		}
	}

	ans := []string{}

	for i := 0; i < h-1; i++ {
		for j := range a[i] {
			if a[i][j]%2 == 1 {
				a[i][j]--
				a[i+1][j]++
				s := fmt.Sprint(i+1, j+1, i+2, j+1)
				ans = append(ans, s)
			}
		}
	}

	i := h - 1
	for j := 0; j < w-1; j++ {
		if a[i][j]%2 == 1 {
			a[i][j]--
			a[i][j+1]++
			s := fmt.Sprint(i+1, j+1, i+1, j+2)
			ans = append(ans, s)
		}
	}

	fmt.Fprintln(out, len(ans))
	for i := range ans {
		fmt.Fprintln(out, ans[i])
	}
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e[200101],dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[200310];
int l[200111];
int j[200331];

long long x,y,z,mod=1000000007;
//string r;
char r[2];

P u[1];
queue<int> q;
//stack<int> s;
set<int> s;
map<int,int> p;

vector<int> v1[200010],v[200101];


bool as(P a,P b)
{
  return a.x<b.x;
}

int up(int n)
{
  if(j[n]==n) return n;
  return j[n]=up(j[n]);
}

int f(int ee)
{
  memset(l,-1,sizeof(l));
  for(int t=1;t<=a;t++)
    if(o[t]==0)
    {
      //
     q.push(t);
    }
  for(;q.size();q.pop())
  {
    for(int t=0;t<=v1[q.front()].size();t++)
      e[t]=0;
    if(q.front()==c&&ee>=0) e[v1[q.front()].size()+1]=0,e[ee]=1;
    for(int t=0;t<v1[q.front()].size();t++)
    if(l[v1[q.front()][t]]>=0) e[l[v1[q.front()][t]]]=1;
    for(int t=0;;t++)
    if(!e[t])
    {
      l[q.front()]=t;
      break;
    }
    for(int h=0;h<v[q.front()].size();h++)
    {
      o[v[q.front()][h]]--;
      if(o[v[q.front()][h]]==0) q.push(v[q.front()][h]);
    }
  }
  //for(int t=1;t<=a;t++)
  //printf("%d ",l[t]);
  //puts("");
  if(l[c]==l[d]){
  b=l[d];
  return 0;}
  if(ee==-1||l[d]==ee)
  return 1;
  return 0;
}

int main()
{
  scanf("%d",&a);
  iota(j+1,j+a+1,1);
  for(int t=1;t<=a;t++)
  {
    scanf("%d",&n);
    if(up(n)!=up(t))
    {
      o[n]++,j[up(n)]=up(t);
      v[t].push_back(n);
      v1[n].push_back(t);
    }
    else c=n,d=t;
  }
  if(f(-1))
  {
    puts("POSSIBLE");
    return 0;
  }
  //printf("%d %d %d\n",b,c,d);
  for(int t=1;t<=a;t++)
  for(int h=0;h<v[t].size();h++)
    o[v[t][h]]++;
  if(f(b))
  {
    //printf("%d %d %d\n",l[1],l[2],l[3]);
   puts("POSSIBLE");
  }
  else puts("IMPOSSIBLE");
  
}



//3


Measured memory_bytes: 24064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
struct node
{
	int time,step;
	int x,y;
}fam[100005];
bool f=1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d %d",&fam[i].time,&fam[i].x,&fam[i].y);
		fam[i].step=fam[i].x+fam[i].y;
		if(fam[i].step<=fam[i].time) 
		{
			if((fam[i].step%2!=0&&fam[i].time%2!=0)||(fam[i].step%2==0&&fam[i].time%2==0));
			else f=0;
		}
		else {printf("No\n");return 0;}
	}
	if(!f) printf("No\n");
	else printf("Yes\n");	
}


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

using namespace std;

#define FOR(i, a) for(int i = 0; i < (int) a; i++)
#define all(v) v.begin(), v.end()
#define f first
#define s second

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


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

	int h, n; cin >> h >> n;
	vi a(n), cost(n);
	FOR(i, n) cin >> a[i] >> cost[i];

	vi dp(h+1, 1e9);

	dp[0] = 0;

	for(int i = 0; i <= h; i++){
		for(int j = 0; j < n; j++){
			if(i-a[j] >= 0){
				dp[i] = min(dp[i], dp[i-a[j]] + cost[j]);
			}else{
				dp[i] = min(dp[i], cost[j]);
			}
		}
	}

	cout << dp[h] << '\n';	

	return 0;
}


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

using namespace std;
#define int long long
#define INF ((10e9)+7)
#define pb push_back
int H,W;
int call(int i,int j,vector<vector<int> >& dp,vector<string> &V )
{
    if(i<0 || i>=H || j<0 || j>=W) return 0;
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    
    dp[i][j]=0;
    if(V[i][j]=='#')
    return 0;
    
    int m=0;
    m+=call(i+1,j,dp,V);
    m=m%(1000000000+7);
    m+=call(i,j+1,dp,V);
    m=m%(1000000000+7);
    return dp[i][j]=(m);
    
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>H>>W;
    vector<string> V(H);
    for(int i=0;i<H;i++)
    cin>>V[i];
    
    vector<vector<int> >dp(H,vector<int>(W,-1) );
    
    dp[H-1][W-1]=1;
    //dp[0][0]=-1;
    cout<<call(0,0,dp,V);
    
    
    
    return 0;
    
}

Measured memory_bytes: 9344
#include<stdio.h>
#include<string.h>
#define LEN 100005
  
typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN + 1];
int head=1, tail, n;

void enqueue(P x){
  Q[tail] = x;
  
  if(tail >= LEN){
    tail=0;
  }
  
  else{
    
    tail++;
  }
  
}

P dequeue(){
  P y;
  y = Q[head];
  
  if(head >= LEN){
    head = 0;
  }
  
  else{
    
    head++;
  } 
  return y;
}


int main(){
  int i, q;
  int time=0;
  scanf("%d %d", &n, &q);
  tail=n+1;
  
  for (i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  while (head != tail){
    if (Q[head].t > q){
      Q[head].t -= q;
      time += q;
      enqueue(dequeue(Q[head]));
    }
    else if (Q[head].t <= q){
      time += Q[head].t;
      printf("%s %d\n",Q[head].name,time);
      dequeue(Q[head]);
    }
  }
  
  return 0;
}

Measured memory_bytes: 10756
/*input
codeforces
atcoder
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m,c;




void solve()
{
    string a,b;

    cin>>a>>b;
int ans=INT_MAX;
    for(i=0;i<=a.size()-b.size();i++)
    {
        int temp=0;
        for(j=0;j<b.size();j++)
        {
            if(b[j]!=a[i+j])
            {
                temp++;
            }




        }
        ans=min(ans,temp);

        }
   cout<<ans;

    }

 
 
 
signed main()
{// inputFile;


    fast;
    int T = 1;
    // cin >> T;
    ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,n;
  cin>>x>>n;
  int a=x;
  int A=x;
  vector<int> p(n);
  for(int i=0;i<n;i++)cin>>p.at(i);
  if(n==0){
    cout<<x<<endl;
    return 0;
  }else{
  int ans1,ans2,ANS;
  sort(p.begin(),p.end());
  for(;;){
    bool ok=true;
    for(int i=0;i<n;i++){
      if(p.at(i)==x)ok=false;
    }
    if(ok){
      ans1=x;
      break;
    }else{
      x++;
    }
  }
  for(;;){
    bool ok=true;
    for(int i=0;i<n;i++){
      if(p.at(i)==a)ok=false;
    }
    if(ok){
      ans2=a;
      break;
    }else{
      a--;
    }
  }
  if(ans1-A>=A-ans2){
    ANS=ans2;
  }else{
    ANS=ans1;
  }
  cout<<ANS<<endl;
  return 0;
  }
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
    int n,a,b,c;
    while(~scanf("%d",&n))
    {
        if(100<=n&&n<=999)
        {
              a=n/100;
            b=n%100/10;
            c=n%10;
            if(n==c*100+b*10+a)
                printf("Yes");
            else printf("No");
        }
    }
}


Measured memory_bytes: 128