akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
constexpr double pi = 2 * acos(0.0);
typedef long long ll;
typedef unsigned long long ull;

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

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

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

	ll count = 0;
	for (int i = N - 1; i >= 0; i--) {
		count += ((A[i] / B[i] + (A[i] % B[i] != 0)) * B[i]) - A[i];
		if (i != 0) A[i - 1] += count;
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 2000000000;

int n;
ll a[100000];
ll rain[100000];

int judge(ll r){//mid > ans の時-1
  rain[0] = r;
  int flag = 0;
  for(int i = 1; i < n; i++){
    rain[i] = 2*a[i-1] - rain[i-1];
    /*if(rain[i] < 0){
      flag = -1;
      break;
    }*/
  }
  if(rain[0] + rain[n-1] > 2*a[n-1]) flag = -1;
  if(rain[0] + rain[n-1] < 2*a[n-1] && flag != -1) flag = 1;
  return flag;
}

int main(){
  cin >> n;
  rep(i, n){
    cin >> a[i];
  }
  int ans;
  ll lb = 0, ub = INF;
  int tmp;
  while(true){
    ll mid = (lb+ub)/2;
    if(mid%2 == 1 && mid+1 != tmp){
      mid++;
    }else if(mid%2 ==1 && mid -1 != tmp){
      mid--;
    }
    tmp = mid;
    int k = judge(mid);
    //cout << lb << " " <<ub<<" " << tmp  << " " << k <<endl;
    if(k == 1){//mid < ans
      lb = mid;
    }else if(k == -1){//mid > ans
      ub = mid;
    }else{
      break;
    }
  }
  rep(i, n){
    cout << rain[i] << " ";
  }
  cout <<endl;
}
      
    
    

Measured memory_bytes: 2816
N = input()
a = input().split(" ")
b = input().split(" ")
c = input().split(" ")

A = []
B = []
C = []

for z in a:
  A.append(int(z))

for x in b:
  B.append(int(x))
  
for y in c:
  C.append(int(y))

manzokudo = 0

for j in range(len(A)):
  manzokudo += B[A[j] - 1]
  try:
    if (A[j] - 1 == A[j-1]) and (j-1 > -1): 
      manzokudo += C[A[j] - 1 - 1]
  except:
    pass
  
print(manzokudo)

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    ll X;
    in(X);
    ll a = 100;
    ll cnt = 0;
    while (a < X) {
        a += a / 100;
        cnt++;
    }
    cout << cnt << endl;


	return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n; cin>>n;
    ll minabs=2e9,ans=0,cnt=0;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        if(a<0)cnt++;
        ans+=abs(a);
        if(minabs>abs(a))minabs=abs(a);
    }
    if(cnt&1)ans-=2*minabs;
    cout<<ans<<endl;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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


