akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[100000];
    REP(i,n)cin >> a[i];
    sort(a,a+n);
    reverse(a,a+n);
    ll ans = 1;
    int b = 0;
    REP(i,n){
        if(a[i]==a[i+1] && a[i]!=-1){
            ans *= a[i];
            a[i] = a[i+1] = -1;
            b++;
        }
        if(b==2)break;
    }
    cout << (b==2?ans:0) << endl;
}

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

int main() {
	int timetable[24][60]={},n,h,m,flag=0;
	for(int i=0;i<2;i++){
		cin>>n;
		for(int j=0;j<n;j++){
			cin>>h>>m;
			timetable[h][m]=1;
		}
	}for(int i=0;i<24;i++){
		for(int j=0;j<60;j++){
			if(timetable[i][j]==1){
				if(flag==1){
					cout<<" ";
					flag=0;
				}	
				cout<<i<<":"<<setfill('0')<<setw(2)<<right<<j;
				flag=1;
			}
		}
	}cout<<endl;
	return 0;
}

Measured memory_bytes: 1176
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 
 
void solve(){
    ll n,k;
    cin>>n>>k;
    ll x[1010];
    rep(i,n) cin>>x[i];
    ll ans=0;
    rep(i,n){
        ans+=min(abs(x[i]*2),abs((x[i]-k)*2));
    }
    cout<<ans<<endl;
}
 
 
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    ll Q=1;
    // cin>>Q;
    rep(_,Q){
 
        solve();
 
    }
   
 
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;

