akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std ;

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    lli n, x, ans=-2*INF ;
    cin>> n ;
    vlli a(n), sumL(n+1, 0), sumR(n+1, 0) ;
    priority_queue<lli,vector<lli>,greater<lli>> lq;
    priority_queue<lli> rq;
    for(int i=1 ; i<=n ; i++)
      {
        cin>>x ;
        sumL[0]+=x ;
        lq.push(x);
      }
    for(int i=0 ; i<n ; i++)
      cin>> a[i] ;
    for(int i=1 ; i<=n ; i++)
      {
        cin>> x ;
        sumR[n]+=x ;
        rq.push(x);
      }
    for(int i=0 ; i<n ; i++)
      {
        lq.push(a[i]);
        sumL[i+1]=sumL[i]+a[i]-lq.top();
        lq.pop();
        rq.push(a[n-1-i]);
        sumR[n-1-i] = sumR[n-i]+a[n-1-i]-rq.top();
        rq.pop();
      }
    for(int i=0 ; i<=n ; i++)
      ans=max(ans, sumL[i]-sumR[i]) ;
    cout<< ans ;
  }


Measured memory_bytes: 4980
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define printd(x) printf("%.12f\n", ans);
#define print(x) cout << (x) << endl;
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
#define all(x) (x).begin(),(x).end()
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main(void) {
    int n;
    cin >> n;
    int a[n];
    rep (i, n) cin >> a[i];
    int q;
    cin >> q;
    int m[q];
    rep (i, q) cin >> m[i];

    vector<bool> CanMake(q, false);

    for (int bit = 0; bit < (1 << n); bit++) {
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                sum += a[i];
            }
        }
        rep (i, q) {
            if (sum == m[i]) CanMake[i] = true;
        }
    }

    rep (i, q) cout << (CanMake[i] ? "yes" : "no") << endl;
    return 0;
}