int main() {
	string s;
	cin >> s;
	reverse(all(s));

	string revst[4] = { "maerd", "remaerd","esare","resare" };
	for (int i = 0; i < s.size(); i++){
		bool flag = true;
		switch (s[i]){
			case 'm':
				for (int j = 0; j < revst[0].size(); j++){
					if (s[i + j] != revst[0][j])
						flag = false;
				}
				i += 4;
				break;
			case 'e':
				for (int j = 0; j < revst[2].size(); j++) {
					if (s[i + j] != revst[2][j])
						flag = false;
				}
				i += 4;
				break;
			case 'r':
				if (s[i + 2] == 'm') {
					for (int j = 0; j < revst[1].size(); j++) {
						if (s[i + j] != revst[1][j])
							flag = false;
					}
					i += 6;
					break;
				}else {
					for (int j = 0; j < revst[3].size(); j++) {
						if (s[i + j] != revst[3][j])
							flag = false;
					}
					i += 5;
					break;
				}
		}
		if (!flag) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 

int main(){
  int n,r;cin>>n>>r;
  if(n>=10)
    cout<<r;
  else
    cout<<r+(100*(10-n));
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

int main () {
  IN(a);
  IN(b);
  IN(c);
  IN(d);
  IN(e);
  IN(k);
  cout << (e-a>k ? ":(" : "Yay!");
}


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

using namespace std;

typedef long long ll;
typedef double long dl;
typedef pair < int , int > pii;
typedef pair < pii, pii > p2i;
const int maxn = (int) 2e5 + 1;
const int mod = (int) 1e9 + 7;
const ll inf = (ll)1e18;

#define fi first
#define se second
#define acel ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define next continue

int n;
int a[maxn];

ll get(int x){
    ll res = 0;
    for(int i = 1; i <= n; i++){
        res += abs(a[i] - (x + i));
    }
    return res;
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int l = -1e9, r = 1e9;
    while(r - l > 1){
        int mid = (r + l) / 2;
        if(get(mid) > get(mid + 1)){
            l = mid;
        }
        else {
            r = mid;
        }
    }
    cout << min(get(l), get(r));

}


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

const int MAXN = 100005;

int N;
double W;
double w[MAXN], v[MAXN];

double V;
vector<pair<double,double> > A;

bool comp(const pair<double,double> &a, const pair<double,double> &b) {
  return a.second*b.first > b.second*a.first;
}

int main() {
  cin >> N >> W;
  for(int i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
  }

  V = 0;

  A.clear();
  for(int i = 0; i < N; ++i) {
    if(w[i] >= 0 && v[i] <= 0) {
      //
    } else if(w[i] <= 0 && v[i] >= 0) {
      W -= w[i];
      V += v[i];
    } else if(w[i] >= 0 && v[i] >= 0) {
      A.push_back(make_pair(w[i],v[i]));
    } else {
      W -= w[i];
      V += v[i];
      A.push_back(make_pair(-w[i],-v[i]));
    }
  }

  sort(A.begin(), A.end(), comp);
  for(int i = 0; i < A.size(); ++i) {
    double x = min(1.0, W/A[i].first);
    W -= A[i].first*x;
    V += A[i].second*x;
  }
  printf("%.6f\n", V);
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

const int NMAX = 2e5 + 5;

int N, h[NMAX], a[NMAX];
long long dp[NMAX];

class FenwickTree
{
    long long A[NMAX];

private:
    static inline int UB (int X)
    {
        return (X & (-X));
    }

public:
    inline void Update (int pos, long long val)
    {
        for(int i = pos; i <= N; i += UB(i))
            A[i] = max(A[i], val);

        return;
    }

    inline long long Query (int pos)
    {
        long long r = 0;

        for(int i = pos; i >= 1; i -= UB(i))
            r = max(r, A[i]);

        return r;
    }
} A;

static inline void Read ()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    for(int i = 1; i <= N; ++i)
        cin >> h[i];

    for(int i = 1; i <= N; ++i)
        cin >> a[i];

    return;
}

static inline void Solve ()
{
    for(int i = 1; i <= N; ++i)
    {
        dp[i] = A.Query(h[i] - 1) + 1LL * a[i];

        A.Update(h[i], dp[i]);
    }

    long long ans = 0;

    for(int i = 1; i <= N; ++i)
        ans = max(ans, dp[i]);

    cout << ans << '\n';

    return;
}

int main()
{
    Read();

    Solve();

    return 0;
}


Measured memory_bytes: 4992
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int day = Integer.parseInt(scan.nextLine());
    int[][] happy = new int[day][3];
    for(int i = 0;i < day;i ++){
      String[] hiki = scan.nextLine().split(" ");
      for(int j = 0;j < 3;j ++){
        happy[i][j] = Integer.parseInt(hiki[j]);
      }
    }
    int[][] dp = new int[day][3];
    dp[0][0] = happy[0][0];
    dp[0][1] = happy[0][1];
    dp[0][2] = happy[0][2];
    for(int i = 1;i < day;i ++){
      dp[i][0] = happy[i][0] + Math.max(dp[i-1][1],dp[i-1][2]);
      dp[i][1] = happy[i][1] + Math.max(dp[i-1][2],dp[i-1][0]);
      dp[i][2] = happy[i][2] + Math.max(dp[i-1][0],dp[i-1][1]);
    }
    System.out.println(Math.max(dp[day-1][0],Math.max(dp[day-1][1], dp[day-1][2])));
  }
}


Measured memory_bytes: 127768
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;
int gc;
vector<int> v;

void factorize(int n){
   for (int i = 2; i*i <= n; ++i)
   {
      if(n%i)continue;
      int expo = 0;
      while(n%i == 0){
         expo++;
         n/= i;
      }
      v.pb(i);
   }
   if(n > 1){
      v.pb(n);
   }
   v.push_back(1);
}

int32_t main(){_

   cin >> a >> b;
   
   gc = __gcd(a, b);

   factorize(gc);

   cout<<sz(v)<<endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;


int main() {
    string s1;
    cin >> s1;
    char c;
    int i=0;
    for (i=0;i<s1.size();i++) {
        c = s1[i];
        if (c == '?') {
           s1[i] = 'D';
        }
     }
        cout << s1 << "\n";
}


Measured memory_bytes: 3368
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define int long long
#define ld long double
#define ll long long
#define mp make_pair

mt19937 rnd(51);


int32_t main()
{ 
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h, a;
	cin >> h >> a;
	cout << h / a + min(1ll, h % a);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	long long N;
	scanf("%ld",&N);
	long long A,B;
	scanf("%ld %ld",&A,&B);
	long long num;
	long long count = 0;
	/*if(A == 0){
		printf("0\n");
		return 0;
	}
	while(N >= A + B){
		count += A;
		N = N - (A + B);
	}
	if(N >= A){
		count += A;
	}
	else{
		count += N;
	}*/

	num = N / (A+B);
	N -= num*(A+B);
	count = A*num;
	// printf("N =%d num = %d\n",N,num);
	if(N >= A){
		count += A;
	}
	else{
		count += N;
	}
	
	printf("%ld\n",count);

	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
import numpy as np

def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    ans = 0
    MOD = 10**9+7
    k = 1
    x = np.max(A)
    n = 1 if x == 0 else int(np.log2(x))+1

    for i in range(n):
        c = np.count_nonzero(A%2)
        A >>= 1
        ans = (ans + c * (N-c) * k) % MOD
        k = (2*k) % MOD

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 48792
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n, k, num, sum;
    cin>>n>>k;
    for(int i=0; i<n; i++) {
        cin>>num;
        if(k-num<k/2) {
            num = k - num;
        }else {
          num = num;
        }
        sum += num;
    }
    cout<<sum*2<<endl;
    return 0;
}

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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

  int N,M;
  cin >> N >> M;
  int L[M],R[M];
  REP(i,M) cin >> L[i] >> R[i];

  int left_max = *max_element(L, L+M);
  int right_min = *min_element(R, R+M);

  cout << max(right_min - left_max + 1, 0) << endl;

  return 0;
}



Measured memory_bytes: 4384
#include<bits/stdc++.h>
using namespace std;
const int N=3010,M=2e5+10,MOD=1e9+7;
struct node{
	int x,y;
}a[N];
int H,W,n,fac[M],inv[M],dp[N];
inline bool cmp(node p,node q){return p.x<q.x||(p.x==q.x&&p.y<q.y);}
inline int C(int x,int y){return 1ll*fac[x]*inv[x-y]%MOD*inv[y]%MOD;}
inline void preprocess()
{
	fac[0]=1;for (register int i=1;i<=H+W;++i) fac[i]=1ll*fac[i-1]*i%MOD;
	inv[0]=inv[1]=1;for (register int i=2;i<=H+W;++i) inv[i]=(-1ll*inv[MOD%i]*(MOD/i)%MOD+MOD)%MOD;
	for (register int i=2;i<=H+W;++i) inv[i]=1ll*inv[i]*inv[i-1]%MOD;
}
int main()
{
	scanf("%d%d%d",&H,&W,&n);
	for (register int i=1;i<=n;++i) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
	a[n+1]=(node){H,W};
	preprocess();
	for (register int i=1;i<=n+1;++i)
	{
		dp[i]=C(a[i].x+a[i].y-2,a[i].x-1);
		for (register int j=1;j<=i-1;++j) if (a[i].x>=a[j].x&&a[i].y>=a[j].y) dp[i]=(dp[i]-1ll*dp[j]*C(a[i].x-a[j].x+a[i].y-a[j].y,a[i].x-a[j].x)%MOD+MOD)%MOD;
	}
	printf("%d\n",dp[n+1]);
	return 0;
}

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

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

  if (abs(a - b) <= d && abs(b - c) <= d) {
    cout << "Yes" << endl;
  } else {
    if (abs(a - c) <= d) {
      cout << "Yes" << endl;
    }else {
      cout << "No" << endl;
    }
  }
}


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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 30;

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

    int h,w,m;
    cin>>h>>w>>m;

    unordered_map<int,int> row;
    unordered_map<int,int> col;
    set<pair<int,int>> hset;

    int max_r = 0, max_c = 0;
    vector<int> maxrow;
    vector<int> maxcol;
    for(int i=0;i<m;i++)
    {
        int r,c;
        cin>>r>>c;
        row[r]++;
        if(row[r] > max_r)
        {
            maxrow.clear();
            maxrow.push_back(r);
            max_r = row[r];
        }
        else if( row[r] == max_r)
            maxrow.push_back(r);
        
        col[c]++;
        if(col[c] > max_c)
        {
            maxcol.clear();
            maxcol.push_back(c);
            max_c = col[c];
        }
        else if( col[c] == max_c)
            maxcol.push_back(c);

        hset.insert({r,c});
    }

    int sum = 0;
    bool flag = false;

    for(int i=0;i<maxrow.size();i++){
        if(flag)
            break;
        for(int j = 0; j<maxcol.size();j++)
        {
            //cout<<maxrow[i]<<" "<<maxcol[j]<<endl;
            if(hset.find({maxrow[i], maxcol[j]}) != hset.end())
            {
                sum = max_r + max_c -1;
            }
            else
            {
                sum = max_r + max_c;
                flag = true;
                break;
            }
        }
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 46404
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = ip(br);
        Set<String> list=new HashSet<>();
        for(int i=0;i<n;i++){
            String[] lines=br.readLine().split(" ");
            if(lines[0].equals("insert")){
                list.add(lines[1]);
            }else{
                if(list.contains(lines[1])){
                    System.out.println("yes");
                }else{
                    System.out.println("no");
                }
            }
        }
    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(BufferedReader br) throws IOException {
        String[] lines = br.readLine().split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static int ip(BufferedReader s) throws IOException {
        return Integer.parseInt(s.readLine());
    }
}

Measured memory_bytes: 189904
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;


int main(){
	int n;
	string s;
	
	cin >> n >> s;
	int ans = 1;
	for(int i=1;i<n;i++){
		if(s[i-1]!=s[i]) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int main(){
  char s[110];
  int cnt = 0;
  while(~scanf("%s",s)){
    string ss = string(s);
    string t = ss; reverse(ALL(t));
    if(ss==t)++cnt;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
int main(){
  int N,A[1000],v;
  int i,j;
  scanf("%d",&N);
  for(i=0;i<=N-1;i++)scanf("%d",&A[i]);
  for(i=0;i<N-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[N-1]);
  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(j=0;j<N-1;j++)printf("%d ",A[j]);
    printf("%d\n",A[N-1]);
  }
  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string.h>
#include<map>
#include<set>
using namespace std;

int main() {
	char s[100001];
	char t[100001];
	char d[] = "\0";
	strncpy(s, d, 100001);
	strncpy(t, d, 100001);
	scanf("%s", s);
	scanf("%s", t);

	std::map<char, std::set<int>* > ss;
	// sのscan
	int i = 0;
	for (char* p = s; *p != '\0'; p++) {
		if (ss.find(*p) == ss.end()) {
			std::set<int>* d = new std::set<int>;
			ss.insert(pair<char, std::set<int>* >(*p, d));
		}
		ss.at(*p)->insert(i);
		i++;
	}
	int nums = i;
	//  cout << nums << endl;

	int pos = 0;
	char* q = t;
	int64_t count = 0;
	while (*q != '\0') {
		auto is = ss.find(*q);
		if (is == ss.end()) {
			cout << "-1" << endl;
			return 0;
		}
		std::set<int>* v = is->second;
		auto it = v->lower_bound(pos);
		if (it == v->end()) {
			count += i - pos;
			pos = 0;
			it = v->lower_bound(pos);
		}
		int nextPos = *it;
		count += nextPos - pos + 1;
		pos = nextPos + 1;
		q++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define all(v) v.begin(),v.end()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=a;i>b;i--)
using namespace std;

int main()
{
    fastio
    int n,m;
    cin>>n>>m;
    int sum=0;
    vector<int> v(n);
    REP(i,0,n)
    {
        cin>>v[i];
        sum+=v[i];
    }
    double value=(double)1/(4*m);
    sort(v.begin(),v.end(),greater<int>());
    if(v[m-1]>=(ceil(value*sum)))
        cout<<"Yes\n";
    else
        cout<<"No\n";
    
}

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

int H, W;

int main(){
	while(1){
		scanf("%d %d", &H, &W);
		if(H==0 && W==0){
			break;
		}else{
			for(int i=0; i<H; ++i){
				for(int j=0; j<W; ++j){
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
		}
	}
}


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

int main() {
    int n; cin >> n;
    int maxi = 0;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        if (a < maxi) {
            cout << "No" << endl;
            return 0;
        }
        maxi = max(maxi, a - 1);
    }
    
    cout << "Yes" << endl;

    return 0;
}

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

namespace YenCoins
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int coinsAmount = int.Parse(input[0]);
            int moneyAmount = int.Parse(input[1]);

            if(coinsAmount * 500 < moneyAmount)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}

Measured memory_bytes: 11092
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if abs(a, c) <= d || (abs(a, b) <= d && abs(b, c) <= d) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func abs(a int, b int) int {
	if a > b {
		return a - b
	} else {
		return b - a
	}
}


Measured memory_bytes: 512
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

S, W = LI()

print("unsafe" if W >= S else "safe")


Measured memory_bytes: 65276
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n; cin>>n;
    string S;
    cin>>S;
    int l[n],r[n];
    for(int i=0;i<n;i++){
        l[i]=0; r[i]=0;
    }
    for(int i=0;i<n;i++){
        if(S[i]=='W'){
            l[i]++;
        }else{
            r[i]++;
        }
    }
    int x[1000000]={},R[1000000]={},L[1000000]={};
    if(S[0]=='E') L[n-1]++;
    if(S[n-1]=='W') R[0]++;
    for(int i=1;i<n;i++){
        R[i]=R[i-1]+r[i];
    }
    for(int i=n-2;i>=0;i--){
        L[i]=L[i+1]+l[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        x[i]=R[i]+L[i];
        ans=max(ans,x[i]);
    }
    cout<<n-ans<<endl;
    
}


Measured memory_bytes: 10884
#include<iostream>
using namespace std;
int main()
{
    int i,j,n,d[50],sum=0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> d[i];
        for(j=0;j<i;j++)sum+=d[j]*d[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import os
import sys
from collections import Counter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

counter = Counter(A)
counts = [0] * (max(A) + 1)
for k, cnt in counter.items():
    if cnt >= 2:
        counts[k] = (cnt - 1) * cnt // 2

s = sum(counts)
ans = []
for a in A:
    cnt = counter[a] - 1
    if cnt >= 2:
        a = s - counts[a] + (cnt - 1) * cnt // 2
    else:
        a = s - counts[a]
    ans.append(a)

print(*ans, sep='\n')



Measured memory_bytes: 31560
#include<stdio.h>
int main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A==5&&B==5&&C==7)
	printf("YES\n");
     else if(A==5&&B==7&&C==5)
	printf("YES\n");
	else if(A==7&&B==5&&C==5)
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
} 

Measured memory_bytes: 128
public class Hello
{
    public static void Main()
    {
        int num = int.Parse(System.Console.ReadLine());
        string[] x = System.Console.ReadLine().Split(' ');
        string[] y = System.Console.ReadLine().Split(' ');

        // p1-p3,???????¨????
        double p1 = 0;
        double p2 = 0;
        double p3 = 0;
        double p = 0;
        for (int i = 0; i < num; i++)
        {
            double diff = System.Math.Abs(double.Parse(x[i]) - double.Parse(y[i]));
            p1 += diff;
            p2 += System.Math.Pow(diff, 2.0);
            p3 += System.Math.Pow(diff, 3.0);
            p = System.Math.Max(p, diff);
        }

        System.Console.WriteLine(p1.ToString("F6"));
        System.Console.WriteLine(System.Math.Pow(p2, 1.0 / 2.0).ToString("F6"));
        System.Console.WriteLine(System.Math.Pow(p3, 1.0 / 3.0).ToString("F6"));
        System.Console.WriteLine(p.ToString("F6"));
    }
}

Measured memory_bytes: 9368
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#define M 1000005
int n,a[M];
std::vector <int> E[M];
bool F[M];
int read(){
	char c=getchar();int ans=0;
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();
	return ans;
}
void Write(int x){
	if (x<10) putchar(x^48);
	else Write(x/10),putchar((x%10)^48);
	return;
}
void DFS(int x,int fa){
	for (register int i=0;i<E[x].size();i++)
		if (E[x][i]!=fa) DFS(E[x][i],x),F[x]|=(!F[E[x][i]]&&(a[x]>a[E[x][i]]));
	return;
}
int main(){

	n=read();
	for (register int i=1;i<=n;i++) a[i]=read();
	for (register int i=1,u,v;i<n;i++) u=read(),v=read(),E[u].push_back(v),E[v].push_back(u);
	for (register int i=1;i<=n;i++){
		for (register int j=1;j<=n;j++) F[j]=0;
		DFS(i,0);if (F[i]) Write(i),putchar(' ');
	}
    putchar('\n');
	return 0;
}


Measured memory_bytes: 24192
n = int(input())
a = list(map(int, input().split()))


def partition(a, left, right):
    standard = a[right]
    cnt = left
    for i in range(left, right+1):
        if i == right:
            if a[i] <= standard:
                a[i],a[cnt] = a[cnt], [a[i]] 
        elif a[i] <= standard:
            a[cnt],a[i] = a[i], a[cnt]
            cnt += 1
    print(*a)
    return cnt

partition(a, 0, len(a)-1)


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, l, j;
  cin >> n >> l;
  int mins = 300, sum = 0;
  for (int i = 1; i <= n; ++ i) {
    if (mins > abs(i + l - 1)) {
      mins = abs(i + l - 1);
      j = i;
    }
    sum += i + l - 1;
  }
  sum -= j + l - 1;
  cout << sum << endl;
  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int r = in.nextInt();
        int s = in.nextInt();
        int p = in.nextInt();
        
        char[] arr = in.next().toCharArray();
        char[] last = new char[k];
        for (int i = 0; i < k ;++i) {
            last[i] = 'x';
        }

        long ans = 0;
        for (int i = 0; i < n; ++i) {
            if (last[i % k] == 'x') {
                if (arr[i] == 'r') { ans += p; last[i % k] = 'p';}
                else if (arr[i] == 'p') { ans += s; last[i % k] = 's';}
                else if (arr[i] == 's') { ans += r; last[i % k] = 'r';}
            } else {
                if (arr[i] == 'r') {
                    if (last[i % k] != 'p') {
                        ans += p;
                        last[i % k] = 'p';
                    } else {
                        last[i % k] = 'x';
                    }
                } else if (arr[i] == 'p') {
                   if (last[i % k] != 's') {
                        ans += s;
                        last[i % k] = 's';
                    } else {
                        last[i % k] = 'x';
                    }
                } else {
                    if (last[i % k] != 'r') {
                        ans += r;
                        last[i % k] = 'r';
                    } else {
                        last[i % k] = 'x';
                    }
                }
            }
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 26816
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
a=[0]
a.extend(n1())

from collections import deque
p=deque([1])
nex=1
town=[0]*(n+1)
town[1]=1
for i in range(n+1):
    last=nex
    nex=a[last]
    p.append(nex)
    if town[nex]==1:
        break
    else:
        town[nex]=1
p.pop()
first=p.index(nex)
length=len(p)
if k<length:
    print(p[k])
else:
    print(p[(k-first)%(length-first)+first])

Measured memory_bytes: 32368
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
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; }

int ans = 1;
int N;
int a[200100];

void solve(int X){
    if(X == 1){
        cout << ans << endl;
        return;
    }
    else{
        ans++;
        if(ans == N+1){
            cout << -1 << endl;
            return;
        }
        solve(a[X]);
    }
}


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    cin >> N;
    REP(i,N){
      cin >> a[i];
      a[i]--;
    }

    solve(a[0]);
}

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

int main()
{
  int a, b, k;
  cin >> a >> b >> k;
  int num = 200;
  while(k != 0) {
    num--;
    if(a % num == 0 && b % num == 0)
      k--;
  }
  cout << num << endl;
    
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A = 0;
  int b,c,d,e;
  cin >> A;
  vector<char>color(A);
  for(int i; i < A; i++){
    cin >> color.at(i);
  }
  for(int a = 0; a < A; a++){
    if(color.at(a) == 'P')b++;
    if(color.at(a) == 'Y')c++;
    if(color.at(a) == 'G')d++;
    if(color.at(a) == 'W')e++;
  }
  if(b != 0 && c != 0 && d != 0 && e != 0)cout << "Four";
  else cout << "Three";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
   


    string s;
    cin >> s;
    ll n = s.length();
    string defS0 = s;
    string tmpS = s;

    reverse(tmpS.begin(), tmpS.end());
    string revS0 = tmpS;

    string defS1 = tmpS = s.substr(0,(n-1)/2);
    reverse(tmpS.begin(), tmpS.end());
    string revS1 = tmpS;

    string defS2 = tmpS = s.substr((n+1)/2,(n-1)/2);
    reverse(tmpS.begin(), tmpS.end());
    string revS2 = tmpS;
    if(defS0 == revS0 and defS1 == revS1 and defS2 == revS2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
//累積和を取る. 2つめの区切りを決めた時、(P,Q)を均等に, (R,S)を均等にしたいから、このときはO(logN)で解ける。全体でO(NlogN)。
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n;
int a[200000];
int ra[200001];

int Max(int a, int b, int c, int d) {
	return max(a, max(b, max(c, d)));
}

int Min(int a, int b, int c, int d) {
	return min(a, min(b, min(c, d)));
}

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 1; i <= n; i++) ra[i] = ra[i - 1] + a[i - 1];
	
	int ans = 1e+18;
	for (i = 2; i <= n - 2; i++) {
		int p = -1, q = -1, r = -1, s = -1;
		int p2 = -1, q2 = -1, r2 = -1, s2 = -1;
		
		int pos1 = lower_bound(ra, ra + n + 1, (ra[i] + 1) / 2) - ra;
		if (pos1 < i) { p = ra[pos1] - ra[0]; q = ra[i] - ra[pos1]; }
		if (pos1 - 1 > 0) { p2 = ra[pos1 - 1] - ra[0]; q2 = ra[i] - ra[pos1 - 1]; }
		
		int pos2 = lower_bound(ra, ra + n + 1, ra[i] + (ra[n] - ra[i] + 1) / 2) - ra;
		if (pos2 < n) { r = ra[pos2] - ra[i]; s = ra[n] - ra[pos2]; }
		if (pos2 - 1 > i) { r2 = ra[pos2 - 1] - ra[i]; s2 = ra[n] - ra[pos2 - 1]; }
		
		//4パターン試す
		if (p > 0 && q > 0 && r > 0 && s > 0) { ans = min(ans, Max(p,q,r,s) - Min(p,q,r,s)); }
		if (p > 0 && q > 0 && r2 > 0 && s2 > 0) { ans = min(ans, Max(p,q,r2,s2) - Min(p,q,r2,s2)); }
		if (p2 > 0 && q2 > 0 && r > 0 && s > 0) { ans = min(ans, Max(p2,q2,r,s) - Min(p2,q2,r,s)); }
		if (p2 > 0 && q2 > 0 && r2 > 0 && s2 > 0) { ans = min(ans, Max(p2,q2,r2,s2) - Min(p2,q2,r2,s2)); }
	}
	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 3456
// https://atcoder.jp/contests/abc085/tasks/abc085_b

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> values{};
    for(int i=0; i<N; ++i) {
        int x;
        cin >> x;
        values.emplace_back(x);
    }
    std::sort(values.begin(), values.end());
    values.erase(std::unique(values.begin(), values.end()), values.end());
    cout << values.size() << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		if((b-a)%2 == 0) {
			System.out.println((b-a)/2);
		}else {
			System.out.println(Math.min(n-b+1,a)+(b-a-1)/2);
		}
		sc.close();
	}
}

Measured memory_bytes: 23764
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int cnt[26];

int main() {
  int n, m;
  string s;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    for (int j = 0; j < m; ++j) {
      ++cnt[s[j] - 'a'];
    }
  }
  int c2 = (n % 2 ? m / 2 : 0) + (m % 2 ? n / 2 : 0);
  int c1 = n % 2 && m % 2 ? 1 : 0;
  for (int i = 0; i < 26; ++i) {
    int cur = cnt[i] % 4;
    if (cur == 1) {
      --c1;
    } else if (cur == 2) {
      --c2;
    } else if (cur == 3) {
      --c1; --c2;
    }
  }
  cout << (c1 >= 0 && c2 >= 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=0; cin>>n;
    vector<ll> a(n+1,0),b(n,0);
    rep(i,n+1) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n){
        if(b[i]<a[i]){
            ans+=b[i];
            a[i]-=b[i];
        }
        else{
            ans+=a[i];
            b[i]-=a[i];
            a[i]=0;
            if(b[i]<a[i+1]){
                ans+=b[i];
                a[i+1]-=b[i];
            }
            else{
                ans+=a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

using ll = long long;

int main(){
  int moves[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
  int h, w;
  cin >> h >> w;
  int ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector <string> maze(h);
  for(auto &i : maze){
    cin >> i;
  }

  auto canMove = [&h, &w, &maze](int y, int x)->bool{
    if(y < 0 || y >= h)return false;
    if(x < 0 || x >= w)return false;
    assert(y >= 0 && y < (int) maze.size());
    assert(x >= 0 && x < (int) maze[0].size());
    if(maze[y][x] == '#')return false;
    return true;
  };
  vector < vector <int> > weight(h, vector <int>(w, INT_MAX));
  weight[ch][cw] = 0;
  priority_queue <pair <int, pair <int,int> > > q;
  q.push({0, {ch, cw}});
  while(!q.empty()){
    int y = q.top().second.first;
    int x = q.top().second.second;
    q.pop();
    // no magic
    {
      for(int i = 0; i < 4; i++){
        int newy = y + moves[i][0];
        int newx = x + moves[i][1];
        if(!canMove(newy, newx))continue;
        int newW = weight[y][x] + 0;
        int &destW = weight[newy][newx];
        // no magic
        if(newW < destW){
          destW = newW;
          q.push({-newW, {newy, newx}});
        }
      }
    }
    // by magic
    {
      for(int newy = max(0, y - 2); newy <= min(y + 2, h - 1); newy++){
        for(int newx = max(0, x - 2); newx <= min(x + 2, w - 1); newx++){
          if(!canMove(newy, newx))continue;
          int newW = weight[y][x] + 1;
          int &destW = weight[newy][newx];
          if(newW < destW){
            destW = newW;
            q.push({-newW, {newy, newx}});
          }
        }
      }
    }
  }
  if(weight[dh][dw] == INT_MAX){
    cout << "-1\n";
  }else{
    cout << weight[dh][dw] << '\n';
  }
  return 0;
}


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

using namespace std;
long long p[123456],a[123456];
int main(int argc, char const *argv[])
{
    int n,k;
    cin >> n >> k;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        p[i]=p[i-1]+labs(a[i-1]-a[i]);
    }
    /*for (int i=1;i<=n;i++)
    {
        cout << a[i] <<" "<<p[i]<< endl;
    }
    cout << endl;*/
    long long ans=1e16;
    for (int i=1;i<=n-k+1;i++)
    {
        ans=min(p[i+k-1]-p[i]+min(abs(a[i]),abs(a[i+k-1])),ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    int n;
    cin >> n;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    ll ret = 0;
    for (int i = n - 1; i >= 0; --i) {
        ret += (a[i] + ret) % b[i] == 0 ? 0 : (b[i] - (a[i] + ret) % b[i]);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	int cnt=0;
	for(int i=0; i<n; i++)
	{
		int num;
		cin>>num;
		if(num>=k)
		 cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 3620
//AC
//不需要解释 

#include<stdio.h>
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m)){
		if(n>=0&&n<=9&&m>=0&&m<=9){
		if(n>=m){
			printf("10\n");
//			printf("%d is not less than %d, so we should print 10.\n",n,m);
		}else{
			printf("0\n");
//			printf("%d is less than %d, so we should print 0.\n",n,m);
		}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    double n; cin >> n;
    double ans = ceil(n / 108 * 100);
    if(floor(ans*108/100) == n) {
        cout << ans << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


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


int MOD=1000000007;


int main(){
  int L,R,ans=2018;
  cin >> L >> R;
  vector<int> data;
  for(int i=L; i<=R; i++){
    if(data.size()==2019) break;
    data.push_back(i%2019);
  }
  sort(data.begin(),data.end());
  for(int i=0; i<data.size(); i++){
    for(int j=0; j<data.size(); j++){
      if(i!=j)
      ans=min(ans,data[i]*data[j]%2019);
    }
  }
  cout << ans << endl;
}


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

static const int MAX_SIZE = 1<<18;
static const long LLong = 1<<30;

typedef long long Int;
Int segMin[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1];

void add(int a, int b, Int x, int k = 0, int l = 0, int r = MAX_SIZE){
    
    if(r <= a || b <= l) return;
    
    if(a <= l && r <= b){
        segAdd[k] += x;
        return;
    }
    
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    
    segMin[k] = min(segMin[k * 2 + 1] + segAdd[k * 2 + 1], segMin[k * 2 + 2] + segAdd[k * 2 + 2]);
}

Int getMin(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE){
    
    if(r <= a || b <= l) return LLong;
    
    if(a <= l && r <= b) return (segMin[k] + segAdd[k]);
    
    Int left = getMin(a, b, k * 2 + 1, l, (l + r) / 2);
    Int right = getMin(a, b, k * 2 + 2, (l + r) / 2, r);
    
    return min(left, right) + segAdd[k];
}

int main(){
    for(int i = 0; i < 2 * MAX_SIZE - 1; i++)
        segMin[i] = segAdd[i] = 0;
    int n, q, b, s, t, x;
    cin >> n >> q;
    for(int i = 0; i < q; i++){
        cin >> b >> s >> t;
        if(b) cout << getMin(s, t + 1) << endl;
        else {
            cin >> x;
            add(s, t + 1, x);
        }
    }
    return 0;
}


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

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

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

int main(){
    int n;
    string s;
    cin >> s;
    cout << (s[0] == '9' || s[1] == '9'  ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int x = sc.nextInt();
	    if (x == 0) {
		    System.out.println("1");
	    } else if (x == 1) {
		    System.out.println("0");
	    }
	}
}

Measured memory_bytes: 35632
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

double distance(pair<lli, lli> a, pair<lli, lli> b){
    return sqrt(pow(a.first-b.first, 2) + pow(a.second-b.second, 2));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n;
    cin >> n;
    vector<lli> order(n);
    vector<pair<lli, lli>> city(n);
    rep(i, n){
        cin >> city[i].first >> city[i].second;
        order[i] = i+1;
    }

    lli cnt = 0;
    double total = 0.0;
    do{
        cnt++;
        for(lli i=0; i<n-1; i++){
            total += distance(city[order[i]-1], city[order[i+1]-1]);
        }
    } while(next_permutation(all(order)));
    cout << total/cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

int checkCount(int size, int list_int[], int count);


int main(){
    int enter_num;
    std::cin >> enter_num;
    int nums[enter_num];
    for(int i = 0; i < enter_num; i++){
        std::cin >> nums[i];
    }
    std::cout << checkCount(enter_num, nums, 0) << std::endl;
}

int checkCount(int size, int list_int[], int count){
    for(int i = 0; i < size; i++){
        if(list_int[i] % 2 != 0){
            return count;
        }
        list_int[i] = list_int[i]/2;
    }
    count++;
    return checkCount(size, list_int, count);
}


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

int main() {
  int h,w; cin>>h>>w;
  vector<vector<int>> c(10, vector<int>(10, 0));
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, 10) rep(j, 10) cin>>c[i][j];
  rep(i, h) rep(j, w) cin>>a[i][j];

  rep(k, 10) {
    rep(i, 10) {
      rep(j, 10) {
        c[i][j]=min(c[i][j], c[i][k]+c[k][j]);
      }
    }
  }
  int p=1e9;
  rep(i, 10) p=min(p, c[i][1]);
  int res=0;
  rep(i, h) {
    rep(j, w) {
      if (a[i][j]==-1) res+=p;
      else res+=c[a[i][j]][1];
    }
  }
  cout<<res<<endl;
}


Measured memory_bytes: 384