akhauriyash/Code-Regression huggingface dataset:
s=input()
flag=0
if len(s)==2:
    if s[0]==s[1]:
        print('1 2')
    else:
        print('-1 -1')
else:
    for i in range(len(s)-2):
        if s[i]==s[i+2] and s[i]!=s[i+1]:
            print(str(i+1)+' '+str(i+3))
            flag=1
            break
        elif s[i]==s[i+1] and s[i]!=s[i+2]:
            print(str(i+1)+' '+str(i+3))
            flag=1
            break
        elif s[i+1]==s[i+2] and s[i+1]!=s[i]:
            print(str(i+1)+' '+str(i+3))
            flag=1
            break
    if flag==0:
        print('-1 -1')
            
    

                


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
long long is_prime(long long n){
  int count = 0;
  for(int i=2; i*i<n;i++){
    if(n % i ==0){
      count++;
      break;
    }
    else
      continue;
  }
  if(count > 0)
    return 1;
  else
    return -1;
}

int main() {
  long long X, judge = 1;
  cin >> X;

  while (judge == 1){
    judge = is_prime(X);
    X++;
  }
  
  cout << X-1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[5][5];
int read(){
	int num = 0, flag = 1; char c = getchar();
	for(; c < '0' || c > '9'; c = getchar())
		if(c == '-') flag = 0;
	for(; c >= '0' && c <= '9'; c = getchar())
		num = (num<<3)+(num<<1)+c-48;
	return flag ? num : -num;
}

int main(){
	for(int i = 1;i <= 3; ++ i)
		scanf("%s",s[i]+1);
	printf("%c%c%c",s[1][1],s[2][2],s[3][3]);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-2):
    if p[i] < p[i+1] and p[i+1] < p[i+2]:
        ans += 1
    elif p[i] > p[i+1] and p[i+1] > p[i+2]:
        ans += 1

print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int x = scanner.nextInt();
    if (x == 1 || x == N * 2 - 1) System.out.println("No");
    else {
      System.out.println("Yes");
      int[] a = new int[N * 2 - 1];
      int c = 2;
      for (int i = 0; i < N - 2; i++) {
        if (c == x) c++;
        a[i] = c++;
      }
      a[N - 2] = 1;
      a[N - 1] = x;
      a[N] = N * 2 - 1;
      for (int i = N + 1; i < N * 2 - 1; i++) {
        if (c == x) c++;
        a[i] = c++;
      }

      StringBuilder sb = new StringBuilder();
      for (int i : a) sb.append(i).append('\n');
      System.out.print(sb.toString());
    }
  }

  private static int process(int[] a) {
    while (a.length > 1) {
      int[] b = new int[a.length - 2];
      for (int i = 1; i <= b.length; i++) {
        b[i - 1] = median(a[i - 1], a[i], a[i + 1]);
      }
      a = b;
    }
    return a[0];
  }

  private static int median(int a, int b, int c) {
    if (a > b) return median(b, a, c);
    if (b > c) return median(a, c, b);
    return b;
  }
}


Measured memory_bytes: 37156
/* maybemaybemaybeno */
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double lld ;
#define f(i,s,n) for(int i=s;i<(int)n;i++) 
// const int MAXN = 2e5+5 ;
#define pb push_back 
#define X first 
#define Y second 
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define pli pair<ll,int> 
#define pil pair<int,ll> 
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<setprecision(10) ;
#define is(x) cout<<#x<<" : "<<x<<endl ;
// #define DEBUG

int main()
{
    fio ;
    /* ======================Start of code ================ */
    string s;cin>>s ;
    int n = s.size() ;
    ll b = 0 ;
    ll total = 0 ;
    f(i,0,n) 
    {
        if(s[i]=='B') b++ ;
        else total+=b ;
    }
    cout<<total<<"\n" ;

    /* ======================End of code ================== */
}

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

