akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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


		int max=0;
		int count = 0;
		String maxs="";
		for(int i=0;i<s.length();i++) {
			switch(s.charAt(i)) {
			case'A':
				count++;
				break;
			case'C':
				count++;
				break;
			case'G':
				count++;
				break;
			case'T':
				count++;
				break;
			default:
				if(max<count) {
					max = count;
					maxs = s.substring(i-count, i);
				}
				count=0;

				break;
			}
			
			
			
		}
		if(max<count) {
			max = count;
			maxs = s.substring(s.length()-count, s.length());
		}
		if(maxs.length()!=0) {
		System.out.println(max);
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int n; cin >> n;
  v<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  cout << a[a.size()-1] << " ";
  int index=lower_bound(a.begin(),a.end(),a[a.size()-1]/2)-a.begin();
  if(abs((double)a[a.size()-1]/2.0-(double)a[index-1])>abs((double)a[a.size()-1]/2.0-(double)a[index]) && index!=a.size()-1) cout << a[index] << endl;
  else cout << a[index-1] << endl;
  return 0;
}


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

class UnionFind {
public:
vector<int> Parent;

UnionFind(int N) {
  Parent = vector<int>(N, -1);
}

int root(int A) {
  if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

int size(int A) {
  return -Parent[root(A)];
}

bool connect(int A, int B) {
  A = root(A);
  B = root(B);
  if (A == B) {
    return false;
  }
  if (size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};

int main(){
  int n, m;
  cin >> n >> m;

  UnionFind uni(n);
  for (int i = 0; i < m; i++)
  {
    int a,b;
    cin >> a >> b;
    a--;
    b--;

    uni.connect(a,b);
  }

  set<int> st;
  for (int i = 0; i < n; i++)
  {
    st.insert(uni.root(i));
  }
  cout << st.size()-1 << endl;
}

Measured memory_bytes: 7408
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int m=3;
  if (a==b || b==c || a==c) {
    m--;
  }
  if (a==b && b==c) {
    m--;
  }
  cout << m << endl;
}

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

using namespace std;




main(){

	long long n, m; cin >> n >> m;

	vector <long long> a(n);


	multiset <long long> s;

	for(long long i = 0; i < n; i++){
		cin >> a[i];
	}


	for(long long i = 0; i < n; i++){
		s.insert(a[i]);
	}


	while(m--){
		long long to = *prev(s.end());
		s.erase(prev(s.end()));
		s.insert(to / 2);
	}


	cout << accumulate(s.begin(), s.end(), 0LL) << endl;

	return 0;
}

Measured memory_bytes: 5760
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    auto abc = aryread();
    abc.sort();
    long ans = long.max;
    do
    {
        ans = ans.min(abs((abc[0] / 2) - (abc[0] - abc[0] / 2)) * abc[1] * abc[2]);
    }
    while (nextPermutation(abc));
    writeln(ans);
}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a;
    cin >> a;
    if(a<=999){
        cout << "ABC";
    }else{
        cout <<"ABD";
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
  int x, a, b;
  int A;

  scanf("%d", &x);
  scanf("%d", &a);
  scanf("%d", &b);

  if(a>=b){
    printf("delicious\n");
    return 0;
  }

  else{
    if(x>=b-a){
      printf("safe\n");
      return 0;
    }

    else{
      printf("dangerous\n");
      return 0;
    }
  }
    return 0;
}
   

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

int main(){
 int N;
 cin >> N;
 
 for(int i=0; i<N; i++){
  int x, y, b, p;
  cin >> x >> y >> b >> p;

  int money1 = x*b+y*p;

  if(b<5) b = 5;
  if(p<2) p = 2;
  int money2 = (x*b+y*p)*4/5;

  if(money1<money2){
   cout << money1 << endl;
  }else{
   cout << money2 << endl;
  }
 }

 return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

int main() {
    //ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);

    int n, m;
    int l[100001], r[100001];
    int mem[100001];
    int ans = 0;
    int count = 0;

    memset(mem,0,sizeof(mem));

    cin >> n >> m;
    for(int i = 0; i < m; i ++){
        cin >> l[i] >> r[i];
    }

    for(int i = 0; i < m; i ++){
        count ++;
        for(int j = l[i]; j <= r[i]; j ++){
            mem[j]  ++;
        }
    }

    for(int i = 1; i <= n; i ++){
        if(mem[i] == m) ans ++;
    }
    cout << ans;

    return 0;
}



Measured memory_bytes: 4784
#!/usr/bin/env python3

N = int(input())
lstA = [int(a) for a in input().split()]

def round():
    for i in range(len(lstA)):
        if lstA[i] % 2 == 0:
            lstA[i] //= 2
        else:
            return False
    return True

cnt = 0
while round():
    cnt += 1
print(cnt)


Measured memory_bytes: 9052
TEST = False

if not TEST:
    N = int(input())
    AS = []
    BS = []
    for i in range(N):
        A, B = [int(x) for x in input().split()]
        AS.append(A)
        BS.append(B)


def getBound(AS, BS):
    """
    >>> getBound([0, 1], [1, 2])
    1 3 3
    >>> getBound([0, 0], [1, 2])
    1 3 3
    >>> getBound([0, 1, 2], [1, 2, 3])
    1 2 2
    >>> getBound([0, 1, 2], [1, 3, 3])
    1 3 3
    >>> getBound([0, 0, 1], [2, 3, 3])
    0 3 4
    """
    N = len(AS)
    AS2 = AS[:]
    AS2.sort()

    BS2 = BS[:]
    BS2.sort()
    if N % 2 == 0:
        lower = AS2[N // 2 - 1] + AS2[N // 2]
        upper = BS2[N // 2 - 1] + BS2[N // 2]
        result = upper - lower + 1
    else:
        lower = AS2[N // 2]
        upper = BS2[N // 2]
        result = upper - lower + 1
    if TEST:
        print(lower, upper, result)
    else:
        return result


def _test():
    import doctest
    doctest.testmod()


if TEST:
    _test()
else:
    print(getBound(AS, BS))


Measured memory_bytes: 28500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int f=0;
	while(n>0)
	{
		int x=n%10;
		if(x==7)
		{
			f=1;
			break;
		}
		n=n/10;
	}
	if(f==1)
		cout<<"Yes"<<"\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3608
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using  namespace std;

typedef long long ll;

int main(int argc, char const* argv[])
{
    // vector<int> a(3), b(3);
    // for (int i = 0; i < 3; i++) {
    //     cin >> a[i] >> b[i];
    // }

    //   1
    // 3 2 4
    
    map<int,int> road;
    for (int i = 0; i < 3; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        road[a]++;
        road[b]++;
    }

    for (int i = 0; i < 4; i++){
        if (road[i] >= 3) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1500100],b[1500100],A[1500100],B[1500100],p[1500100],q[1500100];
int main(){
	int n,m;
	while(cin>>n>>m,n){
		memset(A,0,sizeof(A));
		memset(B,0,sizeof(B));
		memset(p,0,sizeof(p));
		memset(q,0,sizeof(q));
		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;i++){
			A[i+1] = A[i] + a[i];
		}
		for(int i = 0;i < m;i++){
			B[i+1] = B[i] + b[i];
		}
		n++,m++;
		for(int i = 0;i < n;i++){
			for(int j = i + 1;j < n;j++){
				p[A[j] - A[i]]++;
			}
		}
		for(int i = 0;i < m;i++){
			for(int j = i + 1;j < m;j++){
				q[B[j] - B[i]]++;
			}
		}
		int cnt = 0;
		for(int i = 0;i < 1500100;i++){
			cnt += p[i] * q[i];
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 27784
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define forn(i,a,n) for(int i =a; i < n; i++)
#define fi first
#define se second
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long int lli;
typedef pair<lli,lli> pii;

int main(){__
    lli n,m;
    cin >> n >> m;
    vector<pii> a(n);
    forn(i,0,n) cin >> a[i].fi >> a[i].se;
    lli ans =0ll;
    sort(a.begin(), a.end());
    forn(i,0,n){
        ans+= a[i].fi * min(a[i].se,m);
        m-=min(a[i].se,m);
        if(m == 0) break;
    }
    cout << ans << endl;
	return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int MAX_W = 55;
const int MAX_H = 55;
int W, H;
char a[MAX_W][MAX_H+1];
int d[MAX_W][MAX_H+1];
bool flag[MAX_W][MAX_H+1];
map<char, int> hm;

inline bool check(int hx, int hy){ return 0 <= hx && hx < H && 0 <= hy && hy < W; }

int main()
{
  hm['W'] = 1;
  hm['B'] = -1;

  while(cin >> W >> H, W){
    rep(i, H) rep(j, W) cin >> a[i][j];
    rep(i, H) rep(j, W) d[i][j] = 0;
    rep(i, H) rep(j, W) flag[i][j] = false;

    rep(i, H) rep(j, W) if(a[i][j] != '.'){
      stack<pii> st;
      st.push(mp(i, j));
      while(!st.empty()){
        pii here = st.top();  st.pop();
        int hx = here.first;
        int hy = here.second;
        rep(k, 4){
          int nx = hx + dx[k];
          int ny = hy + dy[k];
          if(!check(nx, ny)) continue;
          if(a[nx][ny] == '.' && (!flag[nx][ny] || d[nx][ny] == -hm[a[i][j]])){
            flag[nx][ny] = true;
            d[nx][ny] += hm[a[i][j]];
            st.push(mp(nx, ny));
          }
        }
      }
    }

    int h = 0;
    int b = 0;
    rep(i, H) rep(j, W){
      if(d[i][j] > 0) h += 1;
      if(d[i][j] < 0) b += 1;
    }

    cout << b << ' ' << h << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("src/aoj0027/input.txt"));
			System.setOut(new PrintStream(new FileOutputStream("src/xxxyyyy/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		for (;;) {
			int mm = sc.nextInt();
			int dd = sc.nextInt();
			if ((mm | dd) == 0)
				break;
			System.out.println(solve(mm, dd));
		}
	}

	String solve(int mm, int dd) {
		Calendar cal = Calendar.getInstance();
		cal.set(2004, mm - 1, dd);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		return new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }[w];
	}

	void debug(Object... os) {
		System.err.println(deepToString(os));
	}
}

Measured memory_bytes: 12000
#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 n;
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  cin >> n;
  vector<string> a(n);
  rep(i, n){cin >> a.at(i);}
  // rep(i, n){cout << a[i] << endl;}
  rep(i,n){
    if (a[i] == "AC"){
        ac += 1;
    } else if(a[i] == "WA"){
        wa += 1;
    } else if(a[i] == "TLE"){
        tle += 1;
    } else if(a[i] == "RE"){
        re += 1;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}

Measured memory_bytes: 6424
n,d=map(int,input().split())
import numpy as np
x=[]
for _ in range(n):
  t=np.array(list(map(int,input().split())))
  x.append(t)

cnt=0
for i in range(n):
  for j in range(n):
    if i==j:continue
    k=(sum((x[i]-x[j])**2))**.5
    if int(k)-k==0:
      cnt+=1
print(cnt//2)
    

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

int T,n,anum,bnum,k,l,r;
priority_queue<int,vector<int>,greater<int> >q1, q2;

struct node
{
    int L,R,K;
}A[200005],B[200005];

bool cmp(node x,node y)
{
	return x.K<y.K;
}

signed main()
{
    cin>>T;
    while (T--)
    {
        anum=bnum=0;
        long long ans=0;
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>k>>l>>r;
            if (l>r)  A[++anum].L=l,A[anum].R=r,A[anum].K=k;
            else B[++bnum].L=l,B[bnum].R=r,B[bnum].K=n-k;
            ans+=min(l,r);
        }
        sort(A+1,A+1+anum,cmp);
		sort(B+1,B+1+bnum,cmp);
        for (int i=1; i<=anum;i++)
        {
            if (A[i].K == 0)  continue;
            if (q1.size()<A[i].K)  q1.push(A[i].L-A[i].R);
            else if (q1.size()==A[i].K&&q1.top()<A[i].L-A[i].R)
            {
            	q1.pop();
				q1.push(A[i].L-A[i].R);
			}
        }
        for (int i=1;i<=bnum;i++)
        {
            if (B[i].K==0)  continue;
            if (q2.size()<B[i].K)  q2.push(B[i].R-B[i].L);
            else if (q2.size()==B[i].K&&q2.top()<B[i].R-B[i].L)
            {
            	q2.pop();
				q2.push(B[i].R-B[i].L);
			}
        }
        while (!q1.empty())
        {
        	ans+=q1.top();
        	q1.pop();
		}
        while (!q2.empty())
        {
        	ans+=q2.top();
        	q2.pop();
		}
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 10168
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();

        int cnt = 1;
        for (int i = 0; i < n - 1; i++)
        {
            if(s[i] != s[i+1])
            {
                cnt++;
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//templete
int main() {
    int N;
    cin>>N;
    vint A;
    int idx[SIZE]={};
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        A.pb(a);
        idx[a]=i;
    }
    set<int> tes;
    tes.insert(-1);
    tes.insert(N);
    ll ans=0;
    for(int i=1;i<=N;i++){
        //Nの左右のidx
        auto l=tes.lower_bound(idx[i]), r=tes.upper_bound(idx[i]);
        l--;
        ll left=*l, right=*r;
        cerr<<left<<" "<<right<<endl;

        ans+=i*(idx[i]-left)*(right-idx[i]);
        tes.insert(idx[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

	int n;
	cin >> n;
	vector<int> p(n);
	for (auto& i : p) {
		cin >> i;
	}
	vector<int> q = p;
	sort(q.begin(), q.end(), [](int& a, int& b) {return a < b; });
	int num = 0;
	for (int i = 0; i < n; i++) {
		if (q[i] != p[i])num++;
	}
	if (num <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    bool ok=false;
    rep(i,n){
        if(a[i]%2)ok=true;
    }
    if(ok)cout<<"first"<<endl;
    else cout<<"second"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <deque>
#include <array>
#include <cmath>

using namespace std;

int main()
{
  int k, n;
  deque<int> a;

  cin >> k >> n;

  for (int i = 0; i < n; i++)
  {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  // 初期値は0とn-1の距離
  int max_dif = a[0] + (k - a[n - 1]);

  for (int i = 1; i < n; i++)
  {
    if (a[i] - a[i - 1] > max_dif)
    {
      max_dif = a[i] - a[i - 1];
    }
  }

  cout << k - max_dif << endl;

  return 0;
}

Measured memory_bytes: 1024
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int n,k;
void ev()
{
    vector<pi>vec,v2;
    int last=n;
    for(int i=n-1,j=n;i>=1;i=i-2,j++)
    {
        vec.pb(mp(i+k,j+k));
        last=j;
    }
    reverse(vec.begin(),vec.end());
    for(int i=n-2,j=last+1;i>=0;i=i-2,j++)
    {
         v2.pb(mp(i+k,j+k));
    }
    reverse(v2.begin(),v2.end());
    for(auto x:v2)
    {
        vec.pb(x);
    }
    int cur=2*n+k;
   for(auto x:vec)
   {
       int sum=x.fi+x.si;
       if(sum>cur)return ;
       cur++;
   }
   cur=2*n+k;
   for(auto x:vec)
   {
       cout<<x.fi<<" "<<x.si<<" "<<cur<<endl;
       cur++;
   }
   exit(0);
}
void od()
{
    vector<pi>vec,v2;
    int last=n;
    for(int i=n-1,j=n;i>=0;i=i-2,j++)
    {
        vec.pb(mp(i+k,j+k));
        last=j;
    }
    reverse(vec.begin(),vec.end());
    for(int i=n-2,j=last+1;i>=1;i=i-2,j++)
    {
         v2.pb(mp(i+k,j+k));
    }
    reverse(v2.begin(),v2.end());
    for(auto x:v2)
    {
        vec.pb(x);
    }
    int cur=2*n+k;
   for(auto x:vec)
   {
       int sum=x.fi+x.si;
       if(sum>cur)return ;
       cur++;
   }
   cur=2*n+k;
   for(auto x:vec)
   {
       cout<<x.fi<<" "<<x.si<<" "<<cur<<endl;
       cur++;
   }
   exit(0);
}
 main()

{
    fast
    cin>>n>>k;
    if(n%2==0)ev();
    else od();
    cout<<"-1"<<endl;
    return 0;

}




































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

#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b != c) {
    cout << c << endl;
  } else if (a == c && a != b) {
    cout << b << endl;
  } else {
    cout << a << endl;
  }
}

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

int main() {
  string s;
  cin>>s;
  int counter = 700;
  for (int i=0; i<3; i++){
    if(s[i]=='o'){
      counter+=100;
    }
  }
  cout<<counter<<endl;
  return 0;
}

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

int main()
{
    int r,g,b;
    int res=0;
    cin>>r>>g>>b;
    res=r*100 + g*10 +b;
    if(res%4==0)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

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

int cost(int a, int b) {
  int res = 0;
  while (a < b) {
    res += 1;
    a += 2;
  }
  while (a > b) {
    res += 1;
    a -= 1;
  }
  return res;
}

bool solve() {
  int a, b, c;
  if (scanf("%d%d%d", &a, &b, &c) != 3) { return false; }

  int ans = 1 << 30;
  for (int x = 0; x < 100; ++x) {
    int cur = cost(a, x) + cost(b, x) + cost(c, x);
    ans = min(cur, ans);
  }
  printf("%d\n", ans);
  return true;
}

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

Measured memory_bytes: 256
ans='No'
X=''
Y=''
n=0
a,b=map(int,input().split())
x=[0]*(a*a)
y=[0]*(b*b)
for i in range(a):
    for s in input().split():
        X+=s
for i in range(b):
    for s in input().split():
        Y+=s

for h in range(a-b+1):
    for w in range(a-b+1):
        p_X=''
        for t in range(b):
            p_X+=X[(h+t)*a+w:(h+t)*a+w+b]
        if p_X==Y:
            ans='Yes'
print(ans)

Measured memory_bytes: 40556
#include<cstdio>
#include<vector>


using namespace std;

using vi=vector<int>;
using vvi=vector<vi>;
using ll=long long;


const int white=-1;
const int black=100000000;


vi gx, gy;


void push(int x, int y)
{
	gx.push_back(x);
	gy.push_back(y);
}


int pop(int& x, int& y)
{
	if(gx.size()<=0) return 0;
	x=gx.back();
	y=gy.back();
	gx.pop_back();
	gy.pop_back();
	return 1;
}


void eng_fill(vvi& c, int x, int y, int g)
{
	int vx[]={ 1, 0,-1, 0};
	int vy[]={ 0,-1, 0, 1};
	int nx, ny;
	int w, h;

	w=7;
	h=c.size();
	push(x, y);
	c[y][x]=g;
	while(pop(x, y))
	{
		for(int i=0;i<4;i++)
		{
			nx=x+vx[i];
			ny=y+vy[i];
			if(nx<0 || w<=nx || ny<0 || h<=ny) continue;
			if(c[ny][nx]!=white) continue;
			c[ny][nx]=g;
			push(nx, ny);
		}
	}
}



int engroup(vvi& c)
{
	int w, h, x, y;
	int g=0;

	w=7;
	h=c.size();
	for(y=0;y<h;y++)
	{
		for(x=0;x<w;x++)
		{
			if(c[y][x]!=white) continue;
			eng_fill(c, x, y, g);
			g++;
		}
	}
	return g;
}


int gcd(int a, int b)
{
	int c;
	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


int lcm(int a, int b)
{
	return a/gcd(a, b)*b;
}


int main(void)
{
	int m, q, g, uh, gc;
	ll n, h;
	vvi c, f;

	while(scanf("%lld%d%d", &n, &m, &q)==3)
	{
		uh=lcm(m, 7)/7;
		h=n/uh;
		c.clear();
		c.resize(uh);
		for(auto& ce: c) ce.resize(7, white);

		for(int i=0;i<q;i++)
		{
			int a;
			scanf("%d", &a);
			for(int j=a;j<uh*7;j+=m)
			{
				c[j/7][j%7]=black;
			}
		}
		g=engroup(c);

		f.clear();
		for(int i=0;i<7;i++)
		{
			int u=c[0][i];
			int l=c[uh-1][i];
			int j;
			if(u==black || l==black) continue;
			if(u>l) swap(u, l);
			vi ft={u,l};
			for(j=f.size()-1;j>=0;j--)
			{
				if(ft==f[j]) break;
			}
			if(j<0)
			{
				f.push_back(ft);
//				printf("%d %d\n", ft[0], ft[1]);
			}
		}
		gc=f.size();
# if 0
for(auto ce:c)
{
	for(int x:ce)
	{
		if(x==black) printf(" X ");
		else printf("%2d ", x);
	}
	printf("\n");
}
printf("g=%d h=%d gc=%d\n", g, h, gc);
#endif
		ll result=g*h-gc*(h-1);
		printf("%lld\n", result);
	}

	return 0;
}


Measured memory_bytes: 8316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n, k;
	cin >> n >> k;
	ll a[n], ma = -1;
	for (ll i = 0; i < n; i++){
		cin >> a[i];
		a[i] *= 10;
		ma = max(ma, a[i]);
	}
	ll l = 1, r = ma;
	while (l < r){
		ll mid = (l + r) / 2, c = 0;
		for (ll i = 0; i < n; i++){
			c += a[i] / mid;
			if (a[i] % mid == 0) c--;
		}
		if (c <= k) r = mid;
		else l = mid + 1;
	}
	ll ans = l / 10;
	if (l % 10 != 0) ans++;
	cout << ans;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define debug(x) cout<<x<<endl
#define int long long 
const int mod=1000000007;
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) { return b?gcd(b,a%b):a;}
inline int read() {int num=0, w=0;char ch=0;while (!isdigit(ch)) {w|=ch=='-';ch = getchar();}while (isdigit(ch)) {num = (num<<3) + (num<<1) + (ch^48);ch = getchar();}return w? -num: num;}
// cin.tie(0);
// ios::sync_with_stdio(false);
// head
// long long *long long 		**
//all 
signed main()
{
	int n,m;
	n=read();
	m=read();
	int sum=0;
	for(int i=0;i<n;i++){
		int k=m*m;
		int x=0,y=0;
		x=read();y=read();
		if(x*x+y*y<=k){
			sum++;
		}
	}
	printf("%lld\n",sum );
    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    bool alleven = true;
    rep(i,N){
        if (a[i] % 2 != 0) alleven = false;
    }
    if (alleven) cout << "second" << endl;
    else cout << "first" << endl;
}

Measured memory_bytes: 4056
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	num := nextInt(sc)

	hights := []int{}
	for i := 0; i < num; i++ {
		hights = append(hights, nextInt(sc))
	}
	moveCount, moveCountMax := 0, 0

	for i := 1; i < num; i++ {
		if hights[i-1] >= hights[i] {
			moveCount++
			moveCountMax = int(math.Max(float64(moveCountMax), float64(moveCount)))
		} else {
			moveCount = 0
		}
	}

	fmt.Println(moveCountMax)
}

Measured memory_bytes: 6784
N, M, Q = map(int, input().split())

coordinate = [[0] * N for _ in range(N)]
for _ in range(M):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    coordinate[l][r] += 1

acc = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(N):
        acc[i + 1][j + 1] = acc[i][j + 1] + acc[i + 1][j] - acc[i][j] + coordinate[i][j]

for _ in range(Q):
    p, q = map(int, input().split())
    p, q = p - 1, q - 1
    ans = acc[N][q + 1] - acc[p][q + 1]
    print(ans)

Measured memory_bytes: 15332
n, m, x, y = map(int, input().split(" "))
xs = map(int, input().split(" "))
ys = map(int, input().split(" "))


for i in range(max(xs) + 1, min(ys) + 1):
    if x < i <= y:
        print("No War")
        break
else:
    print("War")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll n, m;
    cin >> n >> m;
    cout << n*m << endl;
}


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

int main(){
	int n;
	cin >> n;
  	vector<string> s(n);
    vector<char*> data;
	for(int i = 0; i< n;i++) {
    	cin >> s[i];
		sort(s[i].begin(),s[i].end());
    }
  	sort(s.begin(),s.end());
  	long long t=0, count = 0;
  	for(int i = 1; i < n; i++) {
    	if(s[i] == s[i-1]) {
        	count++;
        } else {
           	t += count *(count + 1) /2;
          	count = 0;
        }
    }
  	t += count * (count+1)/2;
	cout <<t<< endl;
	
}


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

using namespace std;

int main(void)
{
	int n,a,b;
	int max,min;

	cin>>n>>a>>b;

	if(a<b) max=a;
	else max=b;

	if((a+b)<=n) min=0;
	else min=(a+b)-n;

	cout<<max<<' '<<min<<endl;

	return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

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

#define DEBUG

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

	bool ans = false;
	if(n % 10 == 9) ans = true;
	n /= 10;
	if(n == 9) ans = true;

	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
 

def cumsum(xs):
    pass

def main():
    n = int(input())
    alist = list(map(int, input().split()))
    max_num = 10**9 + 7
    ans = 0
    sum_num = sum(alist)

    for i in range(n-1):
        sum_num -= alist[i]
        ans += alist[i] * sum_num
        

    print(ans%max_num)

if __name__ == "__main__":
    main()

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

using namespace std;


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

  int N;
  long long tmp;
  priority_queue<long long> pq;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    pq.push(tmp);
  }
  long long h=0,w=0;
  int count = 0;
  while (pq.size() > 1 && count < 2) {
    int p = pq.top(); pq.pop();
    if (pq.top() == p) {
      pq.pop();
      if (count == 0) {
        h = p;
        count++;
      }
      else {
        w = p;
        count++;
      }
    }
  }

  if (count == 2) cout << h * w << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){
 
    int N,A[100010]={},C[100010]={},all=0;

    cin >> N;

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

    for(int i=1;i<=N+1;i++){
        all += abs(A[i]-A[i-1]);
    }


    for(int j=1;j<=N;j++){
        C[j]= all -(abs(A[j]-A[j-1])+abs(A[j]-A[j+1]))+abs(A[j-1]-A[j+1]);
    }

    for(int i=1;i<=N;i++){
        cout << C[i] <<endl;
    }
}

Measured memory_bytes: 2048
#include<iostream>

using namespace std;

int main()
{	long long a,b,c,d,e,f,g,h,i;
	cin >> a >> b >> c;
	cin >> d >> e >> f;
	cin >> g >> h >> i;
	if((a-d == b-e) and (b-e == c-f))
	{
		if((d-g == e-h) and (e-h == f-i))
		{
			if((a-g == b-h) and (b-h == c-i))
			{
				if((a-b == d-e) and (d-e == g-h))
				{
					if((b-c == e-f) and (e-f == h-i))
					{
						if((a-c == d-f) and (d-f == g-i))
						{
							cout << "Yes" << endl;	
						}	
						else
						{
							cout << "No" << endl;
						}
					}	
					else
						{
							cout << "No" << endl;
						}
				}	
				else
						{
							cout << "No" << endl;
						}
			} 	
			else
						{
							cout << "No" << endl;
						}
		}
		else
						{
							cout << "No" << endl;
						}
	}
	else
						{
							cout << "No" << endl;
						}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    vector<int> dp(3);
    while(n--)
    {
        vector<int> points(3);
        vector<int> dp_new(3,0);
        for(int &i:points)
        {
            scanf("%d",&i);
        }
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                if(i!=j)
                {
                    dp_new[j]=max(dp_new[j],dp[i]+points[j]);
                }
            }
        }
        
        dp=dp_new;
    }
        cout<<max(max(dp[0],dp[1]),dp[2])<<endl;

}


Measured memory_bytes: 384
/*
    Prodigia comploratus,
    silens, oro:
    "Regnet exitium."
*/
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 2e5 + 5, MOD = 1e9 + 7;
const ll inf = 1e15;
int n;
int go[2][2];

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        for(int j = 0; j + 1 < s.size(); j++){
            ans += (s[j] == 'A' && s[j + 1] == 'B');
        }
        int x, y;
        if(s[0] == 'B')x = 0;
        else x = 1;
        if(s.back() == 'A')y = 0;
        else y = 1;
        go[x][y]++;
    }
    if(!go[0][0]){
        ans += min(go[1][0], go[0][1]);
    }   else {
        if(go[1][0])ans++,go[1][0]--;
        ans += go[0][0] - 1;
        if(go[0][1])ans++, go[0][1]--;
        ans += min(go[1][0], go[0][1]);
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  multiset<int> ms{0, 0, n + 1, n + 1};
  vector<pair<int, int>> a;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.emplace_back(x, i + 1);
  }
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  long long res = 0;
  for (auto& top : a) {
    long long num = top.first;
    int i = top.second;
    auto it = ms.lower_bound(i);
    int r1 = *it++, r2 = *it--;
    it--;
    int l1 = *it--, l2 = *it;
    res += num * (r2 - r1) * (i - l1);
    res += num * (l1 - l2) * (r1 - i);
    ms.insert(i);
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    rep(i, n) {
        int a;
        cin >> a;
        chmax(x, a);
    }
    rep(i, m) {
        int a;
        cin >> a;
        chmin(y, a);
    }

    string ans = "No War";

    if (x>=y) ans = "War";
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;

int main() {

	cin >> N;



	cout << N + N * N + N * N * N << endl;

	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
    ll A,B,C,K;
    ll ans;

    cin >> A >> B >> C >> K;

    if (K <= A){
        ans = K;
    }
    else if (K>A && K <= A+B){
        ans = A;
    }
    else{
        ans = A - (K-(A+B));
    }

    cout << ans << endl;

}


Measured memory_bytes: 3624
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0;
LL a[1000000] ; 
LL dp[3000+2][3000+2][3] ; 
LL f(LL start,LL end,LL chance)
{  if(start>end or start>n or end>n) ret 0 ; 
   if(dp[start][end][chance]!=-1) ret dp[start][end][chance] ; 
   if(chance==1)
     ret dp[start][end][chance] = max(a[start] + f(start+1,end,2),a[end] + f(start,end-1,2)) ; 
   else 
     ret dp[start][end][chance] = min(f(start+1,end,1) - a[start],f(start,end-1,1) - a[end]) ;  
   
}
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n; 
    memset(dp,-1,sizeof(dp)) ; 
    REP(i,n) cin>>a[i] ; 
    cout<<f(1,n,1)<<endl ; 
}
//Check for 0,1 and other corner cases.

Measured memory_bytes: 213504
import java.util.Scanner;

public class Main{
  static String s0, s1, s2;

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

    s0 = sc.next();
    s1 = sc.next();
    s2 = sc.next();

    s0 = s0.toUpperCase();
    s1 = s1.toUpperCase();
    s2 = s2.toUpperCase();

    System.out.print(s0.charAt(0));
    System.out.print(s1.charAt(0));
    System.out.println(s2.charAt(0));
  }
}


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

///////////////////////////////////////////
const long long int INF = INT64_MAX;
//const long long int INF = 1000000;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<=former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
///////////////////////////////////////////////////////////////////////////////////

ll x,y;

int main(){
    cin>>x>>y;
    ll now = x;
    ll ans = 1;
    while(now<=y){
        now*=2;
        ans++;
    }
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

int main() {
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 1012
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define N	    100001
#define rep(i,a,b)  for(int i=a;i<b;i++)
typedef long long ll;
void solve() {
	int n;
	cin>>n;
	vii v, ans;
	rep(i, 0, n) {
		int tem;
		cin>>tem;
		v.pb(mp(tem, i));
	}
	sort(all(v));
	rep(i, 0, n) {
		if(i < n / 2)
			ans.pb(mp(v[i].y, v[n / 2].x));
		else
			ans.pb(mp(v[i].y, v[n / 2 - 1].x));
	}
	sort(all(ans));
	rep(i, 0, n)
		cout<<ans[i].y<<endl;
}
int main() {
	int t;
//	cin>>t;
	t = 1;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 5488
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n=int(input())
W=input_array()

left=0
right=sum(W)
diff=right

for i in range(n):
	left+=W[i]
	right-=W[i]
	diff_tmp=right-left
	# print(diff,diff_tmp)
	if abs(diff)<=abs(diff_tmp):
		print(abs(diff))
		break
	else:
		diff=diff_tmp

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K=1000000007;
int Kai(int i){
  	if (i==0||i==1)return 1;
  	return Kai(i-1)*i;
  
}
int Num(vector<int> T, int X){
    int S=T.size();
    if(S==1)return X;
    int Head=T[0];
    int Count=0;
    for(int i=1; i<S; i++){
        if(T[i]<Head)Count++;
    }
    X+=(Count * Kai(S-1));
    T.erase(T.begin());
    return(Num(T, X));
}

int main (){ 
    int N;
    cin>>N;
    vector<int> P(N), Q(N);
    int PC=0;
    int QC=0;
    for(int i=0; i<N; i++){
        cin>>P.at(i);
        
    }
    for(int i=0; i<N; i++){
        cin>>Q.at(i);
    }
    PC=Num(P, 0);
    QC=Num(Q, 0);
    cout<<abs(PC-QC);
  	//cout<<Kai(5);
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int W,a,b;
  scanf("%d%d%d",&W,&a,&b);

  printf("%d\n",max(abs(a-b)-W,0));

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> T;
typedef long long int ll;




int main(){
    
    string inpu;
    cin >> inpu;
    string outpu="CODEFESTIVAL2016";
    int ans=0;
    for(int i=0;i<outpu.size();i++){
        if(inpu[i]!=outpu[i]) ans++;
    }
    
    cout << ans << endl;
    
    
    
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>

using namespace std;
typedef long long int ll;


int main(int argc, char const *argv[])
{
	char x,y;
	cin >> x >> y;

	cout << (x < y ? "<" : x > y ? ">" : "=") << endl;
}


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

using namespace std;

int main()
{
	string a;
	cin >> a;
	if(a == "SUN") cout << 7 << endl;
	if(a == "MON") cout << 6 << endl;
	if(a == "TUE") cout << 5 << endl;
	if(a == "WED") cout << 4 << endl;
	if(a == "THU") cout << 3 << endl;
	if(a == "FRI") cout << 2 << endl;
	if(a == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
n = int(input())
a = []
b = []

for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a = a[::-1]
b = b[::-1]

ans = 0

for i in range(n):
    if ((a[i] + ans) % b[i]) == 0:
        continue
    else:
        ans += b[i] - ((a[i] + ans) % b[i])

print(ans)

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

int maxTime(int x){
    return (x + 9) / 10 * 10;
}

int remTime(int x){
    return maxTime(x) - x;
}

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    int sum = maxTime(a) + maxTime(b) + maxTime(c) + maxTime(d) + maxTime(e);
    sum -= max({ remTime(a), remTime(b), remTime(c), remTime(d), remTime(e) });
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	const int MAX=20;
	vector<int> last(MAX,-1);
	long long ans=0;
	int bound=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		for(int j=0;j<MAX;j++)
		{
			if(x & (1<<j))
			{
				bound=max(bound,last[j]+1);
				last[j]=i;
			}
		}
		ans+=i-bound+1;
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256