akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}


static void ABC109D_MakeThemEven();

#if 1
int main()
{
	ABC109D_MakeThemEven();
	fflush(stdout);
	return 0;
}
#endif

static void ABC109D_MakeThemEven()
{
	int H, W;
	get2int(H, W);

	int value = 0;
	bool moving = true;
	auto grid = new int[H][500];
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			get1int(grid[h][w]);
		}
	}
	int opeCount = 0;
	std::vector<std::pair<int, int>> from;
	std::vector<std::pair<int, int>> to;

	for (int h = 0; h < H; h++) {
		if (h % 2) {
			for (int w = W - 1; w >= 0; w--) {
				std::pair<int, int> tmpt(-1, -1);
				if (grid[h][w] % 2) {
					if (w > 0) {
						grid[h][w - 1]++;
						tmpt.first = h;
						tmpt.second = w - 1;
					}
					else if (h < H - 1) {
						grid[h + 1][w]++;
						tmpt.first = h + 1;
						tmpt.second = w;
					}

					if (tmpt.first >= 0) {
						opeCount++;
						grid[h][w]--;
						from.push_back(std::pair<int, int>(h, w));
						to.push_back(tmpt);
					}
				}
			}
		}
		else {
			for (int w = 0; w < W; w++) {
				if (grid[h][w] % 2) {
					std::pair<int, int> tmpt(-1, -1);
					if (w < W - 1) {
						grid[h][w + 1]++;
						tmpt.first = h;
						tmpt.second = w + 1;
					}
					else if (h < H - 1) {
						grid[h + 1][w]++;
						tmpt.first = h + 1;
						tmpt.second = w;
					}

					if (tmpt.first >= 0) {
						grid[h][w]--;
						opeCount++;
						from.push_back(std::pair<int, int>(h, w));
						to.push_back(tmpt);
					}
				}
			}
		}
	}
	printf("%d\n", opeCount);
	for (int i = 0; i < opeCount; i++) {
		printf("%d %d %d %d\n", 
			from[i].first + 1, from[i].second + 1,
			to[i].first + 1, to[i].second + 1);
	}

	delete[] grid;
}


Measured memory_bytes: 5228
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N, M, nums[100009];
ll s[200009], v[200009], val[200009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    rep(i,N) cin>>nums[i];
    
    mem(s,0); mem(v,0), mem(val,0);
    ll total=0;
    rep(i,N-1){
        int pre=nums[i], nxt=nums[i+1]+(nums[i+1]<pre?M:0);
        int dist=nxt-pre;
        total+=dist;
        if(dist>1){
            v[pre+2]++;
            v[nxt+1]--;
            s[nxt+1]-=(dist-1);
        }
    }
    
    rep1(i,2*M){
        v[i]+=v[i-1];
        s[i]+=s[i-1]+v[i];
        val[i]=s[i];
    }
    
    ll mx=0;
    rep1(i,M){
        if(mx<val[i]+val[i+M]) mx=val[i]+val[i+M];
    }
    cout1(total-mx);
}

Measured memory_bytes: 5376
#include<iostream>
#include<cstdlib>

using namespace std;

typedef long long ll;
ll INF = 1e10;
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }

int main() {
   int V, E;
   cin >> V >> E;
   ll dp[V][V];
   fill(dp[0], dp[V], INF);
   
   for (int i = 0; i < V; i++) {
      dp[i][i] = 0;
   }
   
   int s, t;
   ll d;
   for (int i = 0; i < E; i++) {
      cin >> s >> t >> d;
      dp[s][t] = d;
   }
   for (int k = 0; k < V; k++) {
      for (int i = 0; i < V; i++) {
         for (int j = 0; j < V; j++) {
            if (dp[i][k] == INF || dp[k][j] == INF) continue;
            dp[i][j] = llmin(dp[i][j], dp[i][k] + dp[k][j]);
         }
      }
   }
   for (int i = 0; i < V; i++) {
      if (dp[i][i] < 0) {
         cout << "NEGATIVE CYCLE" << endl;
         return 0;
      }
   }
   for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
         if (j == V - 1) {
            if (dp[i][j] == INF) cout << "INF" << endl;
            else cout << dp[i][j] << endl;
         } else {
            if (dp[i][j] == INF) cout << "INF ";
            else cout << dp[i][j] << " ";
         }
      }
   }
   return 0;
}



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