Measured memory_bytes: 3104
#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.at(i);
  sort(A.begin(), A.end());
  bool ans = true;
  for (int i = 1; i < N; i++) {
    if (A.at(i-1) == A.at(i)) ans = false;
  }
  if (ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include "stdio.h"
int main()
{
    int n, a[100], j, x, count, i;
    scanf("%d", &n);

    for (i = 0; i <= n - 1; i++)
        scanf("%d", &a[i]);

    for (i = 0; i<n; i++) {
        for (j = n - 1; j > 0; j--)
            if (a[j] < a[j - 1]) {
                x = a[j];
                a[j] = a[j - 1];
                a[j - 1] = x;
                count++;
            }

    }

    for (i = 0; i < n; i++) {
        if (i > 0)
            printf(" ");
        printf("%d", a[i]);
    }

    printf("\n%d\n", count);

    return 0;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n;
	cin>>n;
	int num=0;
	for(int i=1;i<1000001;i++)
	{
		num=(num*10+7)%n;
		if(num==0)
		  {
		  	cout<<i<<endl;
		  	return 0;
		  }
	}
	cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 3592
import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

MOD = 10**9 + 7
def main():
	n = int(input()); arr = read()
	pref = [i for i in arr]
	for i in range(1, n):pref[i] += pref[i-1]
	ans = 0
	for i in range(n):
		ans += (arr[i] * (pref[-1]-pref[i]))%MOD
		ans %= MOD
	print(ans)



if __name__ == "__main__":
	main()


Measured memory_bytes: 105196
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
import random
sys.setrecursionlimit(4100000)


D = int(input())
C = list(map(int,input().split()))

S = []
for i in range(D):
    tmp = list(map(int,input().split()))
    S.append(tmp)


class Schejule:

    def __init__(self, sche):
        self.base = sche
        self.last = [0] * 26
        self.y = 0

    def get_score(self):
        self.y = 0
        for d in range(D):
            self.y += S[d][self.base[d]]

        for d in range(D):
            self.last[self.base[d]] = d + 1

            for j in range(26):
                self.y -= C[j] * (d+1 - self.last[j])

    def change_one(self, day, to):

        org = self.base[day]

        # 差分
        div = 0

        # その日の満足度の変化
        div += S[day][to] - S[day][org]

        # 損失
        org_loss = 0
        cha_loss = 0

        org_last = 0
        cha_last = 0
        for d in range(D):
            if self.base[d] == org:
                org_last = d + 1
            elif self.base[d] == to:
                cha_last = d + 1

            org_loss +=  C[org] * (d+1 - org_last)
            cha_loss +=  C[to ] * (d+1 - cha_last)

        def_loss = cha_loss + org_loss


        org_loss = 0
        cha_loss = 0

        org_last = 0
        cha_last = 0
        for d in range(D):
            if d != day:
                if self.base[d] == org:
                    org_last = d + 1
                elif self.base[d] == to:
                    cha_last = d + 1
            else:
                cha_last = d+1

            org_loss +=  C[org] * (d+1 - org_last)
            cha_loss +=  C[to ] * (d+1 - cha_last)

        aft_loss = cha_loss + org_loss


        # 全体の差分
        div -= aft_loss - def_loss

        # ε-greedy
        if div > 0 or random.randint(0, 9) >= 8:
            next_plan = self.base.copy()
            next_plan[day] = to

            sche_next = Schejule(next_plan)
            sche_next.y = self.y + div

            return sche_next
        else:
            return self



T = [0] * D

for i in range(D):
    max_day = 0
    for j in range(26):
        if S[i][max_day] < S[i][j]:
            max_day = j
    T[i] = max_day


sche_base = Schejule(T)
sche_base.get_score()


best_score = sche_base.y
best_set = sche_base.base.copy()

#print(sche_base.y)

#print(*sche_base.base)

for i in range(5000):
    d = random.randint(0, D - 1)
    t = random.randint(0, 26 - 1)

    sche_base  = sche_base.change_one(d, t)

    if best_score < sche_base.y:
        best_score = sche_base.y
        best_set = sche_base.base.copy()
        #print("updated!!!!")
        #print("best:", best_score, "->", *best_set)

    #print("now: ", sche_base.y, "->", *sche_base.base)
    #print("best:", best_score, "->", *best_set)
    #print("\n")
    #print(*sche_base.base)

    #print(sche_base.y)

for i in range(D):
    print(best_set[i] + 1)









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

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

    //nが1の時
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }


    vector<int> data(n);
    for(int i = 0 ; i < n ; i++){
        cin >> data.at(i);
    }

    sort(data.begin(), data.end());

    if(data.at(0) == 1){
        if(data.at(1) == 1){
            cout << 0 << endl;
            return 0;
        }else{
            cout << 1 << endl;
            return 0;
        }
    }


    vector<bool> flag(1000001,false);

    for(int i = 0 ; i < n ; i++){
        flag.at(data.at(i)) = true;
    }


    for(int i = 0 ; i < n ; i++){
        int num = data.at(i);
        if(flag.at(num)){
            for(int j = num * 2 ; j <= 1000000 ; j += num){
                flag.at(j) = false;
            }
        }
        if(i + 1 != n){
            if(num == data.at(i + 1)){
                flag.at(num) = false;
            }
        }
    }

    int result = 0;

    /*for(int i = 0 ; i < n ; i++){
        if(flag.at(data.at(i))){
            result++;
        }
    }*/
    for(int i = 0 ; i < flag.size() ; i++){
        if(flag.at(i)){
            result++;
        }
    }


    cout << result << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define mp(a,b)   make_pair(a,b)
#define ll        long long
#define mp(a,b)   make_pair(a,b)
#define si(n)     scanf("%d",&n)
#define sl(n)     scanf("%lld",&n)
#define pi(n)     printf("%d\n",n)
#define pl(n)     printf("%lld\n",n)
#define           newline cout << endl;
#define           ff first
#define           ss second
#define           pii pair<int, int>
#define           pll pair<ll, ll>
using namespace std;

template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

pair<bool,pair<string,string> > solve(string s1,string s2){
  bool f = 0;
  int cnt1[26],cnt2[26];
  for(int i=0;i<26;i++){
    vector<int> index;
    for(int j=0;j<s1.length();j++){
      if(s1[j]==char(i+97)){
        index.push_back(j);
      }
    }
    if(index.size()>=1){
      for(int j=1;j<index.size();j++){
        if(s2[index[j]]!=s2[index[j-1]]){
          f=1;
          break;
        }
      }
      if(f==0){
        char changeins11 = s2[index[0]];
        char changeins12 = char(i+97);
        for(int k=0;k<s1.length();k++){
          if(s1[k]==changeins11) s1[k]=changeins12;
          else if(s1[k]==changeins12) s1[k]=changeins11;
        }
      }
    }
  }
  return mp(f,mp(s1,s2));
}

int main(){
  //clock_t tStart = clock();
  string s1,s2;
  cin >> s1 >> s2;
  auto k1 = solve(s1,s2);
  for(int i=0;i<10;i++){
    if(k1.ff==1) break;
    k1 = solve(k1.ss.ff,k1.ss.ss);
    k1 = solve(k1.ss.ff,k1.ss.ss);
  }
  //cout <<  k1.ss.ff << ' ' << k1.ss.ss << endl;
  if(k1.ff==0 && k1.ss.ff==k1.ss.ss) cout << "Yes" << endl;
  else cout << "No" << endl;
  //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  return 0;
}

Measured memory_bytes: 2512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace aizu1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = new int[n];
            int[] B = new int[n];
            int k = 0;
            string[] str = Console.ReadLine().Split(' ');
            A = Array.ConvertAll(str,new Converter<string, int>(s=>int.Parse(s)));

            for (int j = 0; j < n; j++)
            {
                k = (k > A[j]) ? k : A[j];
            }

            int[] C = new int[k+1];
            for(int i=0;i<n;i++)
            {
                C[A[i]] = C[A[i]] + 1;
            }
            for(int i=1;i<=k;i++)
            {
                C[i] = C[i - 1] + C[i];
            }

            for(int i=n-1;i>=0;i--)
            {
                B[C[A[i]]-1] = A[i];
                C[A[i]]--;
            }

            Console.WriteLine(string.Join(" ", Array.ConvertAll(B, (b)=>b.ToString())));
        }
    }
}

