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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  ll n,k; cin >> n >> k;
  vl a(n);
  rep(i,n)cin>>a[i],a[i]--; //0-indexed
  int logK = 1;
  while ((1LL << logK) < k) logK++;
  vvl doubling(logK,vl(n));
  rep(i,n) doubling[0][i] = a[i];
  rep(i,logK-1)rep(j,n) doubling[i + 1][j] = doubling[i][doubling[i][j]]; 

  int now = 0;
  for (int i = 0; k > 0; i++) {
      if (k & 1) now = doubling[i][now];
      k = k >> 1;
  }
  cout << now + 1 << endl;
}


Measured memory_bytes: 99956
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 110;
ll n, arr[maxn];
ll minv, maxv;
int main() {
    cin>>n;
    minv = LLONG_MAX;
    maxv = LLONG_MIN;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
        minv = min(minv, arr[i]);
        maxv=  max(maxv, arr[i]);
    }
    cout<<(maxv-minv)<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    string s, t; cin >> s >> t;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 3128
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,n,m,k,l,in,t,out;
  string str;
  bool mm[1001];
  while(1){
    cin >> m >> n;
    if(n == 0 && m == 0) break;
    for(i=1;i<=m;i++) mm[i] = 1;
    in = 0;
    out = 0;
    for(i=1;i<=n;i++){
      cin >> str;
      in++;
      if(in > m) in -= m;
      if(out == m - 1) continue;
      while(!mm[in]){
	in++;
	if(in > m) in -= m;
      }

      if(i % 5 == 0 && i % 3 == 0 && str != "FizzBuzz"){
	mm[in] = 0;
	out++;
      }
      else if(i % 3 == 0 && i % 5 != 0 && str != "Fizz" || i % 5 == 0 && i % 3 != 0 && str != "Buzz"){
	mm[in] = 0;
	out++;
      }
      else if(i % 5 == 0 && i % 3 == 0 && str == "FizzBuzz") continue;
      else if(i % 3 == 0 && str == "Fizz" || i % 5 == 0 && str == "Buzz") continue;
      else{
	k = 0;
	j = 1;
	for(l=str.size()-1;l>=0;l--){
	  if(str[l] < '0' && '9' < str[l]){
	    k = -1;
	    break;
	  }
	  else{
	    k += (str[l] - '0') * j;
	    j *= 10;
	  }
	}
	if(i != k){
	   mm[in] = 0;
	   out++;
	}
      }
    }
    
    bool c = true;
    for(i=1;i<=m;i++){
      if(mm[i] && c){
	cout << i;
	c = false;
      }
      else if(mm[i]) cout << " " << i;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 928
H,W,D = list(map(int,input().split()))

A = [list(map(int,input().split())) for i in range(H)]

B = [0 for i in range(H*W)]

for i in range(H):
    for j in range(W):
        B[A[i][j]-1] = [i,j]

Q = int(input())

C= [list(map(int,input().split())) for i in range(Q)]

DS = [[0] for i in range(D)]
for i in range(D):
    ds = 0
    j=1
    while j*D + i <H*W:
        ds+=abs(B[j*D + i][0]-B[(j-1)*D + i][0])+abs(B[j*D + i][1]-B[(j-1)*D + i][1])
        DS[i].append(ds)
        j+=1

for i in range(Q):
    l,r=C[i]
    l=l-1
    r=r-1
    q=l%D
    print(DS[q][r//D]-DS[q][l//D])

Measured memory_bytes: 47980
import Control.Applicative
import Data.Char
main = do
  v <- map (map (\x->ord(x) - ord('0'))) . lines  <$> getContents
  mapM_ (putStrLn . show . solve) v

solve::[Int] -> Int
solve v = head $ aux v
  where
    aux ::[Int] -> [Int]
    aux f = if length f == 1 then
              f
            else
              aux (zipWith (\x y->(x+y) `mod` 10) f (tail f))

Measured memory_bytes: 3480
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using Int = long long;
#define REP(i, n) for (int i = 0; i < n; i++)
int main()
{
    int A, B, C, D; cin >> A >> B >> C >> D;
    cout << max(0, min(B, D) - max(A, C)) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int maxX = x;
		int minY = y;
		
		for (int i = 0; i < n; i++) {
			maxX = Math.max(maxX, sc.nextInt());
		}
		
		for (int i = 0; i < m; i++) {
			minY = Math.min(minY, sc.nextInt());
		}
		
		String ans = maxX < minY ? "No War" : "War";
		System.out.println(ans);
		sc.close();
	}
}




Measured memory_bytes: 27268
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int d, L, R;
  cin >> L >> R >> d;
  int ret = 0;
  for (int i = L; i <= R; ++i) {
    if (i % d == 0) ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3188
import java.util.*
import kotlin.comparisons.*

fun main(args : Array<String>) {
  val (n, k) = readLine()!!.split(' ').map(String::toInt)
  val vv = readLine()!!.split(' ').map(String::toLong)
  val h = Math.min(n, k)
  var ans = 0L
  for (l in 0..h) {
    for (r in 0..h - l) {
      val s = (vv.subList(0, l) + vv.subList(n - r, n)).sorted()
      var sum = s.sum()
      val d = k - l - r
      for (i in 0 until d) {
        if (s.size <= i || 0 < s[i]) break
        sum -= s[i]
      }
      ans = Math.max(ans, sum)
    }
  }
  println(ans)
}


Measured memory_bytes: 38152
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll  longinf = 1LL<<60;
const ll mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;cin>>n;
  string s;cin>>s;
  int num[n+1],nnum[n+1];
  num[0]=0;
  nnum[n]=0;
  rep(i,n){
    num[i+1]=num[i]+(s[i]=='W');
    }
  rep(i,n)nnum[n-i-1]=nnum[n-i]+(s[n-i-1]=='E');
  int mi=inf;
  rep(i,n){
    mi=min(mi,num[i]+nnum[i+1]);
    }
  cout<<mi<<endl;
  
  return 0;
  }

Measured memory_bytes: 3076
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int main()
{
  string S,T;
  cin >> S;
  cin >> T;

  if (S.compare(T)== 0){
    cout << "Yes" << endl;
    return 0;
  }

  REP(i,SZ(S)){
    rotate(S.begin(),S.begin()+1,S.end());
    if (S.compare(T) == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const ll N = 1e9, MOD =  998244353;

void solve() {
  ll n;
  cin >> n;
  if (n == 1){
    cout << 0;
    return;
  }
  int ans = 0;
  for (ll i = 2; i*i <= n; ++i) {
        int count = 0;
        while (n % i == 0) {
            count++;
            n /= i;
        }
        int x = 0;
        while (x*(x + 1)/2 <= count)
            x++;
        ans += --x;
    }
     if (n > 2)
            ans++;
    cout << ans;
}

int main()  {
  ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                  


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

string s;
int n, g, p, ans;

int main() {
  cin >> s;
  n = s.size();

  for (int i = 0; i < n; ++i) {
    if (g == p) {
      if (s[i] == 'g') {
	// nothing
      }
      else ans--;
      g++;
    }
    else {
      if (s[i] == 'g') {
	ans++;
      }
      else {
	// nothing
      }
      p++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

v = [0] * n
ans = 0
for i in 0...n
  while v[i] < a[i]
    ans += 1
    it = i
    while it<n && v[it] < a[it]
      v[it] += 1
      it += 1
    end
  end
end
puts ans

Measured memory_bytes: 1788
import itertools

n, m = map(int, input().split())
a_list = []
b_list = []
for i in range(m):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

link_flag = 1
cnt = 0

for k in itertools.permutations(range(n)): #順列を生成して、それらに対して処理
    if k[0] != 0:
        break
    link_flag = 1
    for i in range(len(k)-1):
        if link_flag == 0:
            break
        link_flag = 0
        for j in range(m):
            if k[i]+1 == a_list[j]:
                if k[i+1]+1 == b_list[j]:
                    link_flag = 1
                    #print(k,a_list[j],b_list[j])
                    break
            if k[i]+1 == b_list[j]:
                if k[i+1]+1 == a_list[j]:
                    link_flag = 1
                    #print(k,a_list[j],b_list[j])
                    break
        if i == len(k)-2 and link_flag ==1:
            cnt += 1
print(cnt)


Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	   c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to;string s;
};
vector<node> to[MAXN * 4];
int N,Q,Ncnt;
int ed[MAXN * 4],ans[MAXN],pri[30],siz[MAXN * 4],pla[MAXN];
int dp[MAXN * 4][26][26];
string str[MAXN],order;
void insert(int u,int id,int pos) {
    if(pos == str[id].length()) {ed[u] = id;pla[id] = u;return;}
    for(auto &t : to[u]) {
        if(t.s[0] == str[id][pos]) {
            int l = -1;
            while(l + 1 < str[id].length() - pos && l + 1 < t.s.length()) {
                if(str[id][pos + l + 1] == t.s[l + 1]) ++l;
                else break;
            }
            if(l + 1 == t.s.length()) {
                insert(t.to,id,pos + t.s.length());
                return;
            }
            int nw = ++Ncnt;
            to[nw].pb((node){t.to,t.s.substr(l + 1)});
            t.to = nw;t.s = t.s.substr(0,l + 1);
            if(l + 1 == str[id].length() - pos) {
                ed[nw] = id;pla[id] = nw;
            }
            else {
                to[nw].pb((node){++Ncnt,str[id].substr(pos + l + 1)});
                ed[Ncnt] = id;
                pla[id] = Ncnt;
            }
            return;
        }
    }
    to[u].pb((node){++Ncnt,str[id].substr(pos)});
    ed[Ncnt] = id;pla[id] = Ncnt;return;
}
void pre_Process(int u,int all) {
    if(ed[u]) {ans[ed[u]] = all;siz[u]++;++all;}
    for(auto t : to[u]) {
        pre_Process(t.to,all);
        siz[u] += siz[t.to];
    }

}
void Calc(int u) {
    for(auto t : to[u]) {
        memcpy(dp[t.to],dp[u],sizeof(dp[t.to]));
        for(auto k : to[u]) {
            if(t.to == k.to) continue;
            dp[t.to][k.s[0] - 'a'][t.s[0] - 'a'] += siz[k.to];
        }
    }
    for(auto t : to[u]) {
        Calc(t.to);
    }
}
void Solve() {
    read(N);
    Ncnt = 1;
    for(int i = 1 ; i <= N ; ++i) {
        cin >> str[i];
        insert(1,i,0);
    }
    pre_Process(1,0);
    Calc(1);
    read(Q);
    int k;
    for(int i = 1 ; i <= Q ; ++i) {
        read(k);cin >> order;
        int res = 0;
        for(int j = 0 ; j < 26 ; ++j) {
            for(int t = j + 1 ; t < 26 ; ++t) {
                res += dp[pla[k]][order[j] - 'a'][order[t] - 'a'];
            }
        }
        out(res + ans[k] + 1);enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 341248
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}

int main()
{
    fast


        
    ll a,b;
    cin>>a>>b;

    ll n = __gcd(a,b);

    ll count = 1;

    ll i = 1;

    for(; i*i < n; i++)
    {
        if(n%i == 0)
        {
            if((n/i)&1 && isprime(n/i)) count++;
            if(i&1 && isprime(i)) count++;
            if(i == 2) count++;
        }
    }    

    if(i*i == n && isprime(i))
    {
        count++;
    }

    cout<<count;








    return 0;
}

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

#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define clr(arr, key) memset(arr, key, sizeof arr)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define infinity (1 << 28)
#define LL long long
#define PI acos(-1)
#define gcd(a, b) __gcd(a, b)
#define CF ios_base::sync_with_stdio(0);cin.tie(0);
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define all(v) v.begin(), v.end()
#define no_of_ones __builtin_popcount // __builtin_popcountll for LL
#define SZ(v) (int)(v.size())
#define eps 1e-7

//int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//int col[4] = {1, 0, -1, 0};
//int row[4] = {0, 1, 0, -1};
//int months[13] = {0, ,31,28,31,30,31,30,31,31,30,31,30,31};

using namespace std;

struct point{int x, y; point () {} point(int a, int b) {x = a, y = b;}};
template <class T> T sqr(T a){return a * a;}
template <class T> T power(T n, T p) { T res = 1; for(int i = 0; i < p; i++) res *= n; return res;}
template <class T> double getdist(T a, T b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}    // distance between a and b
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}
template <class T> string tostring(T n) {stringstream ss; ss << n; return ss.str();}
//LL bigmod(LL B,LL P,LL M){LL R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
struct fast{fast(){ios_base::sync_with_stdio(0);cin.tie(0);}}cincout;

#define MAX 100010
/***********************************THE GRASS IS ALWAYS GREENER ON THE OTHER SIDE***********************************/

int main()
{
    // in;
    vector <LL> allNums;
    for(LL i = 0; power(i, 5LL) < 1e17; i++)
        allNums.pb(power(i, 5LL));
    LL x;
    cin >> x;
    for(int i = 0; i < SZ(allNums); i++){
        for(int j = 0; j < SZ(allNums); j++){
            if(allNums[i] - allNums[j] == x){
                cout << i << ' ' << j << "\n";
                return 0;
            }
            if(allNums[i] + allNums[j] == x){
                cout << i << ' ' << -j << "\n";
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3732
#include <stdio.h>

int main(void)
{
	unsigned short int i;
	int n, buf[100]={0};

	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &buf[i]);
	}

	for(i=n-1; i>0; i--){
		printf("%d ", buf[i]);
	}
	printf("%d\n", buf[0]);

	return 0;
}

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

using namespace std;

using ll = long long int;

struct point {
    int x, y;
};

double dist(point a, point b){
    return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}

int main() {

    int n;
    cin >> n;

    point arr[n];

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;

        arr[i] = {x, y};
    }

    vector<int> perm;
    for(int i=0; i<n; i++) perm.push_back(i);

    double ans = 0, cnt = 0;

    do{
        for(int i=0; i<n-1; i++){
            point a = arr[perm[i]];
            point b = arr[perm[i+1]];

            ans += dist(a, b);

//            for(auto i: perm) cout << i << " ";
//            cout << endl;

            cnt++;
        }

    }while(next_permutation(perm.begin(), perm.end()));

    ans *= n-1;

    cout << setprecision(12) <<  ans / cnt << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  unsigned long long n,m,ans,mod=1e9+7;
  cin>>n>>m;
  if(n==1)cout<<(m+1)%mod<<endl;
  else if(m==0)cout<<1<<endl;
  else{
    ans=( ((m/(n-1))%mod) * ((m-n+3+m%(n-1))%mod) )%mod+1+m;
    // ans=((m-(n-1)+2+m%(n-1))%mod*(m/(n-1))%mod)+m+1;
  cout<<ans%mod<<endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll m, d, c;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> m;
	ll sum = 0;
	ll ans = -1;
	rep(i, 1, m){
		cin >> d >> c;
		sum += d*c;
		ans += c;
	}
	ans += (sum-1)/9;
	print(ans)
	return 0;
}

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

bool f[26];
int main(void) {
  string s;
  cin >> s;

  for (int i = 0; s[i] != '\0'; i++) {
    f[s[i] - 'a'] = true;
  }
  for (int i = 0; i < 26; i++) {
    if (!f[i]) {
      printf("%c\n", (char)('a' + i));
      return 0;
    }
  }

  printf("None\n");
  return 0;
}


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

#define f(i,a,b) for (int i = a; i < b; i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n; cin >> n;
	if (n == 3) cout << "2 5 63" << endl;
	else {
		int a[8];
		if (n&1) {
			int b[] = {6,3,9,2,10,4,8,12};
			f(i,0,8) a[i] = b[i];
		} else {
			int b[] = {2,10,3,9,4,8,6,12};
			f(i,0,8) a[i] = b[i];
		}
		f(i,0,n) cout << a[i%8]+12*(i/8) << " ";
		cout << endl;
	}

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 384
from itertools import combinations as comb


def comb2(a):
    return a * (a - 1) // 2


n = int(input())

numS = 2
while True:
    if n < comb2(numS):
        print("No")
        exit()
    elif n == comb2(numS):
        break
    numS += 1

lenS = n * 2 // numS

print("Yes")
print(numS)
ans = {}
for i, room in enumerate(comb(range(numS), 2)):
    # print(room)
    for a in room:
        if a not in ans:
            ans[a] = [str(i + 1)]
        else:
            ans[a].append(str(i + 1))


for ansS in ans.values():
    print(str(lenS) + " " + " ".join(ansS))

Measured memory_bytes: 17140
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    char x,y;
    cin >> x >> y;

    if(x < y){
        cout << "<" << endl;
    }else if(x > y){
        cout << ">" << endl;
    }else{
        cout << "=" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// 2020-09-10 21:38:19
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<char> t(q), d(q);
  rep(i, q) cin >> t[i] >> d[i];
  int ans = n;
  auto ok = [&](int k, int x) {
    rep(i, q) {
      if (s[x] == t[i]) {
        x += (d[i] == 'R') * 2 - 1;
        if (x == -1) return k == 0;
        if (x == n) return k == 1;
      }
    }
    return false;
  };
  {
    int l = -1, r = n;
    while (l + 1 < r) {
      int x = (l + r) / 2;
      if (ok(0, x))
        l = x;
      else
        r = x;
    }
    ans -= l + 1;
  }
  {
    int l = -1, r = n;
    while (l + 1 < r) {
      int x = (l + r) / 2;
      if (ok(1, x))
        r = x;
      else
        l = x;
    }
    ans -= n - r;
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 1000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

string D[7]{"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(){
    string S;cin >> S;
    int ans =0;
    for(int i = 0;i < 7;i++){
        if(S == D[i]){
            ans = i;
            break;
        }
    }
    cout << 7 - ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;cin >> s;
    while (s.size()>0){
        if (s[0]!='A'){
            s.erase(s.begin()+0);
        }
        else  break;
    }
    while (s.size()>0){
        if (s.back()!='Z'){
            s.erase(s.begin()+s.size()-1);
        }
        else break;
    }
    cout << s.size();
    
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n,k,x,y; cin >> n >> k >> x >> y;
    if (n <= k) cout << n*x << endl;
    else cout << k*x+(n-k)*y << endl;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))

from collections import deque 
tmp = 1
num = []
seen = [-1]*(N+1)
 
while seen[tmp] == -1:
    seen[tmp] = tmp
    num.append(tmp)
    tmp = A[tmp]


l = num.index(tmp)
c = len(num) - l

if K < l:
    print(num[K])
else:
    print(num[(K-l)%c+l])

Measured memory_bytes: 96988
N = gets.to_i
red = []
radR = []
N.times do |i|
  red[i] = gets.split.map(&:to_i)
  radR[i] = red[i].inject(:+)
end
#red = red.sort_by.with_index{ |x,i| radR[i] }.reverse
red.sort_by!{ |x| x[1] }
red.reverse!
usedR = Array.new(N, false)
#pp red

blue = []
radB = []
N.times do |i|
  blue[i] = gets.split.map(&:to_i)
  radB[i] = blue[i].inject(:+)
end
# blue = blue.sort_by.with_index{ |x,i| radB[i] }
blue.sort_by!{ |x| x[0] } 
usedB = Array.new(N, false)
#pp blue
ret = 0
N.times do |i|
  N.times do |j|
    if !usedR[j] && red[j][0] < blue[i][0] && red[j][1] < blue[i][1]
      usedR[j] = true
      usedB[i] = true
      ret += 1
      # pp usedB
      break
    end
  end
end
puts ret


Measured memory_bytes: 1788
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;


int main()
{
    int s,t,ans=0;
    cin>>s>>t;
    for(int i=0;i<=s;i++)
    {
        for(int j=0;j<=s;j++)
        {
                int x=t-i-j;
                if(x<=s && x>=0)
                {ans++;} 
        }
    }
    cout<<ans;
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vint;
typedef vector<ll> vll;

vector<bool> c(8, false);

int main(){
    int n,a,ans,s=0;
    cin>>n;

    for(int i=0; i<n; i++){
        cin>>a;
        if(a>=3200) s++;
        else if(a>=2800)c[0]=true;
        else if(a>=2400)c[1]=true;
        else if(a>=2000)c[2]=true;
        else if(a>=1600)c[3]=true;
        else if(a>=1200)c[4]=true;
        else if(a>=800)c[5]=true;
        else if(a>=400)c[6]=true;
        else if(a>=1)c[7]=true;
    }

    ans = count(c.begin(),c.end(),true);
    if(ans==0)cout<<1<<' '<<ans+s<<endl;
    else cout<<ans<<' '<<ans+s<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,x,y;
    cin >> n >> x >> y;
    --x; --y;
    VVI d(n,VI(n));
    REP(i,0,n) REP(j,0,n) d[i][j] = abs(j - i);
    REP(i,0,n) REP(j,i+1,n) {
        d[i][j] = d[j][i] = min(d[i][j], abs(x - i) + abs(y - j) + 1);
    }
    VI cnt(n+1);
    REP(i,0,n) REP(j,i+1,n) cnt[d[i][j]]++;
    REP(i,1,n) {
        cout << cnt[i] << endl;
    }
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 16000
#include <iostream>

void call(int n) {
	int x;
	for (int i = 1; i <= n; i++) {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
			continue;
		}

		do {
			if (x % 10 == 3) {
				printf(" %d", i);
				break;
			}
		} while (x /= 10);
	}
	std::cout << std::endl;
}


int main()
{
	int x;
	std::cin >> x;
	call(x);

	return 0;
}


Measured memory_bytes: 3208
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] days = "Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" ");
        int[] month = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int[] monthDays = new int[12];
        monthDays[0] = 0;
        for (int i = 1; i < 12; i++) {
            monthDays[i] = month[i - 1] + monthDays[i - 1];
        }
        while (true) {
            int m = sc.nextInt();
            int d = sc.nextInt();
            if (m == 0 && d == 0) {
                break;
            }
            System.out.println(days[(monthDays[m - 1] + d + 2) % 7]);
        }

    }
}


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

int sumdigits(int n){
  int sum =0;
  while(n>0){
    sum+=n%10;
    n/=10;
  }
  return sum;
}

int main() {
  int n; 
  cin>>n;
  int res=10000;
  for(int i=1;i<n;i++){
    if((sumdigits(i)+sumdigits(n-i))<res) res =sumdigits(i)+sumdigits(n-i);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
while True:
    a,b,c=map(int,raw_input().split())
    if a==b==c==0:break
    L=[2]*(a+b+c+1)
    N=input()
    T=[]
    for t in range(N):
        i,j,k,r=map(int,raw_input().split())
        if r==1:
            L[i]=L[j]=L[k]=1
        else:
            T.append((i,j,k))
    for i,j,k in T:
        if L[i]==L[j]==1:
            L[k]=0
        elif L[i]==L[k]==1:
            L[j]=0
        elif L[j]==L[k]==1:
            L[i]=0
    for i in range(1,a+b+c+1):
        print L[i]

Measured memory_bytes: 4316
n=int(input())
abs=[list(map(int,input().split()))for i in range(n)]
for i in range(n):
    abs[i].reverse()
abs.sort()
cnt=0
for i in range(n):
    cnt += abs[i][1]
    if cnt > abs[i][0]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 51164
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int d,g; cin >> d >> g;
    vector<vector<int>>dp(d,vector<int>(100001,INF));
    vector<int>lim(d),c(d);
    rep(i,d) cin >> lim[i] >> c[i];
    rep(i,d)dp[i][0] = 0;
    rep(i,d){
        if (i == 0){
            rep(j,lim[0]){
                dp[0][j+1] = 100 * (j+1) + (j+1 == lim[i] ? c[i]:0);
            }
            continue;
        }
        rep(j,dp[i - 1].size()){
            if(dp[i - 1][j] != INF){
                if(dp[i][j] == INF){
                    dp[i][j] = 0;
                    
                }
                cmax(dp[i][j],dp[i-1][j]);
                rep(k,lim[i]){
                    if (dp[i][j + k + 1] == INF)dp[i][j + k + 1] = 0;
                    cmax(dp[i][j + k + 1],dp[i - 1][j] + 100 * (i+1) * (k+1) +
                         (k+1 == lim[i] ? c[i] : 0));
                }
            }
        }
    }
    int ans = INF;
    rep(i,dp.size()){
        rep(j,dp[i].size()){
            if(dp[i][j] != INF and dp[i][j] >= g){
                cmin(ans,j);
            }
        }
    }
    cout << ans ;
}




Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int mod=998244353;
    int n,k;
    cin>>n>>k;
    int l[k],r[k];
    long long ans=0;
    vector<long long>dp(500000);
    for(int i=0;i<k;i++){
        cin>>l[i]>>r[i];
        dp[l[i]]++,dp[r[i]+1]--;
    }
    for(int i=1;i<n;i++){
        ans=(ans+dp[i])%mod;
        for(int j=0;j<k;j++){
            dp[i+l[j]]=(dp[i+l[j]]+ans)%mod;
            dp[i+r[j]+1]=(dp[i+r[j]+1]-ans)%mod+mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7212
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 100010
using namespace std;
char s[maxn];
int n;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int ans=n,num=0;
	for(int i=1;i<=n;i++){
		if((s[i]=='1'&&num%2==0)||(s[i]=='0'&&num%2==1)){
			int tmp=0;
			if(i-1>=n-i+1){
				tmp=i-1;
			}
			else {
				tmp=n-i+1;
				num++;
			}
			ans=min(ans,tmp);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
bool square(int n)
{
  int m=0;
  for (int i=1;m<n;i++)
    m=i*i;
  if (m==n) return true;
  else return false;
}
int main(){
  int a,b,c;
  int i=0;
  cin>>a>>b;
  c=b;
  while (c!=0){
       i++;
       c=c/10;
  }
  int d=1;
  for(int j=1;j<=i;j++)
  d=d*10;
  int sm=a*d+b;
  if (square(sm)) 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 long double D;
ll v[105];
ll save[500];
ll ans,Ans;
int main(void){
	ll n,k; cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k-i;j++){
			ans=0;
			for(int K=0;K<i;K++){
				save[K]=v[K];
			}
			for(int K=0;K<j&&K<n-i;K++){
				save[i+K]=v[n-1-K];
			}
			ll I=i+j;
			sort(save,save+I);
			for(int K=0;K<k-I;K++){
				if(save[K]<0){
					save[K]=0;
				}
			}
			for(int K=0;K<105;K++){
				ans+=save[K];
			}
			Ans=max(ans,Ans);
			//cout<<i<<" "<<j<<" "<<ans<<" "<<Ans<<endl;
			for(int K=0;K<105;K++){
				save[K]=0;
			}
		}
	}
	cout<<Ans<<endl;
    
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int n,x;
    cin >>n>>x;
    vector<int>a(n);
    rep(i,n)cin>>a[i];

    rep1(i,1,n){
        if(a[i-1] + a[i] > x){
            int sub = min(a[i],(a[i-1]+a[i])-x);
            a[i] -= sub;
            ans += sub;

            if(a[i-1]+a[i]>x){
                sub = min(a[i-1],(a[i-1]+a[i])-x);
                a[i-1]-=sub;
                ans += sub;
            }
        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 640
S = input()
a = S[:2]
b = S[2:]
aj = 0
bj = 0
aa = int(a)
bb = int(b)
if 0<aa<13:
  aj = 1
if 0<bb<13:
  bj = 1
p = ''
if aj==bj==0:
  p = 'NA'
elif aj==bj==1:
  p = 'AMBIGUOUS'
elif aj==0 and bj ==1:
  p = 'YYMM'
else:
  p = 'MMYY'
print(p)

Measured memory_bytes: 3060
import java.util.*;

public class Main{

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int l = sc.nextInt();
			int [][] data = new int[n][3];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < 3; j++){
					data[i][j] = sc.nextInt();
				}
			}
			double [][][] dp = new double[n][m+1][m+1];
			for(int i = 0; i < n; i++){
				dp[i][0][0] = 1.0;
				for(int j = 0; j < m; j++){
					for(int k = 0; k < m; k++){
						dp[i][j + 1][k] += dp[i][j][k] * (100 - data[i][0]) / 100;
						dp[i][j + 1][k+1] += dp[i][j][k] * (data[i][0]) / 100;
					}
				}
			}

			for(int i = 0; i < n; i++){
				double prob = 0;
				for(int j = 0; j <= m; j++){
					double sec = (double) l / data[i][2] + j * data[i][1];
					double nowsum = dp[i][m][j];
					for(int k = 0; k < n; k++){
						if(i == k) continue;
						double sum2 = 0;
						for(int kk = 0; kk <= m; kk++){
							double opsec = (double) l / data[k][2] + kk * data[k][1];
							if(opsec > sec){
								sum2 += dp[k][m][kk];
							}
						}
						nowsum *= sum2;
					}
					prob += nowsum;
				}
				System.out.printf("%.6f\n",prob);
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 27624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <climits>
using namespace std;

void floyd(vector<vector<long long> >& d)
{
    for (int k = 0; k < d.size(); k++) {
        for (int i = 0; i < d.size(); i++) {
            if (LLONG_MAX == d[i][k]) continue;
            for (int j = 0; j < d.size(); j++) {
                if (LLONG_MAX == d[k][j]) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{
    int v, e;
    cin >> v >> e;
    vector<vector<long long> > d(v, vector<long long>(v, LLONG_MAX));
    int s, t;
    for (int i = 0; i < v; i++) d[i][i] = 0;
    for (int i = 0; i < e; i++) {
        cin >> s >> t;
        cin >> d[s][t];
    }
    floyd(d);

    // check negative cycle
    for (int i = 0; i < v; i++) {
        if (d[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    for (int i = 0; i < v; i++) {
        for (auto itr = d.at(i).begin(); itr != d.at(i).end(); ++itr) {
            if (itr != d.at(i).begin()) cout << " ";
            if (LLONG_MAX == *itr) cout << "INF";
            else cout << *itr;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3212
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
//素数判定
bool prime(ll n) {
	if (n == 1)return false;
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return true;
}
ll w[114], v[114];
//i個目まで重さがj以下になるように選んだ価値の最大値
ll dp[114][114514];
signed main() {
	ll N, W;
	cin >> N >> W;
	rep(i, N)cin >> w[i] >> v[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			//選ばないときにあわせて初期化（０個目まで）
			dp[0][j] = 0;
			//選んだだけで上限を超えてしまう場合
			if (j < w[i]) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}
		}
	}
	//N個目までに重さがW以下になるように選んだ価値の最大値
	cout << dp[N][W] << endl;
	ggr
}


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

#define MAXN 100005
#define int long long
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

using namespace std;

int n;
int g[MAXN][4];
int dp[MAXN][4];

signed main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= 3; j++)
            cin >> g[i][j];
    for (int j = 1; j <= 3; j++)
        dp[1][j] = g[1][j];
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= 3; j++) {
            for (int k = 1; k <= 3; k++) {
                if (k != j) dp[i][j] = max(dp[i][j], dp[i-1][k] + g[i][j]);
            }
        }
    }
    cout << max(max(dp[n][1], dp[n][2]), dp[n][3]) << endl;
    return 0;
}

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

using namespace std;

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

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

//#define INF (1e10)
#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 << " "; prll(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); } } premain;

double eps = 1e-7;
double inf = 1e10;


#define N_MAX	(300)
double X[N_MAX];
double Y[N_MAX];

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

		if (0 == N) {
			break;
		}

		//input
		REP(i, N) {
			cin >> X[i] >> Y[i];
		}

		int ans = 1;

		//problem
		//2点を通る単位円に含まれる点を数える
		REP(i, N) REP(j, N) {
			if (i == j) continue;
			double dx = (X[i] - X[j]);
			double dy = (Y[i] - Y[j]);
			double d2 = (dx * dx) + (dy * dy);
			double d = sqrt(d2);
			if ((2.0 + eps) < d) continue;

			double v = sqrt(1.0 - (d2 / 4));
			double cx = (X[i] + X[j]) / 2 - (v * dy / d);
			double cy = (Y[i] + Y[j]) / 2 + (v * dx / d);
			
			int cnt = 0;
			REP(k, N) {
				double tmpx = (X[k] - cx);
				double tmpy = (Y[k] - cy);
				if ((tmpx * tmpx) + (tmpy * tmpy) < (1.0 + eps)) {
					cnt++;
				}
			}
			if (ans < cnt) {
				ans = cnt;
			}
		}

		print(ans);
	}
	return 0;
}



Measured memory_bytes: 3228
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

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

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )


ans=0
for i in range(0,K+1):
  R = ( (M%p) *pow(M-1,N-1-i,p) )%p
  L = combi(N-1,i)
  ans = (ans + (R*L)%p)%p
  
print(ans)

Measured memory_bytes: 81312