akhauriyash/Code-Regression huggingface dataset:
from collections import deque
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.insert(0, 0)
    J = [-1] * (N + 1)
    T = []
    que = deque([1])
    count = 0
    l = 0
    while que:
        i = que.popleft()
        if J[i] != -1:
            l = J[i]
            break
        J[i] = count
        count += 1
        T.append(i)
        que.append(A[i])
    if K < l:
        return T[K]
    else:
        return T[(K-l)%(len(T)-l) + l]
print(main())


Measured memory_bytes: 33808
#include <bits/stdc++.h>
using namespace std;
int n;
std::string s;
std::vector<std::string> vec;
std::set<std::string> m;
int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        m.insert(s);
        vec.push_back(s);
    }
    if (m.size() != n) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 1; i < vec.size(); i++) {
        if (vec[i-1][vec[i-1].size()-1] != vec[i][0]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main(){
    vector<vector<ll>> a(3,vector<ll>(3));
    vector<vector<ll>> x(3,vector<ll>(3,0));
    rep(i,3){
        rep(j,3){
            cin>>a[i][j];
        }
    }
    ll n; cin>>n;
    rep(i,n){
        ll b; cin>>b;
        rep(j,3){
            rep(k,3){
                if(a[j][k]==b) x[j][k]=1;
            }
        }
    }
    bool res=false;
    rep(i,3){
        if(x[i][0]*x[i][1]*x[i][2]==1) res=true;
    }
    rep(i,3){
        if(x[0][i]*x[1][i]*x[2][i]==1) res=true;
    }
    if(x[0][0]*x[1][1]*x[2][2]==1) res=true;
    if(x[2][0]*x[1][1]*x[0][2]==1) res=true;
    if(res) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll n;cin>>n;ll i;vll a(n);ain(i,n,a);
  //caricuratell k=0;
  ll k=0;
  rep(i,n){if(a[i]!=(i+1)){k++;}}
  //output
  if((k==0)||(k==2)){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
}

Measured memory_bytes: 256
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>

int gcd(int m, int n) {
  while (n) std::swap(m %= n, n);
  return m;
}

int main() {
  size_t n;
  int d;
  scanf("%zu %d", &n, &d);

  std::vector<int> x(n);
  for (auto& xi: x) scanf("%d", &xi), xi -= d;

  int res = 0;
  for (auto xi: x) res = gcd(res, xi);
  if (res < 0) res = -res;
  printf("%d\n", res);
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
int main(){
  random_device rnd;
  mt19937 mt(rnd());
  int D;
  cin >> D;
  vector<int> c(26);
  for (int i = 0; i < 26; i++){
    cin >> c[i];
  }
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; i++){
    for (int j = 0; j < 26; j++){
      cin >> s[i][j];
    }
  }
  vector<int> last(26, -1);
  for (int i = 0; i < D; i++){
    int t = min(8, D - i);
    vector<vector<int>> L(26, vector<int>(t, 0));
    for (int j = 0; j < 26; j++){
      for (int k = 0; k < t; k++){
        L[j][k] = c[j] * (i + k - last[j]);
      }
    }
    int mx = 0;
    int a = 0;
    vector<int> best(t);
    vector<vector<int>> L2 = L;
    for (int j = 0; j < 33000; j++){
      vector<int> next(t, 0);
      if (j < 21000){
        for (int k = 0; k < t; k++){
          next[k] = mt() % 26;
        }
      } else if (j < 29000){
        next = best;
        for (int k = 0; k < 3; k++){
          int pos = mt() % t;
          int upd = mt() % 26;
          next[pos] = upd;
        }
      } else {
        next = best;
        for (int k = 0; k < 2; k++){
          int pos = mt() % t;
          int upd = mt() % 26;
          next[pos] = upd;
        }
      }
      int diff = 0;
      for (int k = 0; k < t; k++){
        diff += s[i + k][next[k]];
        for (int l = k; l < t; l++){
          diff += L2[next[k]][l] - (l - k) * c[next[k]];
          L2[next[k]][l] = (l - k) * c[next[k]];
        }
      }
      if (diff > mx){
        mx = diff;
        best = next;
      }
      for (int k = 0; k < t; k++){
        if (L2[next[k]].back() != L[next[k]].back()){
          L2[next[k]] = L[next[k]];
        }
      }
    }
    cout << best[0] + 1 << endl;
    last[best[0]] = i;
  }
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seqH = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var longest = 0;
        var l = 0;
        for (int r = 1; r < seqH.Length; ++r)
        {
            if (seqH[r] <= seqH[r - 1])
            {
                continue;
            }

            longest = Math.Max(longest, r - l);
            l = r;
        }
        longest = Math.Max(longest, seqH.Length - l);
        Console.WriteLine(longest - 1);
    }
}


Measured memory_bytes: 30172
'use strict';

const main = input => {
  input = input.split('\n');
  const S = input[1].split(' ').map(Number);
  const T = input[3].split(' ').map(Number);
  console.log(
    // T.reduce((acc, v) => (binaryIndexOf(S, v) === -1 ? acc : acc + 1), 0),
    T.reduce((acc, v) => (binaryIndexOf_(S, v) === -1 ? acc : acc + 1), 0)
  );
};

const binaryIndexOf = (arr, key) => {
  let left = 0;
  let right = arr.length;
  while (left < right) {
    const mid = Math.floor((left + right) / 2);
    if (arr[mid] === key) {
      return mid;
    }
    if (arr[mid] > key) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return -1;
};

const binaryIndexOf_ = (arr, key) => {
  let left = 0;
  let right = arr.length - 1;
  while (left <= right) {
    const mid = Math.floor((left + right) / 2);
    if (arr[mid] === key) {
      return mid;
    }
    if (arr[mid] > key) {
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  return -1;
};

// Time Limit Exceeded
//
// function bs(arr, key) {
//   const len = arr.length;
//   if (len === 0) {
//     return false;
//   }
//   const mid = Math.floor(len / 2);
//   const midKey = arr[mid];
//   if (midKey === key) {
//     return true;
//   }
//   return bs(midKey > key ? arr.slice(0, mid) : arr.slice(mid + 1), key);
// }

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 32588
#include <iostream>
#include <vector>
#include <queue>

struct DJSet {
  int n;
  std::vector<int> upper;

  DJSet(int n) : upper(n, -1){}

  int root(int x) {
    return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
  }

  bool equiv(int x, int y){
    return root(x) == root(y);
  }

  void setUnion(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (upper[x] < upper[y]){
      x ^= y;
      y ^= x;
      x ^= y;
    }
    upper[y] += upper[x];
    upper[x] = y;
  }
  
};

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> X(M), Y(M), Z(M);
  std::vector<int> exist(N, 0);
  DJSet ds(N);
  for (int i = 0; i < M; ++i) {
    std::cin >> X[i] >> Y[i] >> Z[i];
    Z[i] %= 2;
    --X[i];
    --Y[i];
    ds.setUnion(X[i], Y[i]);
    exist[X[i]] = 1;
    exist[Y[i]] = 1;
  }
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    if (exist[ds.root(X[i])] != 1) continue;
    ++ans;
    exist[ds.root(X[i])] = 2;
  }
  for (int i = 0; i < N; ++i) {
    if (exist[i] == 0)  ++ans;
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}


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

int main(){
int K;
vector<int> vec={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
cin >> K;
cout<< vec.at(K-1) <<endl;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

int main() {
char a;
cin >> a;

if(a=='a')cout << "vowel" << endl;
else if(a=='i')cout << "vowel" << endl;
else if(a=='u')cout << "vowel" << endl;
else if(a=='e')cout << "vowel" << endl;
else if(a=='o')cout << "vowel" << endl;
else{
  cout << "consonant" << endl;
}

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n;
    cin>>n;
    int sum=0;
	rep(i,1,n+1){
		rep(j,1,n+1){
			rep(k,1,n+1){
				sum+=__gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

const int maxl = 112345;
const int maxn = (1 << 18) + 5;

int n, q;
int f[(1 << 9) + 1][maxl], v[maxn], w[maxn];

void dfs(int u) {
  FOR(i, 1, w[u] - 1) f[u][i] = max(f[u][i - 1], f[u >> 1][i]);
  FOR(i, w[u], int(1e5)) f[u][i] = max(f[u][i - 1], max(f[u >> 1][i], f[u >> 1][i - w[u]] + v[u]));
  if ((u << 1) <= min(n, (1 << 9) - 1)) dfs(u << 1);
  if ((u << 1 | 1) <= min(n, (1 << 9) - 1)) dfs(u << 1 | 1);
}

int main() {
  scanf("%d", &n);
  FOR(i, 1, n) scanf("%d%d", v + i, w + i);
  dfs(1);
  scanf("%d", &q);
  while (q--) {
    int u, L;
    scanf("%d%d", &u, &L);
    if (u < 1 << 9) {
      printf("%d\n", f[u][L]);
      continue;
    }
    vector<pii> tmp;
    while (u >= 1 << 9) {
      tmp.eb(v[u], w[u]);
      u >>= 1;
    }
    vector<int> V(1 << tmp.size()), W(1 << tmp.size());
    FOR(mask, 1, int(V.size()) - 1) {
      V[mask] = V[mask & (mask - 1)] + tmp[__builtin_ctz(mask)]._1;
      W[mask] = W[mask & (mask - 1)] + tmp[__builtin_ctz(mask)]._2;
    }
    int ans = 0;
    REP(mask, int(V.size())) if (W[mask] <= L) chkmax(ans, f[u][L - W[mask]] + V[mask]);
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 207492
import math
K = int(input())
result = 0
# 全て等しい場合はそれ自身が最大公約数
for i in range(1, K+1):
    result += i
# 二つが等しい場合は二つある方を選ぶので2倍、二数の公約数の三倍で6倍
d = {}
for i in range(1, K+1):
    for j in range(i+1, K+1):
        d[(i, j)] = math.gcd(i, j)
        result += 6 * d[(i, j)]
# 三つバラバラなら6倍
for i in range(1, K+1):
    for j in range(i+1, K+1):
        for k in range(j+1, K+1):
            tmp = 0
            if i < j:
                tmp = d[(i, j)]
            else:
                tmp = d[(j, i)]
            if tmp < k:
                result += 6 * d[(tmp, k)]
            else:
                result += 6 * d[(k, tmp)]
print(result)


Measured memory_bytes: 77792
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y)
{
    if (y < 0) {
        return dceil(-x, -y);
    }
    if (x < 0) {
        return -dfloor(-x, y);
    }
    return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y)
{
    if (y < 0) {
        return dfloor(-x, -y);
    }
    if (x < 0) {
        return -dceil(-x, y);
    }
    return x / y;
}

int main()
{
    int n;
    cin >> n;
    vector<int64_t> a(n);

    int64_t s = 0;
    rep(i, n)
    {
        cin >> a[i];
        s += a[i];
    }

    for (int64_t i = max(s - n * (n - 1), 0L); i <= s; i++) {
        int64_t t = 0;
        rep(j, n)
        {
            t += dceil(a[j] + i - (n - 1), n + 1);
        }
        if (t == i) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

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

using namespace std;

const int K = 26;

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

    int d;
    cin >> d;
    vector<int> c(K);
    for (int i = 0; i < K; ++i) {
        cin >> c[i];
    }
    vector<vector<int>> s(d, vector<int>(K));
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < K; ++j) {
            cin >> s[i][j];
        }
    }
    vector<int> ans;
    vector<int> last(26, -1);
    for (int i = 0; i < d; ++i) {
        vector<double> x;
        for (int j = 0; j < K; ++j) {
            x.push_back(s[i][j] * c[j] * (i - last[j]));
        }

        double sum = 0;
        for (int j = 0; j < K; ++j) {
            sum += x[j];
        }
        for (int j = 0; j < K; ++j) {
            x[j] /= sum;
        }

        double prob = (double) (rand() % RAND_MAX) / (double) RAND_MAX;
        double cur = 0;
        for (int j = 0; j < K; ++j) {
            if (cur + x[j] <= prob) {
                cur += x[j];
                continue;
            }
            ans.push_back(j);
            last[j] = i;
            break;
        }
    }

    for (auto u : ans) {
        cout << u + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 3680
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll inf =1LL << 62;


int main(void){
	int dp[2][256];
	int tar[20000];
	int d[16];
	const int  INF = 1 << 30;
	int n,m;
		while(cin >> n >> m,n|m){
		rep(i,m)
			cin >> d[i];
		rep(i,n)
			cin >> tar[i];
		rep(i,256){
			dp[0][i]=INF;
			dp[1][i]=INF;
		}
		dp[0][128]=0;
		rep(i,n){
			rep(j,256)rep(k,m){
				int next=j+d[k];
				next=max(next,0);
				next=min(next,255);
				int cost=(next-tar[i])*(next-tar[i]);
				dp[1][next]=min(dp[1][next],dp[0][j]+cost);
			}
			rep(j,256){
				dp[0][j]=dp[1][j];
				dp[1][j]=INF;
			}
		}
		int ans=INF;
		rep(i,256)
			ans=min(ans,dp[0][i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();
        long m = sc.nextLong();

        long ans = 0;

        if (n > m / 2) {
            ans = m / 2;
        } else {
            ans += n;
            m -= n * 2;
            ans += m / 4;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
#define f first
#define s second
typedef pair<int,int> pii;
const int N=3e3+5;
const int mod=998244353;
const ll inf=1e18+7;
ll a[N],dp[N][N];int n;
ll calc(int l,int r){
    if(l>r){
        return 0;
    }
    if(dp[l][r]!=-1){
        return dp[l][r];
    }
    if((l+n-r-1)%2==0){
        return dp[l][r]=max(calc(l+1,r)+a[l],calc(l,r-1)+a[r]);
    }
    return dp[l][r]=min(calc(l+1,r)-a[l],calc(l,r-1)-a[r]);
}
int main()
{
    fill(&dp[0][0], &dp[0][0] + N*N, -1);
    scanf("%d",&n);
    forn(i,0,n-1){
        scanf("%d",&a[i]);
    }
    printf("%lld\n",calc(0,n-1));
    return 0;
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;cin>>n;
	vector<pair<ll,P>> sum(n);
	for(int i = 0; i < n; i++) {
		ll x,y;cin>>x>>y;
		sum[i] = mp(x + y,mp(x,y));
	}
	sort(ALL(sum),greater<pair<ll,P>> ());
	ll t = 0;
	ll a = 0;
	for(int i = 0; i < n; i++) {
		if(i % 2== 0){t += (sum[i].sc).fs;}
		else {a += (sum[i].sc).sc;}
	}
	cout << t - a << endl;
	return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    char[] c = s.toCharArray();
    if((c[0] == c[1] && c[1] == c[2]) || c[1] == c[2] && c[2] == c[3]){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed); cout.precision(18)
typedef long long ll;
typedef long double ld;

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);
	int n,m;cin>>n>>m;
	map<int,set<pair<int,int> > > h;
	pair<int,int> ans[m];
	rep(i,0,m){
		int p,y;
		cin>>p>>y;
		h[p].insert(mp(y,i));
	}
	iter(it,h){
		int ind = 1;
		iter(it1,(*it).S){
			ans[(*it1).S] = mp((*it).F,ind);
			ind++;
		}
	}
	rep(i,0,m){
		int x=ans[i].F,y=ans[i].S;
		vector<int> temp;
		rep(k,0,6){
			temp.pb(y%10);
			y/=10;
		}
		rep(k,0,6){
			temp.pb(x%10);
			x/=10;
		}
		rep(j,0,temp.size()){
			cout<<temp[temp.size()-1-j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 16384
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String[] s = S.split("");
        String T = s[2]+s[1]+s[0];
        if(S.equals(T)) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22740
s = list(input())
t = list(input())
ls, lt = len(s), len(t)
ss = [0] * ls
alph1 = [-1] * 130
alph2 = [-1] * 130
for i in range(ls):
    c = 1
    m, n = ord(s[i]), ord(t[i])
    if alph1[m] == -1:
        alph1[m] = ord(t[i])
    else:
        if not alph1[m] == ord(t[i]):
            c = 0
    if alph2[n] == -1:
        alph2[n] = ord(s[i])
    else:
        if not alph2[n] == ord(s[i]):
            c = 0
    if c == 0:
        break
print("Yes" if c == 1 else "No")

Measured memory_bytes: 8112
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(void) {
  int dia=0, rect=0;
  int side1, side2, diagonal;
  char c1, c2;

  while(cin >> side1 >> c1 >> side2 >> c2 >> diagonal) {
    if(diagonal * diagonal == side1*side1 + side2*side2) rect++;
    else if(side1 == side2 ) dia++;
  }
  cout << rect << endl << dia << endl;
  return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  cin.ignore();

  for (int i = 1; i <= 50000; i++){
    if(i * 108 / 100 == n){
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
  return 0;
}
    


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


int main() {
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long int N,M,H,W,x,i,j,k,ans,count,cost,tmp;
    long long int S[300000];
    long long int T[300000];
    long long int U[300000];
    //long long int Ssum[300000];
    //string T,U,V,ans2;
    bool flag;
    count=0;
    ans=std::pow(10,18);
    ans=0;
    flag=false;
        cin >> N;
        //count=0;
    for (i=1;i<100;i++){
        for (j=1;j<100;j++){
            for (k=1;k<100;k++){
                x=i*i+j*j+k*k+i*j+j*k+k*i;
                if (x<10050 && i+j+k<123  ){
                    S[x]+=1;
                    
                    
                }
                
            }
        }
    }
    //cout << count<<endl;
    for (j=1;j<=N;j++){
        count=0;
 
        cout << S[j]<<endl;
    }
    
    
    
    //cout << ans<<endl;

    return 0;
    
}


Measured memory_bytes: 3652
#include <stdio.h>

int main(){
	int road[4]={0,0,0,0};
	int a,b;
	int i;
	int count=0;
	
	for(i=0;i<3;i++){
		scanf("%d %d",&a,&b);
		road[a-1]++;
		road[b-1]++;
	}
	
	for(i=0;i<4;i++){
		if(road[i]%2==1)	count++;
	}
	
	if(count==2)	printf("YES");
	else	printf("NO");
	
	return 0;
}

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

int		main() {
	int	N;

	cin >> N;
	vector<int>	nums(N);
	for (int i = 0; i < N; i++)
	{
		int a;

		cin >> a;
		nums.at(i) = a;
	}
	sort(nums.begin(), nums.end());
	nums.erase(unique(nums.begin(), nums.end()), nums.end());
	cout << nums.size() << endl;
}


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

signed main() {
  int H, N;
  cin >> H >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    H -= a;
  }

  if (H <= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll n;cin>>n;
    string s;cin>>s;
    rep(i,0,3){
        ll ans[n];
        ans[0]=i%2;
        ans[1]=i/2;
        rep(i,2,n-1){
            ll sum=0;
            sum+=ans[i-2];
            sum+=ans[i-1];
            if(s[i-1]=='o'){
                sum++;
            }
            if(sum%2==0){
                ans[i]=0;
            }else{
                ans[i]=1;
            }
        }
        ll sum=0;
        sum+=ans[n-2];
        sum+=ans[n-1];
        sum+=ans[0];
        if(s[n-1]=='o'){
            sum++;
        }
        if(sum%2==1){
            continue;
        }
        sum=0;
        sum+=ans[n-1];
        sum+=ans[0];
        sum+=ans[1];
        if(s[0]=='o'){
            sum++;
        }
        if(sum%2==1){
            continue;
        }
        rep(i,0,n-1){
            if(ans[i]==1){
                cout<<"S";
            }else{
                cout<<"W";
            }
        }
        cout<<endl;
        return 0;
    }
    cout<<-1<<endl;
    
    return 0;
}





Measured memory_bytes: 4552
import java.lang.Math

const val MOD = 1000000007L

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val a = readLine()!!.split(" ").map { it.toLong() }.toLongArray()
  val r = Math.sqrt(0.5+a.max()!!).toLong()
  var s = 0L
  for (i in 0 until n) s = (s+inv(a[i]))%MOD
  for (p in 2L..r) {
    var m = 0
    for (i in 0 until n) {
      var t = 0
      while (a[i]%p == 0L) {
        a[i] /= p
        t++
      }
      m = Math.max(m,t)
    }
    s = (s*pow(p,m))%MOD
  }
  for (p in a.filter { it != 1L }.toSet()) s = (s*p)%MOD
  println(s)
}

fun pow(a: Long, b: Int): Long {
  var p = 1L
  var m = a
  var k = b
  while (k > 0) {
    if ((k and 1) == 1) p = (p*m)%MOD
    m = (m*m)%MOD
    k = k shr 1
  }
  return p
}

fun inv(n: Long): Long {
  var a = (n%MOD+MOD)%MOD
  var b = MOD
  var c = 0L
  var x = 1L
  while (b != 0L) {
    val p = a/b
    var q = b
    b = a%b
    a = q
    q = x
    x = c
    c = q-p*c
  }
  return (x%MOD+MOD)%MOD
}

Measured memory_bytes: 40136
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    long long int a,b,x,c=0;
    cin >> a >> b >> x;
    if(a!=0){
        cout << b/x-(a-1)/x << "\n";
    }else{
        cout << b/x+1 << "\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  int ans=0;
  int highest=0;
 rep(i,n) cin>>p[i];
 rep(i,n) {
   ans+=p[i];
   if(highest<p[i]){
     highest=p[i];
   }
 }
  cout<<ans-highest/2<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/


typedef tuple<int, int, string> Data;

int n, k;
vs v;
map<Data, string> dp;
string fail(1000, 'Z'), src;

bool check(string& s, string& t)
{
	int cnt = 0, p = 0;
	REP(j, s.size())
	{
		if (s[j] == t[p])
		{
			cnt++;
			p++;
		}
	}
	return cnt == t.size();
}

string solve(int used, int last, string back)
{
	if (used == (1 << n) - 1) return "";
	Data d = make_tuple(used, last, back);
	if (dp.count(d)) return dp[d];
	string tmp = v[last];
	reverse(ALL(tmp));
	tmp += back;
	REP(i, n)
	{
		if (((used >> i) & 1) || !check(tmp, v[i])) continue;
		int nused = used | (1 << i);
		int nlast = i;
		string nback = tmp;
		REP(j, k)
		{
			nback.erase(nback.begin() + nback.find(v[i][j]));
		}
		string ans(fail);
		chmin(ans, solve(nused, nlast, nback));
		if (ans != fail)
		{
			string res;
			res += 'A' + i;
			res += ans;
			return dp[d] = res;
		}
	}
	return dp[d] = fail;
}

int main()
{
	//cout << check(string("CDEAFB"), string("EDFB"));
	
	cin >> n >> k;
	v.resize(n);
	REP(i, n) cin >> v[i];
	REP(i, n) src.push_back('A' + i);
	REP(i, n)
	{
		int used = 1 << i;
		int last = i;
		string back = src;
		REP(j, k)
		{
			back.erase(back.begin() + back.find(v[i][j]));
		}
		sort(ALL(back));
		string ans(fail);
		do
		{
			chmin(ans, solve(used, last, back));
		} while (next_permutation(ALL(back)));
		if (ans != fail)
		{
			cout << char('A' + i) << ans << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 66512
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace abc116b
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            Console.ReadKey(true);
#endif
        }
        public void Solve(ConsoleInput cin)
        {
            int N = cin.ReadInt;
            int[] L = new int[10];
            for (int i = 0; i < N; i++)
            {
                L[i] = cin.ReadInt;
            }

            int Lmax = 0;
            int Imax = 0;
            int Lsum = 0;

            Imax = 0;
            Lmax = L[0];
            Lsum = L[0];

            for (int i = 1; i < N; i++)
            {
                if (Lmax < L[i])
                {
                    Imax = i;
                    Lmax = L[i];
                }
                Lsum += L[i];
            }

            if (2 * L[Imax] < Lsum)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

nn = 200200
mod = 10**9+7

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
inv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % mod
for i in range(1, nn)[::-1]:
    inv[i] = fainv[i] * fa[i-1]

C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a-b] % mod if 0 <= b <= a else 0

N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

BU = [1] * N
TD = [1] * N
SI = [1] * N
for i in R[::-1]:
    a = 1
    s = 1
    for j in X[i]:
        a = a * BU[j] % mod
        s += SI[j]
    SI[i] = s
    BU[i] = inv[s] * a % mod

for i in R:
    c = len(X[i])
    AL = [1] * (c + 1)
    AR = [1] * (c + 1)
    for k, j in enumerate(X[i]):
        AL[k+1] = AL[k] * BU[j] % mod
    for k, j in list(enumerate(X[i]))[::-1]:
        AR[k] = AR[k+1] * BU[j] % mod
    for k, j in enumerate(X[i]):
        TD[j] = TD[i] * AL[k] % mod * AR[k+1] % mod * inv[N - SI[j]] % mod

for i in range(N):
    print(BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N-1, SI[i] - 1) % mod)

Measured memory_bytes: 127436
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    String x = sc.next();
    String y = Integer.toString(x.length() - 2);
    System.out.print(x.charAt(0) + y + x.charAt(x.length() -1));

 
  }
}

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

int main(){
  int K,N,A[200001],i,Max=0;
  cin>>K>>N;
  for(i=0;i<N;i++) cin>>A[i];
  for(i=0;i<N-1;i++){
    if(Max<A[i+1]-A[i]) Max=A[i+1]-A[i];
  }
  if(K-A[N-1]+A[0]>Max) Max=K-A[N-1]+A[0];
  cout<<K-Max<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>

#define MAX 3500

int main(){
  int n;
  scanf("%d", &n);

  for(int i = 1; i <= MAX; i++){
    for(int j = 1; j <= MAX; j++){
      if(4 * i * j - n * i - n * j == 0)
        continue;

      double t1 = i, t2 = j;
      double k = (n * t1 * t2) / (4 * t1 * t2 - n * t1 - n * t2);
      if(fabs(k - (int)k) > 1e-12)
        continue;
      if(k <= 0 || k > 3500)
        continue;

      double t = 4 * t1 * t2 * k - n * (t1 * t2 + t2 * k + k * t1);
      if(fabs(t) < 1e-9){
       // printf("%f\n", t);
        printf("%d %d %d\n", i, j, (int)k);
        return 0;
      }
    }
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
const int MAX=1e9+7;

int main()
{
    int n,m,x;
    int a[105];
    cin>>n>>m>>x;
    for(int i=0;i<m;i++)
        cin>>a[i];
    int m1=0,m2=0,cnt=0;
    for(int i=0;i<m;i++)
       {
           if(a[i]>x) m1++;
           if(a[i]<x) m2++;
       }
       cnt=min(m1,m2);
       cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        HashMap<Long, Long> A = new HashMap<>();
        long sum = 0;
        for (int i = 0; i < N; i++) {
            long val = scanner.nextLong();

            sum += val;
            A.put(val, A.getOrDefault(val,0L) + 1);
        }

        int Q = scanner.nextInt();
        for (int i = 0; i < Q; i++) {
            long B = scanner.nextLong();
            long C = scanner.nextLong();

            long count = A.getOrDefault(B,0L);
            A.remove(B);
            A.put(C, count + A.getOrDefault(C,0L));

            sum -= B * count;
            sum += C * count;

            System.out.println(sum);
        }
    }

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


Measured memory_bytes: 66576
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S, T;
  cin >> S >> T;
  vector<int> data(26, -1), datab(26, -1);
  int a, b, flag = 1;
  for(int i = 0; i < S.size(); i++){
    a = S.at(i) - 'a';
    b = T.at(i) - 'a';
    if(data.at(a) == -1 || data.at(a) == b){
      data.at(a) = b;
    } else {
      flag = 0;
      break;
    }
    if(datab.at(b) == -1 || datab.at(b) == a){
      datab.at(b) = a;
    } else {
      flag = 0;
      break;
    }
  }
  if(flag == 1)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 776
N,M = map(int, input().split())
citys = [list(map(int,input().split()))+[i] for i in range(M)]

citys.sort(key = lambda x:x[1])
nums = [0]*(N+1)
states = [None]*M

for p,y,i in citys:
    nums[p] += 1
    states[i] = [str(p), str(nums[p])]

for s in states:
    print(s[0].zfill(6)+s[1].zfill(6))


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll x,y;
    cin >> x >> y;
    ll cou=0;
    for(ll i=x;i<=y;i*=2){
        cou++;
    }
    cout << cou << endl;
}


Measured memory_bytes: 256
// aribon3-2-3_4_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    int n = S.size();

    int ans = n;
    REP(i, n - 1){
        if (S[i] != S[i+1]){
            ans = min(ans, max(i+1, n-i-1));
        }
    }

    print(ans);


    return 0;
}


Measured memory_bytes: 512
A, B, H, M = map(int, input().split())

import numpy as np


d1  = np.pi*H/12*2+np.pi*M/12/60*2
d2  = np.pi*M/60*2

if d1 >= d2:
    deg = d1 - d2
else:
    deg = d2 - d1

deg = np.min([deg, 2*np.pi-deg])

# 余弦定理
c = np.sqrt(A**2 + B**2 - 2*A*B*np.cos(deg))
print(c)

Measured memory_bytes: 27244
const fs = require("fs");

function Main(input){
  input = input.split("\n");
  var numArray = input[1].split(" ");
  var max = Math.max.apply(null, numArray);
  var min = Math.min.apply(null, numArray);
  console.log(Math.abs(max - min));
}
Main(fs.readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int hairu=sc.nextInt();
        int ans=0;
        for(int i=0;i<n;i++){
            hairu+=sc.nextInt();
            int deru=sc.nextInt();
            int S=hairu-deru;
            if(S<0){
                ans=0;
                break;
            }else if(S>ans){
                ans=S;
            }
            hairu=S;
        }
        System.out.println(ans);
    }
}

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

int main(){
  int i, n, s=0, t=0;
  int a[10000], b[10000];

  while(1){
    cin >> n;
    if (n==0) break;

    for (i=0; i<n; i++){
      cin >> a[i] >> b[i];
      if (a[i]>b[i]){
	s=s+a[i]+b[i];
      } else if (a[i]<b[i]){
	t=t+a[i]+b[i];
      } else {
	s+=a[i]; t+=b[i];
      }
    }
    cout << s << " " << t << endl;
    s=0; t=0;
  }

  return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, l;
    cin >> n >> l;

    int ans = 0, minv = INT_MAX;
    rep(i, 0, n) {
        if (abs(minv) > abs(i + l)) { minv = i + l; }
        ans += i + l;
    }
    cout << ans - minv << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second
lint N;
map<lint, lint> m;
lint cnt;
lint l;
lint res;
vector<P> A;
lint rec(lint i, lint v){
    lint res = 0;
    if(i==l){
        lint q = (N-v) / v;
        if(q==0) return 0;
        if(N/q == N%q) return q;
        else return 0;
    }
    else{
        for(lint x=0; x<=A[i].second; x++){
            res += rec(i+1, v*pow(A[i].first, x));
        }
    }
    return res;
}

vector<P> factoring(lint N){
    vector<P> res;  
    lint n=N;
    for(lint i=2; i*i<=N; i++){
        lint x = 0;
        while(n%i==0){
            x++;
            n /= i;
        }
        if(x) res.push_back(make_pair(i, x));
    }
    if(n>1) res.push_back(make_pair(n, 1));
    return res;
}

signed main(){
    cin>>N;
    A = factoring(N);
    l = A.size();
    cout << rec(0, 1) << endl;
    return 0;
}


lint pow(lint n, lint x){
    lint res = 1;
    while(x){
        if(x%2) res *= n;
        x = x>>1;
        n *= n;
    }
    return res;
}

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

int a,b,c;

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

Measured memory_bytes: 256
//    _        _   __
//   (_)      | | / /
//    __ ___  | |/ / ___    ____
//   | |/ _ `\|   | / _ `\ / _  \
//   | | (_) | |\ \| (_) || (_) |
//   | |\__,_|_| \_\___,_|\____/
// _/ |
//|__/
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007LL
#define lowbit(x) (x&-x)
using namespace std;
using ll = long long;


int main(){
	ios::sync_with_stdio(false);cin.tie(NULL);
	int n;
	cin>>n;
	if(n==1){
		cout<<1<<endl;
		cout<<0<<endl;
	}
	else if(n==2){
		cout<<2<<endl;
		cout<<0<<endl;
		cout<<11<<endl;
	}
	else{
		cout<<n-1<<endl;
		for(int i=0;i<n-1;i++){
			cout<<1;
			for(int j=0;j<i;j++){
				cout<<0;
			}
			cout<<1;
			cout<<endl;
		}
	}
	return 0;
}
/*
1000001
100001
10001
1001
101
11

3

111
11
0
*/


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int n,f;
int main(){
	cin>>n;
	for(int i = 1; i <= n; i++){
		if(f == 3)break;
		int a,b;
		cin>>a>>b;
		if(a == b)f++;
		else f = 0;
	}
	if(f >= 3)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int f(int i)
{
  if(i%2==0) return i/2;
  else return 3*i+1;
}

int main()
{
  int s,tmp;
  cin>>s;
  tmp=s;

  if(s==1 || s==2 || s==4) cout<<4<<endl;
  else
  for(int i=2;i<1000000;i++)
  {
    if(f(tmp)==4 || f(tmp)==2 ||  f(tmp)==1)
    {
      cout<<i+3<<endl;
      break;
    }

    else tmp=f(tmp);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}
// 本体

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> a(n + 1), s(n + 1, 0);
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if(i - a[i] >= 0){
			ans += s[i - a[i]];
		}
		if(a[i] + i <= n) {
			s[a[i] + i]++;
		}
	}
	dump(ans);
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 1005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

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

int dp[SIZE][SIZE];

void solve(){
  int n,m;
  string X,Y;
  cin >> X >> Y;
  n = X.size();
  m = Y.size();
  fill(dp[0],dp[0]+SIZE,0);
  rep(i,0,n) rep(j,0,m){
    int a=0,b=0,c=0;
    if(i>0)a = dp[i-1][j];
    if(j>0)b = dp[i][j-1];
    if(i>0 && j>0)c = dp[i-1][j-1];
    dp[i][j] = max({a,b,c+(X[i]==Y[j]?1:0)});
  }
  cout << dp[n-1][m-1] << endl;
}

int main(){

  int q;
  cin >> q;
  rep(i,0,q){
    solve();
  }

  return 0;
}



Measured memory_bytes: 6972
n = int(input())
H = list(map(int, input().split()))

dp = [10 ** 9 for i in range(n)]
dp[0] = 0
for i in range(n):
        if i - 1 >= 0:
                dp[i] = min(dp[i], dp[i - 1] + abs(H[i] - H[i-1]))
        
        if i - 2 >= 0:
                dp[i] = min(dp[i], dp[i - 2] + abs(H[i] - H[i-2]))

#print(dp)
print(dp[n-1])

Measured memory_bytes: 13976
#include<bits/stdc++.h>
#define to first
#define wgt second 

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vec;
typedef vector<vec> Graph;

Graph G(11000);
int n,d[11000];

void SPFA()
{
	bool used[11000];
	queue<int> que;
	memset(used,false,sizeof(used));
	fill(d,d+n,INT_MAX);
	d[0]=0;
	que.push(0);
	while(!que.empty())
	{
		int u=que.front();que.pop();
		for(int i=0;i<G[u].size();i++)
			if(d[G[u][i].to]>d[u]+G[u][i].wgt)
			{
				d[G[u][i].to]=d[u]+G[u][i].wgt;
				que.push(G[u][i].to);
			}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int u,t;
		scanf("%d%d",&u,&t);
		for(int j=0;j<t;j++)
		{
			int v,w;
			scanf("%d%d",&v,&w);
			G[u].push_back(make_pair(v,w));
		}
	}
	SPFA();
	for(int i=0;i<n;i++)
		printf("%d %d\n",i,d[i]);
	return 0;
}

Measured memory_bytes: 7964