akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    for(int i = 0; i <= n; i++){
        for( int j = 0; j <= m; j++){
           if(k == (i * m + j * n - 2 * i*j)){
            printf("Yes");
            return 0;
           }
        }
    }

    printf("No");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define inf 1145141919

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}

int main(void){
    int a,n,x[16]={0},i,res=0,res2=0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++){
        scanf("%d",&a);
        x[(a/400)]++;
    }
    for(i = 0;i <= 15;i++){
        if(i<=7){if(x[i] != 0){res++;}}
        else{res2+=x[i];}
    }
    printf("%d %d\n",max(res,1),res+res2);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INF (1e9)
#define N 1005
using namespace std;

int main(){
  int n,a[N];
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++)
      cin>>a[i];
    sort(a,a+n);
    int ans=INF;
    for(int i=0;i<n-1;i++)
      ans=min(ans,a[i+1]-a[i]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3152
k, s = map(int, input().split())
def two_sum(k, s):
    if s < 0:
        return 0
    elif k >= s:
        return s + 1
    elif s//2 > k:
        return 0
    else:
        return s + 1 - 2 * (s - k)

ans = 0
for x in range(k+1):
    ans += two_sum(k, s - x)
print(ans)

Measured memory_bytes: 9160
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  int a, b, c; cin >> a >> b >> c;
  if(a == b && a != c) cout << "Yes" << endl;
  else if(a == c && a != b) cout << "Yes" << endl;
  else if(b == c && b != a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second

const int maxn = 1e5 + 12, lg = 20;
int n, par[maxn], cnt;
set <int> ad[maxn];
vector <pair <int, int> > q;
map <pair <int, int>, int> mp;

void add(int a, int b) {
	mp[make_pair(a, b)]++;
	mp[make_pair(b, a)]++;
	ad[a].insert(b);
	ad[b].insert(a);
	if(mp[make_pair(a, b)] == 2) q.push_back(make_pair(a, b));
	return;
}

int getpar(int a) {
	if(par[a] == a) return a;
	par[a] = getpar(par[a]);
	return par[a];
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) par[i] = i;
	for (int i = 0; i < 2 * (n - 1); i++) {
		int u, v;
		cin >> u >> v;
		v--, u--;
		add(u, v);
	}
	while(cnt < q.size()) {
		if(q.size() >= n) return cout << "NO\n", 0;
		int u, v;
		u = q[cnt].F, v = q[cnt].S, cnt++;
		v = getpar(v), u = getpar(u);
		if(u == v) continue;
		if(ad[u].size() < ad[v].size()) swap(u, v);
		par[v] = u;
		ad[u].erase(v);
		while(ad[v].size()) {
			int x = *ad[v].begin();
			ad[v].erase(x);
			ad[x].erase(v);
			if (x == u) continue;
			mp[make_pair(x, v)] = mp[make_pair(v, x)] = 0;
			add(x, u);
		}
	}
	if(q.size() == n - 1) return cout << "YES", 0;
	return cout << "NO", 0;
}


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

ll dp[501][501];
ll sum[501];

ll get(int l, int r) {
    ll ret = sum[r];
    if (l) ret -= sum[l-1];
    return ret;
}

ll solve(int l, int r) {
    ll& ret = dp[l][r];
    if (l == r) return ret = 0;
    else if (ret != 1e15) return ret;

    ret = 1e15;
    for (int m=l; m<r; ++m) {
        ret = min(ret, solve(l, m) + solve(m+1, r) + get(l, r));
    }

    return ret;
}

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    fill(dp[0], dp[N], 1e15);

    rep(i, N) {
        sum[i] = A[i];
        if (i>0) sum[i] += sum[i-1];
    }

    cout << solve(0, N-1) << endl;
    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  ll a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(a[0]%2==a[1]%2){
    cout<<a[2]-a[1]-a[0]+(a[1]+a[0])/2+(a[1]+a[0])%2<<endl;
  }else{
    cout<<a[2]-a[1]-a[0]+(a[1]+a[0])/2+(a[1]+a[0])%2+1<<endl;
  }

  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <queue>
using namespace std;
int K;
int count;
bool check(){
    if(K==count){
        return true;
    }else{
        return false;
    }
}

int main(){
    cin >> K;
    count =0;
    queue<long long > que;
    for(int i=1;i<10;i++){
        que.push(i);
    }
    while(true){
        long long k=que.front();
        count++;
        que.pop();
        if(check()){
            cout << k <<endl;
            return 0;
        }
        if(k%10!=0){
            que.push(10*k+k%10-1);
        }
        que.push(10*k+k%10);
        if(k%10!=9){
            que.push(10*k+k%10+1);
        }
    }
    return 0;
}

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

int main() {

int N;cin >> N;
vector<int64_t> A(N+1);
  A.at(0)=2;A.at(1)=1;

for (int i;i<N-1;i++){
  A.at(i+2)=A.at(i)+A.at(i+1);
}

cout << A.at(N) << endl;

}

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

int main(){
    int N; cin >> N;
    double ans;
    int input;
    for( int i = 0; i < N; i++ ){
        cin >> input;
        ans += (double)1/input;
    }
    cout << fixed << setprecision(10);
    cout << 1/ans << endl;
}

Measured memory_bytes: 256
#include"iostream"
#include<vector>
using namespace std;
long long cnt = 0;
vector<int>G;
void shellsort(int num[], int n);
void insertionsort(int num[], int n, int g);
int main()
{
	int n;
	cin >> n;
	int*num = new int[n];
	int i;
	for (i = 0; i < n; ++i)
	{
		cin >> num[i];
	}
	shellsort(num, n);
	delete[]num;
	return 0;
}
void shellsort(int num[],int n)
{
	int i;
	for (int h = 1;;)
	{
		if (h > n)break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (i = G.size()-1; i>=0; --i)
		insertionsort(num, n, G[i]);
	cout << G.size()<< endl;
	for (i = G.size() - 1; i >= 0; --i)
	{
		cout << G[i];
		if (i)cout << ' ';
	}
	cout << endl << cnt << endl;
	for (i = 0; i < n; ++i)
		cout << num[i] << endl;
}
void insertionsort(int num[], int n,int g)
{
	int i, j;
	int key;
	for (i = g; i < n; i++)
	{
		key = num[i];
		j = i - g;
		while (j >= 0 && num[j] > key)
		{
			num[j + g] = num[j];
			j-=g;
			cnt++;
		}
		num[j + g] = key;
	}
}


Measured memory_bytes: 6708
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll N;
    cin >> N;
    map<string, int> C;
    string str;
    rep(i, N){
        cin >> str;
        C[str]++;
    }
    str = "AC";
    cout << str << " x " << C[str] << endl;
    str = "WA";
    cout << str << " x " << C[str] << endl;
    str = "TLE";
    cout << str << " x " << C[str] << endl;
    str = "RE";
    cout << str << " x " << C[str] << endl;
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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

    // n > m とする
    if (n < m) swap(n, m);

    ll ans = 0;
    if (n - m > 1) {
        cout << ans << endl;
        return 0;
    } else {
        ++ans;
        for (int i = n; i >= 1; i--) {
            ans *= i;
            ans %= MOD;
        }
        for (int j = m; j >= 1; j--) {
            ans *= j;
            ans %= MOD;
        }

        if (n == m) {
            ans *= 2;
            ans %= MOD;
        }
        cout << ans << endl;
    }
}


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

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

     int diff=abs(a-b);

     if(diff%2==0){
          int ans=(diff)/2;
          cout<<ans;
          return 0;
     }
    
     int ans=min(a+(b-a-1)/2, n-b+1+(n-(a+(n-b+1)))/2);
     cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 102;
int h,w,n,a[N*N],ans[N][N];

int main(){
    read3i(h,w,n);
    lp(i,1,n) readi(a[i]);

    int curr = 1;
    lp(i,1,h){
        if(i&1) lp(j,1,w) ans[i][j] = curr, curr += !--a[curr];
        else lpd(j,w,1) ans[i][j] = curr, curr += !--a[curr];
    }
    lp(i,1,h){
        lp(j,1,w) printf("%d ",ans[i][j]);
        puts("");
    }
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);
*/


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
int main(){
    int n,m,x,a,l=0,r=0;
    scanf("%d%d%d",&n,&m,&x);
    for(int i=0;i<m;i++){
        scanf("%d",&a);
        if(a<x)l++;
        else r++;
    }
    printf("%d",std::min(l,r));
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int r, g, b, k;
    
    scanf("%d%d%d%d", &r, &g, &b, &k);
    
    rep(i, k){
        if (r>=g) {
            g=g*2;
        } else if (g>=b) {
            b=b*2;
        }
    }
    
    if (r<g&&g<b) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
static const int NMAX = 100000;
static const int INF = (1<<30)-1;
ll N,X,x[NMAX+1];

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

int main(){
  cin >> N >> X;
  for(int i=0;i<N;i++) cin >> x[i];

  ll d,dmin = INF;

  if(N==1) dmin = abs(x[0]-X);

  for(int i=0;i<N-1;i++){
    d = gcd(abs(x[i+1]-X),abs(x[i]-X));
    if(d < dmin) dmin = d;
  }
  cout << dmin << endl;
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[]str = Console.ReadLine().Split();
		int M = int.Parse(str[0]);
		int K = int.Parse(str[1]);
		int M2 = (int)Math.Pow(2,M);
		if(K>=M2){
			Console.WriteLine("-1");
		} else if(M==1 && K==1){
			Console.WriteLine("-1");
		} else if(K==0){
			Console.Write("0 0");
			for(var i=1;i<M2;i++){
				Console.Write(" "+i+" "+i);
			}
		} else {
			Console.Write("0");
			for(var i=1;i<M2;i++){
				if(i!=K){
					Console.Write(" "+i);
				}
			}
			Console.Write(" "+K);
			for(var i=M2-1;i>=0;i--){
				if(i!=K){
					Console.Write(" "+i);
				}
			}
			Console.Write(" "+K);
		}
	}
}

Measured memory_bytes: 16828
#include<stdio.h>
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main()
{
	int a,b,g,lcm;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		g=gcd(a,b);
		lcm=a/g*b;
		printf("%d %d\n",g,lcm);
	}
	return 0;
}