Measured memory_bytes: 186580
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i, n) cin >> s[i];

    int sum = 0;
    REP(i, n)
    {
        FOR(j, 1, s[i].size())
        {
            if(s[i][j-1] == 'A' && s[i][j] == 'B') sum++;
        }
    }
    int a = 0, b = 0, ab = 0;
    REP(i, n)
    {
        if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A') ab++;
        else if(s[i][0] == 'B') b++;
        else if(s[i][s[i].size()-1] == 'A') a++;
    }

    if(ab > 0)
    {
        if(a > 0)
        {
            a--;
            sum += 1;
        }
        sum += ab - 1;
        if(b > 0)
        {
            b--;
            sum += 1;
        }
    }

    sum += min(a, b);
    cout << sum << endl;
}

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

int main() {
    int a[10];
    int b[10]={0};
    for (int i=0; i<6; ++i) {
        cin >> a[i];
        ++b[a[i]];
    }

    for (int i=0; i<6; ++i) {
        if (b[i] == 3) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

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

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    vector<int> s(n);
    s[0] = a[0];
    for(int i = 1; i < n; i++){
        s[i] = s[i-1] + a[i];
    }

    int ans = 1;
    for(int i = n-2; i >= 0; i--){
        if(s[i] * 2 >= a[i+1]){
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1920
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long total = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                for (int k = 1; k <= n; k++) {
                    total += getGCD(i, j , k);
                }
            }
        }
        System.out.println(total);
    }
    
    static int getGCD(int x, int y, int z) {
        return getGCD(x, getGCD(y, z));
    }
    
    static int getGCD(int x, int y) {
        if (x % y == 0) {
            return y;
        } else {
            return getGCD(y, x % y);
        }
    }
}