int main(){
  int N, M; cin >> N >> M;
  vector<string> A(N), B(M);
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = 0; i < M; i++) cin >> B[i];

  for(int i = 0; i < N - M + 1; i++){
    for(int j = 0; j < N - M + 1; j++){
      bool ok = true;
      for(int k = 0; k < M; k++){
        if(A[i + k].substr(j, M) != B[k]) ok = false;
      }
      if(ok){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

void sort(int *a,int *b,int *c){
	int temp;
	if(*a < *b){
		temp = *a;	*a = *b;	*b = temp;
	}
	if(*a < *c){
		temp = *a;	*a = *c;	*c = temp;
	}
}

int main(void)
{
	int num,l,a,b,c;
	
	scanf("%d",&l);
	
	for(num = 0 ; num < l ; num++){
		scanf("%d %d %d",&a,&b,&c);
		sort(&a,&b,&c);
		
		if((a*a) == (b*b) + (c*c)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 580
import sys

inf = float("inf")


def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

string = input()
length = len(string)
count = 0
for i in range(length//2):
    if string[i]!=string[~i]:
        count+=1
print(count)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}

ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}

ll CON(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m*CON(m-1,n)/(m-n);
}
 
int main()
{
  ll a;
  cin >> a;
  if(a%2==0)printf("%lld",a*a/4);
  else printf("%lld",(a+1)*(a-1)/4);
}

Measured memory_bytes: 256
# X:整数　N:長さ
# p1 ... pN
# 含まれない整数のうちXに近いものを答える
import sys
X, N = map(int, input().split())
p = []
for i in sys.stdin:
    p = list(map(int, i.split()))
#p = list(map(int, input().split()))
for i in range(X, -51, -1):
    l = i
    if i not in p:
        break
for j in range(X, 151):
    r = j
    if j not in p:
        break
print(l if abs(l-X) <= abs(r-X) else r)

Measured memory_bytes: 9200
#include <cstdio>
#include <cstring>

int main()
{
    char ring[101], p[101], line[505];
    scanf("%s", ring);
    scanf("%s", p);

    int ring_length, p_length;
    ring_length = strlen(ring);
    p_length = strlen(p);

    for(int i = 0; i < 5; i++){
      strcpy((line+i*(ring_length)),ring);
    }

    char string[101];
    int line_length = strlen(line);
    int counter = 0, k = 0;

    while(1){
        int i;
        for(i = 0; i < p_length; i++){
            if(i + k < line_length){
              string[i] = line[i + k];}
            else{
              break;
            }
        }
        string[i] = '\0';
        if(strcmp(string, p) == 0){
            counter = 1;
            break;
        }
        k++;
        if(k == line_length - p_length + 1 + 1) break;
    }

    if(counter == 0) printf("No\n");
    else printf("Yes\n");

    return 0;
}

Measured memory_bytes: 964
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, K = in.next().toInt
  val A = new Array[Long](N+1)
  for (i <- 1 to N) {
    A(i) = in.next().toLong
  }

  // 
  for (i <- 1 to N) {
    A(i) += A(i-1)
    A(i) %= K
  }

  for (i <- 1 to N) {
    A(i) += K - (i % K)
    A(i) %= K
  }

  val hash = Map[Long, Int]()
  if (K > 1)
    hash += (0L -> 1)
  var ans = 0L
  for (i <- 1 to N) {
    val now = A(i)

    if (hash.contains(now))
      ans += hash(now)

    if (hash.contains(now))
      hash(now) += 1
    else
      hash += (now -> 1)

    if (i >= K-1) {
      hash(A(i-(K-1))) -= 1
    }
  }

  println(ans)
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 75540
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>
#include <random>
#include <ctime>
#include <fstream>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;


const int D = 365;
const int si = 26;
vector<int> c(si);
vector<vector<int>> s(D, vector<int>(si));

struct cand {
    int score;
    int hist[D];
    int cc;
    vector<int> last;
    cand(int _cc) {
        score = 1000000;
        cc = _cc;
        last = vector<int>(si);
    }
};

bool operator<(const cand &left, const cand &right) {
	return left.score < right.score;
}

random_device r;
MaxHeap<cand> ans_heap;
int cc = 0;
const int width = 110, branch = 35, reading = 1;
int times = 1;
cand example(0);

void input() {
    int n; cin >> n;
    rip(i,si,0) {
        cin >> c[i];
        cc += c[i];
    }
    rip(i,D,0) rip(j,si,0) cin >> s[i][j];
}

cand gen_next(cand now, int day) {
	rip(i, reading, 0) {
		int a = r() % si;
        now.hist[day + i] = a;
        now.score += s[day+i][a];
        now.cc += cc-c[a]*(day+i-now.last[a]);
        now.last[a] = day+i;
        now.score -= now.cc;
	}
	return now;
}

void beem(int day) {
	MaxHeap<cand> cand_heap;
	rip(i, width, 0) {
		cand now = ans_heap.top();
		ans_heap.pop();
		rip(j, branch, 0) {
			cand next = gen_next(now, day);
			cand_heap.push(next);
		}
    }
    swap(ans_heap, cand_heap);
}

void output(cand ans) {
    rip(i, D, 0) printf("%d\n", ans.hist[i]+1);
}

int main() {
    input();
	rip(i, width, 0) {
		ans_heap.push(example);
	}
	rip(i, D/reading, 0) {
		beem(i*reading);
		times++;
	}
	output(ans_heap.top());
	// cout << ans_heap.top().score << endl;
}

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

int main()
{
    long long count=0;
	string s1,s2;
    cin>>s1>>s2;
    for(int i=0;i<s1.length();i++)
    {
        if(s1[i]!=s2[i])
            count++;
    }
    cout<<count;
    
}

Measured memory_bytes: 3916
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
long long dp[3001][50];
int n,m,s;
int main(){
	while(1){
		memset(dp,0,sizeof(dp));
		scanf("%d %d %d",&n,&m,&s);
		if(!n) break;
		dp[0][0]=1;
	for (int i=1;i<=m;i++){
		for (int j=n*n;j>=0;j--){
			for (int k=i;k<=s;k++){
					dp[k][j]+=dp[k-i][j-1];
					dp[k][j]%=100000;
				}
			}
		}
		printf("%d\n",dp[s][n*n]);
	}
}

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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007
#define tc             ll tc;scanf("%lld",&tc);while(tc--)

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/

int main()
{

    ll n;
    cin >> n;
    vector<ll> v;
    ll s=0;
    for(ll i=0;i<n;i++)
    {

        ll x;
        cin >> x;
        s+=x;
        v.pb(x);
    }
    ll ans=0;
    for(ll i=0;i<v.size();i++)
    {

        s-=v[i];
        ll ai=v[i], aj=s;
        ai=((ai%mod)*(aj%mod))%mod;
        ans=(ans%mod)+(ai%mod);
        ans%=mod;
    }
    cout << ans;
}


Measured memory_bytes: 5356
n = gets.chomp.to_i
t0 = 1
a0 = 1
n.times do
  t1, a1 = gets.chomp.split(" ").map(&:to_i)
  dd = [(t0 - 1) / t1, (a0 -1) / a1].max + 1
  t0 = t1 * dd
  a0 = a1 * dd
end
puts t0 + a0

Measured memory_bytes: 1788
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int N=in.nextInt();
    int M=in.nextInt();
    int a[]=new int [M];
    int i;long p=0;
    for(i=0;i<M;i++)
    {
      a[i]=in.nextInt();p=p+a[i];
    }
    if(p>N)
      System.out.println("-1");
    else
    {
      System.out.println(N-p);
    }
  }
}
    

Measured memory_bytes: 46320
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  int a, b;cin>>a>>b;
  int tmp, res;
  for(int i=0;i<2;i++){
    if(a>b){
      tmp=a;a=b;b=tmp;
    }
    res+=b;
    b--;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
import math
S = input()

ans = [0 for _ in range(len(S))]
current_char = 'R'
pos_RL = -1
count = 0

for i in range(len(S)):
    if S[i] == current_char:
        count += 1
        # print('#',count,ans,i,current_char)
    else:
        if current_char == 'R':
            current_char = 'L'
            pos_RL = i-1
            ans[pos_RL+1] += math.floor(count/2)
            ans[pos_RL] += math.ceil(count/2)
        else:
            current_char = 'R'
            ans[pos_RL] += math.floor(count/2)
            ans[pos_RL+1] += math.ceil(count/2)
        # print('$',count,ans,i,current_char)
        count = 1
if current_char == 'R':
    current_char = 'L'
    pos_RL = i-1
    ans[pos_RL+1] += math.floor(count/2)
    ans[pos_RL] += math.ceil(count/2)
else:
    current_char = 'R'
    ans[pos_RL] += math.floor(count/2)
    ans[pos_RL+1] += math.ceil(count/2)


for a in ans:
    print(a, end=' ')
print()

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

#define INF 987654321
#define ll long long

int N;
ll res = 0;
vector<int> v[200201], chk(22);

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		int t;
		scanf("%d", &t);
		int n = 0;
		while (t)
		{
			if (t & 1) v[i].push_back(n);
			t >>= 1;
			n++;
		}
	}

	int l = 0;
	for (int i = 0; i < N; i++) // r = i
	{
		for (int j = 0; j < v[i].size(); j++)
		{
			while (chk[v[i][j]])
			{
				for (int k = 0; k < v[l].size(); k++)
					chk[v[l][k]] = 0;
				l++;
			}
			chk[v[i][j]] = 1;
		}

		res += i - l + 1;
	}

	printf("%lld", res);
	return 0;
}

Measured memory_bytes: 18944
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}
// const long long INF = 10000000000000000; // 10e16	


/* params	
 * @s -> start, n -> 要素数, G -> グラフ, d -> 結果(参照渡し)	
 * グラフの要素を0 ~ n - 1として見る	
*/	

struct edge { long long to, cost;};	
typedef pair<long long, long long> P_dij;	
void dijkstra(const long long s, const long long n,	
  vector< vector<edge> > const &G, vector<long long> & d){	
  d.resize(n);	
  for(int i=0; i<n; i++) d[i] = INF; 	
  priority_queue<P_dij, vector<P_dij>, greater<P_dij>> que;	
  d[s] = 0;	
  que.push(P_dij(0, s));	
  while (!que.empty()) {	
    P_dij p = que.top();	
    que.pop();	
    long long v = p.second;	
    if(d[v] < p.first)continue;	
    for(int i=0;i<G[v].size(); i++){	
      edge e = G[v][i];	
      if(d[e.to] > d[v] + e.cost){	
        d[e.to] = d[v] + e.cost;	
        que.push(P_dij(d[e.to], e.to));	
      }	
    }	
  }	
}	

/* END END END */	

int main() {
  int v, e, r;
  cin >> v >> e >> r;
  vector<vector<edge>> g(v);
  vector<ll> d;
  for (int i = 0; i < e; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    edge e1 = {b, c};
    // edge e2 = {a, c};
    g[a].push_back(e1);
    // g[b].push_back(e2);
  }

  dijkstra(r, v, g, d);
  // nfor (auto itr : d) cout << itr << endl;
  
  for (int i = 0; i < v; ++i) {
    if (d[i] == INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }
}



Measured memory_bytes: 19420
/*Anikash Chakraborty cpp*/
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define w(t) int t; cin>>t; while(t--)
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<long long>
#define MAX 1000002
#define MOD 1000000007
#define ll long long
 
using namespace std;
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; } 
ll n;
ll dp[MAX][3],a[MAX][3];
ll solve(ll n,ll turn){
    if(n==0) return 0;
    if(dp[n][turn]!=-1) return dp[n][turn];
    ll ans=0;
    if(turn==0){
        ans+=max(a[n][1]+solve(n-1,1),a[n][2]+solve(n-1,2));
    }
    else if(turn ==1){
        ans+=max(a[n][2]+solve(n-1,2),a[n][0]+solve(n-1,0));
    }
    else{
        ans+=max(a[n][1]+solve(n-1,1),a[n][0]+solve(n-1,0));
    }
    return dp[n][turn]=ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    memset(dp,-1,sizeof dp);
    f(i,1,n+1) cin>>a[i][0]>>a[i][1]>>a[i][2];
    cout<<max({solve(n,1),solve(n,2),solve(n,0)})<<endl;
    
    return 0;
}



Measured memory_bytes: 34108
def solve(string):
    s, t = string.split()
    s, t = s[::-1], t[::-1]
    for i, _ in enumerate(s):
        for j, _ in enumerate(t):
            if not (i + j < len(s)) or (s[i + j] != t[j] and s[i + j] != "?"):
                break
            if j == len(t) - 1:
                return (s[:i] + t + s[i + len(t):])[::-1].replace("?", "a")
    return "UNRESTORABLE"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let k: usize = read();

    let mut l: Vec<u32> = (0..n).map(|_| read()).collect();

    l.sort_by(|x, y| x.cmp(y).reverse());

    let mut sum = 0;
    let mut i = 0;
    for d in l {
        i += 1;
        if i > k {break;}
        sum += d;    
    }
    println!("{}", sum);
}


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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO; 
	
	int n;
	cin >> n;
	int mx = 0;

	map<string, int> mp;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		mp[s]++;
		mx = max(mp[s], mx);
	}
	vector<string> best;
	
	for (auto it: mp) {
		if (it.second == mx) {
			best.push_back(it.first);
		}
	}

	
	sort(best.begin(), best.end());
	for (int i = 0; i < (int) best.size(); ++i) {
		cout << best[i] << endl;
	}
	
}


