akhauriyash/Code-Regression huggingface dataset:
using System;

namespace A___Between_Two_Integers
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c = int.Parse(input[2]);
            if (a <= c && c <= b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13140
#include<cstdio>
#include<iostream>
#include<queue>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<cstdlib>
#include<stack>
#include<ctime>
#include<map>
#include<list>
using namespace std;
typedef long long ll;

ll a[100005],s[100005],tmp[100005];
ll n,ans;

ll msort(ll l,ll r)
{
	ll ttmp=0;
	if(r>l+1)
	{
		ll mid=(l+r)/2;
		ttmp=msort(l,mid)+msort(mid,r);
		for(ll i=l; i<r; i++)
		{
			tmp[i]=s[i];
		}
		ll tmp1=l,tmp2=mid,tmp3=l;
		while(tmp1<mid && tmp2<r)
		{
			if(tmp[tmp1]<=tmp[tmp2]) s[tmp3++]=tmp[tmp1++];
			else
			{
				s[tmp3++]=tmp[tmp2++];
				ttmp+=mid-tmp1;
			}
		}
		while(tmp1<mid) s[tmp3++]=tmp[tmp1++];
		while(tmp2<r) s[tmp3++]=tmp[tmp2++];
	}
	return ttmp;
}

bool chack(ll mid)
{
	s[0]=0;
	for(ll i=1; i<=n; i++)
	{
		if(a[i]>=mid) s[i]=s[i-1]+1;
		else s[i]=s[i-1]-1;
	}
	ll ttmp=msort(0,n+1);
	if(ans-ttmp>=(ans+1)/2) return true;
	else return false;
}

int main()
{
	scanf("%lld",&n);
	for(ll i=1; i<=n; i++) scanf("%lld",&a[i]);
	ll l=1,r=1000000010,mid;
	ans=1ll*(n+1)*n/2;
	while(l<r-1)
	{
		mid=(l+r)/2;
		if(chack(mid)) l=mid;
		else r=mid;
	}
	printf("%lld\n",l);
 	return 0;
}	

Measured memory_bytes: 6092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}


ll f[5000001];

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

ll C(ll n, ll r, ll MOD)
{

 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
int dp[504][504]={0};
int main()
{
    ll n,m,q;
    cin>>n>>m>>q;


    for(int i=0;i<m;i++)
    {

        int a,b;
        cin>>a>>b;
        dp[a][b]++;
    }
    for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) dp[i][j]+=dp[i][j-1];}
    for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) dp[i][j]+=dp[i-1][j];}

    for(int i=0;i<q;i++)
    {

        int a,b;
        cin>>a>>b;
        cout<<dp[n][b]-dp[a-1][b]<<endl;
    }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 200005, INF = 0x3f3f3f3f3f3f3f3f;

ll N, arr[MAXN], dp[MAXN][7];

ll f() {
	dp[0][0] = 0;
	dp[0][1] = dp[0][2] = dp[0][3] = dp[0][4] = INF;
	for (int pos = 1; pos <= N; pos++) {
		for (int st = 0; st <= 4; st++) {
			ll &ret = dp[pos][st];
			if (st == 0) {
				ll costNow = arr[pos];
				ret = costNow + dp[pos-1][0];
			}
			if (st == 1) {
				ll costNow = arr[pos] == 0 ? 2 : arr[pos]%2 == 1;
				ret = INF;
				for (int i = 0; i <= 1; i++) {
					ret = min(ret, costNow + dp[pos-1][i]);
				}
			}
			if (st == 2) {
				ll costNow = arr[pos] % 2 == 0;
				ret = INF;
				for (int i = 0; i <= 2; i++) {
					ret = min(ret, costNow + dp[pos-1][i]);
				}
			}
			if (st == 3) {
				ll costNow = arr[pos] == 0 ? 2 : arr[pos] % 2 == 1;
				ret = INF;
				for (int i = 0; i <= 3; i++) {
					ret = min(ret, costNow + dp[pos-1][i]);
				}
			}
			if (st == 4) {
				ll costNow = arr[pos];
				ret = INF;
				for (int i = 0; i <= 4; i++) {
					ret = min(ret, costNow + dp[pos-1][i]);
				}
			}
		}
	}
	ll ret = INF;
	for (int i = 0; i < 5; i++) {
		ret = min(ret, dp[N][i]);
		// cerr << i << " " << dp[N][i] << "\n";
	}
	return ret;
}

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

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

	ll ans = f();
	cout << ans << "\n";
}