Measured memory_bytes: 2032
// D - 3N Numbers
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VL = vector<ll>;
#define rp(i,n) for(int i=0;i<(n);++i)
#define NMAX 100000

int N;
VL A(3*NMAX);

void f(VL &V, ll sign){
	V[0] = A[0];
	priority_queue<int> que;
	que.push(sign*A[0]);
	for(int i=1; i<3*N; ++i){
		que.push(sign*A[i]);
		ll topA = 0;
		if(que.size() > N){
			topA = sign*que.top();
			que.pop();
		}
		V[i] += V[i-1] + A[i] - topA;
	}
}

int main(){
	cin>>N;
	rp(i, 3*N) cin>>A[i];

	VL F(3*N), B(3*N);
	f(F, -1L);
	reverse(A.begin(), A.begin()+3*N);
	f(B, 1L);

	ll maxfb = LLONG_MIN;
	rp(i, N+1){
		int f = N - 1 + i;
		int b = 3*N - 1 - N - i;
		maxfb = max(maxfb, F[f]-B[b]);
	}
	cout<< maxfb <<endl;
}

Measured memory_bytes: 8180
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> H >> W;
	vector< string > grid(H);
	rep(i, H) cin >> grid[i];
	vector< vector< int > > A(H, vector< int >(W, 0)), B(W, vector< int >(H, 0));
	rep(_, 2) {
		rep(i, H) {
			int l = -1;
			rep(j, W + 1) {
				char c;
				if (j < W) {
					if (_)
						c = grid[j][i];
					else
						c = grid[i][j];
				}
				if (j >= W || c == '#') {
					for (int k = l + 1; k < j; k++)
						A[i][k] = j - l - 1;
					l = j;
				} else {
				}
			}
		}
		swap(W, H);
		swap(A, B);
	}
	int ans = 0;
	rep(i, H) rep(j, W) if (grid[i][j] == '.') chmax(ans, A[i][j] + B[j][i] - 1);
	//cout << A << B;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 67072