Measured memory_bytes: 27192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 100002
ll max(ll a,ll b){return a>b?a:b;}
struct node{
	ll b,c;
}op[maxn];
bool cmp(node a,node b){return a.c>b.c;}
ll n,m,a[maxn],s,pn,pop;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<m;i++)
		cin>>op[i].b>>op[i].c;
	sort(op,op+m,cmp);
	while(pn<n&&pop<m){
		ll chg=op[pop].b;
		while(chg&&pn>=0)a[pn]=max(a[pn],op[pop].c),chg--,pn++;
		pop++;
	}
	for(int i=0;i<n;i++)
		s+=a[i];
	cout<<s;
    return 0;
}


Measured memory_bytes: 2560
const euq = (a, b) => {
  let mod = a
  while (mod != 0) {
    mod = a % b
    a = b
    b = mod
  }

  return a
}

const solve = (x, cities) => {
  // ...
  const l = [x, ...cities].sort((a, b) => a - b)
  let diffs = {}
  l.map((ll, i) => {
    if (i == 0) return

    diffs[l[i] - l[i - 1]] = true
  })

  let rr = {}
  let nn = Object.keys(diffs).map(Number)
  if (nn.length == 1) {
    return nn[0]
  }
  let last = nn[0]
  let c = nn
    .sort((a, b) => b - a)
    .map((s, i) => {
      if (i == 0) return 1
      let r = euq(nn[i], last)
      last = r
      return r
    })

  return last
}