using namespace std;

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

    vector<int> C(N - 1), S(N - 1), F(N - 1);
    for (int i = 0; i < N - 1; i++) cin >> C[i] >> S[i] >> F[i];

    for (int i = 0; i < N; i++) {// 最初の駅のループ
        int ans = 0;
        for (int j = i + 1; j < N; j++) { // 駅 j に進むために
            if (ans < S[j - 1]) {// 最初の列車を待つ
                ans = S[j - 1] + C[j - 1];
            } else {// 次の列車の時間
                int over = ans - S[j - 1];
                int pass = (over + F[j - 1] - 1)/F[j - 1];
                ans = S[j - 1] + F[j - 1]*pass + C[j - 1];
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mp(x,y) make_pair(x,y)

void solve(){
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<vector<int>> v(n);
    for(int i=0;i<m;i++){
        int x,y; cin>>x>>y; x--; y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int ans=0;
    for(int  i=0;i<n;i++){
        int g=0;
        for(auto x : v[i]){
            if(a[x] >= a[i]) g=1;
        }
        if(g==0) ans++;
    }
    cout<<ans<<'\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tc;
    tc=1;
    while(tc--){
        solve();
    }
return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  
  
  for(int i = 0; i< N; i++){
    int w;
    cin >> w ;
    W.at(i) = w;
  }
   int S1 = W.at(0);
   int S2 = 0;
    for(int i = 1; i< N; i++){
    S2 += W.at(i);
    
  }
  
  
  int d = abs(S1 - S2);
  
  for(int i =1; i<N-1; i++){
    S1 += W.at(i);
    S2 -= W.at(i);
    if( abs(S1 - S2) < d){
      d =  abs(S1 - S2);
    }
  }
  cout << d << endl;
      
    
}


Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,m,a[100010],par[100010],con=0,ans=0;
vector <LL> fol[100010],all;

LL FIND(LL pos)//dsu
{
	if(par[pos]!=pos) par[pos]=FIND(par[pos]);
	return par[pos];
}

inline void UNION(LL pos1,LL pos2)
{
	par[FIND(pos1)]=FIND(pos2);
}

int main()
{
	rep(i,100005) par[i]=i;
	cin>>n>>m;
	rep(i,n) scanf("%I64d",&a[i]);
	rep(i,m)
	{
		LL x,y;
		scanf("%I64d%I64d",&x,&y);
		UNION(x,y);
	}
	rep(i,n)
	{
		if(FIND(i)==i) con++;
		fol[FIND(i)].pb(a[i]);
	}
	if(con==1)
	{
		puts("0");
		rt0;
	}
	if(con*2-2>n)
	{
		puts("Impossible");
		rt0;
	}
	rep(i,n)
	{
		if(fol[i].size()==0) continue;
		sort(fol[i].begin(),fol[i].end());
		ans+=fol[i][0];
		repn(j,fol[i].size()-1) all.pb(fol[i][j]);
	}
	sort(all.begin(),all.end());
	rep(i,con-2) ans+=all[i];
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 7296
import sys
input = sys.stdin.readline


N = int(input().rstrip())
a_dict = {}
for i in range(N):
  a_dict[i+1] = int(input().rstrip())

target = 1
next_target = a_dict[target]
cont = True
ans = 0

if next_target == 2:
  cont = False
  ans += 1

while cont:
  target = next_target
  next_target = a_dict[target]
  ans += 1
  del a_dict[target]
  if next_target not in a_dict:
    ans = -1
    cont = False
  elif next_target == 2:
    ans += 1
    cont = False
print(ans)


Measured memory_bytes: 51804
#include<iostream>

using namespace std;

int hit(int *ans, int *q){
	int i, hit = 0;
	for(i = 0; i < 4; i ++){
		if(ans[i] == q[i]) hit ++;
	}
	return hit;
}

int blow(int *ans, int *q){
	int i, j, blow = 0;
	for(i = 0; i < 4; i ++){
		for(j = 0; j < 4; j  ++){
			if(ans[i] == q[j] && i != j) blow ++;
		}
	}
	return blow;
}

int main(){
	int  q[4], ans[4], i, cut1, cut2;

	while(cin >> q[0] >> q[1] >> q[2] >> q[3]){
		cut1 = 0, cut2 = 0;
		for(i = 0; i < 4; i ++){
			cin >> ans[i];
		}

		cut1 = hit(ans, q);
		cut2 = blow(ans, q);

		cout << cut1 << " " << cut2 << endl;
	}

	return 0;
}

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

// {{{
#define PI pair<int, int>
#define mk make_pair
#define reg register
#define ll long long
#define rep(i, a, b) for(reg int i = a; i <= b; ++i)
#define per(i, a, b) for(reg int i = a; i >= b; --i)
// }}}

using namespace std;

inline int min(reg int a, reg int b) { return a < b ? a : b; }
inline int max(reg int a, reg int b) { return a > b ? a : b; }
inline int read() {
  reg int s = 0; reg char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return s;
}

int main() {
  int n = read(), k = read();
  if (k == 1) cout << 0 << endl;
  else   cout << n - k << endl;
  return 0; 
}


/*******************************************
 _________________________________________
< COWSAY.cpp is created by zrz who is weak >
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
********************************************/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll a, b, k; cin >> a >> b >> k;
    ll ta = a;
    a = max(0LL, a - k);
    b = max(0LL, min(b, b - (k - ta)));
    cout << a << ' ' << b << '\n';
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class mint:
    def __init__(self, x):
        self.__x = x % md

    def __str__(self):
        return str(self.__x)

    def __add__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x + other)

    def __sub__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x - other)

    def __rsub__(self, other):
        return mint(other - self.__x)

    def __mul__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * other)

    __radd__ = __add__
    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * pow(other, md - 2, md))

    def __rtruediv__(self, other):
        return mint(other * pow(self.__x, md - 2, md))

    def __pow__(self, power, modulo=None):
        return mint(pow(self.__x, power, md))

md = 10**9+7
n,a,b=MI()
r_max =200005
com=[0]*r_max
com[0]=mint(1)
for i in range(1,r_max):
    com[i]=com[i-1]*(n-i+1)/i

ans=pow(2,n,md)-1-com[a]-com[b]
print(ans)



Measured memory_bytes: 46164
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,l;
  std::cin>>n>>l;

  ll prev;
  std::cin>>prev;

  rep(i,1,n){
    ll a;
    std::cin>>a;
    if(prev+a>=l){
      std::cout<<"Possible"<<"\n";
      rep(j,1,i)std::cout<<j<<"\n";
      for(ll j=n-1;j>=i+1;j--)std::cout<<j<<"\n";
      std::cout<<i;
      return 0;
    }
    prev=a;
  }

  std::cout<<"Impossible";

  return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

ll a,b,c;

int main() {
    cin >> a >> b >> c;
    ll res = b+min(b,c);
    res = min(c,a+b+1);
    res+= b;
    put(res);
    return 0;
}



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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

//拡張ユークリッドの互除法
int extgcd(int a, int b, int& x, int& y) {
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

// mod逆元
int mod_inverse(int a, int m) {
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

// 階乗、階乗逆元テーブル
int fact[1100000], fact_inv[1100000];
int mod_fact(int n, int m) {
    fact[0] = fact_inv[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i % m;
        fact_inv[i] = mod_inverse(fact[i], m);
    }
}

int K, N;
int mod = 998244353;
int tw[110000];

int C(int n, int r) {
    return fact[n] * fact_inv[r] % mod * fact_inv[n - r] % mod;
}
int H(int n, int r) {
    return C(n + r - 1, r);
}
signed main() {
    cin >> K >> N;
    mod_fact(110000, mod);
    tw[0] = 1;
    for (int i = 1; i < 110000; i++)tw[i] = tw[i - 1] * 2 % mod;
    vint ans;
    for (int i = 3; i <= K + 2; i += 2) {
        int cur = 0;
        for (int j = 0; j <= i / 2; j++) {
            if (N < j)continue;
            (cur += H(K - i + j + 1, N - j) * C(i / 2, j) % mod * tw[j] % mod) %= mod;
        }
        ans.push_back(cur);
        ans.push_back(cur);

    }
    for (int i = 0; i < K - 1; i++)cout << ans[i] << endl;
    cout << ans[ans.size() - 1] << endl;
    for (int i = K - 2; i >= 0 ; i--)cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 6144
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  string S;
  get(S);
  string ans = "CODEFESTIVAL2016";
  int c = 0;
  FOR(i, 16) {
    if (S[i] != ans[i])
      c++;
  }
  print(c);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iK = int.Parse(sS[1]);
            sS = System.Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = (int)Math.Ceiling((double)(iN - 1) / (iK - 1));

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 18400
#include <bits/stdc++.h>
using namespace std;
long n,k;
void solve()
{
    vector < long > a(n);
    long i,ans=2000000000;
    for (i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    for (i=k-1;i<n;i++)
        ans=min(ans,a[i]-a[i+1-k]);
    cout<<ans<<endl;
}
int main()
{
    while(cin>>n>>k)
        solve();
}

Measured memory_bytes: 1024
t,*n=map(int,open(0))
for k in n:print(sum(k**j*[0,765144583,346175634,347662323,5655049,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286,539588932,729548371,700407153,404391958,962779130,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286][(k&1)*16+j]for j in range(16))%(10**9+7))

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     fopen     freopen("in.txt","r",stdin)
#define     fwrite    freopen("o.txt","w",stdout)
#define     f0(n)     for(int i=0;i<n;i++)
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))
#define     gcd(a,b)  __gcd(int a,int b)

int main()
{
    __

    int a[5],ans=0;
    f0(3) cin>>a[i];

    sort(a,a+3);
    ans=((a[2]*10)+a[1])+a[0];
    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext())calc(in);
	}
	private static void calc(Scanner in){
		int sum=0,d = in.nextInt();
		for(int i=1;d*i<=600-d;i++)
			sum+=Math.pow(d*i, 2)*d;
		System.out.println(sum);
	}
}

Measured memory_bytes: 17196
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	map<string, int>m;
	int q = in();
	REP(i, q)
	{
		int n = in();
		string key;
		int x;
		switch (n)
		{
		case 0:
			key = in<string>();
			x = in();
			m[key] = x;
			break;
		case 1:
			key = in<string>();
			try
			{
				cout << m.at(key) << endl;
			}
			catch (out_of_range)
			{
				cout << 0 << endl;
			}
			break;
		case 2:
			key = in<string>();
			m.erase(key);
			break;
		}
	}
}


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