#include<iostream>
#include<algorithm>
#include<utility>

#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define P pair<int, int>

using namespace std;

char field[12][12];
int cnt;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
char depth;

void dfs(int x,int y){
	/*
	rep(i, 12){
		rep(j, 12){
			
			if (field[i][j] == '1'){
				cout << field[i][j];
			}
			else{
				cout << field[i][j];
			}

			if (j == 11){
				cout << endl;
			}
		}
	}
	cout << endl;
	*/

	field[x][y] = '0';
	rep(i, 4){		
		int ddx = x + dx[i], ddy = y + dy[i];
		if (0<=ddx && ddx<12 && 0<=ddy && ddy<12 && field[ddx][ddy] == '1'){
			dfs(ddx, ddy);
		}
		
	}
	

}


int main(){
	while (1){
		cnt = 0;
		rep(i, 12){
			rep(j, 12){
				char c;
				cin >> c;
				if(cin.eof()){
					return 0;
				}
				field[i][j] = c;
				/*if (j == 11){
					char EnTeR;
					cin >> EnTeR;
				}*/
			}
		}

		/*
		rep(i, 12){
			rep(j, 12){
				if (field[i][j] == '1'){
					cout << "テ「ツ鳴?;
				}
				else{
					cout << "テ「ツ鳴。";
				}

				if (j == 11){
					cout << endl;
				}
			}
		}
		*/


		rep(i, 12){
			rep(j, 12){
				if (field[i][j] == '1'){
					cnt++;
					dfs(i, j);
				}
			}
		}

		cout << cnt << endl;



	}

	
}