const main = (input) => {
  const [head, rest] = input.split("\n")
  const [n, x] = head.split(" ").map(Number)

  return solve(x, rest.split(" ").map(Number))
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}


Measured memory_bytes: 28964
n = int(input())
s = [int(input()) for i in range(n)]
l = [i for i in s if i % 10 != 0]
su = sum(s)
if su % 10 == 0:
    try:
        print(su - min(l))
    except:
        print(0)
else:
    print(su)

Measured memory_bytes: 3060
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(ll i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 2e5 + 5;
const ll OO = 1e9 + 7;
using namespace std;


int main() {
    IO;
    int n;
    cin >> n;
    map<string, int> cnt;
    vector<string> ans;
    rep(i, 0, n) {
        string s;
        cin >> s;
        cnt[s]++;
    }
    int mx = 0;
    for (auto i:cnt) mx = max(mx, i.S);

    for (auto i:cnt) {
        if (i.S == mx) {
            ans.pb(i.F);
        }
    }
    for (auto i:ans) cout << i << endl;

}


Measured memory_bytes: 25584
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll D, Z = min(X, Y);
  if(X > Y){
    D = A;
  }else{
    D = B;
  }

  ll ans=0;
  if(A + B <= 2*C){
    ans += (A+B)*Z;
  }else{
    ans += 2*C*Z;
  }

  if(D <= 2*C){
    ans += D*(max(X, Y)-Z);
  }else{
    ans += 2*C*(max(X, Y)-Z);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define PI 3.1415926535897932
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i, a, n) for (int i = a; i < n; i++)
using namespace std;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,m; cin>>n>>m;
    vi v(n); 
    int sum=0;
    f(i,0,n) {
        cin>>v[i];
        sum+=v[i];
    }
    sort(all(v));
    if(v[n-m]>=1.0*sum/(4*m)) cout<<"Yes";
    else cout<<"No\n";

    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A[1000],a,b;
    A[1]=1;
    for (int i=2;i<1000;i++){
        A[i]=A[i-1]+i;
    }
    cin>>a>>b;
    
    cout<<A[b-a]-b<<endl;
}

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