Measured memory_bytes: 35856
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    i64 n;
    cin >> n;
    akari<int> as(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
    }
    //1 is most left
    //LIS?
    int ans = n, cur = 0;
    for (int i = 0; i < n; i++)
    {
        if (as[i] == cur + 1)
        {
            cur++;
            ans--;
        }
    }
    if (ans == n)
    {
        ans = -1;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
//const int MOD = pow(10, 9) + 7;
const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int P, Q, R;
  cin >> P >> Q >> R;

  int ans = min({P + Q, Q + R, R + P});

  cout << ans << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f

long long N;
long long p[100010];
long long L[100010],R[100010];
long long ans;
stack<pair<long long,long long> > st;
int main()
{
    cin>>N;
    for(long long i=1;i<=N;i++) cin>>p[i];
    st.push(make_pair(inf,0));
    for(long long i=1;i<=N;i++)
    {
        while(p[i]>st.top().first) st.pop();
        L[i]=st.top().second;
        st.push(make_pair(p[i],i));
    }
    while(!st.empty()) st.pop();
    st.push(make_pair(inf,N+1));
    for(long long i=N;i>=1;i--)
    {
        while(p[i]>st.top().first) st.pop();
        R[i]=st.top().second;
        st.push(make_pair(p[i],i));
    }

    for(long long i=1;i<=N;i++)
    {
        long long x=L[i],y=R[i],xx,yy;
        if(x==0) xx=0;
        else xx=L[x];
        if(y==N+1) yy=N+1;
        else yy=R[y];
        long long x_x=0,y_y=N+1;
        for(long long k=x-1;k>=xx;k--)
            if(p[k]>p[i])
            {
                x_x=k;
                break;
            }
        for(long long k=y+1;k<=yy;k++)
            if(p[k]>p[i])
            {
                y_y=k;
                break;
            }

        //cout<<x_x<<" "<<x<<" "<<y<<" "<<y_y<<endl;
        ans+=((x-x_x)*(y-i)+(i-x)*(y_y-y))*p[i];
    }
    cout<<ans;
}


Measured memory_bytes: 4096
#include <cstdio>
using namespace std;

int main() {
	int n; scanf("%d", &n);
	if (n == 1) {
		printf("Hello World\n");
		return 0;
	}
	else {
		int a, b; scanf("%d", &a); scanf("%d", &b);
		printf("%d\n", a + b); return 0;
	}
}

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

int main(){
  int N,flag = 0;
  string temp;
  cin >> N;
  for(int i = 0; i < N; i++){
  	cin >> temp;
  	if(temp == "Y") flag = 1;
  }
  

  if(flag == 1){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

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

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//



template<class T> int former(const vector<T> &v, T x){
        return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}

template<class T> int latter(const vector<T> &v, T x){
        return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main(){
        int A, B, Q; cin >> A >> B >> Q;
        vector<long long> s(A), t(B);
        for(int i = 0; i < A; i++) cin >> s[i];
        for(int i = 0; i < B; i++) cin >> t[i];
        s.push_back(INF); s.push_back(-INF); sort(all(s));
        t.push_back(INF); t.push_back(-INF); sort(all(t));

        for(int k = 0; k < Q; ++k){
                long long x;
                cin >> x;
                long long res = INF;

                for(int i = 0; i < 2; i++){
                        long long first = (i ? s[former(s,x)] : s[latter(s,x)]);
                        for(int j = 0; j < 2; j++){
                                long long second = (j ? t[former(t, first)] : t[latter(t,first)]);
                                chmin(res, abs(x - first) + abs(first - second));
                        }
                }

                for(int i = 0; i < 2; i++){
                        long long first = (i ? t[former(t, x)] : t[latter(t,x)]);

                        for(int j = 0; j < 2; j++){
                                long long second = (j ? s[former(s, first)] : s[latter(s, first)]);
                                chmin(res, abs(x - first) + abs(first - second));
                        }
                }
                cout << res << endl;
        }
}


Measured memory_bytes: 2912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
    int a;
    ll b,n;
    cin >> a >> b >> n;
    int ans;
    if(n>=b-1)
        ans = floor((b-1)*a/b)-a*floor((b-1)/b);
    else
        ans = floor(n*a/b)-a*floor(n/b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3516
#!/usr/bin/env python3
import sys, math, fractions, itertools

MOD = 1000000007  # type: int

def solve(h: int, w: int, k: int):
    wc = [1] * 9

    for i in range(2, 9):
        wc[i] = wc[i-1] + wc[i-2]

    dp = [0] * (w+2)
    dp[1] = 1
    for i in range(h):
        tmp = [0] * (w+2)
        for j in range(1, w+1):
            tmp[j] = dp[j] * wc[j-1] * wc[w-j]
            if j > 1:
                tmp[j] += dp[j-1] * wc[j-2] * wc[w-j]
            if j < w:
                tmp[j] += dp[j+1] * wc[j-1] * wc[w-j-1]
            tmp[j] = tmp[j] % MOD
        dp = tmp
    print(dp[k])

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(H, W, K)

if __name__ == '__main__':
    main()


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    map <string,ll> mp;
    for(i = 0;i < n;++i){
        string s;
        cin >> s;
        if(mp.count(s)) continue;
        else{
            mp[s] = 0;
        }
    }
    cout << mp.size() << endl;


    return 0;
}


Measured memory_bytes: 19220
#include <stdio.h>
 
int main() {
  int n;
  char suits[52];
  int ranks[52];
  int i, j;
 
  int cards[4][14] = {{}};
 
  scanf("%d ", &n);
  for(i = 0; i < n; ++i) {
    scanf("%c %d ", &suits[i], &ranks[i]);
 
    if(suits[i] == 'S') {
      cards[0][ranks[i]] = 1;
    } else if(suits[i] == 'H') {
      cards[1][ranks[i]] = 1;
    } else if(suits[i] == 'C') {
      cards[2][ranks[i]] = 1;
    } else if(suits[i] == 'D') {
      cards[3][ranks[i]] = 1;
    }
  }
 
  for(i = 0; i < 4; ++i) {
    for(j = 1; j <= 13; ++j) {
      if(cards[i][j] == 0) {
    if(i == 0) printf("S ");
    else if(i == 1) printf("H ");
    else if(i == 2) printf("C ");
    else if(i == 3) printf("D ");
    printf("%d\n", j);
      }
    }
  }
 
  return 0;
}


Measured memory_bytes: 2076
n, w = map(int, input().split(' '))
items = [[]] * n
for i in range(n):
  weight, val = map(int, input().split(' '))
  items[i] = [weight, val]

# print(n, w)
# print(items)

dp = []
for i in range(n+1):
  dp.append([])
  for j in range(w+1):
  	dp[i].append(0)

# print(len(dp), len(dp[0]), dp[0][0])

for i in range(n):
  weight , val = items[i]
  for sum_w in range(w+1):
    # i番目のアイテムを選択する
    if sum_w - weight >= 0:
      dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight] + val)
    # i番目のアイテムを選択しない
    dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
print(dp[n][w])

Measured memory_bytes: 144744
#include <bits/stdc++.h>
#include <string.h>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15

 int main(){

 long long a,b,c,k;
 cin>>a>>b>>c>>k;


   if(k%2 == 1)
    cout<<b-a<<endl;
   else
    cout<<a-b<<endl;

  return 0;
 }

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

typedef long long ll;

const int N = 200010;
int n, m;
int a[N];
priority_queue<int>q;

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), q.push(a[i]);
	while(m--) {
		int u = q.top(); q.pop();
		q.push(u / 2);
	}
	ll ans = 0;
	while(!q.empty()) ans += q.top(), q.pop();
	printf("%lld\n", ans);
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)