int main(){
 	int h,w;
	cin >> h >> w;
	vector<string> a(h+2);
	for(int i = 1; i <= h; i++)
		cin >> a[i];
	for(int i = 0; i <= h+1; i++) {
		if(i == 0 || i == h+1) {
			for(int j = 0; j <= w+1; j++)
				cout << "#";
			cout << endl;
		} else {
			cout << "#"<< a[i] << "#" << endl;
		}
	}
}


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

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

    constexpr double e = std::numeric_limits<double>::epsilon();

    long double A = sqrt(a);
    long double B = sqrt(b);
    long double C = sqrt(c);

    long double AB = sqrt(a) + sqrt(b);
    long double epsilon = 1e-14;

    // cout << std::setprecision(20) << AB + epsilon << endl;
    
    if(AB + epsilon < C) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
  fio();
  string s, t;
  cin >> s >> t;
  t += s;
  cout << t << endl;
  return 0;
  int x;
  cin >> x;
  for (int a = x; a <= inf; a++) {
    bool flag= true;
    for (int j = 2; j < a; j++) {
      if (a % j == 0) flag = false;
        
    }
    if (flag) {
      cout << a << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif

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

    const ll MOD = (ll)1e9 + 7;
    int N, M; cin >> N >> M;
    vl A(M); REP(i, M) cin >> A[i];

    vb broken(N+MGN, false);
    REP(i, M) broken[A[i]] = true;;

    vl dp(N + MGN, 0);
    dp[N] = 1; // AMAX <= N-1

    for (int i = N - 1; i >= 0; i--) {
        if (broken[i]) {
            dp[i] = 0;
            continue;
        }

        dp[i] = (dp[i + 1] + dp[i + 2]) % MOD;
    }

    ll ans = dp[0];
    cout << ans << endl;

    return 0;
}

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

int main() {
  long x, y;
  std::cin >> x >> y;
  if (x == y || !(x % y)) std::cout << -1 << std::endl;
  else {
    for (long long i = 0; i < 1000000000000000000; i++) {
      if (x * i % y != 0) {
        std::cout << x * i << std::endl;
        break;
      }
    }
  }
  return 0;
}


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

int main()
{  
  #ifndef ONLINE_JUDGE
	 freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);

  #endif
   
    long long a;
    cin>>a;

    cout<<(a+ (pow (a,2) ) + (pow (a,3)) )<<endl;;


 }

Measured memory_bytes: 4288
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####
from collections import defaultdict as ddic, Counter, deque
import heapq, bisect, itertools
MOD = 10 ** 9 + 7

N = rri();A=rrm()

S = sum(A)
S %= MOD
ans = S*S % MOD
for x in A:
    ans -= x*x % MOD
    ans %= MOD
ans *= pow(2, MOD-2, MOD)
ans %= MOD
print ans


Measured memory_bytes: 99012
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m, sum = 0;
    cin >> n >> m;
    std::vector<int> a(n);
    for(int i = 0; i < m; i++){
        cin >> a[i];
        sum += a[i];
    }
    if(n >= sum) cout << n - sum;
    else cout << "-1";
    
    
}


Measured memory_bytes: 7212
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,k = MAP()
h = MAP()

dp = [MOD]*n
dp[0]=0

for i in range(n-1):
    for j in range(i+1,min(i+k+1,n)):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[n-1])

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

#define ALERT 1
#define SAFE  2
#define WARNING 3

int retval( double a, double b )
{
	double tp1, tp2;
	double theta;

	if ( a > b ) { 
		tp1 = a; tp2 = b;
	} else {
		tp1 = b; tp2 = a;
	}


	if ( tp1 - tp2 > 180 ) {
		theta = 360 - ( tp1 - tp2 );		
	} else {
		theta = tp1 - tp2;	
	}

	if ( theta >=0 && theta < 30 ) {
		return ALERT;
	} else if ( theta >= 90 && theta <= 180 ) {
		return SAFE;
	} else 
	{
		return WARNING;
	}
}

int main()
{
	int timenum = 0;
	char t[6], *tp;
	double h, m;

	scanf( "%d", &timenum );
	for ( int i = 0 ; i < timenum ; i++ ) {
		scanf( "%s", t );
		tp = strtok( t, ":" );
		h = atof( tp );
		tp = strtok( NULL, ":" );
		m = atof( tp );

		h = h * 360.0 / 12 + m * 30.0 / 60;
		m = m * 360 / 60;
		

		if ( ALERT == retval( h, m ) ) {
			printf( "alert\n" );
		} else if ( SAFE == retval(h, m ) ) {
			printf( "safe\n" );
		} else if ( WARNING == retval( h, m ) ) {
			printf( "warning\n" );
		}
	} 
	return 0;
}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
const ll INF = 1e16;

void solver(string &s, string &t, bool &flg){

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    bool comp = false;
    int max_loop = min(s.size(), t.size());
    for(int i = 0; i != max_loop; ++i){
        if(s.at(i) < t.at(i)){
            flg = true;
            comp = true;
            break;
        }
        else if(s.at(i) > t.at(i)){
            flg = false;
            comp = true;
            break;
        }
        else{}
    }

    if(comp == false){
        if(s.size() < t.size()) flg = true;
        else flg = false;
    }

    return;
}