int main(void){
  int n, T;
  cin >> n >> T;
  int c[n], t[n];
  for(int i = 0; i < n; i++) cin >> c[i] >> t[i];
  bool f[n];
  for(int i = 0; i < n; i++) {
    if(t[i] <= T) f[i] = true;
    else f[i] = false;
  }
  int cost = 10000;
  for(int i = 0; i < n; i++){
    if(f[i] && c[i] < cost) cost = c[i];
  }
  if(cost != 10000)
    cout << cost << endl;
  else
    cout << "TLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    int ct=0;
    for(int i=0; i<n; i++){
        int a; cin>>a;
        if(a%2==1) ct++;
    }
    if(ct%2==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//AtCoder1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream> 
#include <algorithm>
#include <math.h> 
using namespace std;

int main()
{
    int N;
    cin >> N;
    cout << ceil(N/2.0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
int main() {
  int N,A,B,C;
  std::cin >> N >> A >> B >> C;
  std::list<int> L;
  for (auto i=0;i<N;i++){
    int ll;
    std::cin >> ll;
    L.push_back(ll);
  }
  std::function<int(std::list<int>,int,int,int,int)> f =
    [&](std::list<int> l,int al, int bl, int cl, int mp) {
    if(l.empty()){
      if (al==0|| bl==0||cl==0)
        return 1 << 30;
      return std::abs(A-al) + std::abs(B-bl) + std::abs(C-cl)
        + mp - 30;
    }
    int ll = l.front();
    l.pop_front();
    return std::min({
      f(l,al+ll,bl,cl,mp+10),
      f(l,al,bl+ll,cl,mp+10),
      f(l,al,bl,cl+ll,mp+10),
      f(l,al,bl,cl,mp)});
  };
  std::cout << f(L,0,0,0,0) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>


using namespace std;
string yn(bool a)
{
  if (a){return "Yes";}
  else{return "No";}
}

bool sosuu(int n)
{
  int i=3;
  if(n==1){return false;}
  if(n==2){return true;}
  if(n%2==0){return false;}
  while(true)
  {
    if(n%i==0&&n!=i){return false;}
    if(i>sqrt(n)+1){break;}
    i+=2;
  }
  return true;

}

int main()
{
  ios::sync_with_stdio(false);
  int q;
  cin >> q;

  int res[100001];
  res[1]=0;
  res[2]=0;
  res[3]=0;
  for(int i=3;i<100000;i++)
  {
    res[i+1]=res[i]+sosuu(i)*sosuu((i+1)/2);
  }
  vector<int>l(q);
  vector<int>r(q);
  for(int i=0;i<q;i++)
  {
    cin>>l[i]>>r[i];
    cout<<res[r[i]+1]-res[l[i]]<<'\n';
  }


}

Measured memory_bytes: 1792
while True:
    n = int(input())
    if n == 0: break
    squares = [(0,0)]
    x_max, x_min, y_max, y_min = 0, 0, 0, 0
    for i in range(1,n):
        p, d = map(int, input().split())
        x, y = squares[p]
        if d == 0:
            x -= 1
        elif d == 1:
            y -= 1
        elif d == 2:
            x += 1
        elif d == 3:
            y += 1
        squares.append((x,y))
        x_max = max(x_max, x)
        x_min = min(x_min, x)
        y_max = max(y_max, y)
        y_min = min(y_min, y)
    print(x_max - x_min + 1, y_max - y_min + 1)

Measured memory_bytes: 6724
#include<bits/stdc++.h>
 using namespace std;
 
typedef long long int ll;
#define endl "\n"
#define fi first
#define sec second 
#define pb push_back
#define test cout<<"debuged\n";
#define INF ll(1e18)
#define MOD 1000000007
#define debug(x) cout<<x<<"\n";
#define pll pair<ll,ll>
#define mp make_pair
#define Minato_Namikaze ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define MAX 200015
 
int main()
{
 
 
ll w,s;
cin>>w>>s;
if(w<=s)cout<<"unsafe\n";
else cout<<"safe\n";

}

Measured memory_bytes: 3628
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X = MAP()
x = LIST()

if N == 1:
	print(abs(x[0] - X))
	exit()

ans = gcd(abs(x[0]-X), abs(x[1]-X))
for i in range(2, N):
	ans = gcd(ans, abs(x[i]-X))

print(ans)

Measured memory_bytes: 16324
A, B, C, X, Y = map(int, input().split())
ans = 0
if (A+B)/2 >= C:
    if X >= Y:
        if A/2 <= C:
            ans += C * Y * 2
            ans += A * (X-Y)
        else:
            ans += C * X * 2
    else:
        if B/2 <= C:
            ans += C * X * 2
            ans += B * (Y-X)
        
        else:
            ans += C * Y *2
else:
    ans = A*X + B*Y
    
print(ans)

Measured memory_bytes: 9000
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);

    sort(a.begin(), a.end());
    cout << a.at(n-1) - a.at(0) << endl;
}

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

int main()
{

    ll n,m,s=0;

    cin>>n>>m;

    ll a[m+1];

    for(int i=0;i<m;i++)
    {
        cin>>a[i];s=s+a[i];
    }

    if(n<s)
        cout<<"-1\n";

    else //if(n==s)
        //cout<<
        cout<<(n-s)<<endl;


    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define INF 10000000

typedef long long ll;
typedef pair<ll, ll> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z


int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

void solve(void){
    ll n, a, b;
    cin >> n >> a >> b;
    ll xs[n];
    rep(n, i) scanf("%lld", &xs[i]);
    ll ans = 0;
    rep(n-1, i) ans += min(b, a*(xs[i+1]-xs[i]));
    printf("%lld\n", ans);
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    s = str(input()).replace("\n", "")

    for i in range(len(s) - 2, 0, -2):
        s_new = s[:i]
        if s_new[:int(len(s_new)/2)] == s_new[int(len(s_new)/2):]:
            print(len(s_new))
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long
#define mod 1000000007;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0, hoge = 1;
	while (1) {
		if (hoge >= b)break;
		hoge = a + hoge - 1;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A,B = [],[]
for i in range(N):
    n=int(input())
    A.append(n)
    for k in range(n):
        x,y = map(int,input().split())
        B.append([i,x,y])
ans = 0
for i in range(2**N):
    cnt = 0
    ok = True
    for j in range(N):
        #正直者を1にする
        if (i>>j) & 1:
            cnt += 1
            for k in range(len(B)):
                if B[k][0] != j:
                    continue
                else:
                    if ((i >> (B[k][1]-1)) & 1) and B[k][2] == 1:
                        continue
                    elif ((i >> (B[k][1]-1)) & 1 == 0) and B[k][2] == 0:
                        continue
                    else:
                        ok = False
                        break
    if ok:
        ans = max(ans,cnt)
print(ans)

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

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


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

typedef long long ll;

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

    int n; cin >> n;
    set<int> st;
    for(int i=0;i<n;i++){
        int d; cin >> d;
        st.insert(d);
    }
    cout << st.size() << endl;
    return 0;
}

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

int main(){
    long long ans = 0;
    
    long long n, c;
    cin >> n >> c;
    
    vector<long long> x(n+2);
    vector<long long> v(n+1);
    x[0] = 0;
    x[n+1] = c;
    v[0] = 0;
    for (int i = 1; i<=n; i++){
        cin >> x[i] >> v[i];
    }
    
    vector<long long> turn_right(n);
    turn_right[0] = 0;
    for (int i = 1; i<n; i++){
        turn_right[i] = turn_right[i-1] + v[i] - (x[i] - x[i-1])*2;
    }
    
    long long left_max = 0;
    long long tmp = 0;
    for (int i = n; i>0; i--){
        tmp += v[i] - (x[i+1] - x[i]);
        left_max = max(left_max, tmp);
        ans = max(ans, left_max + turn_right[i-1]);
    }
    
    vector<long long> turn_left(n+2);
    turn_left[n+1] = 0;
    for (int i = n; i>0; i--){
        turn_left[i] = turn_left[i+1] + v[i] - (x[i+1] - x[i])*2;
    }
    
    long long right_max = 0;
    tmp = 0;
    for (int i = 1; i<=n; i++){
        tmp += v[i] - (x[i] - x[i-1]);
        right_max = max(right_max, tmp);
        ans = max(ans, right_max + turn_left[i+1]);
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 3328
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
	int i, c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";
	
	if ( T[u].p == NIL ) cout << "root, ";
	else if ( T[u].l == NIL ) cout << "leaf, ";
	else cout << "internal node, ";
	
	cout << "[";
	
	for ( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r ) {
		if (i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

// 再帰的に深さを求める
int rec(int u, int p) {
	D[u] = p;
	if ( T[u].r != NIL ) rec(T[u].r, p); // 右の兄弟に同じ深さを設定
	if ( T[u].l != NIL ) rec(T[u].l, p + 1);// 最も左の子に自分の深さ+1を設定
	return 0;
}

int main() {
	int i, j, d, v, c, l, r;
	cin >> n;
	for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;
	
	for ( i = 0; i < n; i++ ) {
		cin >> v >> d;
		for ( j = 0; j < d; j++ ) {
			cin >> c;
			if ( j == 0 ) T[v].l = c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}
	for ( i = 0; i < n; i++ ) {
		if (T[i].p == NIL) r = i;
	}
	
	rec(r, 0);
	
	for ( i = 0; i < n; i++ ) print(i);
	
	return 0;
}



Measured memory_bytes: 7776
#include <stdio.h>

int main(void) {
  int n;
  int i, j;
  int r;
  int max, min;

  scanf("%d", &n);
  scanf("%d", &r);

  max = -1e9;
  min = r;
  
  for (i = 1; i < n; i++) {
    scanf("%d", &r);
    max = ((r - min) > max) ? (r - min) : max;
    min = (r < min) ? r : min;
   }

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



Measured memory_bytes: 2000
N = int(input())
A = list(map(int, input().split()))

if N == 0:
  if A[0] != 1:
    print(-1)
  else:
    print(1)
  exit()

if A[0] != 0:
  print(-1)
  exit()

if A[1] > 2:
  print(-1)
  exit()

B = [0] * (N + 1)
B[0] = 1
for i in range(1, N + 1):
  b = B[i - 1] * 2
  if b < A[i]:
    print(-1)
    exit()
  B[i] = b - A[i]

L = [0] * (N + 1)
L[N] = A[N]
for i in range(N - 1, 0, -1):
  L[i] = min(B[i - 1] * 2, A[i] + L[i + 1])
  if L[i] < 0:
    print(-1)
    exit()

print(sum(L) + 1)

Measured memory_bytes: 706632
#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() {
    string S, T;
    cin >> S;
    cin >> T;

    int mini = 100000;
    rep(i, S.size() - T.size() + 1) {
        int a = T.size();
        rep(j, T.size()) {
            if (S[i + j] == T[j]) {
                a--;
            }
        }
        mini = min(mini, a);
    }
    cout << mini << endl;
    return 0;
}


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

using namespace std;

struct UnionFindTree{
  vector<int> parent;
  vector<int> cardinality;
  
  UnionFindTree(int n) : parent(n), cardinality(n){
    for(int i = 0; i < n; i++){
      parent[i] = i;
      cardinality[i] = 1;
    }
  }
  
  int root(int x){
    if(parent[x] == x) return x;
    else return parent[x] = root(parent[x]);
  }
  
  void unite(int x, int y){
    int root_x = root(x);
    int root_y = root(y);
    if(root_x != root_y){
      parent[root_x] = root_y;
      cardinality[root_y] += cardinality[root_x];
    }
  }
  
  bool same(int x, int y){
    return root(x) == root(y);
  }
  
  int num_of_friends_of(int x){
    return cardinality[root(x)];
  }
};

int main(){
  int n, m;
  cin >> n >> m;
  
  struct UnionFindTree island(n);
  
  vector<pair<int, int>> bridge(m);
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    bridge[i] = make_pair(a - 1, b - 1);
  }
  
  vector<long long> uncomfortableness(m, (long long)n * (n - 1) / 2);
  
  for(int i = m - 1; i > 0; i--){
    int a = bridge[i].first;
    int b = bridge[i].second;
    
    if(island.same(a, b)) uncomfortableness[i - 1] = uncomfortableness[i];
    else{
      uncomfortableness[i - 1] = uncomfortableness[i] - (long long)island.num_of_friends_of(a) * island.num_of_friends_of(b);
      island.unite(a, b);
    }
  }
  
  for(int i = 0; i < m; i++) cout << uncomfortableness[i] << endl;
  
  return 0;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main() {
	int l,r,d; scanf("%d%d%d", &l, &r, &d);
	int a1=l/d, a2=r/d;
	printf("%d\n", a2-a1+(l%d==0?1:0));
}


Measured memory_bytes: 1708
// ProblemURL : https://atcoder.jp/contests/code-festival-2016-qualb/tasks/codefestival_2016_qualB_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	t := "CODEFESTIVAL2016"
	ans := 0
	for i := range s {
		if s[i] != t[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
from heapq import heappush, heappop
import collections


class MinCostFlowDijkstra:
    def __init__(self, N):
        self.N = N
        self.edges = collections.defaultdict(list)

    def add(self, fro, to, cap, cost, directed=True):
        # edge[fro]: to, cap, cost, rev(逆辺)
        if directed:
            self.edges[fro].append([to, cap, cost, len(self.edges[to])])
            self.edges[to].append([fro, 0, -cost, len(self.edges[fro]) - 1])
        else:  # TODO: must be Verified
            self.edges[fro].append([to, cap, cost, len(self.edges[to])])
            self.edges[to].append([fro, 0, -cost, len(self.edges[fro]) - 1])
            self.edges[to].append([fro, cap, cost, len(self.edges[fro])])
            self.edges[fro].append([to, 0, -cost, len(self.edges[to]) - 1])

    def minCostFlow(self, start, goal, flow):
        res = 0
        potential = collections.defaultdict(int)
        prevVertex = collections.defaultdict(int)
        prevEdge = collections.defaultdict(int)

        while flow > 0:
            dist = collections.defaultdict(lambda: float('inf'))
            dist[start] = 0
            que = []
            heappush(que, (0, start))

            while que:
                k, v = heappop(que)
                if dist[v] < k:
                    continue
                for i, (to, cap, cost, _) in enumerate(self.edges[v]):
                    if cap > 0 and dist[to] > dist[v] + cost + potential[v] - potential[to]:
                        dist[to] = dist[v] + cost + potential[v] - potential[to]
                        prevVertex[to] = v
                        prevEdge[to] = i
                        heappush(que, (dist[to], to))
            if dist[goal] == float('inf'):
                return -1

            for i in range(self.N):
                potential[i] += dist[i]

            d = flow
            v = goal
            while v != start:
                d = min(d, self.edges[prevVertex[v]][prevEdge[v]][1])
                v = prevVertex[v]
            flow -= d
            res += d * potential[goal]
            v = goal
            while v != start:
                e = self.edges[prevVertex[v]][prevEdge[v]]
                e[1] -= d
                self.edges[v][e[3]][1] += d
                v = prevVertex[v]
            #print(d, flow, prevVertex, prevEdge)
        return res


V, E, F = map(int, input().split())
graph = MinCostFlowDijkstra(V)
for _ in range(E):
    u, v, c, d = map(int, input().split())
    graph.add(u, v, c, d)

print(graph.minCostFlow(0, V-1, F))


Measured memory_bytes: 6300
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a,b = na()
n = int(str(a)+str(b))
arr = [i for i in range(1,320)]
flag = 0
for i in arr:
    s = n // i
    if s**2 == n:
        flag = 1
        break
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064