int main()
{
	int a,b,c,count=0;
	cin>>a>>b>>c;
	bfor(i,min(a+1,b+1),1)
	{
		if(a%i==0&&b%i==0) count++;
		if(count==c)
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def main(n,x):
    ans = 0
    for m in range(2, min(n,x//2)+1):
        for s in range(1, m):
            for b in range(m+1, min(n+1,x)):
                if s+m+b == x:
                    ans+=1
          
    print(ans)          
    return
                
    return

if __name__ == '__main__':
    n,x = na()
    while n!=0 or x!= 0:
        main(n,x)
        n,x = na()



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int f(int a) {
    if(a & 1) return 1;
    return 2 * (f(a /2));
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> v(N);
    int Grundy = 0;
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        Grundy ^= a;
        v[i] = f(a);
        v[i] <<= 1;
        v[i]--;
    }
    sort(v.begin(), v.end(), greater<int>());
    int ans = 0;
    for(int i = 0; i < v.size(); i++) {
        if(chmin(Grundy, Grundy ^ v[i])) ans++;
    }
    if(Grundy != 0) ans = -1;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#ifndef localfile
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma GCC optimize("unroll-loops")
#endif
#define int long long
#define x first
#define y second
typedef pair<int, int> pii;
vector<int> g[1009];

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

    int n = 4;
    for (int i = 0; i< n - 1; i ++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    int cnt1 = 0, cnt2 = 0;

    for (int i = 0; i < n; i ++) {
        if (g[i].size() == 2) {
            cnt2++;
        }

        else if (g[i].size() == 1) {
            cnt1++;
        }

        else {
            cout << "NO";
            return 0;
        }
    }

    if (cnt1 == 2) {
        cout << "YES";
    }

    else {
        cout << "NO";
    }

    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0 || n==1) return dp[n]=1;
  if(dp[n]!=-1) return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  for(i=0;i<50;i++) dp[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}


Measured memory_bytes: 2028
def c_bridge(N, M, Edges):
    def dfs(v):
        is_visited[v] = True  # 現在の頂点を訪問済にする
        for v2 in range(N):
            if not graph[v][v2] or is_visited[v2]:
                continue  # 頂点v2に行けないか、行く必要がない
            dfs(v2)

    graph = [[False for _ in range(N)] for _ in range(N)]
    for a, b in Edges:
        graph[a - 1][b - 1] = True
        graph[b - 1][a - 1] = True

    # 各辺は橋か？ グラフからその辺を取り除いて、グラフが連結かを判定
    ans = 0
    for a, b in Edges:
        # 辺を取り除く
        graph[a - 1][b - 1] = False
        graph[b - 1][a - 1] = False

        # すべての辺を未訪問として初期化
        is_visited = [False for _ in range(N)]
        # 全頂点に到達できなければ、除いた辺は橋である
        dfs(0)
        ans += 1 if not all(is_visited) else 0

        # 辺を復元
        graph[a - 1][b - 1] = True
        graph[b - 1][a - 1] = True
    return ans

N, M = [int(i) for i in input().split()]
Edges = [[int(i) for i in input().split()] for j in range(M)]
print(c_bridge(N, M, Edges))

Measured memory_bytes: 3064
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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 INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	cin >> n >> m;
	priority_queue<ll> q;
	ll sum = 0;
	rep(i, n) {
		ll a;
		cin >> a;
		q.push(a);
	}
	rep(i, m) {
		ll k = q.top();
		k /= 2;
		q.pop();
		q.push(k);
	}
	while (!q.empty()) {
		sum += q.top();
		q.pop();
	}
	cout << sum << endl;
}



Measured memory_bytes: 1400
package main

import "fmt"

func main() {
	arr := scanNums(5)
	res := []int{}
	for i, a := range arr {
		if a == 0 {
			res = append(res, i)
		}
	}
	for _, re := range res {
		fmt.Print(re+1)
	}
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 1772
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var c = ReadLineIntSpilit();
            var result = 0;

            if(c[0]-c[1] > 0) {
                result = c[0]-c[1];
            }

            Console.WriteLine(result);
            ReadLine();
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

using namespace std;
typedef long long ll;

bool equal(map<char, int> m1, map<char, int> m2) {
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    for (int i = 0; i < alphabet.size(); i++) {
        if (m1[alphabet[i]] != m2[alphabet[i]]) {
            return false;
        }
    }
    return true;
}

bool equal(string s1, string s2) {
    for (int i = 0; i < s1.size(); i++) {
        if (s1[i] != s2[i]) {
            return false;
        }
    }
    return true;
}

ll combi2(ll n) {
    return n * (n - 1) / 2;
}

//int main() {
//    string s;
//    ll N;
//    cin >> N;
//    vector<map<char, int> > map_vector;
//    string alphabet = "abcdefghijklmnopqrstuvwxyz";
//    for (ll i = 0; i < N; i++) {
//        cin >> s;
//        map<char,  int> m;
//        for (ll i = 0; i < alphabet.size(); i++) {
//            m[alphabet[i]] = 0;
//            for (ll j = 0; j < s.size(); j++) {
//                if (alphabet[i] == s[j]) {
//                    m[alphabet[i]]++;
//                }
//            }
//        }
//        map_vector.push_back(m);
//    }
//    ll ans = 0;
//    for (ll i = 0; i < map_vector.size(); i++) {
//        for (ll j = i + 1; j < map_vector.size(); j++) {
//            if (equal(map_vector[i], map_vector[j])) ans++;
//        }
//    }
//    cout << ans << endl;
//}

//int main() {
//    string s;
//    vector<string> sv;
//    int N; cin >> N;
//    for (int i = 0; i < N; i++) {
//        cin >> s;
//        sort(s.begin(), s.end());
//        sv.push_back(s);
//    }
//
//    int ans = 0;
//    for (int i = 0; i < N; i++) {
//        for (int j = i + 1; j < N; j++) {
//            if (equal(sv[i], sv[j])) {
//                ans++;
//            }
//        }
//    }
//    cout << ans << endl;
//}

int main() {
    string s;
    vector<string> sv;
    map<string, ll> m;
    int N; cin >> N;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> s;
        sort(s.begin(), s.end());
        if (m[s] > 0) {
            m[s]++;
        } else {
            m[s] = 1;
            sv.push_back(s);
        }
    }

    for (const auto e : sv) {
        if (m[e] > 1) {
            ans += combi2(m[e]);
        }
    }

//    for (int i = 0; i < N; i++) {
//        for (int j = i + 1; j < N; j++) {
//            if (equal(sv[i], sv[j])) {
//                ans++;
//            }
//        }
//    }
    cout << ans << endl;
}



Measured memory_bytes: 16628
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int queueAmount = scan.nextInt();
		int qTime = scan.nextInt();
		int totalTime = 0;
		int[] proNum = new int[queueAmount+1];	//?????°?????????????????????1????????¨??????
		String[] proID = new String[queueAmount+1];

		for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		}
		int dataTop = 0;
		int dataBottom = queueAmount-1;
		proNum[queueAmount] = 0;
		
		while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		}
	}
}