int top, S[1000];

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

int pop()
{
    top--;
    return S[top+1];
}
int main() {
    char s[1] = {};
    int a,b;
    top = 0;


    while (scanf("%s",s) != EOF) {
        if (s[0] == '+' ) {
            a = pop();
            b = pop();
            push(a+b);
        }
        else if (s[0] == '-' ) {
            b = pop();
            a = pop();
            push(a-b);
        }
        else if (s[0] == '*' ) {
            a = pop();
            b = pop();
            push(a*b);
        }
        else {
            push(atoi(s));
        }
    }

    printf("%d\n",pop());
    return 0;
}


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

long long solve1(const vector<int>&A) {
	int i = 1, j = A.size() - 1;
	long long ans = 0, left = A[0], right = A[0];
	while (i <= j) {
		ans += abs(A[j] - left);
		left = A[j];
		j--;
		if (i > j) break;
		ans += abs(A[j] - right);
		right = A[j];
		j--;
		if (i > j) break;
		ans += abs(left - A[i]);
		left = A[i];
		i++;
		if (i > j) break;
		ans += abs(right - A[i]);
		right = A[i];
		i++;
	}
	return ans;
};

long long solve2(const vector<int>& A) {
	int i = 0, j = A.size() - 2;
	long long ans = 0, left = A.back(), right = A.back();
	while (i <= j) {
		ans += abs(left - A[i]);
		left = A[i];
		i++;
		if (i > j) break;
		ans += abs(right - A[i]);
		right = A[i];
		i++;
		if (i > j) break;
		ans += abs(A[j] - left);
		left = A[j];
		j--;
		if (i > j) break;
		ans += abs(A[j] - right);
		right = A[j];
		j--;
	}
	return ans;
};

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	cout << max(solve1(A), solve2(A)) << endl;
}