int main(){

    string s, t;
    cin >> s >> t;

    bool flg = false;
    solver(s, t, flg);

    if(flg) cout << "Yes"s << endl;
    else cout << "No"s << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    string S;
    cin >> S;
    if(S[2]==S[3] && S[4]==S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
using namespace std;
const int MAXN = 1010;
const int MAXM = 50;
int X[MAXN], Y[MAXN], len[MAXM];
int n;
char s[MAXM];
void work() {
  scanf("%d", &n);
  for(reg int i = 1; i <= n; ++i) scanf("%d%d", &X[i], &Y[i]);
  int tmp = abs(X[1] + Y[1]) % 2;
  for(reg int i = 1; i <= n; ++i) {
    if(abs(X[i] + Y[i]) % 2 != tmp) {
      puts("-1");
      return;
    }
  }
  printf("%d\n", 32 - tmp);
  int tot = 0;
  len[++tot] = 1;
  printf("1");
  if(tmp) {
    /* for(reg int i = 1; i <= 30; ++i) len[++tot] = (1 << i);
    for(reg int i = 1; i <= 30; ++i) printf(" %d", len[i]);
    */
    for(reg int i = 1; i <= 30; ++i) printf(" %d", len[++tot] = (1 << i));
    puts("");
  } else {
    /* for(reg int i = 0; i <= 30; ++i) len[++tot] = (1 << i);
    for(reg int i = 0; i <= 30; ++i) printf(" %d", len[i]); */
    for(reg int i = 0; i <= 30; ++i) printf(" %d", len[++tot] = (1 << i));
    puts("");
  }
  for(reg int i = 1; i <= n; ++i) {
    ll nowx = 0, nowy = 0;
    for(reg int j = tot; j >= 1; j--) {
      ll nxtx = X[i] - nowx, nxty = Y[i] - nowy;
      if(abs(nxtx) > abs(nxty)) {
        if(nxtx > 0) nowx += len[j], s[j] = 'R';
        else nowx -= len[j], s[j] = 'L';
      } else {
        if(nxty > 0) nowy += len[j], s[j] = 'U';
        else nowy -= len[j], s[j] = 'D';
      }
    }
    printf("%s\n", s + 1);
  }
}
signed main() {
  int _ = 1;
  // scanf("%d", &_);
  while(_--) {
    work();
  }
  return 0;
}


Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  int ans=1;int A,B;
  int K;
  for(int i=0;i<N;i++){
    cin>>K;
    A=ans*2;B=ans+K;
    ans=min(A,B);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string ans = "";
	int w = tx-sx, h = ty-sy;
	for (int i = 0; i < w; i++) {
		ans += "R";
	}
	for (int i = 0; i < h; i++) {
		ans += "U";
	}
	for (int i = 0; i < w; i++) {
		ans += "L";
	}
	for (int i = 0; i < h; i++) {
		ans += "D";
	}
	ans += "D";
	for (int i = 0; i <= w; i++) {
		ans += "R";
	}
	for (int i = 0; i <= h; i++) {
		ans += "U";
	}
	ans += "LU";
	for (int i = 0; i <= w; i++) {
		ans += "L";
	}
	for (int i = 0; i <= h; i++) {
		ans += "D";
	}
	ans += "R";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll MOD = 2019;

///modulo version
ll binpow(ll a,ll b) {
if (b == 0)return 1;ll res = binpow(a, b / 2)%MOD;
if (b % 2)return ((res%MOD * res%MOD)%MOD * a%MOD)%MOD;else return (res%MOD * res%MOD)%MOD;}

ll inv(ll A)
{
    return binpow(A,MOD-2);
}
//modulo arithmetic
inline ll add(ll a, ll b)
{
	ll res = a + b;
	if(res >= MOD)
		return res - MOD;
	return res;
}

inline ll mult(ll a, ll b)
{
	ll  res = a;
	res *= b;
	if(res >= MOD)
		return res % MOD;
	return res;
}

inline ll sub(ll a, ll b)
{
	return (a%MOD-b%MOD+MOD)%MOD;
}
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	string s;
 	cin>>s;
 	ll n=s.size();
 	map<ll,ll>mp;
 	mp[0]=1;
 	ll val=0;
 	for(ll i=0;i<n;i++)
 	{
 		val*=10;
 		val+=s[i]-'0';
 		val%=MOD;
 		ll cur = binpow(10,n-1-i) * val;
 		cur%=MOD;
 		mp[cur]++;
 	}
 	ll ans=0;
 	for(pll x:mp)
 	{
 		ll f=x.second;
 		ans+=(f*(f-1))/2;
 	}
 	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3792
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {
	
	public static void main(String[] args) throws IOException {
		new Main().exec();
	}
	
	int n = 0;
	boolean[] adj = null;
	
	public void exec() throws IOException {
	    //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		InputUtil in = new InputUtil();
		PrintWriter out = new PrintWriter(System.out);
		n = in.nextInt();
		adj = new boolean[n*n];
		
		for(int i=1; i<=n; i++) {
			int nodeId=in.nextInt();
			int edgeNum = in.nextInt();
			for (int j=0; j<edgeNum; j++) {
				adj[(nodeId-1)*n + (in.nextInt()-1)] = true;
			}
		}
		
		for(int i=0; i<n; i++) {
			out.print(adj[i*n]?1:0);
			for(int j=1; j<n; j++) {
				out.print(' ');
				out.print(adj[i*n+j]?1:0);
			}
			out.println("");
		}
		out.flush();
	}
}

class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}

Measured memory_bytes: 26480
package main

import "fmt"

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var a, b, v, w, t int
	fmt.Scan(&a, &v, &b, &w, &t)
	if t*(v-w) >= abs(b-a) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1752
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int s = sc.nextInt();
		int nextVal = 0;
		boolean isExist = false;
		int cnt = 0;

		ArrayList<Integer> aryList = new ArrayList<Integer>();
		aryList.add(s);

		while(!isExist){
			nextVal = calc(s);

			if(aryList.contains(nextVal)){
				cnt = aryList.size() + 1;
 				isExist = true;
			}

            aryList.add(nextVal);
			s = nextVal;
		}

		System.out.println(cnt);

		sc.close();
	}

	private static int calc(int target){
		int ret = 0;

		if(target%2 == 0){
			ret = target / 2;
		}else{
			ret = 3 * target + 1;
		}

		return ret;
	}
}