Measured memory_bytes: 75924
#include <stdio.h>

int main(void)
{
	int x,y,z,a,b,d;
	char c[3][3];
	for(x=0;x<3;x++) scanf("%s",c[x]);
	for(x=0;x<3;x++) printf("%c",c[x][x]);
	return 0;
}

Measured memory_bytes: 128
class String
  def edit_distance(str)
    n = size
    m = str.size
    dp = Array.new(n + 1) { Array.new(m + 1, [n, m].max) }
 
    list = str.chars
 
    n.times do |i|
      dp[i][0] = i
    end
 
    m.times do |j|
      dp[0][j] = j
    end
 
    chars.each_with_index do |s, i|
      list.each_with_index do |t, j|
        if s == t
          dp[i + 1][j + 1] = dp[i][j]
        else
          dp[i + 1][j + 1] = [dp[i][j + 1], dp[i + 1][j], dp[i][j]].min + 1
        end
      end
    end
 
    dp[n][m]
  end
end

s1 = gets.chomp
s2 = gets.chomp

puts s1.edit_distance(s2)



Measured memory_bytes: 14724
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(auto &i:a){cin>>i;}
    ll mx=200001;
    vector<vector<double>> dp(n,vector<double>(mx,E));
    for(int i=1;i<mx;i++){
        dp[0][i]=(double)abs(a[0]-i)/a[0];
    }
    for(int i=0;i+1<n;i++){
        for(ll t=1;t<mx;t++){
            for(ll h=1;t*h<mx;h++){
                dp[i+1][t*h]=min(dp[i+1][t*h],max(dp[i][t],(double)abs(a[i+1]-t*h)/a[i+1]));
            }
        }
    }
    double ans=E;
    for(auto &i:dp.back()){ans=min(ans,i);}
    cout<<fixed<<setprecision(12)<<ans<<endl;
    
    
    return 0;
}



