akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    int a,b; cin >> a >> b;
    if(a == b) cout << "Draw" << endl;
    else if(a==1) cout << "Alice" << endl;
    else if(b==1) cout << "Bob" << endl;
    else if(a > b) cout << "Alice" << endl;
    else cout << "Bob" << endl;
    return 0;
}

Measured memory_bytes: 256
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scd(x) scanf("%lf", &x)
#define scld(x) scanf("%Lf", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	int N;
	sci(N);
	string A, B;
	cin >> A >> B;
	for (int i = 0; i < N; ++i) {
		printf("%c%c", A[i], B[i]);
	}
	printf("\n");
	return 0;
}

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

typedef long long ll;

int a[1010];

int main() {
	int n, i, j, cnt=0;
	cin >> n;
	string s;
	cin >> s;
	string res = "";
	for(i=0; i <n; ++i) {
		if(s[i] == '(')	{
			res+="(";
			cnt++;
		}
		else {
			res+=")";
			cnt--;
		}
		if(cnt<0) {
			res="("+res;
			cnt = 0;
		}
		// cout << cnt << " " << res << endl;
	}
	while(cnt>0) {
		res+=")";
		cnt--;
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int n = s.length();
      int k = n;
      for(int i = 0;i < n;i++){
        if(s.charAt(i)=='C'){
          k=i;
          break;
        }
      }
      for(int j = k;j < n;j++)
        if(s.charAt(j)=='F'){
          System.out.println("Yes");
          return;
        }
      System.out.println("No");
    }
}

Measured memory_bytes: 21972
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        int M=N*N*N;
        double ans=M/27.0;
        while(Math.abs(ans*27-M)>1e-6){
            double diff=Math.abs(ans*27-M);
            if(M>27*ans) ans=ans+diff/2;
            else ans=ans-diff/2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 20692
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

ll pow(ll a,ll n){
	ll b=1;
	while(n>0){
		if(n&1) b=(b*a)%10;
		a=(a*a)%10;
		n >>=1;
	}
	return b;
}


int main(void){
	ll n,m,k;
	cin >> n  >> m >> k;
	n%=10;
	ll ans=0;
	
	if(n){
		ll init=n;
		ll cur=n;
		ll len=1;
		
		ans+=n;k--;
		
		ll next=pow(n,m);
		
		while( k&&(cur*next)%10!=init){
			cur=(cur*next)%10;
			ans+=cur;
			len++;
			k--;
		}
		ans+=(k/len)*ans;
		k%=len;
		cur=init;
		while(k){
			ans+=cur;
			cur=(cur*next)%10;
			k--;
		}
	}else
		ans=0;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <climits>
#include <stack>
#include <string>
#include <random>
#include<set>
struct Vote {
	std::string name;
	int vote;
	bool operator<(const Vote &that) const {
		return (vote == that.vote) ? name > that.name : vote < that.vote;
	}
	bool operator==(const Vote &that) const {
		return vote == that.vote && name == that.name;
	}
	bool operator>(const Vote &that) const {
		return (vote == that.vote) ? name < that.name : vote > that.vote;
	}
};
bool can_take(const std::vector<Vote> &favorite, const Vote vote, int rest_vote, const int count) {
	for (auto i = favorite.size() - count; i < favorite.size(); ++i) {
		if (favorite[i] < vote) {
			if (favorite[i].name < vote.name) {
				rest_vote -= vote.vote - favorite[i].vote;
			}
			else {
				rest_vote -= vote.vote - favorite[i].vote + 1;
			}
			if (rest_vote < 0) return false;
		}
		else {
			return true;
		}
	}
	return true;
}
bool can_take(const std::vector<Vote> &fav, const std::vector<Vote> &no_chara, const int k, const int l, const int count) {
	auto else_count = k - count;
	if (else_count >= no_chara.size()) return true;
	else {
		return can_take(fav, no_chara[no_chara.size() - else_count - 1], l, count);
	}
}

void solve() {
	int n, m, k, l;
	std::cin >> n >> m >> k >> l;
	if (n == 0) return;
	std::vector<Vote> elseC;
	std::vector<Vote> favC;
	{
		std::map<std::string, int> estimated;
		std::string name; int vote;
		for (auto i = 0; i < n; ++i) {
			std::cin >> name >> vote;
			estimated.insert(std::make_pair(name, vote));
		}
		for (auto i = 0; i < m; ++i) {
			std::cin >> name;
			favC.push_back(Vote{ name, estimated[name] });
			estimated.erase(name);
		}
		for (const auto &pair : estimated) {
			elseC.push_back(Vote{ pair.first, pair.second });
		}
		std::sort(elseC.begin(), elseC.end());
		std::sort(favC.begin(), favC.end());
	}
	int left = 0;
	int right = std::min(m, k);
	while (left < right) {
		auto mid = (left + right + 1) / 2;
		if (can_take(favC, elseC, k, l, mid)) {
			left = mid;
		}
		else {
			right = mid - 1;
		}
	}
	std::cout << right << std::endl;
	solve();

}

int main() {
	solve();
}
/*



*/



Measured memory_bytes: 65424
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
#define omajinai ios::sync_with_stdio(false);cin.tie(nullptr);

#pragma region typedef 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#pragma endregion

#pragma region define
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#pragma endregion

#pragma region const
const ll INF = 1e18;
const ld PI = 3.141592653589793;
#pragma endregion

#pragma region function
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;
}
#pragma endregion

int main(){
omajinai;
    int n, k; cin >> n >> k;
    ll h[110000]; rep(i, n) cin >> h[i];

    ll dp[110000];

    rep(i, 110000) dp[i] = INF;
    dp[0] = 0;
  
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }

    cout << dp[n-1] << endl;
return 0;
}