Measured memory_bytes: 1140
import java.io.*;
import java.util.*;
import java.math.*;
class Main
{ 
    public static final int M = 1000000007;
    public static void main(String[] args)throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] s = br.readLine().split(" ");  
        int[] a = new int[s.length];
        for(int i=0;i<s.length;i++)
            a[i]=Integer.parseInt(s[i]);
        Arrays.sort(a);
        int sum=0;
        for(int i=1;i<s.length;i++)
            sum+=a[i]-a[i-1];
        out.println(sum);
        out.flush();
        
    }
    /** Loops
    *   i: for(int i=0;i<n;i++)
    *   j: for(int j=0;j<n;j++)
    *   k: for(int k=0;k<n;k++)

    *   ArrayList<Integer> arr1 = new ArrayList<>();
    
    *   HashMap
    *   HashMap<Integer, Integer> hm = new HashMap<>();
    *   for (Map.Entry<String,String> entry : hm.entrySet()) 
            out.println(entry.getValue());
    
    *   Count frequencies
        for(int i=0;i<n;i++)
        {
            Integer c = hm.get(Integer.parseInt(s[i]));
            if(c==null)
                hm.put(Integer.parseInt(s[i]),1);
            else
                hm.put(Integer.parseInt(s[i]),++c);
        }
    **/     
    public static long modularExpo(long x,long n,int M)
    {
        long result=1;
        while(n>0)
        {
            if(n%2==1)
                result=(result*x)%M;
            x=(x*x)%M;
            n=n/2;
        }   
        return result;                                              
    }
    //FLT, only when a and M are co-prime
    public static long modInverse(int a,int M)
    {
        long g = gcd(a,M);
        if(g!=1)
            return -1;
        return modularExpo(a,M-2,M);
    }
    public static long gcd(int a, int b) 
    {
        if(b==0)
            return a;
        else
            return gcd(b, a % b);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  int n;
  cin >> n;
  vector<P> a(n,P(0,0));
  rep(i,n){
    cin >> a[i].first;
    a[i].second=i+1;
  }
  sort(a.begin(),a.end());
  FOR(i,0,n){
    cout << a[i].second << " ";
  }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int n, k, ans = 1e9;
int ban[10];
void dfs(int x, int b) {
	if(b > 1000000) {
		return;
	}
	if(x >= n) {
		ans = min(ans, x);
		return;
	}
	for(int i = 0; i < 10; ++i) {
		if(!ban[i]) {
			dfs(x + i * b, b * 10);
		}
	}
}
int main() {
	cin >> n >> k;
	for(int i = 0; i < k; ++i) {
		int x;
		cin >> x;
		ban[x] = 1;
	}
	dfs(0, 1);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, M, C = map(int, input().split())
    B = [int(b) for b in input().split()]
    count = 0
    for i in range(N):
        A = [int(a) for a in input().split()]
        point = C
        for i, a in enumerate(A):
            point += a * B[i]
        if point > 0: count += 1
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9044
#include <iostream>
#include <vector>
using namespace std;
#define MAX 1

std::vector<bool> IsPrime;

void sieve(size_t num) {
  if (num + 1 > IsPrime.size()) {  // resizeで要素数が減らないように
    IsPrime.resize(num + 1, true);  // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false;  // 0は素数ではない
  IsPrime[1] = false;  // 1は素数ではない

  for (size_t i = 2; i * i <= num; ++i)      // 0からsqrt(max)まで調べる
    if (IsPrime[i])                          // iが素数ならば
      for (size_t j = 2; i * j <= num; ++j)  // (max以下の)iの倍数は
        IsPrime[i * j] = false;              // 素数ではない
}

int main() {
  int x;
  cin >> x;
  sieve(110000);
  for (int i = x; i < 110000; i++) {
    if (IsPrime[i]) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

class unionfind
{
public:
  vector<int> parent;

  unionfind(int N)
  {
    parent = vector<int>(N, -1);
  }

  int root(int X)
  {
    if (parent.at(X) < 0) return X;
    return parent.at(X) = root(parent.at(X));
  }

  int size(int X)
  {
    return -parent.at(root(X));
  }

  bool unite(int X, int Y)
  {
    int x = root(X);
    int y = root(Y);
    if (x == y) return false;
    
    if (size(x) < size(y)) swap(x, y);
    parent.at(x) += parent.at(y);
    parent.at(y) = x;
    return true;
  }
};

signed main()
{
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for (int i = 0; i < N; i++)
  {
    int p;
    cin >> p;
    P.at(i) = p - 1;
  }

  unionfind uf(N);

  for (int i = 0; i < M; i++)
  {
    int x, y;
    cin >> x >> y;
    x--; y--;
    uf.unite(x, y);
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (uf.root(i) == uf.root(P.at(i))) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include "includes.h"
//#include <iostream>
//#include <>
using namespace std;
//using P = pair<long long, long long>;
typedef long long ll;
#define INF 10000000000000
//typedef struct edge{
//    ll from;
//    ll to;
//    ll cost;
//} edge;
//
int main() {
  	ll x, y, t;
  	cin >> x >> y;
  	ll ans[10][10];
  	ll data[x][y];
  	ll result = 0;
  	for(int i=0;i<10;i++) {
  		for(int j=0;j<10;j++) {
          	cin >> ans[i][j]; 
        }
	}
  	//for(int i=0;i<ed;i++) {
    //	cin >> s >> t >> d;
    //  	ans[s][t] = d;
    //}
  
  	for(int k=0;k<10;k++) {
    	for(int i=0;i<10;i++) {
        	for(int j=0;j<10;j++) {
              	if(ans[i][k] != INF && ans[k][j] != INF) {
            		ans[i][j] = min(ans[i][j], ans[i][k]+ans[k][j]);
                }
            }
        }
    }
  	for(int i=0;i<x;i++) {
    	for(int j=0;j<y;j++) {
        	cin >> t;
          	if(t==-1) continue;
          	result += ans[t][1];
          	//cout << result << endl;
        }
    }
  	cout << result << endl;
}

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

int main(){
  int n;
  while(scanf("%d\n", &n)){
    int asum = 0, bsum = 0, a[10000], b[10000];
    if(n == 0) return 0;

    for(int i = 0;i < n;i++) scanf("%d %d\n", &a[i], &b[i]);
    for(int i = 0;i < n;i++){
      if(a[i] > b[i]) asum += a[i]+b[i];
      else if(a[i] < b[i]) bsum += a[i]+b[i];
      else {
         asum += a[i];
         bsum += b[i];
      }
   }
   printf("%d %d\n", asum, bsum);
  }
}



Measured memory_bytes: 3188
n, m = tuple(map(int, raw_input().split()))
x = sorted(list(map(int, raw_input().split())))
y = [list(map(int, raw_input().split())) for i in range(m)]
y.sort(key = lambda x: x[1], reverse=True)
y_pos = 0
for index, value in enumerate(x):
  b = y[y_pos][0]
  c = y[y_pos][1]
  if value < c:
	  x[index] = c
	  y[y_pos][0] = b-1
	  if b == 1:
		  y_pos += 1
		  if y_pos == len(y):
			  break
  else:
	  break

print(sum(x))


Measured memory_bytes: 29500
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <limits.h>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    map<long, int> zatsu;
    vector<pair<long, long>> points;
    for (int i=0; i<n; i++) {
        long x, y;
        cin >> x >> y;
        zatsu[x] = zatsu[y] = 1;
        points.push_back({x, y});
    }
    int cnt = 0;
    vector<long> zinv(1, 0);
    for (auto &z:zatsu) {
        z.second = ++cnt;
        zinv.push_back(z.first);
    }
    int rui[105][105]{{0}};
    for (auto &p:points)
        rui[zatsu[p.first]][zatsu[p.second]] = 1;
    for (int i=1; i<=cnt; i++)
        for (int j=1; j<=cnt; j++)
            rui[i][j] += rui[i-1][j] + rui[i][j-1] - rui[i-1][j-1];
    long ans = LONG_MAX;
    for (int xi=1; xi<=cnt; xi++) {
        for (int yi=1; yi<=cnt; yi++) {
            for (int xj=xi; xj<=cnt; xj++) {
                for (int yj=yi; yj<=cnt; yj++) {
                    int inside = rui[xi-1][yi-1] + rui[xj][yj] - rui[xi-1][yj] - rui[xj][yi-1];
                    if (inside >= k)
                        ans = min(ans, (zinv[xj] - zinv[xi]) * (zinv[yj] - zinv[yi]));
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std ;
int main()
{
	int x;
	scanf("%d", &x);
 	  if(x<1200)
 	  {
	    cout<<"ABC"	;
	  }
	  else
	  {
	  	cout<<"ARC"	;
	  }
	    
	
} 

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

int main() {
	// your code goes here
	int N;
	cin >>N;
	int A;
	long plus=1;
	long minus =1;
	for(int i=0; i<N; i++){
		cin >>A;
		plus*=3;
		if(A%2==0){minus*=2;}
	}
	cout << plus - minus <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll X;
    cin >> X;
    ll ans = 0;
    ll t = 100;
    while(t<X){
        t = t + t*0.01;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h> 
using namespace std;
#define LL long long


int main() 
{ 
    int n;
    cin>>n;
    int m=(n/500)*1000;
    n=n-(n/500)*500;
    int x=(n/5)*5;
    n=n-x;
    (n==1)? cout<<m+x<<"\n":cout<<m+x<<"\n";
	return 0; 
} 


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() 
{
	int n,i;
	cin >> n;
	for(i=1;i<100000;i++){
		if(i*i>n){
			break;
		}
	} 	
	cout << (i-1)*(i-1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    vector<int> num(200), numodd;
    rep(i, 200) {
        num[i] = ((i + 1) * (i + 2) * (i + 3)) / 6;
        if (num[i] % 2) numodd.push_back(num[i]);
    }
    int len = (int)numodd.size();

    vector<int> dp1(1000001, 1e9);
    vector<int> dp2(1000001, 1e9);
    dp1[0] = 0;
    dp2[0] = 0;

    rep(i, 200) {
        repd(j, num[i], 1000001) {
            chmin(dp1[j], dp1[j - num[i]] + 1);
        }
    }

    rep(i, len) {
        repd(j, numodd[i], 1000001) {
            chmin(dp2[j], dp2[j - numodd[i]] + 1);
        }
    }


    while (1) {
        int N;
        cin >> N;
        if (N == 0) break;
        cout << dp1[N] << " " << dp2[N] << endl;
    }
    return 0;
}


Measured memory_bytes: 10504
num = gets.to_i
arr = gets.split.map(&:to_i)
dp = Array.new(num, Float::INFINITY)
dp[0] = 0

(num-1).times do |i|
	dp[i+1] = [(arr[i] - arr[i+1]).abs + dp[i], dp[i+1]].min
	if dp[i+2]
		dp[i+2] = [(arr[i] - arr[i+2]).abs + dp[i], dp[i+2]].min
	end
end

p dp[-1]

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

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;
const int MAX_V = 1e5 + 1;

struct edge {
    int to, cost;
};

int color[MAX_V];
vector<edge> G[MAX_V];

bool visited[MAX_V];

void dfs(int current, int cost, int prev) {
    visited[current] = true;
    // cout << current << " " << cost << " " << prev << endl;
    if (cost == -1) {
        color[current] = 0;
    } else {
        color[current] = (cost % 2) ? (color[prev] ^ 1) : color[prev];
    }
    rep(G[current].size(), i) {
        int next = G[current][i].to;
        if (visited[next]) {
            continue;
        }
        dfs(next, G[current][i].cost, current);
    }
}

edge make_edge(int to, int cost) {
    edge res;
    res.to = to;
    res.cost = cost;
    return res;
}

signed main() {
    int n;
    cin >> n;
    rep(n - 1, i) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u].push_back(make_edge(v, w));
        G[v].push_back(make_edge(u, w));
    }
    fill(visited, visited + n + 1, false);
    dfs(1, -1, 0);
    
    rep2(1, n + 1, i) {
        cout << color[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10240
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		int N = sc.nextInt();
		for(int i = 0; i < N; i++) {
			int r = 0;
			int p = 0;
			int o = 0;
			for(;;) {
				String s = sc.next();
				if(s.equals("HIT")) {
					r++;
					if(r >= 4) {
						p += r - 3;
						r = 3;
					}
				}
				else if(s.equals("HOMERUN")) {
					p += 1 + r;
					r = 0;
				}
				else if(s.equals("OUT")) {
					o++;
				}
				if(o == 3) break;
			}
			System.out.println(p);
		}
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
 
// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
using namespace __gnu_pbds;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const int INF = 1e16;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9 + 7;

int dp[102][100005];

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, k;
    cin >> n >> k;
    vector<int> v(n+1);
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    dp[0][0] = 1;
    vector<int> pref(k+1);
    for(int i = 1; i <= n; i++)
    {
        pref[0] = dp[i-1][0];
        for(int s = 1; s <= k; s++)
        {
            pref[s] = pref[s-1] + dp[i-1][s];
            pref[s] %= mod;
        }
        for(int j = 0; j <= k; j++)
        {
            dp[i][j] = pref[j] - (j > v[i] ? pref[j-v[i]-1] : 0);
            if(dp[i][j] < 0)
                dp[i][j] += mod;
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}

Measured memory_bytes: 79232
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int count = 0;
        for (int i = 100; i >= 1; i--) {
            if (a % i == 0 && b % i == 0)
                count++;
            if (count == k) {
                System.out.println(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

using mint = modint998244353;
using vm = vector<mint>;

int main() {
  int n;
  cin >> n;
  int n2 = n*2;
  vector<int> a;
  {
    map<int, int> mp;
    rep(i, n2) {
      int h;
      cin >> h;
      mp[h]++;
    }
    for (P p : mp) a.push_back(p.second);
  }

  vm f(n2+1);
  vm finv(n2+1);
  vm f2(n+1);
  {
    f[0] = 1;
    rep(i, n2) f[i + 1] = f[i]*(i+1);
    finv[n2] = 1/f[n2];
    for (int i=n2; i>=1; --i) finv[i-1] = finv[i] * i;
    f2[0] = 1;
    rep(i, n) f2[i+1] = f2[i] * (i*2 + 1);
  }

  int m = a.size();
  vector<vm> d(m);
  rep(i, m) {
    int na = a[i];
    int e = na/2;
    d[i] = vm(e+1);
    rep(j, e+1) {
      d[i][j] = f[na] * f2[j] * finv[na - 2*j] * finv[2*j];
    }
  }

  while(d.size() > 1) {
    vector<vm> pd;
    swap(d, pd);
    for (int i=0; i<pd.size(); i+=2) {
      int j = i+1;
      if (j >= pd.size()) {
        d.emplace_back(pd[i]);
        break;
      }
      d.emplace_back(convolution(pd[i], pd[j]));
    }
  }

  mint ans;
  rep(i, d[0].size()) {
    mint now = d[0][i] * f2[n-i];
    if (i%2 == 1) ans -= now;
    else ans += now;
  }
  cout << ans.val() << endl;
  return 0;
}


Measured memory_bytes: 12696
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	string c1,c2;
	cin >> c1 >> c2;
	if (c1[0]==c2[2]&&c2[0]==c1[2]&&c1[1]==c2[1]) {
		cout<<"YES"<<endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

int main(){
  long long a;
  string b;
  long long bb;
  cin>>a>>b;
  bb=0;
  for(int i=0;i<b.length();i++){
    if(b.at(i)!='.'){
      bb=bb*10+b.at(i)-'0';
    }
  }
  cout<<setprecision(18)<<a*bb/100<<endl;
  return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n;
ll a[maxn];

int32_t main()
{
    IOS
    double now=0;
    cin>>n;
    int ans=1;
    for (int i=1;i<=n;i++)
        cin>>a[i],now+=log10(a[i]),ans*=a[i];
    if (now>=18.3) return cout<<-1<<endl,0;
    if (ans>inff) cout<<-1<<endl;
    else cout<<ans<<endl;

}



Measured memory_bytes: 4812
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] b = Console.ReadLine().Split();
            int a;
            int A = int.Parse(b[0]);
            int B = int.Parse(b[1]);
            a = A * B / 2;
            Console.Write(a);
        }
    }
}

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

int main(){
  string s;cin>>s;
  int ans=0;
  if(s=="RRR") ans=3;
  if(s=="SRR") ans=2;
  if(s=="RRS") ans=2;
  if(s=="RSS") ans=1;
  if(s=="SRS") ans=1;
  if(s=="SSR") ans=1;
  if(s=="RSR") ans=1;

  cout<<ans;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>

int top, S[1000];

void init_stack()
{
	top = -1;
}

void push(int v)
{
	S[++top] = v;
}

int pop()
{
	return S[top--];
}

int do_op(int a, int b, char op)
{
	int r = 0;
	
	switch (op) {
	case '+':
		r = a + b;
		break;
	case '-':
		r = a - b;
		break;
	case '*':
		r = a * b;
		break;
	}
	
	return r;
}

int main(int argc, char *argv[]) 
{
	char a[100];
	int op1, op2;

	//init_stack();
	while (scanf("%s", a) != EOF) {
		if (isdigit(*a)) {
			push(atoi(a));
		} else {
			op2 = pop();
			op1 = pop();
			push(do_op(op1, op2, *a));
		} 
	}
	
	printf("%d\n", pop());
	
	return 0;
}


Measured memory_bytes: 2040
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	ll N;
	vector<P> a;
	cin >> N;
	rep(N){
		ll b;
		cin >> b;
		a.emplace_back(b, (ll)i);
	}
	a.emplace_back(0LL, 0LL);
	sort(rall(a));
	vector<ll> ans(N, 0LL);
	//rep(N) cout << a[i].first << " " << a[i].second << endl;
	ll min_i = a[0].second;
	rep(N){
	    if(min_i > a[i].second) min_i = a[i].second;
	    ans[min_i] += (ll)(i+1) * (a[i].first - a[i+1].first);
	}
	rep(N){
	    printf("%lld\n", ans[i]);
	}
}


Measured memory_bytes: 3440
N=int(input())
listA=[[0,0,0]] #最初の位置を置く
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;        
        
def main():
  for i in range(N): #i番目の場所とi+1番目の場所を順次比較していく
    # マンハッタン距離　別名:City block distance  
    # 京都のような碁盤目状の地域の移動にかかる距離
    Manhattan_distance=abs(listA[i+1][1]-listA[i][1])+abs(listA[i+1][2]-listA[i][2])
    
    # 偶奇での不可と可能
    if listA[i+1][0]%2!=(listA[i+1][1]+listA[i+1][2])%2:
      return "No"
    
    #時間差%2 != マンハッタン距離　
    #奇数時間と偶数時間で到達可能区域が異なる
    if (listA[i+1][0]-listA[i][0])%2!=Manhattan_distance%2: 
      return "No"
    
    # 距離的制約
    if (listA[i+1][0]-listA[i][0])<Manhattan_distance:
      return "No"
  
  return "Yes"


print(main())

Measured memory_bytes: 27312
#include <cstdio>
#include <algorithm>
#include <set>
#include <iostream>

using namespace std;

const int N = 100'009;

int a[N];
int b[N];
int ab[N];
int o[N];

int main() {
  int n;
  scanf("%d", &n);
  long long sa = 0, sb = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", a + i, b + i);
    sa += a[i];
    sb += b[i];
    ab[i] = a[i] + b[i];
  }
  long long ans = min(sa, sb);
  if (n % 2 == 0) {
    sort(ab, ab + n);
    long long cur = 0;
    for (int i = 0; i < n / 2; ++i) {
      cur += ab[i];
    }
    ans = min(ans, cur);
  }
  auto cmp_mn = [](int i, int j) {
    int mni = min(a[i], b[i]);
    int mnj = min(a[j], b[j]);
    int mxi = max(a[i], b[i]);
    int mxj = max(a[j], b[j]);
    if (mni != mnj) {
      return mni > mnj;
    }
    return i < j;
  };
  auto cmp_mx = [](int i, int j) {
    int mni = min(a[i], b[i]);
    int mnj = min(a[j], b[j]);
    int mxi = max(a[i], b[i]);
    int mxj = max(a[j], b[j]);
    if (mxi != mxj) {
      return mxi < mxj;
    }
    return i < j;
  };
  set<int, decltype(cmp_mn)> mn(cmp_mn);
  set<int, decltype(cmp_mx)> mx(cmp_mx);
  long long cur = 0;
  for (int i = 0; i < n; ++i) {
    cur += min(a[i], b[i]);
    mn.insert(i);
    mx.insert(i);
  }
  while ((int)mn.size() >= 3) {
    int i = *mn.begin();
    int j = *mx.begin();
    if (i != j) {
      cur -= min(a[i], b[i]);
      cur += max(a[j], b[j]);
      mn.erase(i);
      mn.erase(j);
      mx.erase(i);
      mx.erase(j);
    } else {
      long long tmp_mn = cur;
      tmp_mn -= min(a[i], b[i]);
      mx.erase(i);
      int k_mn = *mx.begin();
      tmp_mn += max(a[k_mn], b[k_mn]);
      mx.insert(i);
      long long tmp_mx = cur;
      tmp_mx += max(a[i], b[i]);
      mn.erase(i);
      int k_mx = *mn.begin();
      tmp_mx -= min(a[k_mx], b[k_mx]);
      mn.insert(i);
      mn.erase(i);
      mx.erase(i);
      if (tmp_mn < tmp_mx) {
        cur = tmp_mn;
        mn.erase(k_mn);
        mx.erase(k_mn);
      } else {
        cur = tmp_mx;
        mn.erase(k_mx);
        mx.erase(k_mx);
      }
    }
    ans = min(ans, cur);
  }
  printf("%lld\n", ans);
}


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

using namespace std;

typedef long long ll;

int a[21];
int b[21];

int main(int, char**)
{
	int n, m, c;
	cin >> n >> m >> c;

	int ans = 0;
	for (int i = 0; i < m; ++i)
			cin >> b[i];

	for (int j = 0; j < n; ++j) {
			ll wa = c;
			for (int i = 0; i < m; ++i) {
					int x;
					cin >> x;
					wa += (b[i] * x);
			}

			if (wa > 0) ans++;
	}


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


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

constexpr Int mod = 998244353;
template <class M> class segment_tree{
public:
	typedef typename M::value_type value_type;
	size_t n;
	vector<value_type> v;
	value_type e = M::unit();
	segment_tree(size_t size){
		n = 1;
		while(n < size) n <<= 1;
		v.resize(2*n, e);
		for(size_t i=1; i<n+size; ++i) v[i] = e;
	}
	segment_tree(vector<value_type> a){
		size_t size = a.size();
		n = 1;
		while(n < size) n <<= 1;
		v.resize(2*n, e);
		for(size_t i=0; i<size; ++i) v[n+i] = a[i];
		for(size_t i=n-1; i>0; --i) v[i] = M::operate(v[2*i], v[2*i+1]);
	}
	void point_update(size_t k, value_type val){
		k += n;
		v[k] = val;
		k >>= 1;
		while(k > 0){
			v[k] = M::operate(v[2*k], v[2*k+1]);
			k >>= 1;
		}
	}
	void point_operate(size_t k, value_type lval){
		k += n;
		v[k] = M::operate(lval, v[k]);
		k >>= 1;
		while(k > 0){
			v[k] = M::operate(v[2*k], v[2*k+1]);
			k >>= 1;
		}
	}
	value_type range_get(size_t l, size_t r){ // [l, r)
		value_type lres = e;
		value_type rres = e;
		l += n;
		r += n;
		while(l < r){
			if(l & 1){
				lres = M::operate(lres, v[l]);
				++l;
			}
			if(r & 1){
				--r;
				rres = M::operate(v[r], rres);
			}
			l >>= 1;
			r >>= 1;
		}
		return M::operate(lres, rres);
	}
	value_type operator[](size_t k){
		return v[k+n];
	}
};
struct max_monoid{
	using value_type = Int;
	static value_type unit(){
		return -1'000'000'007;
	}
	static value_type operate(value_type l, value_type r){
		return max(l, r);
	}
};

using P = pair<Int, Int>;
map<P, Int> mp;
Int func(Int l, Int r, vector<Int> &s){
	if(l == r) return 1;
	if(l+1 == r) return 2;
	if(mp.find(P(l, r)) != mp.end()) return mp[P(l, r)];
	return mp[P(l, r)] = (func(l+1, r, s) + func(min(r, s[l]+1), r, s)) % mod;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	Int n; cin >> n;
	vector<P> v(n);
	for(auto &i:v) cin >> i.first >> i.second;
	sort(v.begin(), v.end());
//	for(Int i=0; i<n; ++i)
//		cout << i << " " << v[i].first << " " << v[i].second << "\n";
	vector<Int> x(n);
	for(Int i=0; i<n; ++i) x[i] = v[i].first;
	vector<Int> r(n);
	for(Int i=0; i<n; ++i)
		r[i] = lower_bound(x.begin(), x.end(), v[i].first+v[i].second)-x.begin()-1;
//	for(Int i=0; i<n; ++i)
//		cout << i << " " << x[i] << " " << r[i] << "\n";
	segment_tree<max_monoid> st(r);
//	for(Int i=0; i<st.n; ++i)
//		cout << i << " " << st[i] << "\n";
	vector<Int> s(n);
	s[n-1] = n-1;
	for(Int i=n-2; i>=0; --i){
		s[i] = st.range_get(i, r[i]+1);
		st.point_update(i, s[i]);
	}
//	for(Int i=0; i<n; ++i)
//		cout << i << " " << x[i] << " " << s[i] << "\n";
	cout << func(0, n, s) << "\n";
}

Measured memory_bytes: 43364
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int get_id(char c){
	if(c>='a'&&c<='z')return c-'a';
	if(c>='A'&&c<='Z')return c-'A'+26;
	return c-'0'+52;
}
char rev(int x){
	if(x<26)return 'a'+x;
	if(x<52)return 'A'+x-26;
	return '0'+x-52;
}
int cnt[66],func[66],n,tot_ask;
string cmp="";
int dp[199][199];
int dist(string s){
	memset(dp,inf,sizeof dp);
	dp[0][0]=0;tot_ask++; 
	for(int i=0;i<=s.size();i++){
		for(int j=0;j<=cmp.size();j++){
			if(j)dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
			if(i)dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
			if(i&&j)dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(s[i-1]!=cmp[j-1]));
		}
	}
	return dp[s.size()][cmp.size()];
}
int ask(string s){
	#ifdef LOCAL
		return dist(s);
	#endif
	cout<<"? "<<s<<endl;
	fflush(stdout);int x;cin>>x;return x;
}
int Get(string ret,string s,int pos,char c){
	int tot=ret.size()+1+s.size()-pos;
	string ss=ret+c+getstr(s,pos,s.size()-1);
	tot=ss.size();
	#ifdef LOCAL
		return dist(ss)==n-tot;
	#endif
	return n-tot==ask(ss);
}
string merge(string s1,string s2){
	int pos=0;
	string ret="";
	if(rand()&1)swap(s1,s2);
	for(int i=0;i<s1.size();i++){
		while(pos<s2.size()&&Get(ret,s2,pos,s1[i])==0)
		ret.push_back(s2[pos]),pos++;
		ret.push_back(s1[i]);
	}
	while(pos<s2.size())ret.push_back(s2[pos++]);
	return ret;
}
int main(){
	srand(time(0));
	for(int i=0;i<128;i++)cmp.push_back(rev(rand()%62));
	for(int i=0;i<62;i++){
		string s="";s.push_back(rev(i));
		for(int i=0;i<7;i++)s=s+s;
		int got=ask(s);
		cnt[i]=128-got;
	}
	for(int i=0;i<62;i++)n+=cnt[i];
	set<pair<int,string> >s;
	for(int i=0;i<62;i++){
		if(cnt[i]){
			string ins="";
			for(int j=0;j<cnt[i];j++)ins.push_back(rev(i));
			s.insert(make_pair(cnt[i],ins));
		}
	}
	while(s.size()>1){
		string s1=s.begin()->second;s.erase(s.begin());
		string s2=s.begin()->second;s.erase(s.begin());
		string s3=merge(s1,s2);
		s.insert(make_pair(s3.size(),s3));
	}
	cout<<"! "<<s.begin()->second<<endl;
	if(tot_ask>=870-128)assert(0);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3768
//
// Created by user on 3/10/2020.
//
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base :: sync_with_stdio(0); cin.tie(0);
    int n, p;
    string s;
    cin >> n >> p >> s;
    map<int, int> Map;
    Map[0] = 1;
    int number = 0, power = 1;
    long long ans = 0;
    if (p == 2 or p == 5) {
        for (int i = 0; i < n; ++i) {
            if ((s[i] - '0') % p == 0) {
                ans += i + 1;
            }
        }
        cout << ans;
        return 0;
    }
    for(int i = n - 1; i >= 0; --i) {
        number = (number + (s[i]-'0') * power) % p;
        ans += Map[number];
        ++Map[number];
        power = power * 10 % p;
    }
    cout << ans;
}

Measured memory_bytes: 916