Measured memory_bytes: 35588
H, W = map(int, input().split())
N = int(input())
arr = list(map(int, input().split()))
ans = [[0]*W for _ in range(H)]
count = 0
index = 0
for h in range(H):
    for w in range(W):
        if h % 2 == 0:
            ans[h][w] = index + 1
        else:
            ans[h][W-1-w] = index + 1
        count += 1
        if count == arr[index]:
            count = 0
            index += 1
for h in range(H):
    for w in range(W):
        print(ans[h][w], end=" ")
    print()

Measured memory_bytes: 3920
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>


using namespace std;


long long dp[100000][13] = {};

int main()
{
	const int numKind = 10;
	const int modVal = 13;
	const long long answerMod = 1000000007;

	string s;
	cin >> s;

	int n = s.length();
	dp[0][0] = 1;

	for (int i = 0; i < n; i++)
	{
		int c;
		if (s[i] == '?')
			c = -1;
		else
			c = s[i] - '0';

		for (int j = 0; j < numKind; j++)
		{
			if (c != -1 && c != j)
				continue;

			for (int k = 0; k < modVal; k++)
				dp[i + 1][(k * numKind + j) % modVal] += dp[i][k];
		}

		for (int j = 0; j < modVal; j++)
		{
			dp[i + 1][j] %= answerMod;
		}

	}


	cout << dp[n][5];

	return 0;
}



Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n,m,ans=0;
   cin >> n >> m;
   vector<int> Isred(n),num(n,1);
   Isred[0] = 1;
   for(int i=0;i<m;i++){
       int x,y;
       cin >> x >> y;
       x--;y--;
       num[x]--;
       num[y]++;
       if(Isred[x]) Isred[y] = 1;
       if(num[x]==0) Isred[x] = 0;
   }
   for(int i=0;i<n;i++){
       if(Isred[i] == 1) ans++;
   }
   cout << ans << endl;
}

Measured memory_bytes: 1024
n,y=map(int,input().split())

for i in range(0,n+1):
  for j in range(0,n+1-i):
    if 10000*i+5000*j+1000*(n-i-j)==y:
      print(i,j,n-i-j)
      exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
int main(){
  char S ;
  cin >> S;
  
  if ( isupper (S)) {
    cout << "A"<< endl;
  }
  
  else if ( iswlower (S)){
    cout << "a" << endl;
  }
  
}

Measured memory_bytes: 3620
n = int(input())
a = []
for _ in range(12):
	a.append([int(0) for _ in range(10)])
for _ in range(n):
	b, f, r, v = map(int, raw_input().split())
	a[3*(b-1) + f-1][r-1] += v
for i in range(4):
	for j in range(3):
		print ' ' + ' '.join(map(str, a[3*i + j]))
	if i < 3:
		print '#' * 20

Measured memory_bytes: 4656
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
string s;