Measured memory_bytes: 5292
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  long long max;
  max = a*c;
  max = (max > a*d)? max : a*d;
  max = (max > b*c)? max : b*c;
  max = (max > b*d)? max : b*d;
  cout << max << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int N; 
    cin >> N;
    vector < pair<long, long > > W(N);
    for(int i=0; i<N; i++){
        cin >> W[i].first >> W[i].second;
    }
    sort(W.begin(), W.end(), [](const pair<long, long> &a, const pair<long, long> &b){
        return a.second < b.second;
    });
    long sum = 0;
    bool ok = true;
    for(int i=0; i<N; i++){
        sum += W[i].first;
        if(sum > W[i].second){
            ok = false;
            break;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e2 + 2;
ll n,i,ans;
ll a[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
        if(i == 1) ans += 2 * a[i];
        else{
            if(a[i] > a[i - 1]) ans += a[i];
            else{
                ans -= a[i - 1];
                ans += 2 * a[i];
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def dfs(depth:int, inbis:str, f:list, p:list):
    if depth != 10:
        return max(dfs(depth+1, inbis+"1",f,p),
                   dfs(depth+1, inbis+"0",f,p))
        
    else:
        if inbis.count("1") == 0:
            return -10**10
        else:
            biz = [int(i) for i in inbis]
            ans = 0
            for i in range(len(f)):
                common = [biz[j]*f[i][j] for j in range(10)]
                ans += p[i][sum(common)]
                
            return ans

n = ni()
f = []
p = []
for _ in range(n):
    f.append(list(li()))
for _ in range(n):
    p.append(list(li()))
    
print(dfs(0,"",f,p))

Measured memory_bytes: 3064
object Main {
  // NOTE: Destructive: arr
  def printInsertSort(arr: Array[Int]): Unit= {
    for (i <- (1 until arr.length)) {
      // Print arr
      println(arr.mkString(" "))
      val v = arr(i)
      var j = i - 1
      while(j >= 0 && arr(j) > v) {
        arr(j+1) = arr(j)
        j -= 1
      }
      arr(j+1) = v
    }
    // Print arr
    println(arr.mkString(" "))
  }

  def main(args: Array[String]): Unit = {
    // Skip n
    io.StdIn.readLine()

    // Read arry string
    var arrString: String = io.StdIn.readLine()
    // Convert it to real int array
    val arr: Array[Int] = arrString.split(" ").map(_.toInt)

    // Print insert sort step
    printInsertSort(arr)
  }
}


Measured memory_bytes: 45848
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = 1
vote_A = 1
for x, y in TA:
	# n = max(ceil(vote_T/x),ceil(vote_A/y))
	# n = max(-(-vote_T // x), -(-vote_A // y))
	n = max((vote_T//x + (vote_T%x!=0)),vote_A//y + (vote_A%y!=0))
	vote_T = x * n
	vote_A = y * n
print(vote_A + vote_T)

Measured memory_bytes: 3956
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
    // code
    int n, m;
    cin >> n >> m;
    vector<P> bridge;
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        bridge.push_back(make_pair(b, a));
    }

    sort(ALL(bridge));

    int removeCnt = 0;
    int lastRemove = 0;
    REP(i, bridge.size()) {
        if (bridge[i].second <= lastRemove && lastRemove < bridge[i].first) {
            continue;
        } else {
            lastRemove = bridge[i].first - 1;
            removeCnt++;
        }
    }

    cout << removeCnt << endl;

    return 0;
}

Measured memory_bytes: 1400
n = int(input())
p = [int(v) for v in input().split()]


cnt = 0
for i in range(1, n - 1):
    if p[i-1] < p[i] and p[i] < p[i+1] or p[i-1] > p[i] and p[i] > p[i+1]:
        cnt += 1
print(cnt)


Measured memory_bytes: 38384
# coding: utf-8

a,b,c = (int(x) for x in input().rstrip().split())

if a < b and a < c and b < c:
    print("Yes")
else:
    print("No")
    
    

# <?php

#     fscanf(STDIN,"%d %d %d",$a,$b,$c);
    
#     if ($a < $b &&  $a < $c && $b < $c)  {
#         echo "Yes".PHP_EOL;
#     } else {
#         echo "No".PHP_EOL;
#     }

# ?>


Measured memory_bytes: 5604
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

//Tsuruga Parking
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int m = sc.nextInt();
			int n = sc.nextInt();
			if((m|n)==0)break;
			int[] t = new int[n+1];
			for(int i=1;i<=n;i++)t[i]=sc.nextInt();
			int[][] p = new int[m][2];
			List<Integer> ans = new ArrayList<Integer>();
			Queue<Integer> q = new LinkedList<Integer>();
			int r = 10;
			while(ans.size()<n){
				if(r%10==0&&1<=r/10&&r/10<=n)q.add(r/10);
				for(int i=0;i<m;i++)for(int j=0;j<2;j++)if(p[i][j]>0)t[p[i][j]]--;
				for(int i=0;i<m;i++){
					if(p[i][0]>0&&t[p[i][0]]<=0){
						ans.add(p[i][0]);
						p[i][0] = p[i][1];
						p[i][1] = 0;
						if(p[i][0]>0&&t[p[i][0]]<=0){
							ans.add(p[i][0]);
							p[i][0] = 0;
						}
					}
				}
				boolean f = true;
				while(!q.isEmpty()&&f){
					f = false;
					int dmin = Integer.MAX_VALUE;
					int umin = Integer.MAX_VALUE;
					int d = -1;
					int u = -1;
					for(int i=0;i<m;i++){
						if(p[i][0]==0){
							f = true;
							p[i][0] = q.poll();
							break;
						}
						else if(p[i][1]==0){
							if(t[p[i][0]]>=t[q.peek()]){
								if(t[p[i][0]]-t[q.peek()] < umin){
									umin = t[p[i][0]]-t[q.peek()];
									u = i;
								}
							}
							else{
								if(t[q.peek()]-t[p[i][0]] < dmin){
									dmin = t[q.peek()]-t[p[i][0]];
									d = i;
								}
							}
						}
					}
					if(f)continue;
					if(u>=0){
						p[u][1] = p[u][0];
						p[u][0] = q.poll();
						f = true;
					}
					else if(d>=0){
						p[d][1] = p[d][0];
						p[d][0] = q.poll();
						f = true;
					}
				}
				r++;
			}
			for(int i=0;i<n;i++){
				if(i>0)System.out.print(" ");
				System.out.print(ans.get(i));
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

sys.setrecursionlimit(10**9)

n,m = map(int, input().split())
G = [[] for i in range(n)]

in_ = set()
for i in range(m):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    in_.add(b)

dist = [-1]*n

from collections import deque
def dfs(cur):
    if dist[cur] != -1:
        return dist[cur]
    r = 0
    for to in G[cur]:
        r = max(r, dfs(to)+1)
    dist[cur] = r
    return r

for i in range(n):
    if i in in_:
        continue
    dfs(i)

ans = max(dist)

print(ans)

Measured memory_bytes: 165040
def ask(q):
    print(q, flush=True)
    inp = input()
    if inp == "Vacant":
        exit()
    return inp


n = int(input())

l = ask(0)
r = ask(n-1)
left = 0
right = n-1

for _ in range(18):
    mid = (right + left) // 2
    m = ask(mid)

    if l == m and (mid - left) % 2 == 1:
        right = mid
        r = m
    elif l != m and (mid - left) % 2 == 0:
        right = mid
        r = m
    else:
        left = mid
        l = m


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

int main(){
    int N, K;  cin >> N >> K;
    vector<int> X(N);
    for(int i=0; i<N; i++) cin >> X[i];

    if(0 <= X[0]){
        cout << X[K-1] << endl;
        return 0;
    }else if(X[N-1] <= 0){
        cout << abs(X[N-K]) << endl;
        return 0;
    }

    int a = lower_bound(X.begin(), X.end(), 0) - X.begin();
    int ans = 1e9;
    if(a + K-1 < N) ans = X[a+K-1];
    if(a - K >= 0) ans = min(ans, abs(X[a-K]));
    for(int i=1; i<K; i++){
        if(!(a+i-1<N && a-K+i >= 0)) continue;

        ans = min(ans, 2*X[a+i-1] - X[a-K+i]);
    }
    for(int i=1; i<K; i++){
        if(!(a-i>=0 && a+K-i-1<N)) continue;
        ans = min(ans, -2*X[a-i] + X[a+K-i-1]);
    }
    cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  
  int a;
  int count = 0;
  int min = 100;
  for(int i=0; i<n; i++) {
    cin >> a;
    while(1) {
      if(a%2==0) {
        count++;
        a /= 2;
      }
      else if(count<min) {
        min = count;
        break;
      }
      else break;
    }
    count = 0;
  }
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 3636
import Control.Monad (forM_)
import qualified Data.Vector.Mutable as MV

main :: IO ()
main = do
    n    <- readLn   :: IO Int
    if n == 0 || n == 1 then
        print 1
    else do
        memo <- MV.replicate (n + 1) 1 :: IO (MV.IOVector Integer)
        forM_ [2..n] $ \i -> do
            a <- MV.read memo (i - 2)
            b <- MV.read memo (i - 1)
            MV.write memo i (a + b)
        MV.read memo n >>= print


Measured memory_bytes: 3824
import java.util.TreeSet;
import java.util.Scanner;
import java.util.Iterator;

class Elem implements Comparable <Elem> {
	int a_, idx_;
	Elem (int a, int idx) {
		a_ = a;
		idx_ = idx;
	}

	public int compareTo (Elem o) {
		if (a_ != o.a_)
			return o.a_ - a_;
		return o.idx_ - idx_;
	}
}

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner (System.in);
		int N = sc.nextInt();
		TreeSet<Elem> set = new TreeSet<Elem> ();
		for (int i=0; i<N; i++) {
			int a = sc.nextInt ();
			set.add (new Elem (a, i));
		}
		Iterator <Elem> iter = set.iterator ();
		int dif = 0, idx = 0;
		while (iter.hasNext ()) {
			Elem e = iter.next ();
			if (idx%2==0) 
				dif += e.a_;
			else
				dif -= e.a_;
			idx ++;
		}
		System.out.println (dif);
	}
}

Measured memory_bytes: 21460
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X,Y,A,B,C;

    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A),q(B),r(C);
    REP(i,A) cin >> p[i];
    REP(i,B) cin >> q[i];
    REP(i,C) cin >> r[i];
    VSORT(p);
    VSORT(q);
    VSORT(r);
    reverse(ALL(r));

    ll x=A-X,y=B-Y;
    p.push_back(MOD);q.push_back(MOD);r.push_back(0);
    ll ans = 0;
    int i = 0; 
    while(!(x == A && y == B)){
        if(p[x] < q[y]){
            if(p[x] < r[i]){
                ans += r[i];
                i++;
            }else{
                ans += p[x];
            }
            x++;
        }else{
            if(q[y] < r[i]){
                ans += r[i];
                i++;
            }else{
                ans += q[y];
            }
            y++;
        }
    }

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 3456
a = int(input())
b = int(input())

if a == 1:
  if b == 2:
    print(3)
  elif b == 3:
    print(2)
elif a == 2:
  if b == 1:
    print(3)
  elif b == 3:
    print(1)
else:
  if b == 2:
    print(1)
  elif b == 1:
    print(2)


Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	char s[4];
	for (int i = 0; i < 4; i ++ ) {
		cin >> s[i];
	}
	int c = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == s[i + 1])
			c++;
	}
	if (c == 0)
		cout << "Good" << endl;
	else
		cout << "Bad" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 22;
int a[N], b[N], c[N];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i];
    }
    rep(i, 1, n) {
        cin >> b[i];
    }
    rep(i, 1, n - 1) {
        cin >> c[i];
    }
    int ans = 0;
    rep(i, 1, n) {
        ans += b[a[i]];
        if(i > 1 && a[i - 1] == a[i] - 1) {
            ans += c[a[i - 1]];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from operator import mul
from functools import reduce

n, a, b = map(int, input().split())

mod = 10 ** 9 + 7

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     :
      return 1
    elif y == 1     :
      return x % mod
    elif y % 2 == 0 :
      return power(x, y//2)**2 % mod
    else            :
      return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))

r1 = min(a, n - a)
r2 = min(b, n - b)

if r1 > r2:
  r1, r2 = r2, r1

numer1 = reduce(mul, range(n, n - r1, -1), 1)
denom1 = reduce(mul, range(1, r1 + 1), 1)
numer2 = reduce(mul, range(n - r1, n - r2, -1), numer1)
denom2 = reduce(mul, range(r1 + 1, r2 + 1), denom1)

print((power(2, n) - 1 - div(numer1, denom1) - div(numer2, denom2)) % (10 ** 9 + 7))


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


int main() {
int n,m,c;
cin >> n >> m >>c;
int a[20][20];
int b[20];
int ans = 0;
for(int i = 0;i < m;i++){
  cin >> b[i];
}

for(int j = 0;j < n;j++){
int sum = 0;
  for(int i = 0;i < m;i++){
  cin >> a[j][i];
sum += a[j][i]*b[i];
}
if((sum+c)>0){
  ans++;
  
}
}


cout << ans << endl;
  }

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

using namespace std;

typedef long long ll;

ll n,a,b,x[100010]={0};
ll d[100010]={0};

signed main(){
    cin>>n>>a>>b;
    for(int i=0;i<n;++i){
        cin>>x[i];
    }

    ll s=0;
    for(int i=0;i<n-1;++i){
        d[i]=x[i+1]-x[i];
        s+=min(d[i]*a,b);
    }

    cout<<s<<endl;

    return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

utility = 0
prev = -1

for i in A:
    utility += B[i-1]
  
    if prev == i-1:
        utility += C[i-2]
        
    prev = i

print(utility)

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;


int main(){
  string s;
  cin >> s;
  if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
    cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

_n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

min = 0
sum_all = a.map(&:abs).tap { |ary| min = ary.min }.inject(:+)
ans = (a.count { |aa| aa < 0 } % 2).zero? ? sum_all : sum_all - 2 * min

puts ans


Measured memory_bytes: 10500
n = int(input())
a_ls = list(map(int, input().split())) 
# キーはa_lsのユニークな値、valueは出現回数
a_dict = {}
for a in a_ls:
    if not a in a_dict.keys():
        a_dict[a] = 0
    a_dict[a] += 1   

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# キーはa_lsのset要素, 値はそれで何通りできるか
every_dict = {}
for i in a_dict.keys():
    if a_dict[i] > 1:
        every_dict[i] = comb(a_dict[i],2)
    else:
        every_dict[i] = 0

values_ls = every_dict.values()
_sum = sum(values_ls)
ans_dict = {}
for i in set(a_ls):
    if a_dict[i] - 2 > 0:
        ans_dict[i] = _sum - every_dict[i] + (every_dict[i] *  (a_dict[i] - 2)) // a_dict[i]
    else:
        ans_dict[i] = _sum - every_dict[i]

for i in a_ls:
    print(ans_dict[i])


Measured memory_bytes: 44700
#include<iostream>
#include<algorithm>

using namespace std;

int n;
int d[100001];

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) cin >> d[i];
	sort(d, d + n);
	int ans;
	ans = d[n / 2] - d[n / 2 - 1];
	cout << ans << endl;
	return 0;
}

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


void solver() {
  int n;
  long long k;
  cin >> n >> k;
  vector<int> as(n);

  for (int i = 0; i < n; i++) {
    cin >> as[i];
    as[i] -= 1;
  }

  vector<bool> isReached(n);
  vector<int> flow;
  isReached[0] = true;
  int prev = 0;
  int loopA = 0;
  flow.push_back(prev);
  for (int i = 0; i < n; i++) {
    int next = as[prev];
    if (isReached[next]) {
      loopA = next;
      break;
    }

    isReached[next] = true;
    flow.push_back(next);
    prev = next;
  }

  bool freeze = true;
  vector<int> loopFlow;
  vector<int> nonLoopFlow;
  int in_cnt = 0;
  int out_cnt = 0;
  for (int i = 0; i < flow.size(); i++) {
    if (flow[i] == loopA) freeze = false;

    if (freeze) {
      nonLoopFlow.push_back(flow[i]);
      out_cnt++;
    } else {
      loopFlow.push_back(flow[i]);
      in_cnt++;
    }
  }

  //for (int i = 0; i < nonLoopFlow.size(); i++) {
  //  cout << nonLoopFlow[i] << "\n";
  //}

  int ans = 0;
  if (k < out_cnt) {
    int idx = k % out_cnt;
    ans = nonLoopFlow[idx];
  } else {
    k -= out_cnt;
    int idx = k % in_cnt;
    ans = loopFlow[idx];
  }

  cout << ans + 1 << "\n";
}

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 6384
#include<stdio.h>
int main()
{
    int tc;
    scanf("%d",&tc);
    int flag = 0;
    for(int i = 1;i<=9;i++)
    {
        for(int j = 1;j<=9;j++)
        {
            if(i * j == tc)
            {
                flag = 1;    
                break;
            } 
        }
        if(flag == 1) break;
    }
    if(flag == 1) printf("Yes\n");
    else{
        printf("No\n");
    }
}

Measured memory_bytes: 2088
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()

if 1 <= A <= 9 and 1 <= B <= 9:
	print(A*B)
else:
	print(-1)

Measured memory_bytes: 6096
#include<bits/stdc++.h>
#define mkp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itii;
const ll inf = 1e6;
ll lower[inf];
ll road[inf];
int main()
{
	ll n,m;
	cin>>n>>m;
	vector<ll> vi;
	for(ll i=0;i<n;i++) 
	{
		ll a;
		cin>>a;
		vi.push_back(a);
	}
	for(ll i=0;i<m;i++){
		ll a,b;
		cin>>a>>b;
		a--;
		b--;
		if(vi[a]<vi[b])
		{
			lower[b]++;
		}
		else if(vi[a]>vi[b])
		{
			lower[a]++;
		}
		road[a]++;
		road[b]++;
	}
	ll cnt = 0;
	for(ll i=0;i<n;i++)
	{
		if(lower[i] == road[i])
			cnt++;
		else if(road[i] == 0)
			cnt++;
	}
	cout<<cnt<<endl; 
	return 0;
}

Measured memory_bytes: 5616
def combination_mod(n, r, mod):
    x = 1
    y = 1

    for i in range(r):
        x *= n - i
        y *= r - i
        x %= mod
        y %= mod

    return (x * pow(y, mod - 2, mod)) % mod


n, a, b = map(int, input().split())
mod = 10 ** 9 + 7


ans = pow(2, n, mod) - 1
ans %= mod
ans -= combination_mod(n, a, mod)
ans %= mod
ans -= combination_mod(n, b, mod)
ans %= mod

print(ans)



Measured memory_bytes: 63144
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define NIL -1

const int MAXN = 1e5 + 10;
vector<int> adj[MAXN];
bool vis[MAXN];
int dist[MAXN];

int dfs(int n)
{
    vis[n] = true;
    //  cout << "n= " << n << "\n";
    if (adj[n].size() == 0)
    {

        dist[n] = 0;
        return dist[0];
    }
    int mx = 0;
    for (int i = 0; i < adj[n].size(); i++)
    {
        if (vis[adj[n][i]] == false)
        {
            //  cout << " child " << adj[n][i] << "\n";
            mx = max(dfs(adj[n][i]), mx);
        }
        else
        {
            mx = max(mx, dist[adj[n][i]]);
        }
    }
    dist[n] = 1 + mx;
    //  cout << "dist " << n << " = " << dist[n] << "\n";
    return dist[n];
}
void ans(int n)
{
    for (int i = 1; i <= n; i++)
    {
        vector<int>::iterator it;
        for (it = adj[i].begin(); it != adj[i].end(); it++)
        {
            dist[*it]++;
        }
    }
    queue<int> q;
    int a = 0;
    for (int i = 1; i <= n; i++)
        if (dist[i] == 0)
            q.push(i);
    s(dist, 0);
    //cout << q.size() << "\n";
    while (!q.empty())
    {
        int p = q.front();
        q.pop();
        //  cout << "p= " << p << "\n";
        a = max(a, dfs(p));
    }
    cout << a << "\n";
}

void solve()
{
    s(vis, false);
    s(dist, 0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        adj[x].pb(y);
    }
    ans(n);
}
int main()
{
#ifdef WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    int t;
    t = 1;
    /// cin >> t;
    for (int I = 1; I <= t; I++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 15664
w, h, n = map(int,input().split())

x_l = 0
x_r = w
y_l = 0
y_h = h

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
      if x > x_l:
        x_l = x
    elif a == 2:
        if x < x_r:
          x_r = x
    elif a == 3:
        if y > y_l:
          y_l = y
    else:
        if y < y_h:
          y_h = y

menseki = 0
if x_l <= x_r and y_l <= y_h:
  menseki = (y_h - y_l)*(x_r - x_l)

print(menseki)


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

int main(){
	string S,T;
	int size;
	char s;

	cin >> S;
	cin >> T;

	size = S.size();

	for(int i=0;i<size;i++){
		if(S == T){
			cout << "Yes" << endl;
			return 0;
		}
		s = S[0];
		for(int j=1;j<size;j++){
			S[j-1] = S[j];
		}
		S[size - 1] = s;
	//	cout << S << endl;
	}

	cout <<"No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)
int a[999][8],n,t,d[99];char s[999];main(){scanf("%d%s",&n,s);a[0][1]=d[79]=1;d[73]=2;r(i,n)r(j,8)r(k,8)if(j&k&&k>>d[s[i]]&1)a[i+1][k]+=a[i][j]%10007;r(i,8)t+=a[n][i];printf("%d\n",t%10007);}

Measured memory_bytes: 1040
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    for (i in 1..N) {
        if (readInputLine().toInt() % 2 == 1) {
            println("first")
            return
        }
    }
    
    println("second")
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37272
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll n;cin>>n;
    string s;cin>>s;
    ll ss=s.size();
    vector<ll> num(ss);
    rep(i,ss){
        num[i]=(ll)(s[i]-'A');
    }

    rep(i,ss){
        cout<<(char)('A'+((num[i]+n)%26));
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();

      	int th = x/500;
      	int g = (x - (th*500))/5;

		int ans =(th*1000)+(g*5);

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 22740
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
ans = 0
for i in range(N):
  ans += B[A[i]-1]
  if i > 0 and A[i] - A[i-1] == 1: ans += C[A[i-1]-1]
    
print(ans)

Measured memory_bytes: 9072
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int LMAX = 150;

struct xy{
    int x, y;

    bool operator >(const xy& o) const {
        int own = x*x+y*y;
        int other = o.x*o.x+o.y*o.y;
        if(own!=other)
            return own > other;
        return y>o.y;
    }
};

int main() {
    int h, w;
    while(cin >> h >> w, h|w){
        xy trg ={w, h};
        xy mini={LMAX, LMAX};

        FOR(y, 1, LMAX+1){
            FOR(x, 1, LMAX+1){
                xy now={x,y};
                if(x > y && mini > now && now > trg){
                    mini = {x, y};
                }
            }
        }

        cout << mini.y << " " << mini.x << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <stack>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string a;
    cin >> a;
    int n = a.size();
    stack<int> col;
    int odp = 0;
    for (int i = 0; i < n; ++i)
    {
        if (col.size() != 0)
        {
            if (col.top() != a[i] - '0')
            {
                col.pop();
                odp += 2;
            }
            else
                col.push(a[i] - '0');
        }
        else
            col.push(a[i] - '0');
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 720
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
string str;
vector<ll> v;
ll val(ll n)
{
    return (n*(n+1))/2;
}
int main()
{
    ll i,n,t,k,j,x=0,y=-1,m,ans=0,px=0,py=0,cnt=1;
    cin>>str;
    n  = str.size();
    bool flag = false;
    for(i=0;i<n-1;i++)
    {
       if(str[i]=='>' && str[i+1]=='<')
       {
           flag = true;
           if(y==-1)
           {
                x = 0;
                for(j=i;j>=0;j--)
                {
                    if(str[j]=='>')
                    {
                        x++;
                    }
                    else break;
                }
           }
           else x = y;
            ans+= val(x);
            x = 0;
            y = 0;
            for(j=i+1;j<n;j++)
            {
                if(str[j]=='<')
                {
                    y++;
                }
                else break;
            }
            //if(j!=n)
              //  y--;
            //cout<<cnt++<<" "<<ans<<endl;
       }
       else if(str[i]=='<' && str[i+1]=='>')
       {
           flag = true;

            if(y==-1)
            {
                x = 0;
                for(j=i;j>=0;j--)
                {
                    if(str[j]=='<')
                    {
                        x++;
                    }
                    else break;
                }
            }
            else
                x = y;
            y = 0;
            for(j=i+1;j<n;j++)
            {
                if(str[j]=='>')
                {
                    y++;
                }
                else break;
            }
            if(x>y)
            {
                ans+= val(x);
                y--;
            }
            else
            {
                ans+= val(x-1);
            }
            //cout<<cnt++<<" "<<ans<<endl;
       }

    }
    if(!flag)
    {
        ans+= val(n);
    }
    else
    {
        if(y>0)
        {
            ans+= val(y);
        }
    }

    pf(ans);


    return 0;
}



Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
   if (A + B < C + D) {
    cout << "Right" << endl;
  }
   if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int N, M, X, C[15], A[15][15];

int val[15];
int INF = 999999999;


int check(void) {

	for (int i = 1; i <= M; i++) {
		if (val[i] < X) { return -1; }
	}

	return 1;

}
int main(void) {

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

	int ans = INF;

	for (long long int k = 0; k < (1LL << N); k++) {
		for (int i = 1; i <= M; i++) { val[i] = 0; }  int cost = 0;

		long long int tmp = k;
		for (int i = 1; i <= N; i++) {
			if ((tmp >> (i - 1)) & 1) {
				cost += C[i];
				for (int j = 1; j <= M; j++) {
					val[j] += A[i][j];
				}
			}
		}

		if (check() == 1) { ans = min(ans, cost); }

	}

	if (ans == INF) { cout << -1 << endl; }
	else { cout << ans << endl; }

	return 0;
}

Measured memory_bytes: 3636
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a = int(input())
b = list(map(int, input().split()))
c = [0] * (a + 1)
d = [0] * (a + 1)
for i in range(1, a + 1):
    c[i] = g_c_d(b[i-1], c[i-1])
    d[-i-1] = g_c_d(b[-i], d[-i])
e = 0
for i in range(len(c)-1):
    e = max(e, g_c_d(c[i], d[i+1]))
print(e)


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

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

    static class DKnapsack1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int W = in.nextInt();

            int[] w = new int[n + 1];
            int[] v = new int[n + 1];

            for (int i = 1; i <= n; i++) {
                w[i] = in.nextInt();
                v[i] = in.nextInt();
            }

            long[][] dp = new long[n + 1][W + 1];

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= W; j++) {
                    if (j < w[i]) {
                        dp[i][j] = dp[i - 1][j];
                        continue;
                    }
                    dp[i][j] = Math.max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
                }
            }

            out.println(dp[n][W]);
        }

    }
}



Measured memory_bytes: 125908
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
b,a=map(list, zip(*sorted(zip(b,a))) )
s=0
for i in range(n):
    s+=a[i]
    if s>b[i]:
        print("No")
        break
else:print("Yes")
        

Measured memory_bytes: 49036
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fucking interest
*******************************
Higher, higher, even higher, to the point you won’t even be able to see me
https://www.a2oj.com/Ladder16.html
*******************************
300IQ as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         K = Math.min(K, 100);
         //solve
         while(K-->0)
         {
            int[] ranges = new int[N];
            for(int i=0; i < N; i++)
            {
               int begin = i-arr[i];
               int end = i+arr[i];
               begin = Math.max(begin, 0);
               ranges[begin]++;
               if(end < N-1)
                  ranges[end+1]--;
            }
            int curr = 0;
            for(int i=0; i < N; i++)
            {
               curr += ranges[i];
               arr[i] = curr;
            }
         }
         for(int x: arr)
            sb.append(x+" ");
         System.out.println(sb);
      }
   }

Measured memory_bytes: 59484