Measured memory_bytes: 640
function split(s, c)
  if string.find(s, c) == nil then
    return { s }
  end

  local cs = {}
  
  local lastPos = 0
  for part, p in string.gmatch(s, "(.-)" .. c .. "()") do
    table.insert(cs, part)
    lastPos = p
  end

  table.insert(cs, string.sub(s, lastPos))

  return cs
end

n=io.read("*n")

print(n*n*n)

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

n = int(input())
ki = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ki[a].append([b, i])
ans = [-1] * (n - 1)


# print(ki)


def d(index, color):
    cnt = 1
    for (t, jid) in ki[index]:
        if cnt == color:
            cnt += 1
        ans[jid] = cnt
        d(t, cnt)
        cnt += 1


d(0, 0)
print(max(ans))
for i in ans:
    print(i)


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

int main(){
  int A, B;
  cin >> A >> B;
  
  if(A-2*B <= 0){
    cout << 0 << endl;
  }
  else{
    cout << A-2*B << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author acesine
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int H = in.nextInt(), W = in.nextInt();
            for (int i = 0; i < W + 2; i++) {
                out.print("#");
            }
            out.print("\n");
            for (int i = 0; i < H; i++) {
                out.println(String.format("#%s#", in.next()));
            }
            for (int i = 0; i < W + 2; i++) {
                out.print("#");
            }
            out.print("\n");
        }

    }
}