int f(){
	int res=0,t=0;
	vi a(n);
	for(int i=0;i<n;i++) if(s[i]=='<') a[i]++;
	for(int i=1;i<n;i++) a[i]+=a[i-1];
	for(int i=0;i<n;i++){
		if(s[i]=='>') t++;
		int l=i-1,r=n-1;
		while(r-l>1){
			int m=(l+r)/2;
			if(a[m]-a[i]>=t) r=m;
			else l=m;
		}
		if(a[r]-a[i]==t){
			res=max(res,r+1);
		}
		else break;
	}
	reverse(s.begin(),s.end());
	for(int i=0;i<n;i++){
		if(s[i]=='>') s[i]='<';
		else s[i]='>';
	}
	return res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>s;
	cout<<max(f(),f())<<endl;
}


Measured memory_bytes: 3732
input_line = input()
input_list = [int(x) for x in input_line.split()]

five_counter = 0
seven_counter = 0
for i in input_list:
    if i==7:
        seven_counter+=1
    elif i==5:
        five_counter+=1
if seven_counter==1 and five_counter==2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ll 				long long
#define int             long long int
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define modp            998244353
#define inf             (ll)1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void solve()
{
	int n;
	cin >> n;
	int a[n]; int cnt = 0;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
	{
		for(int j = i+1; j < n; j++)
		{
			for(int k = j+1; k < n; k++)
			{
				vector<int> temp;
				temp.push_back(a[i]);
				temp.push_back(a[j]);
				temp.push_back(a[k]);
				sort(temp.begin(), temp.end());
				if(temp[0]+temp[1] > temp[2] && temp[0] != temp[1] && temp[1] != temp[2])
					cnt++;
				temp.clear();
			}
		}
	}
	cout << cnt;
}
 
int32_t main()
{
	FIO
    // w(t)
    {
    	solve();
    }
    return 0;
}
	

	

Measured memory_bytes: 3648
from fractions import gcd
a,b,c,d=map(int,input().split())
lcm=c*d//gcd(c,d)
nc=b//c-a//c
nd=b//d-a//d
nlcm=b//lcm-a//lcm
if a%c==0:
  nc+=1
if a%d==0:
  nd+=1
if a%lcm==0:
    nlcm+=1
print(b-a+1-nc-nd+nlcm)

Measured memory_bytes: 5044
#include <stdio.h>

#define N 10000000

char e[ N + 1 ] = { 1, 1, 0 };

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( j = 2; j < N; ++j )
  {
    if ( e[ j ] ) continue ;

    for ( i = j * 2; i <= N; i += j )
    {
      e[ i ] = 1;
    }
  }

  for ( ; ; )
  {
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    for ( ; n >= 13; --n )
    {
      if ( !( e[ n ] || e[ n - 2 ] || e[ n - 6 ] || e[ n - 8 ] ) )
        break ;
    }

    printf ( "%d\n", n );
  }

  return ( 0 );
}

Measured memory_bytes: 9000
#include <stdio.h>
int main(void){
   
   int H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
   
    return 0;
}



Measured memory_bytes: 2608
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int h,a;
    cin>>h>>a;
    if(h%a>0) cout<<h/a+1<<endl;
    else cout<<h/a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
using namespace std;
int n,m;
vector<ll> a(1001),b(1001),c(1001); 
int bit;
vector<vector<ll>> d;

ll dp(int r, int p){
	if(p == n){ //もうケーキない
		if(r < m)return -1000000000000000;
		return 0;
	}
	if(r == m){ //これ以上食べられない
		return 0;
	}
	if (d[r][p] < 1000000000000000){
		return d[r][p];
	}
	return d[r][p] = max(dp(r, p+1), (a[p]*(((bit/4)&1)?1:(-1)))+(b[p]*(((bit/2)&1)?1:(-1)))+(c[p]*((bit&1)?1:(-1)))+dp(r+1, p+1));
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	/*for(bit = 0;bit < 8;bit++){
		cout << (((bit/4)&1)?1:(-1)) << (((bit/2)&1)?1:(-1)) << (((bit)&1)?1:(-1)) << endl;
	}*/
	//cout << (((5/2)&1)?1:(-1)) << endl;
	   
	cin>>n>>m;
	
	rep(i, n){
		cin>>a[i]>>b[i]>>c[i];
	}
	ll ans = 0;
	for(bit = 0;bit < 8;bit++){
		d = vector<vector<ll>>(m+1, vector<ll>(n+1, (ll)1000000000000000));
		ll t = dp(0, 0);
		if(t>ans)ans = t;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 16100