Measured memory_bytes: 12800
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, q = MI()
    connected_graph = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = MI()
        connected_graph[b - 1].append(a - 1)
        connected_graph[a - 1].append(b - 1)

    points = [0] * n

    for j in range(q):
        p, x = MI()
        points[p - 1] += x

    ans = [-1] * n
    ans[0] = points[0]
    queue = cl.deque([])
    queue.append(0)
    while len(queue) > 0:
        target = queue.popleft()
        connecteds = connected_graph[target]
        for connected in connecteds:
            if ans[connected] != -1:
                continue
            else:
                ans[connected] = ans[target] + points[connected]
                queue.append(connected)

    print(*ans, sep=" ")


main()


Measured memory_bytes: 119064
import java.util.Scanner;

class Main{
    static int judge(int a,int b){
	int cnt=0;
	if(a<b){
	    return cnt;
	}
	cnt++;
	if(a>b){
	    return cnt;
	}
	cnt++;
	return cnt;
    }

    public static void main(String args[]){
	String s[]={" < "," > "," == "};

	Scanner scan=new Scanner(System.in);

	int a=scan.nextInt();
	int b=scan.nextInt();
	int ans=judge(a,b);

	System.out.println("a"+s[ans]+"b");
    }
}

Measured memory_bytes: 17164
def main():
    N = int(input()) - 1
    digits = []

    while True:
        a, b = N // 26, N % 26
        if a == 0:
            digits.append(b)
            break
        digits.append(b)
        N = a - 1

    digits.reverse()
    chars = map(to_alphabet, digits)
    print(''.join(chars))


def to_alphabet(x: int):
    return chr(65 + x).lower()


if __name__ == "__main__":
    main()


Measured memory_bytes: 9044
using System;

class plogram
{
    static void Main()
    {

        string str = Console.ReadLine();
        string[] array = str.Split(' ');

        int N = int.Parse(array[0]);
        int K = int.Parse(array[1]);

        string S = Console.ReadLine();

        string i = S.Substring(0, K - 1);
        string j = S.Substring(K-1, 1);
        if (j == "A")
        {
            j = "a";
        }
        else if (j == "B")
        {
            j = "b";
        }
        else
        {
            j = "c";
        }
        string k = S.Substring(K, S.Length-K);

        Console.WriteLine(i + j + k);
    }
}

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