Measured memory_bytes: 21972
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }else if(s=="ARC"){
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1e9+7;
ll ans,n,fa[5010],a[5010],b[5010],v[5010],f[2][5010],jc[5010],k;
ll find(ll x){
	if(x==fa[x])return x;
	return fa[x]=find(fa[x]);
}
ll ksm(ll x,ll y){
	ll xlh=1;
	while(y){
		if(y&1)xlh=xlh*x%p;
		x=x*x%p;
		y/=2;
	}
	return xlh;
}
int main(){
	ll i,x,y,j,now=0,la,hh=0;
	scanf("%lld",&n);jc[0]=1;
	for(i=1;i<=n;i++){
		jc[i]=jc[i-1]*i%p;
		scanf("%lld",&a[i]);fa[i]=i;
		if(a[i]==-1)k++;
	}
	for(i=1;i<=n;i++)if(a[i]!=-1){
		x=find(i);y=find(a[i]);
		if(x==y)v[x]=1,ans++;
		 else fa[x]=y;
	}
	for(i=1;i<=n;i++){
		x=find(i);
		if(!v[x])b[x]++;
	}
	//sej=ksm(n-1,k);
	ans=(n-ans)*ksm(n-1,k)%p;
	//printf("%lld\n",ans);
	f[0][0]=1;
	for(i=1;i<=n;i++)if(find(i)==i&&!v[i]){
		hh++;
		la=now;now^=1;
		memset(f[now],0,sizeof(f[now]));
		for(j=0;j<=n;j++)if(f[la][j]){
			f[now][j]=(f[now][j]+f[la][j])%p;
			f[now][j+1]=(f[now][j+1]+f[la][j]*b[i]%p)%p;
		}
	}
	f[now][1]=(f[now][1]-hh+p)%p;
	for(i=1;i<=k;i++)ans=(ans-f[now][i]*ksm(n-1,k-i)%p*jc[i-1]%p+p)%p;
	printf("%lld",ans);
}

Measured memory_bytes: 4092
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;

class UnionFind{
private:
    vector<int> p,s;
	int cnt;
public:
	UnionFind(){}
	UnionFind(int N){
		cnt = N;
		p = s = vector<int>(N+1,0);
		for(int i=1;i<=N;i++){
			p[i] = i; s[i] = 1;
		}
	}
	int find(int x){
		if(p[x]==x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x==y) return;
		if(s[x]>s[y]){
			p[y] = x;
			s[x] += s[y];
		}else{
			p[x] = y;
			s[y] += s[x];
		}
		cnt--;
	}
	bool is_same_set(int x,int y) {return find(x)==find(y);}
	int size(int x) {return s[find(x)];}
	int compnents_number(){return cnt;}
};

int N,Q;

void dfs(int n,int p,vector<vector<int>>& c,vector<int>& marked,vector<ll>& val,UnionFind& uf){
    uf.unite(n,p);
    val[uf.find(n)] = p;
    for(auto x:c[n]){
        if(marked[x]) dfs(x,x,c,marked,val,uf);
        else dfs(x,p,c,marked,val,uf);
    }
}

int main(){
    while(cin >> N >> Q && N){
        vector<int> p(N+1),num(Q+1),marked(N+1,0);
        vector<ll> val(N+1);
        vector<char> C(Q+1);
        vector<vector<int>> c(N+1);
        map<int,int> m;
        UnionFind uf(N);
        for(int i=2;i<=N;i++){
            cin >> p[i];
            c[p[i]].push_back(i);
        }
        marked[1] = 1;
        m[1]++;
        for(int i=1;i<=Q;i++){
            cin >> C[i] >> num[i];
            if(C[i]=='M'){
                marked[num[i]] = 1;
                m[num[i]]++;
            }
        }
        dfs(1,1,c,marked,val,uf);
        ll ans = 0;
        for(int i=Q;i>=1;i--){
            if(C[i]=='Q') ans += val[uf.find(num[i])];
            else{
                m[num[i]]--;
                if(m[num[i]]==0){
                    ll a = val[uf.find(p[num[i]])];
                    uf.unite(a,num[i]);
                    val[uf.find(num[i])] = a;
                    m.erase(num[i]);
                }
            }
        }
        cout << ans << endl;
    }
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll h; cin >> h;
  ll now = 1;
  ll res = 0;
  while(h) {
    res += now;
    now *= 2;
    h /= 2;
  }
  cout << res << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
typedef long long ll;
int main(void)
{
    int X,Y,Z;
    cin>>X>>Y>>Z;
    swap(X,Y);
    swap(X,Z);
    cout<<X<<" "<<Y<<" "<<Z<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    d = int(input())
    if d == 25:
        print('Christmas')
    elif d == 24:
        print('Christmas Eve')
    elif d == 23:
        print('Christmas Eve Eve')
    else:
        print('Christmas Eve Eve Eve')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38508
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
    int n;
    int res[10] = {0};
    cin >> n;
    if(n==0) break;
    REP(i,n){
	int t;
	cin >> t;
	res[t]++;
    }
    REP(i,10){
	if(res[i] == 0){
	    cout << "-" << endl;
	}else{
	    REP(j,res[i]){
		cout << "*";
	    }
	    cout << endl;
	}
    }
    }
    return 0;
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

typedef pair<int, int> P;

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> x(n), ans(n * n, -1);
	set<int> st;
	vector<int> rem;
	vector<P> pt;
	REPU(i, 0, n) {
		cin >> x[i];
		ans[x[i] - 1] = i + 1;
		st.insert(x[i]);
		pt.push_back(P(x[i], i));
		REPU(j, 0, n - i - 1) rem.push_back(i + 1);
	}
	sort(ALL(rem), [&x](const int v1, const int v2) {
		return x[v1 - 1] < x[v2 - 1];
	});
	int m = n * n;
	if (st.size() != n) puts("No");
	else {
		sort(ALL(pt));
		int cur = 0;
		REPU(i, 0, n) {
			int up = pt[i].first, cnt = pt[i].second, id = cnt;
			if (cnt == 0) continue;
			while (cnt > 0 && cur < up) {
				if (ans[cur] > 0) cur++;
				else {
					ans[cur++] = id + 1;
					cnt--;
				}
			}
			if (cnt > 0) {
				puts("No"); return 0;
			}
		}
	}
	REPD(i, m - 1, -1) {
		if (ans[i] == -1) {
			ans[i] = rem.back();
			rem.pop_back();
		}
	}
	vector<vector<int>> g(n + 1);
	REPU(i, 0, m) {
		g[ans[i]].push_back(i + 1);
	}
	REPU(i, 1, n + 1) {
		if (g[i][i - 1] != x[i - 1]) {
			puts("No"); return 0;
		}
	}
	puts("Yes");
	REPU(i, 0, m) printf("%d%c", ans[i], " \n"[i == m - 1]);

	return 0;
}


Measured memory_bytes: 3704
//Date: 18-08-2020 //Author: Rishabh Paul

#include<bits/stdc++.h>
using namespace std;

// // long long solve() {
// // 	int n;
// // 	char c;
// // 	scanf("%d\n", &n);
// // 	map<int ,int> f;
// // 	f[0] = 1;
// // 	int s = 0;
// // 	long long ans = 0LL;
// // 	for (int i = 0; i < n; i++) {
// // 		scanf("%c", &c);
// // 		s += (c - '0') - 1;
// // 		ans += f[s]++;
// // 	}
// // 	return ans;
// // }

// // int main () {
// // 	int t;
// // 	scanf("%d", &t);
// // 	while(t--) {
// // 		printf("%lld\n", solve());
// // 	}
// // 	return 0;
// // }


// // int main () {
// // 	string s;
// // 	cin >> s;
// // 	if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') {
// // 		cout << 0 << "\n"; return 0;
// // 	}
// // 	if (s[1] == 'R') {
// // 		if (s[0] == 'R' && s[2] == 'R') {
// // 			cout << 3 << "\n"; return 0;
// // 		}
// // 		if (s[0] == 'R' || s[2] == 'R') {
// // 			cout << 2 << "\n"; return 0;
// // 		}
// // 		cout << 1 << "\n"; return 0;
// // 	}
// // 	cout << 1 << "\n"; return 0;
// // }


// int main () {
// 	int n;
// 	scanf("%d", &n);
// 	vector<int> a(n);
// 	for (int i = 0; i < n; i++) {
// 		scanf("%d", &a[i]);
// 	}
// 	int ans = 0;
// 	vector<int>::iterator ip; 
// 	for (int i = 0; i < n; i++) {
// 		for (int j = i + 1; j < n; j++) {
// 			for (int k = j + 1; k < n; k++) {
// 				vector<int> t;
// 				t.push_back(a[i]);
// 				t.push_back(a[j]);
// 				t.push_back(a[k]);
// 				sort(t.begin(), t.end());
// 				if (t[0] + t[1] > t[2]) {
// 					ip = unique(t.begin(), t.end());
// 					t.resize(distance(t.begin(), ip));
// 					if (t.size() == 3) {
// 						ans++;
// 					}
// 				}
// 			}
// 		}
// 	}
// 	printf("%d\n", ans);
// 	return 0;
// }


int main () {
	long long x, k, d;
	scanf("%lld %lld %lld", &x, &k, &d);
	x = abs(x);
	if (k == 1) {
		printf("%lld\n", min(abs(x - d), abs(x + d)));
		return 0;
	}
	long long f = x / d;
	if (f > k) {
		printf("%lld\n", min(abs(x - k * d), abs(x + k * d)));
		return 0;
	}
	x = x - f * d;
	k -= f;
	if (k % 2 == 0) {
		printf("%lld\n", abs(x));
		return 0;
	}
	printf("%lld\n", abs(x - d));
	return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <bitset>
#include <string>
#include <cctype>
using namespace std;

long long manyFormula(string str){
    
    //int n = str.size();
    long long sum = 0;
    
    for(int i = 0; i < (1 << (str.size()-1) ); i++){
        
        bitset<10> bit(i);
        int savePosi = 0;
        int saveLength = 1;
        string num;
        
        for(int j = 0; j < (str.size()-1); j++){
            if(bit.test(j)){
                num = str.substr(savePosi, saveLength);
                //cout << "num = " << num << " savePosi = " << savePosi << " saveLength = " << saveLength << " i がある "<<endl;
                sum += stoll(num);
                saveLength = 1;
                savePosi = j + 1;
            }
            else saveLength++;
        }
        
        num = str.substr(savePosi, saveLength);
        sum += stoll(num);
        //cout << "num = " << num << " savePosi = " << savePosi << " saveLength = " << saveLength <<endl;
    }
    
    return sum;
}


int main(void){
    
    string S;
    cin >> S;
    
    long long ans = manyFormula(S);
    
    cout << ans << endl;
    
}


Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <string.h>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b;
	cin >> a >> b;
	cout << max({ a + b,a - b,a*b }) << endl;
	return 0;
}



Measured memory_bytes: 256
# coding: utf-8

# AtCoder Grand Contest 017
# B - Moderate Differences

# This code is compatible with both Python 2 and 3;
# however, in Python 2, the int type must be 64 bits,
# due to the range of the parameters of this problem.

import sys, re

def solve(N, A, B, C, D):
  for i in range(N):
    upper = i * D - (N - 1 - i) * C
    lower = i * C - (N - 1 - i) * D
    if lower <= B - A and B - A <= upper:
      return True
  return False

for line in sys.stdin:
  words = re.split(r'\s+', line.strip())
  N, A, B, C, D = [int(w) for w in words]  # convert to int
  result = solve(N, A, B, C, D)
  print('YES' if result else 'NO')


# 以降, コメント:
#
# 左から第0マス, 第1マス, ..., 第N-1マスと呼ぶ.
# 第0マスに0, 第N-1マスにB-Aを書いても結果 (YES or NO) は変わらない
# ので, 以降, 青橋君は第0マスに0を書くものと仮定する.
#
# 第kマス (0 <= k < N) に書くことのできる数は,
#   (i * C - (k - i) * D)以上 (i * D - (k - i) * C)以下
# (ただし 0 <= i <= k) の整数である
# (これらの数は書くことができる, かつこれら以外は書くことができない).
# このことはkに関する数学的帰納法で示すことができる.
#
# 従って, 0以上N-1以下のある i について
# B-A が (i * C - (N-1-i) * D)以上 (i * D - (N-1-i) * C)以下のとき,
# かつそのときのみ, 青橋君は第N-1マスにB-Aを書くことができる.

Measured memory_bytes: 18436
import java.util.Scanner;


public class Main {
	static int N,Y;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
			 N = sc.nextInt();
			 Y = sc.nextInt();
		  sc.close();

		  int sen = 0;
		  int gsen = 0;
		  int jsen = 0;

		  boolean f = false;

		  int pp = 10000*N;
		  if(pp == Y){
			  System.out.println(N + " 0 0");
		  }else{
			  int qq = pp-Y;
			  for(int i = 0 ; i < N+1 ; i++){
				  for(int j = 0 ; j < N+1 ; j++){
					  if(i + j > N){
						  continue;
					  }else if(5000 * i + 9000 * j == qq){
						  f = true;
						  gsen = i;
						  sen = j;
						  jsen = N-i-j;
						  break;

					  }else{
						  continue;
					  }
				  }
			  }

			  if(!f){
				  System.out.println("-1 -1 -1");
			  }else{
				  System.out.println(jsen + " " + gsen + " " + sen);
			  }
		  }
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    ll a[100010], b[100010];
    rep(i,0,n) {
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    repr(i,n-1,0) {
        ll k;
        a[i] += ans;
        if(a[i] == 0) k = 0;
        else if(a[i] < b[i]) k = b[i] - a[i];
        else {
            if(a[i] % b[i] == 0) k = 0;
            else k = b[i] - (a[i] % b[i]);
        }
        // printf("k = %lld\n", k);
        ans += k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
use proconio::input;
use std::collections::BTreeSet;

fn main() {
    input! {
        n:usize,
        mut s:[i64;1<<n]
    };
    s.sort();
    // println!("{:?}",s);
    let mut slms = vec![s[(1<<n)-1]];
    let mut rest:BTreeSet<i64> = s.into_iter()
                            .enumerate()
                            .filter(|(i,_)|*i!=(1<<n)-1)
                            .map(|(i,x)|(x*(1<<n) as i64)+i as i64)
                            .rev().collect();
    
    for _ in 0..n {
        let mut stck = Vec::new();
        for &slm in &slms {
            let tmp = {
                let mut it = rest.range(0..slm*(1<<n) as i64).rev();
                if let Some(&v) = it.next() {
                    let x = v/((1<<n) as i64);
                    stck.push(x);
                    Some(v)
                }
                else {None}
            };
            // eprintln!("{} {} {:?} {:?}",i,slm,tmp,slms);
            if let Some(e) = tmp {
                rest.remove(&e);
            }
        }
        for x in stck {
            slms.push(x);
        }
    }

    let ans = if rest.is_empty() {"Yes"} else {"No"};
    println!("{}",ans);
}


Measured memory_bytes: 15448
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0

for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if (L[i] == L[j]) or (L[j] == L[k]) or (L[k] == L[i]):
                continue
            if (L[i] + L[j] > L[k]) and (L[j] + L[k] > L[i]) and (L[k] + L[i] > L[j]):
                ans += 1

print(ans)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
            using namespace std;
            #define rep(i,a,b) for(ll i =a; i<b;++i)
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            #define mk(x,y)  make_pair(x,y)
            typedef  long long  int ll;
            const int N = ( 2e6 + 5 );
            const int mod = 1e9+7;
            ll  n ,a[N],k,c,l[N],r[N];

    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt ; pt %= mod;
        if(n&1)
            pt *= a , pt %= mod;
        return pt;
    }



    int main()
    {
         IOS;
      //     freopen("a_example (2).txt","r",stdin);
      //     freopen("c.txt","w",stdout);

        int ts =1;
      //  cin>>ts;
        while(ts--)
        {
            cin >> k;
            ll i=  1;
             queue <ll  > q;
             rep(i,1,10) q.push(i);
            while(q.empty() == false)
            {
               ll val = q.front();
               q.pop();
               k--;
               if(k ==0 )
               {
                   cout << val;
                   break;
               }
               if(val % 10 != 0)
               {
                   q.push(10*val + val%10 -1);
               }
               q.push(10*val + val%10);
               if(val % 10 != 9)
               {
                   q.push(10*val + val%10 +1);
               }
            }
        }
    }


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

using namespace std;

int main()
{
  string ABCD;
  cin>> ABCD;

  string ret;
  int A,B,C,D;
  A=ABCD[0]-'1'+1;
  B=ABCD[1]-'1'+1;
  C=ABCD[2]-'1'+1;
  D=ABCD[3]-'1'+1;
  for(int i=0;i<2;i++)
  for(int j=0;j<2;j++)
  for(int k=0;k<2;k++)
  {
    int tmp=A;
    if(i==0)tmp+=B;
    else tmp-=B;
    if(j==0)tmp+=C;
    else tmp-=C;
    if(k==0)tmp+=D;
    else tmp-=D;
    if(tmp==7)ret=to_string(A)+(i?"-":"+")+to_string(B)+(j?"-":"+")+to_string(C)+(k?"-":"+")+to_string(D);
  }
  cout<< ret<<"=7"<< endl;

  return 0;
}


Measured memory_bytes: 256
s = input()

length = len(s)
acgt = set("ACGT")

ans = 0
for i in range(length):
    for j in range(length):
        moji = s[i:][::-1]
        moji = moji[j:][::-1]
        if set(moji) <= acgt:
            ans = max(ans,len(moji))

print(ans)

Measured memory_bytes: 3064
N = gets.to_i
A = N.times.map { |_| gets.to_i }
first = A.max
first_count = A.sort_by { |v| -v }[0,2].uniq.length == 2 ? 1 : 2

tmp = A.dup.tap { |v| v.delete(first) }

second = tmp.max
second_count = tmp.sort_by { |v| -v }[0,2].uniq.length == 2 ? 1 : 2

A.each do |v|
  puts (v == first && first_count == 2) || (v != first) ? first : second
end


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

int main(){
    int X; cin >> X;
    cout << ((X >= 30) ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(ll x, ll y)
{
	return (x|y)&(~x|~y);	
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
	ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
	string str,str1;
	cin>>str;
	if(str[2]==str[3] && str[4]==str[5])
	{
		cout<<"Yes";
	}
	else
		cout<<"No";
}

Measured memory_bytes: 256