Measured memory_bytes: 22740
#include <iostream>
using namespace std;
    
int main ()
{
    int A,B;
    cin >> A>>B;
    if (A==B)
    {
        cout<< "Draw";
    }
    else
    {
         if (A==1) cout << "Alice";
         if (B==1) cout << "Bob";
         if (A!=1&&B!=1) 
        {
             if (A>B) cout<< "Alice";
             if (B>A) cout<< "Bob";
        }
    }
return 0;
}

Measured memory_bytes: 256
x = gets.to_i

print(8) if x <= 599
print(7) if x >= 600 and x <= 799
print(6) if x >= 800 and x <= 999
print(5) if x >= 1000 and x <= 1199
print(4) if x >= 1200 and x <= 1399
print(3) if x >= 1400 and x <= 1599
print(2) if x >= 1600 and x <= 1799
print(1) if x >= 1800 and x <= 1999

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

int main(){
    int a,b;
    char op;
    vector<int> x,y;
    vector<char> c;
    do{
        cin >> a >> op >> b;
        x.push_back(a);
        y.push_back(b);
        c.push_back(op);
    }while(op != '?');
    
    for(int i=0; i<x.size()-1; i++){
        if(c[i] == '+')
            cout << x[i]+y[i] << endl;
        else if(c[i] == '-')
            cout << x[i]-y[i] << endl;
        else if(c[i] == '*')
            cout << x[i]*y[i] << endl;
        else if(c[i] == '/') 
            cout << x[i]/y[i] << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	int res = 0, a =0;
	for (int i = 0; i < n; i++) {
		int tmp;
		scanf("%d", &tmp);
		if (a <= tmp) {
			a = tmp;
			res++;
		}
	}
	printf("%d", res);

	return 0;
}

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

int ans, n;
char s[105];


int main() {
    scanf("%s\n", s + 1);
    n = strlen(s + 1);

    for (int i = 1; i <= n / 2; i++)
    ans += s[i] != s[n - i + 1];

    printf("%d\n", ans);

	return 0;
}


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

bool isPrime(int number)
{
	if (number < 2) return false;
	else if (number == 2) return true;
	else if (number % 2 == 0) return false;
	for (int i = 3; i < number; i+=2)
	{
		if (number%i == 0)
			return false;
	}

	return true;
}

bool is_prime(const unsigned n) {
	switch (n) {
	case 0: // fall-through
	case 1: return false;
	case 2: // fall-through
	case 3: return true;
	} // n > 3 が保証された

	if (n % 2 == 0) return false;
	if (n % 3 == 0) return false;
	// 2と3の倍数でないので6の倍数ではないことが保証された

	if (n % 6 != 1 && n % 6 != 5) return false;
	// 6の倍数前後の数(素数かもしれない数)であることが保証された

	// 6の倍数前後の数を使って試し割りをする
	for (unsigned i = 5; i*i <= n; i += 6) {
		if (n%i == 0) return false; // 6n-1
		if (n % (i + 2) == 0) return false; // 6n+1
	}

	return true;
}

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

	int numbers[10000];
	for (int i = 0; i < numElemet; i++) cin >> numbers[i];

	int cnt = 0;
	for (int i = 0; i < numElemet; i++)
	{
		if (is_prime(numbers[i])) cnt++;
	}

	cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3112
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

bool sh(string s){
    int n=s.size();
    int ng=0;
    rep(i,n/2){
        if(s[i]!=s[n-1-i]){
            ng++;
        }
    }
    // cout<<s<<endl;
    if(ng==0){
        return true;
    }
    else{
        return false;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    string s;
    cin>>s;
    int k=0;
    int n=s.size();
    if(sh(s)==false) k++;
    if(sh(s.substr(0,n/2))==false) k++;
    if(sh(s.substr(n/2+1,n/2))==false) k++;
    if(k==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{long long a,s;
 cin>>a>>s;
 long long p=ceil((double)a/2);

 long long o=ceil((double)s/2);
 long long j=p*o;
 long long u=ceil((double)(a-1)/2)*ceil((double)(s-1)/2);
 if(a==1||s==1)
   cout<<1;
 else
   cout<<j+u;
 return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._
import scala.collection.mutable.PriorityQueue

object Main extends App {
  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val prices = PriorityQueue(readLine.split(" ").map(_.toLong): _*)
  (1 to m).foreach { i => prices.enqueue(prices.dequeue / 2)}
  println(prices.sum)
}

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

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

using ll = long long;

ll gcd(ll x, ll y) {
    if (x % y == 0LL) return y;
    else return gcd(y, x % y);
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll X = gcd(A,B);
  ll i = 2LL;
  ll cnt = 0LL;
  ll Y = X;
  bool can = false;
  while(i*i<=X && i<=Y){
    can = false;
    while(Y % i == 0LL){
      can = true;
      Y /= i;
    }
    if(can) cnt++;
    if(i==2LL) i++;
    else if(i==3LL) i+=2LL;
    else if(i%6LL==5LL) i+=2LL;
    else i+=4LL;
  }
  if(Y!=1) cnt++;
  cout << cnt + 1LL << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){
    int n, k, x, y;
    scanf("%d%d%d%d", &n, &k, &x, &y);

    if(k>n) {
        printf("%d", n*x);
    }
    else {
        printf("%d", k*x+(n-k)*y);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    if(S[2]==S[3]
    && S[4]==S[5])cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"
const int inf=1e9;
const int M=1e9+7;


int32_t main()
{
    boost;
  	int n,tmp;
  	cin>>n;
  	int f=0;
  	map<int,int>mp;
  	for(int i=0;i<n;i++){
      cin>>tmp;
      mp[tmp]++;
      if(mp[tmp]>1)
        f=1;
    }
  	if(f)
      cout<<"NO"<<endl;
  	else
      cout<<"YES"<<endl;
}



Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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 main(){
    int n,m;
    cin >> n >> m;
    priority_queue<int,vector<int>,greater<int>>a;
    rep(i,n){
        int A;
        cin >> A;
        a.push(A);
    }
    vector<pair<int,ll>>ch(m);
    rep(i,m){
        int b;
        ll c;
        cin >> b >> c;
        ch[i]=make_pair(b,c);
    }
    sort(ch.begin(), ch.end(), [](auto &left, auto &right) {
    return left.second > right.second;
    });
    ll ans = 0;
    bool flag=true;
    rep(i,m){
        if(!flag)break;
        rep(j,ch[i].first){
            if(a.empty()){
                flag=false;
                break;
            }
            if(ch[i].second>a.top()){
                ans+=ch[i].second;
                a.pop();
            }
            else{
                ans+=a.top();
                a.pop();
            }
        }
    }
    while(!a.empty()){
        ans+=a.top();a.pop();
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2296
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i;
  int N;
  string s[100001];
  int numAC=0;
  int numWA=0;
  int numTLE=0;
  int numRE=0;
  
  cin >> N;
  for(i=1;i<=N;i++){
    cin >> s[i];
    if(s[i]=="AC")
      numAC++;
    else if(s[i]=="WA")
      numWA++;
    else if(s[i]=="TLE")
      numTLE++;
    else
      numRE++;
  }
  
  cout << "AC x " << numAC <<endl;
  cout << "WA x " << numWA <<endl;
  cout << "TLE x " << numTLE <<endl;
  cout << "RE x " << numRE <<endl;
  
  
}

Measured memory_bytes: 6760
from sys import stdin
from sys import setrecursionlimit
from queue import deque
setrecursionlimit(10 ** 7)

n,m = map(int,stdin.readline().rstrip().split())
li = [[]for _ in range(n)]
lin = []

length = {}
length_path = [0]*n

for i in range(m):
    a,b = map(int,stdin.readline().rstrip().split())
    a -= 1
    b -= 1
    li[a].append(b)
    li[b].append(a)
    if a < b:
        length[(a,b)] = 1
    else:
        length[(b,a)] = 1
    lin.append([a,b])


work_queue = deque([])
visited = [False]*n
work_queue.append(0)
while work_queue:
    now = work_queue.popleft()
    visited[now] = True
    for i in li[now]:
        if visited[i]:
            continue
        work_queue.append(i)
        visited[i] = True
        if now < i:
            length_path[i] = length_path[now]+length[(now,i)]
        else:
            length_path[i] = length_path[now]+length[(i,now)]
kotae = [0]*n

for num,i in enumerate(li):
    ima = i
    now = 10**10
    for j in ima:
        if length_path[j] < now:
            now = length_path[j]
            k = j
    kotae[num] = k+1
print("Yes")
for i in kotae[1:]:
    print(i)

Measured memory_bytes: 79904
'''
6が側面に来るようにして、6,5を繰り返す
'''
x = int(input())
cnt = 0
cnt += (x // 11) * 2
if 0 < (x % 11) <= 6:
    cnt += 1
elif 6 < (x % 11) < 11:
    cnt += 2
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
	int x,y;
	while(scanf("%d %d",&x,&y) != EOF){
	if(x==0 && y==0)
	break;
	if(x>y){
	int z;
	z=x; x=y; y=z;
	}
	printf("%d %d\n",x,y);
}
}


Measured memory_bytes: 2140
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
vector<pair<int,int> >v;
vector<pair<int,int> >vv;
vector<pair<int,pair<int,int> > >vvv;
int par[200007];
int init()
{
	int i;
	for(i=1;i<=2e5+5;i++)
		par[i]=i;
	return 0;
}
int parent(int aa)
{
	if(par[aa]==aa)
		return aa;
	return par[aa]=parent(par[aa]);
}
int union_(int aa,int bb)
{
	if(parent(aa)!=parent(bb))
		par[parent(aa)]=parent(bb);
	return 0;
}
int main()
{
	init();
	int m;
	scanf("%d",&m);
	int i;
	for(i=1;i<=m;i++)
	{
		int aa,bb;
		scanf("%d %d",&aa,&bb);
		v.pb(mp(aa,i));
		vv.pb(mp(bb,i));
	}
	sort(v.begin(),v.end());
	sort(vv.begin(),vv.end());
	for(i=1;i<v.size();i++)
		vvv.pb(mp(abs(v[i-1].fi-v[i].fi),mp(v[i-1].se,v[i].se)));
	for(i=1;i<vv.size();i++)
		vvv.pb(mp(abs(vv[i-1].fi-vv[i].fi),mp(vv[i-1].se,vv[i].se)));
	sort(vvv.begin(),vvv.end());
	long long int ans=0;
	for(i=0;i<vvv.size();i++)
	{
		if(parent(vvv[i].se.fi)!=parent(vvv[i].se.se))
			ans=ans+vvv[i].fi,union_(vvv[i].se.fi,vvv[i].se.se);
	}
	printf("%lld\n",ans);
	return 0;
}

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


int a[5];

int main(){
	for (int i = 0; i < 5; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + 5);
	for (int i = 4; i >= 0; i--) {
		if (i == 0) {
			printf("%d\n", a[i]);
		}
		else {
			printf("%d ", a[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 2768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll A,B,N;
    cin>>A>>B>>N;
    cout<<min(min(N*A/B,A-1LL),(ll)((double)A-(double)A/(double)B));
}

Measured memory_bytes: 3568
n=int(input())
s=['']*n
a=[0]*n
for i in range(n):
  s[i],v=input().split()
  a[i]=int(v)
x=input()
flg=False
ans=0
for i in range(n):
  if flg:
    ans+=a[i]
  if s[i]==x:
    flg=True
print(ans)


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

const int MAX_N = 1000010;

// is_p[i] := i ツつェツ素ツ青板づ個づ?つォ true
bool is_p[MAX_N+1] = {false,false};

// ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
void sieve(){
	for(int i = 2 ; i <= MAX_N ; i++ )
		is_p[i] = true;
	for(int i = 2 ; i*i <= MAX_N ; i++ ){
		if( is_p[i] ){
			for(int j = i+i ; j <= MAX_N ; j += i ){
				is_p[j] = false;
			}
		}
	}
}

int main(){
	int a, d, n;
	sieve();
	while( cin >> a >> d >> n, a || d || n ){
		int cnt = 0, ans;
		for(int i=a ; ; i += d ){
			if( is_p[i] ){
				cnt++;
				if( cnt == n ){
					ans = i;
					break;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
//#include<iostream>//list<> l,size() push_front(x) push_back(x) pop_front() pop_back() front() back() begin() end() insert(p,x) erase(p) clear()
#include<cstdio>//vector<> v, v.size(), v.push_back(), v.pop_back(), v.begin(), v.end(), v.insert(p,x), v.erase(p), v.clear();p:µü´úÆ÷
#include<list>//both vector and list can use "[]" list insert and delete only need O(1), vector O(n).
//#include<algorithm>
using namespace std;
int main()
{

  int q, x;
  char com[20];
  list<int> v;
  scanf("%d", &q);
  for(int i=0; i<q; i++)
  {
    scanf("%s", com);
    if(com[0] == 'i')
    {
      scanf("%d", &x);
      v.push_front(x);
    }
    else if(com[6] == 'L')
      v.pop_back();
    else if(com[6] == 'F')
      v.pop_front();
    else if(com[0] == 'd')
    {
      scanf("%d", &x);
      for(list<int>::iterator it = v.begin(); it != v.end(); it++)
      {
        if(*it == x)
        {
          v.erase(it);
          break;
        }
      }
    }
  }
  int i=0;
  for(list<int>::iterator it = v.begin(); it!=v.end(); it++)
  {
    if(i++)
      printf(" ");
    printf("%d", *it);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 33876
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scn = new Scanner(System.in);

		String N = scn.next();

        int s = 0;
//        while(num != 0){
//            s += num % 10;
//            num /= 10;
//        }

        for (int i = 0; i < N.length(); i++) {
        	s += Integer.parseInt(N.substring(i, i+1));
        }

//        System.out.println(s);
//        if (s > 8) {
    		System.out.println(s % 9 == 0 ? "Yes" : "No");
//		} else {
//			if (s == 0) {
//				System.out.println("Yes");
//			} else {
//				System.out.println("No");
//			}
//        }


	}
}


Measured memory_bytes: 50148
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
	string s;
  	cin>>s;
  	ll sum = 0;
  	for(char c:s){
    	int d = c-'0';
      	sum += d;
    }
  	if(sum%9)	cout<<"No";
  	else 		cout<<"Yes";
	return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int v[n];
  int tot = 0;
  for(int i=0; i<n; i++) cin >> v[i];
  tot += abs(v[0]);
  for(int i=1; i<n; i++) tot += abs(v[i] - v[i-1]);
  tot += abs(v[n-1]);
  
  //for zero
  cout << tot - abs(v[0]) - abs(v[0] - v[1]) + abs(v[1]) << endl;
  
  for(int i=1; i<n-1; i++){
    cout << tot - abs(v[i] - v[i-1]) - abs(v[i] - v[i+1]) + abs(v[i-1] - v[i+1]) << endl;
  }
  
  //for last
  cout << tot - abs(v[n-1] - v[n-2]) - abs(v[n-1]) + abs(v[n-2]) << endl;
}

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

using namespace std;

// This is the template of Errichto which can be found on https://codeforces.com/submissions/Errichto

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
#define LOCAL 1
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,0},{0,-1},{0,1},{1,0},{1,1},{-1,-1},{-1,1},{1,-1}};

int main()
{
    ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin >> v[i];
    int ans=0;
    for(int i=0; i<n; i++)
    {
        if((v[i]%2==1) && ((i+1)%2==1)) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
N = gets().chomp!.to_i
arr = gets().split.map{|p|
	p.to_i
}

MAX = arr.max
MIN = arr.min

puts 2*N-1
if MAX.abs >= MIN.abs then
	# 全ての数にMAXを足して
	temp = arr.index(MAX) + 1 #indexで求まったのは0始まりの位置なので
	1.upto(N) { |i|
		puts "#{temp} #{i}"
	}

	2.upto(N) { |i|
		puts "#{i-1} #{i}"
	}
	exit
else
	# 全ての数からMINを引いて
	temp = arr.index(MIN) + 1 #indexで求まったのは0始まりの位置なので
	1.upto(N) { |i|
		puts "#{temp} #{i}"
	}

	N.downto(2) { |i|
		puts "#{i} #{i-1}"
	}
	exit
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

// list up all prime factors, including how many times does it have the prime
template <typename T = int>
void primeFactors(T a, map<T, int> &facs) {
    double sqrtA = sqrt(a);
    for (int i = 2; i <= sqrtA + 1e-10; ++i) {
        while (a % i == 0) {
            facs[i]++;
            a /= i;
        }
    }
    if (a > sqrtA)
        facs[a]++;
    return;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, p;
    cin >> n >> p;
    map<lint, int> facs;
    primeFactors(p, facs);
    lint ret = 1;
    for (auto &f : facs) {
        lint pow = f.second / n;
        for (int i = 0; i < pow; ++i) {
            ret *= f.first;
        }
    }
    cout << ret << "\n";
    return 0;
}

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

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

typedef complex<double> P;

#define EPS (1e-10)
#define EQ(a, b) (abs((a)-(b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real) && EQ((a).imag(), (b).imag()))

P unit_vector(P a) { return a/abs(a); }
P normal_vector1(P a) { return a * P(0, 1); }
P normal_vector2(P a) { return a * P(0, -1); }
double distance_p_p(P a, P b) { return abs(a-b); }

int N;

int main()
{
	while (cin >> N, N) {
		vector<P> ps;

		rep(i, N) {
			double x, y;
			cin >> x >> y;
			ps.push_back(P(x, y));
		}

		int ans = 1;
		rep(i, N) {
			REP(j, i+1, N) {
				P p, q;
				p = ps[i]; q = ps[j];

				double d = distance_p_p(p, q);
				if (d > 2) continue;

				P pq_c = (q - p)/2.0;
				P a = unit_vector(normal_vector1(q-p));
				P b = unit_vector(normal_vector2(q-p));

				P c1 = (p + pq_c) + a*(sqrt(1.0-d*d/4.0));
				P c2 = (p + pq_c) + b*(sqrt(1.0-d*d/4.0));

				int buf1, buf2;
				buf1 = buf2 = 2;
				rep(k, N) {
					if (k == i || k == j) continue;
					if (distance_p_p(ps[k], c1) <= 1)
						buf1++;
					if (distance_p_p(ps[k], c2) <= 1)
						buf2++;
				}
				ans = max(ans, max(buf1, buf2));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int N;
    std::cin >> N;
    int min = 0, cnt = 0, P;
    for (int i = 0; i < N; ++i) {
        std::cin >> P;
        if (i == 0) {
            min = P;
            cnt++;
        } else {
            if (P <= min) {
                ++cnt;
                min = P;
            }
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}


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

int main(void)
{
    int k, n;
    cin >> k >> n;
    vector<int> a(2*n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i+n] = a[i] + k;
    int answer = k;
    rep (i, n) {
        if (a[i+n-1] - a[i] < answer) answer = a[i+n-1] - a[i];
    }
    cout << answer << endl;

}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int ll;
ll N;
int main(int argc, char const *argv[]) {
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  vector<ll> C(N);

  for (ll j = 0; j < N; j++) {
    cin >> A[j];
  }
  sort(A.begin(), A.end());
  for (ll j = 0; j < N; j++) {
    cin >> B[j];
  }
  sort(B.begin(), B.end());
  for (ll j = 0; j < N; j++) {
    cin >> C[j];
  }
  sort(C.begin(), C.end());
  ll ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    auto A_iter=lower_bound(A.begin(),A.end(),B[i]);
    A_iter--;
    ll sum_A=distance(A.begin(),A_iter)+1;
    auto C_iter=upper_bound(C.begin(),C.end(),B[i]);
    ll sum_C = -distance(C.end(),C_iter);
    ans+=sum_A*sum_C;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int P = sc.nextInt();
    int Q = sc.nextInt();
    int R = sc.nextInt();
    System.out.println(P + Q + R - Math.max(Math.max(P,Q),Math.max(Q,R))); 
  }
}

Measured memory_bytes: 20948
n = gets.chomp.to_i
ab = []
n.times do
  a,b= gets.chomp.split.map(&:to_i)
  ab.push([a, b])
end

ab.sort!{|i,j| i[1] <=> j[1] }

sum = 0
ab.each do |a, b| 
  sum += a
  if sum > b
    puts 'No'
    exit
  end
end

puts 'Yes'


Measured memory_bytes: 18524
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
double aa[50],b=0;
string ss[50];
int a;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>aa[i]>>ss[i];
		if(ss[i]=="JPY"){
			b+=aa[i];
		}else{
			b+=(aa[i]*380000.0);
		}
	}
	printf("%.6f",b);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int n,j;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		j = i;
		if (i % 3 == 0) {
			cout <<" "<<i;
		}
		else {
			while (j > 0) {
				if (j % 10 == 3) {
					cout << " " <<i;
					break;
				}
				else{
					j = j / 10;
				}
			}
		}
	}
	cout << endl;
}

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

int main()
{
    string str;
    int n,x,y,z;
    cin>>n;
    x=n/500;
    x*=2;
    x*=500;
    n%=500;
    n/=5;
    n*=5;

   cout<<n+x<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
int x[8], y[8];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int N;
    cin >> N;
    double sum = 0;
    int cnt = 0;
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    vector<int> v(N);
    iota(all(v), 0);
    do {
        double cur = 0;
        for (int i = 1; i < N; i++) {
            int dx = x[v[i]]-x[v[i-1]], dy = y[v[i]]-y[v[i-1]];
            cur += sqrt(dx*dx+dy*dy);
        }
        sum += cur;
        cnt++;
    } while (next_permutation(all(v)));
    cout << fixed << setprecision(7) << sum / cnt << '\n';
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <algorithm>
#define NODE_SIZE 101
#define NIL -1

using namespace std;

int adj[NODE_SIZE][NODE_SIZE];
int depth[NODE_SIZE];
int n, d;

void bfs(int node, int parent){
    depth[node] = depth[parent] + 1;
    for(int i = 1; i <= n; i++){
        if(adj[node][i] && (depth[i] == NIL || depth[i] > depth[node] + 1)){
            bfs(i, node);
        }
    }
}

int main(){
    int u, k, v;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        depth[u] = NIL;
        while(k--){
            cin >> v;
            adj[u][v] = 1;
        }
    }


    depth[0] = NIL;
    bfs(1, 0);
    for(int i = 1; i <= n; i++){
        cout << i << " " << depth[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;

	pair<pair<string, int >, int> p[110];

	string S[110];
	int P[110];


	for (int i = 1; i <= N; i++) {
		cin >> S[i];
		cin >> P[i];

		p[i] = make_pair(make_pair(S[i], -P[i]), i);
	}

	sort(p + 1, p + N + 1);

	for (int i = 1; i <= N; i++) {
		cout << p[i].second << "\n";
	}
}

Measured memory_bytes: 256