int main() {
  int n, k, d;
  int b, ans = 0;

  cin >> n >> k;
  vector<int> a(n, 0);
  for (int i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> b;
      a[b - 1] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main(){
    string s;
    int a[30]={};
    cin>>s;
    for(int i=0; i<s.size(); i++){
        a[s[i]-'a']++;
    }
    for(int i=0; i<26; i++){
        if(a[i]==2){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
    
  
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();  // input Integer
    int b = sc.nextInt();
    List<Integer> list = new ArrayList<Integer>();
    for(int i=1;i<=a;i++){
      int tmp = sc.nextInt();
      list.add(tmp);
    }
    Collections.sort(list);
    int sum = 0;
    for(int i=0;i<b;i++){
      sum+=list.get(i);
    }
    System.out.println(sum);
  }
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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 */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long

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

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int n, k, sum = 0;
    cin >> n >> k;
    rep(i, n)
    {
        int x;
        cin >> x;
        sum += min(0 + x, abs(k - x)) * 2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
st = [list(map(str, input().split())) for _ in range(n)]
totaltime = [0]*(n+1)
for i in range(n):
  totaltime[n-1-i] = totaltime[n-i]+int(st[n-1-i][1])
x = input()

k = 0
while x != st[k][0]:
  k+=1
print(totaltime[k+1])

Measured memory_bytes: 3064
n=int(input())
arr=list(map(int,input().split()))
acum1=[0]
acum2=[0]
for i in range(n):
  if i%2==0:
    acum1.append(acum1[-1]+arr[i])
    acum2.append(acum2[-1]+0)
  else:
    acum1.append(acum1[-1]+0)
    acum2.append(acum2[-1]+arr[i])
if n%2==0:
  ans=max(acum1[n-1]-acum1[0],acum2[n]-acum2[1])
  for i in range(1,n+1,2):
    if i+3>n:
      continue
    tmp=(acum1[i]-acum1[0])+(acum2[n]-acum2[i+2])
    ans=max(ans,tmp)
else:
  ans=max(acum1[n-2]-acum1[0],acum2[n-1]-acum2[1],acum1[n]-acum1[2])
  for i in range(1,n+1,2):
    if i+3>n-1:
      continue
    tmp=(acum1[i]-acum1[0])+(acum2[n-1]-acum2[i+2])
    ans=max(ans,tmp)
  for i in range(2,n+1,2):
    if i+3>n:
      continue
    tmp=(acum2[i]-acum2[1])+(acum1[n]-acum1[i+2])
    ans=max(ans,tmp)
  for i in range(1,n+1,2):
    if i+4>n:
      continue
    tmp=(acum1[i]-acum1[0])+(acum1[n]-acum1[i+3])
    ans=max(ans,tmp)
  acummax=[-10**18]
  for i in range(1,n+1):
    if i+2>n:
      acummax.append(-10**18)
    else:
      if i%2==0:
        acummax.append(acum2[i]+acum1[n]-acum1[i+2])
      else:
        acummax.append(-10**18)
  for i in range(n-1,-1,-1):
    acummax[i]=max(acummax[i],acummax[i+1])
  for i in range(1,n+1,2):
    if i+6>n:
      continue
    tmp=(acum1[i]-acum1[0]-acum2[i+2])+acummax[i+3]
    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 45220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  sort(all(A));
  cout << A[N-1] << " ";
  ll ans = 0;
  auto ansr = lower_bound(all(A),A[N-1]/2);
  auto ansl = lower_bound(all(A),A[N-1]/2)-1;
  //cout << *ansl << " " << *ansr << endl;
  if(*ansr==A[0]){
    cout << *ansr << endl;
    return 0;
  }
  //cout << abs((A[N-1]+1)/2 - *ansl) << " " << abs(A[N-1]/2 - *ansr);
  if(abs((A[N-1]+1)/2 - *ansl) > abs((A[N-1]+1)/2 - *ansr) && *ansr != A[N-1]){
    ans = *ansr;
  }
  else ans = *ansl;
  cout << ans << endl;
}


Measured memory_bytes: 1024
N = int(input())
counter = 0
flag = True
for i in range(N):
    D1, D2 = map(int,input().split())
    if D1 == D2:
        counter += 1
    else:
        counter = 0
    if counter == 3:
        print('Yes')
        flag = False
if flag:
    print('No')

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

using namespace std;

#define lint long long
#define P pair<int, int>

int main(){
    int N, Q;
    string S;

    cin >> N >> Q >> S;

    int r[Q], l[Q];

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

    int lis[N];
    lis[0] = 0;
    int cnt = 0;
    for(int i = 0; i < S.length() - 1; ++i){
        if(S[i] == 'A' && S[i + 1] == 'C'){
            cnt++;
        }
        lis[i + 1] = cnt;
    }

    for(int i = 0; i < Q; ++i){
        cout << - lis[r[i] - 1] + lis[l[i] - 1] << endl;
    }
}

Measured memory_bytes: 2176
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))


def segfunc(a,b):
    return a+b

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res


n, M, Q = mi()

#####単位元######
ide_ele = 0
#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

L = [0]*n
init(L)

lrpq = dp2(0, 3, M+Q)

for i in range(M):
    l, r = mi()
    lrpq[i][1] = l-1
    lrpq[i][2] = r-1

for i in range(M, M+Q):
    p, q = mi()
    lrpq[i][0] = i
    lrpq[i][1] = p-1
    lrpq[i][2] = q-1

lrpq = sorted(lrpq, key=lambda x:(x[2], x[0]))

ans = [0]*(Q)

for i in range(M+Q):
    if lrpq[i][0] == 0:
        L[lrpq[i][1]] += 1
        update(lrpq[i][1], L[lrpq[i][1]])
    else:
        ans[lrpq[i][0]-M] = query(lrpq[i][1], lrpq[i][2]+1)

for num in ans:
    print(num)

Measured memory_bytes: 73024
#include<stdio.h>


int main(int argc, char const *argv[]) {
	int a,b;
	scanf("%d %d",&a,&b);
	a=(a+11)%13;
	b=(b+11)%13;
	if(a>b) printf("Alice\n");
	else if(a<b) printf("Bob\n");
	else printf("Draw\n");
	return 0;
}

Measured memory_bytes: 128
using System;

namespace aoj7a
{
    class Program
    {
        static void Main(string[] args)
        {
            
            for(;;)
            {
                string[] line = (Console.ReadLine()).Split(' ');
                int m = int.Parse(line[0]);
                int f = int.Parse(line[1]);
                int r = int.Parse(line[2]);

                if(m == -1 && f == -1 && r == -1)
                {
                    break;
                }

                if( m == -1 || f == -1)
                {
                    Console.WriteLine("F");
                }
                else if( m + f >= 80)
                {
                    Console.WriteLine("A");
                }
                else if( m + f >= 65)
                {
                    Console.WriteLine("B");
                }
                else if( m + f >= 50)
                {
                    Console.WriteLine("C");
                }
                else if( m + f >= 30)
                {
                    if(r >= 50)
                    {
                        Console.WriteLine("C");
                    }
                    else
                    {
                        Console.WriteLine("D");
                    }
                }
                else
                {
                    Console.WriteLine("F");
                }
            }
        }
    }
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<char, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    string s, t; cin >> s >> t;
    REP( i, s.size() ){
        rotate( s.rbegin(), s.rbegin() + 1, s.rend() );
        if( s == t ){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;



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

	ll A, B; scanf("%lld %lld", &A, &B);
	if (B % A == 0) {
		puts("-1");
		return 0;
	}
	for (ll i = B + 1; i < B + A; i++) {
		ll cnt1 = i / A + i % A;
		ll cnt2 = i / B + i % B;
		if (cnt1 < cnt2) {
			cout << i << endl;
			return 0;
		}
	}
	puts("-1");
	return 0;
}


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

using ll = long long;

template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;

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

    ll res = 0;
    for(int i = N - 1; i >= 0; --i) {
        res += (B[i] - ((A[i] + res) % B[i])) % B[i];
    }
    cout << res << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for (int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef vector<vector<vector<ll>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
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;
}

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// vector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)

// ll dp[1005][3] = {99999999};

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    int n;
    cin >> n;
    vector<vector<ll>> a(n + 1, vector<ll>(3));
    rep(i, 0, n) rep(j, 0, 3) cin >> a[i][j];
    vector<vector<ll>> dp(n + 1, vector<ll>(3));
    //dp[i][j]:i日目にjを選んだ場合の幸福度の総和の最大値
    dp[0][0] = 0;
    // rep(i,0,3) {
    //     dp[1][i] = 
    // }
    rep(i, 0, n) {
        rep(j, 0, 3) {
            if (i == 0) {
                dp[i+1][j] = a[i][j];
                continue;
            }
            rep(k, 0, 3) {
                if (j == k) continue;
                chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }

    }
    ll ans = 0;
    rep(i,0,3) chmax(ans,dp[n][i]);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 14080
n=input()
s=raw_input().split()
a=[0 for i in range(n)]
b=[0 for i in range(100005)]
sum=0
for i in range(n):
    a[i]=int(s[i])
for i in range(n-1):
    if a[i]==i+1:
        sum+=1
        if a[i+1]==i+2:
            a[i],a[i+1]=0,0
if a[n-1]==n: sum+=1
print sum


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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  int ai=a[n-1];
  int aj;
  int sa=1000000001;
  if(ai%2==0){
    int x=ai/2;
    for(int i=0;i<n-1;i++){
      if(abs(x-a[i])<=sa){
        aj=a[i];
        sa=abs(x-a[i]);
      }
    }
  }
  else{
    int x=ai/2;
    int y=x+1;
    for(int i=0;i<n-1;i++){
      if(abs(x-a[i])<=sa){
        aj=a[i];
        sa=abs(x-a[i]);
      }
      if(abs(y-a[i])<=sa){
        aj=a[i];
        sa=abs(y-a[i]);
      }
    }
  }
  cout<<ai<<" "<<aj<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 3010
#define MOD 1000000007
#define INV 500000004
inline void trim(int &x) { (x >= MOD) && (x -= MOD); }
inline void up(int &x, int y) { trim(x += y); }
int n, q, b = 1, ans = 0, a[MAXN], f[MAXN][MAXN];
int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			f[i][j] = a[i] > a[j];
		}
	}
	for (int x, y; q; q--) {
		scanf("%d%d", &x, &y);
		for (int i = 1; i <= n; i++) {
			if (i != x && i != y) {
				f[i][x] = f[i][y] = 1LL * INV * (f[i][x] + f[i][y]) % MOD;
				f[x][i] = f[y][i] = 1LL * INV * (f[x][i] + f[y][i]) % MOD;
			}
		}
		f[x][y] = f[y][x] = 1LL * INV * (f[x][y] + f[y][x]) % MOD;
		trim(b <<= 1);
	}
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			up(ans, f[i][j]);
		}
	}
	printf("%lld\n", 1LL * ans * b % MOD);
	return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 2036
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string str;
    getline(cin, str);
    while(str.size() != 1 || str[0] != '.') {
        bool check = 1;
        int a = 0, b = 0;
        stack<char> st;
        rep(i, str.size()) {
            if(str[i] == '(') {
                ++ a;
                st.push('(');
            } else if(str[i] == ')') {
                -- a;
                if(st.size() and st.top() == '(') st.pop();
                else check = 0;
            } else if(str[i] == '[') {
               ++ b;
               st.push('[');
            } else if(str[i] == ']') {
                -- b;
                if(st.size() and st.top() == '[') st.pop();
                else check = 0;
            }
            if(a < 0 || b < 0) check = 0;
        }
        if(a != 0 || b != 0 || st.size()) check = 0;
        // cerr << a << " " << b << endl;
        if(check) cout << "yes" << endl;
        else cout << "no" << endl;
        getline(cin, str);
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


Measured memory_bytes: 3212
n,m = gets.chomp.split.map(&:to_i)

foods = Array.new(m,0)
sum = 0

n.times do |ni|
    line = gets.chomp.split.map(&:to_i)
    line[0].times do |ki|
        foods[line[ki+1]-1]+=1
        if foods[line[ki+1]-1] == n
            sum += 1
        end
    end
end

puts sum

Measured memory_bytes: 1788
//abc139-c
#include <bits/stdc++.h>
using namespace std;

int main(void){
    int EPS =1e-9;
    int n,count=0,re=0;
    cin >> n;
    int h[n];
    //for(int i=0;i<n;i++) cin >> h[i];
    
    while(n--){
        int h; cin>>h;
            if(EPS>=h){
                count++;
            } else {
                re = max(re, count);
                count=1;
            }
        EPS=h;
    }
    cout << max(re, count)-1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)

int N, A, B;
vector<int>h;

//k回で殲滅できるか。
//まず全体にB*kのダメージ。
//残ったモンスターに(A-B)の単体攻撃をk回すると考える。

bool check(ll k) {

	ll cnt = 0;
	for (int i = 0; i < N; i++) {
		ll ret = (ll)((ll)h[i] - (ll)B*k);

		if (ret > 0) {
			cnt += (ret + (A - B) - 1) / (A - B);
		}

	}

	if (k >= cnt)return true;
	else return false;
}

ll bs() {

	ll ng = -1;
	ll ok = 1e9 + 1;

	while (abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;

		if (check(mid)) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}

	return ok;
}

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

	h.resize(N);

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



	cout << bs() << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  int N, n = 0, count = 0;
  cin >> N;
  vector<int> a(N);
  vector<bool> b(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    b.at(i) = false;
  }
  while (true) {
    n = a.at(n) - 1;
    if (b.at(n)) {
      cout << -1 << endl;
      break;
    } else {
      b.at(n) = true;
    }
    count++;
    if (n == 2 - 1) {
      cout << count << endl;
      break;
    }
  }
}

signed main() {
  solve();

  return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
const long M=1e9+7;
long pow(long a,int b){return b?b%2?pow(a*a%M,b/2)*a%M:pow(a*a%M,b/2):1;}
long memo[1<<18];
main()
{
	*memo=1;
	for(int i=1;i<1<<18;i++)memo[i]=memo[i-1]*i%M;
	long h,w,a,b;cin>>h>>w>>a>>b;
	long ans=0,now;
	for(int i=b;i<w;i++)
	{
		now=memo[h-a-1+i]%M*pow(memo[h-a-1],M-2)%M*pow(memo[i],M-2)%M;
		now=now*memo[a+w-i-2]%M*pow(memo[a-1],M-2)%M*pow(memo[w-i-1],M-2)%M;
		ans=(ans+now)%M;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

int main(){
	string s;

	cin >> s;
	
	vector< pair<char, int> > chars;
	for (auto c: s) {
		bool found = false;
		for (size_t i = 0; i < chars.size(); ++i) {
			if (c == chars.at(i).first) {
				chars.at(i).second += 1;
				found = true;
			}
		}
		if (!found) {
			chars.push_back(make_pair(c, 1));
		}
	}
	
	string ret = "No";
	bool fifty = true;
	for (auto p : chars) {
		if (p.second != 2) {
			fifty = false;
		}
	}

	if (chars.size() == 2 && fifty) {
		ret = "Yes";
	}

	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int 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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> l(N);
    vector<int> r(N);
    for(int i=0; i<N; i++){
      cin >> l[i] >> r[i];
    }
    sort(l.begin(),l.end());
    sort(r.begin(),r.end());
    ll ans = 0;
    for(int i=-100010; i<=100010; i++){
      // ,i]
      int r_num = upper_bound(r.begin(),r.end(),i) - r.begin();
      // (i,
      int l_num = N - (upper_bound(l.begin(),l.end(),i) - l.begin());
      if(i < 0){
        ans += min(r_num,l_num+1)*2;
      }else{
        ans += min(r_num+1,l_num)*2;
      }
      // cout << i << " " << r_num << " " << l_num << "\n";
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N, M, K;
	cin >> N >> M >> K;
	rep(i, M + 1) {
		rep(j, N + 1) {
			if (i == 0 || j == 0) {
				if (i*N + j*M == K) {
					cout << "Yes" << endl;
					return 0;
				}
			}
			else {
				if (N*i + M*j - 2 * (i *j ) == K) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	var text string

	fmt.Scan(&text)
	// fmt.Println(text)

	var Q int
	var T int
	var F int
	var C string
	fmt.Scan(&Q)

	var buf [500100]byte
	startcursor := 200050
	endcursor := startcursor + len(text)
	// // var buf [30]byte
	// buf[3] = 'a'
	copy(buf[startcursor:], []byte(text))
	// fmt.Printf("%v\n", text)
	// fmt.Printf("%v %v\n", startcursor, endcursor)
	// fmt.Printf("%v\n", buf)
	// fmt.Printf("%v\n", text[3])

	R := 0 // 0: original, 1: reversed
	for i := 0; i < Q; i++ {
		fmt.Scan(&T)
		// fmt.Printf("type %d\n", T)
		if T == 1 {
			// fmt.Printf("type1 %s\n", Reverse(text))
			// text = Reverse(text)
			R = (R + 1) % 2
		} else {
			fmt.Scan(&F, &C)
			if (F == 1 && R == 0) || (F == 2 && R == 1) {
				// text = C + text
				startcursor--
				buf[startcursor] = C[0]
			} else {
				buf[endcursor] = C[0]
				endcursor++
				// text = text + C
			}
			// fmt.Printf("%v, %v, %v, %v\n", Q, T, F, text)
		}
	}

	// fmt.Printf("%v\n", buf)
	// fmt.Printf("%v %v\n", startcursor, endcursor)
	text = string(buf[startcursor:endcursor])
	// fmt.Printf("%s\n", text)
	// fmt.Printf("%v\n", buf[startcursor:endcursor])
	if R == 1 {
		text = Reverse(text)
	}
	fmt.Println(text)
}


Measured memory_bytes: 7552
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String S = sc.next();
		int min = 1000;
		for (int i = 0; i < S.length() - 2; i++) {
			int t = Math.abs(Integer.parseInt(S.substring(i, i+3))-753);
			if (t < min) {
				min = t;
			}
		}
		System.out.println(min);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22996
#include <stdio.h>

int solve(int S[], int size, int i, int m){
  int res=0;
  if(m==0)
	return 1;
  if(i>=size)
	return 0;
  res=solve(S, size, i+1, m) || solve(S, size, i+1, m-S[i]);
  return res;
	}

int main(){
  int n;
  int i;
  int A[22];
  scanf("%d", &n);
  for(i=0; i<n; ++i){
	scanf("%d", &A[i]);
  }
  int q, num;
  scanf("%d", &q);
  for(i=0; i<q; ++i){
	scanf("%d", &num);	
	if(solve(A, n, 0, num)==1)
	  printf("yes\n");
	else if(solve(A, n, 0, num)==0)
	  printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  if (b == 0){
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main(){
  while (1){
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0){
      break;
    }
    vector<int> b(m);
    for (int i = 0; i < m; i++){
      cin >> b[i];
    }
    vector<int> r(n);
    for (int i = 0; i < n; i++){
      cin >> r[i];
    }
    int V = m + n + 2;
    vector<set<int>> E(V);
    for (int i = 0; i < m; i++){
      for (int j = 0; j < n; j++){
        if (gcd(b[i], r[j]) > 1){
          E[i].insert(m + j);
        }
      }
    }
    for (int i = 0; i < m; i++){
      E[V - 2].insert(i);
    }
    for (int j = 0; j < n; j++){
      E[m + j].insert(V - 1);
    }
    int ans = 0;
    while (1){
      vector<int> prev(V, -1);
      vector<bool> used(V, false);
      used[V - 2] = true;
      queue<int> Q;
      Q.push(V - 2);
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (int w : E[v]){
          if (!used[w]){
            used[w] = true;
            prev[w] = v;
            Q.push(w);
          }
        }
      }
      if (!used[V - 1]){
        break;
      } else {
        int c = V - 1;
        while (c != V - 2){
          E[prev[c]].erase(c);
          E[c].insert(prev[c]);
          c = prev[c];
        }
        ans++;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 8464
import java.io.*; 
import java.util.*; 
 
class Main 
{ 
     public static void main(String[] args) 
     { 
         Scanner sc = new Scanner(System.in); 
          
         int H = sc.nextInt(); 
         int W = sc.nextInt(); 
          
         while (H != 0 || W != 0) { 
             for (int i = 0; i < H; i++) { 
                 for (int j = 0; j < W; j++) { 
                    if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)) { 
                         System.out.printf("#"); 
                    } 
                     else { 
                         System.out.printf("."); 
                     } 
                 } 
                 System.out.printf("\n"); 
             } 
             System.out.printf("\n"); 
              
             H = sc.nextInt(); 
             W = sc.nextInt(); 
         } 
     } 
 } 



Measured memory_bytes: 64232
import collections

n = int(input())
v = list(map(int,input().split()))
a = [v[i] for i in range(n) if i%2==0]
b = [v[i] for i in range(n) if i%2==1]

a = collections.Counter(a)
b = collections.Counter(b)

A = a.most_common()[:2]
A.append(("x",0))
B = b.most_common()[:2]
B.append(("x",0))
if A[0][0]==B[0][0]:
    print(n-max(A[0][1]+B[1][1],A[1][1]+B[0][1]))
else:
    print(n-A[0][1]-B[0][1])


Measured memory_bytes: 18784
(N,) = map(int, input().split())
As = list(enumerate(map(int, input().split())))
As.sort(key=lambda x: -x[1])
dp = [[0] * (N + 1) for _ in range(N + 1)]
for i, (pos, val) in enumerate(As):
    for j in range(i + 1):
        k = i - j
        dp[j + 1][k] = max(dp[j + 1][k], dp[j][k] + abs(j - pos) * val)
        dp[j][k + 1] = max(dp[j][k + 1], dp[j][k] + abs(N - 1 - k - pos) * val)
print(max(dp[i][N - i] for i in range(N + 1)))


Measured memory_bytes: 100336
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef list<int> li;
typedef list<li> lli;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x;
	ll cost;
};
ll a[200002];

int main(){

	int n;
	cin>>n;
	rep(i,n)cin>>a[i];
	ll ma=a[0],t=0;
	for(int i=1; i<n; i++){
		ma=max(ma,a[i]);
		if(a[i]<ma)t+=ma-a[i];
	}
	cout<<t<<endl;

	return 0;
}


Measured memory_bytes: 5160
while True:
    n, x = [int(x) for x in input().split()]
    if n == x == 0:
        break
    cnt = 0
    for a in range(1, x // 3):
        for b in range(a + 1, x // 2):
            c = x - a - b
            if b < c <= n:
                cnt += 1
    print(cnt)

Measured memory_bytes: 7704
using System;

using System .Linq;


namespace ConsoleApplication2
{
    using System;

    public class Dice
    {

        public static void Main( String[] args )
        {

            string yesNo = "No";
             string dataA = Console .ReadLine();
             string dataB = Console .ReadLine();
         //   string dataA = "1 2 3 4 5 6";
          string[] diceA = dataA .Split();
            // string dataB = "4 5 6 1 2 3";
         //   string dataB = "6 4 5 2 3 1";
              string[] diceB = dataB .Split();

            //test??¨
             //string[] diceA = { "1" , "2" , "3" , "4" , "5" , "6" };
            //string[] diceB = { "6" , "2" , "4" , "3" , "5" , "1" };

            //string[] diceTemp =  dataB .Split();
            
              
           // string[] diceTemp1 = dataB .Split();

            int i = 0;
            int j = 0;
            do
            {
                do
                {
                    //??????
                    for ( int k = 0 ; k < diceA .Length ; k++ )
                    {
                        if ( !diceA[k] .Equals( diceB[k] ) )
                        {
                            yesNo = "No";
                            break;

                        }
                        if ( k == diceA .Length - 1 )
                        {
                            yesNo = "Yes";

                        }
                    }
                    if ( yesNo == "Yes" )
                    {
                        break;
                    }
                    //?????????????¨??????¢???east??¨??????

                    diceB = turn( 3 , 5 , 2 , 0 , diceB );
                   
                    j++;
                } while ( j < 4 );

                if ( yesNo == "Yes" )
                {
                    break;
                }
                j = 0;
                //??????????????????????????¢ south??¨???


                
                 if ( i == 3 )
                {
                    //east???south
                    diceB = dataB .Split();
                    diceB = turn( 2 , 5 , 3 , 0 , diceB );

                    
                }
                else if ( i == 4 )
                {
                    //west ???south
                    diceB = dataB .Split();
                    diceB = turn( 3 , 5 , 2 , 0 , diceB );
                    
                    
                }

                diceB = turn( 4 , 5 , 1 , 0 , diceB );
         
                i++;
            } while ( i < 6 );



            Console .WriteLine( yesNo );
           


        }

        public static string[] turn( int a , int b , int c , int d , string[] dice )
        {
            string temp = dice[a];
            dice[a] = dice[b];
            dice[b] = dice[c];
            dice[c] = dice[d];
            dice[d] = temp;
            return dice;
        }
    }


}

Measured memory_bytes: 8948
# coding=utf-8

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

for i in range(Q):
    qtype, b, e = map(int, input().split())
    if qtype == 0:
        print(min(A[b:e]))
    elif qtype == 1:
        print(max(A[b:e]))



Measured memory_bytes: 5636