akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const int MOD = (int)1e9+7;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;

const int MAX_N = 100050;
int n;
int a[MAX_N];

int main(void) {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	rep(i,0,n) {
		cin >> a[i];
	}
	multiset<int> s;
	int total = 0;
	rep(i,0,n) {
		if(s.empty()) {
			s.insert(-a[i]);
			total++;
			continue;
		}

		auto it = s.upper_bound(-a[i]);
		if(it == s.end()) {
			s.insert(-a[i]);
			total++;
		} else {
			s.erase(it);
			s.insert(-a[i]);
		}
	}
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  long long N;
  long long  ans = 0;
  string S;

  cin >> S;
  istringstream ss1 =  istringstream(S);
  ss1 >> N;
  
  // cout << "---------" << endl;

  // cout << N << endl;

  int l = S.length();
  int t = 10;
  vector<int> n(l);
  for(int i = 0; i < l; i++){
    n[l-i-1] = N%t;
    N = N/10;
  }
  // cout << "---------" << endl;

  int minx = 1000;
  for(int i = 0; i< l-2; i++){
    int num = n[i]*100 + n[i+1]*10+n[i+2];
    minx = min(minx, abs(753 - num));
    // cout << 753 << "-" <<num<< "="<< abs(753 - num)<< endl;
  }
  // cout << "---------" << endl;
  cout << minx << endl;
} 


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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template<class T>
struct Point {
    T x, y;
    Point& operator+=(const Point a) { x += a.x; y += a.y;  return *this; }
    Point& operator-=(const Point a) { x -= a.x; y -= a.y;  return *this; }
    Point operator+(const Point a) const {return Point(*this) += a; }
    Point operator-(const Point a) const {return Point(*this) -= a; }
    bool operator<(const Point &a) const { return (x != a.x ? x < a.x : y < a.y); }
    T dot(Point a) { return x*a.x + y*a.y; }
    T cross(Point a) { return x*a.y - y*a.x; }
    T abs() { return sqrt(this->dot(*this)); }
    explicit Point(T a = 0,T b = 0) : x(a), y(b) {};
};

int main() {
    auto f = [&](Point<int> a, Point<int> b){
        if(a.dot(a) != b.dot(b)) return a.dot(a) < b.dot(b);
        else return a.x < b.x;
    };
    vector<Point<int>> v;
    for (int i = 1; i <= 201; ++i) {
        for (int j = i+1; j <= 201; ++j) {
            v.emplace_back(i, j);
        }
    }
    sort(v.begin(), v.end(), f);
    int h, w;
    while(cin >> h >> w, h|w){
        auto ans = *upper_bound(v.begin(), v.end(), Point<int>(h, w), f);
        cout << ans.x << " " << ans.y << "\n";
    }
    return 0;
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define repd(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll;
using namespace std;

int main() {
    int k,x;cin>>k>>x;
    if(k==1)cout<<x<<endl;
    else{
        repd(i,x-k+1,x+k)cout<<i<<' ';
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1e9 + 7
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
int main() {
        ll n;
        cin >> n;
        set<int> a = {2, 4, 5, 7, 9}, b = {0, 1, 6, 8}, c = {3};
        if(a.find(n % 10) != a.end())
            cout << "hon";
        else if(b.find(n % 10) != b.end())
            cout << "pon";
        else
            cout << "bon";
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int n,m,pow_2[10];
int main()
{
	scanf("%d%d",&n,&m);
	pow_2[0]=1;
	for(int i=1;i<=5;i++)
	{
		pow_2[i]=pow_2[i-1]*2;
	}
	printf("%d",pow_2[m]*(1900*m+100*(n-m)));
}

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

cumsum = [0]
cummaxsum = [0]
for a in A:
    cumsum.append(cumsum[-1] + a)
    cummaxsum.append(cummaxsum[-1] + max(0, a))

ans = 0
for left in range(N-K+1):
    right = left + K

    # 区間leftからrightまで、負になるなら0（白色)、正になるなら累積和をもとに（黒色）
    score = max(0, cumsum[right] - cumsum[left])
    # 左端からleftまで自由に色を塗る
    score += cummaxsum[left]
    # rightから右端まで自由に色を塗る
    score += cummaxsum[-1] - cummaxsum[right]

    ans = max(ans, score)

print(ans)

Measured memory_bytes: 17116
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(ll)(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })



int main(){
    vl h,a;
    ll N;
    cin >> N;
    FOR(hjkl,0,N){
        ll x;
        cin >> x;
        h.pb(x);
    }
    FOR(hjk,0,N){
        ll x;
        cin >> x;
        a.pb(x);
    }
    set<pll> hull;
    hull.insert(mp(h[0], a[0]));
    FOR(i,1,N){
        ll hei = h[i];
        ll b = a[i];
        auto it = hull.lower_bound(mp(hei,0));
        if(it == hull.end()){
            ll ges = prev(hull.end())->yy;
            hull.insert(mp(hei,b+ges));
            continue;
        }
        if(it == hull.begin()){
            if(it->xx == hei){
                pll old_head = *it;
                pll new_head = mp(hei,b);
                hull.erase(it);
                hull.insert(max(old_head, new_head));
            } else {
                hull.insert(mp(hei, b));
            }
            for(auto it = next(hull.begin()); it != hull.end(); it++){
                if(it->yy > hull.begin()->yy) break;
                auto bu = prev(it);
                hull.erase(it);
                it = bu;          
            }
            continue;
        }
        it = prev(it);
        pll new_ele = mp(hei,it->yy+b);
        if(next(it)->xx == hei){
            if(next(it)->yy > new_ele.yy){
                continue;
            } 
        }
        hull.insert(new_ele);
        for(auto it = next(hull.find(new_ele)); it != hull.end(); it++){
            if(it->yy > new_ele.yy) break;
            auto bu = prev(it);
            hull.erase(it);
            it = bu;
        }
    }
    cout << prev(hull.end())->yy << endl;
} //cin.tie(0) bei schnellem Wechseln




Measured memory_bytes: 15856
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
from collections import deque
from bisect import *
K=int(input())
flag=0
cnt=0
ans=0
for i in range(K):
    cnt=(cnt+7*pow(10,i,K))%K
    if cnt==0:
        flag=1
        ans=i+1
        break
if flag==0:
    print(-1)
else:
    print(ans)





Measured memory_bytes: 72872
#include<stdio.h>
#include<string.h>
int main() {
	long long int n=0;
	int z;
	int black=0;
	char str[200050];
	scanf("%s", str);
	z = strlen(str);
	for (int i = 0; i < z; i++) {
		if (str[i] == 'B') { black++; }
		else {
			n += black;
		}
		
	}
	printf("%lld", n);
}

Measured memory_bytes: 384
#include <iostream>
#include <string.h>
using namespace std;

int main(){
	int  N,T[50];
	char S[50][100],X[100];
	int i,j,k,total=0;

	cin>>N;

	for(i=0;i<N;i++){
		cin>>S[i]>>T[i];
	}
	cin>>X;

	for(i=0;i<N;i++){
		if(strcmp(S[i],X)==0){	//S[i]=Xのときの処理
			while(i<N-1){
				total+=T[i+1];
				i++;
			}
		}
	}

	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
ABC = []
for _ in range(N-1):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))

Q, K = map(int, input().split())
XY = []
for _ in range(Q):
    x,y = map(int, input().split())
    XY.append((x,y))
    
edges = ABC[:]

graph = {}
for a,b,c in edges:
    if not a in graph:
        graph[a] = {}
    if not b in graph:
        graph[b] = {}
    graph[a][b] = c
    graph[b][a] = c


from heapq import heappush, heappop

def dijkstra(graph, start):
    A = [None] * (N+1)
    queue = [(0, start)]
    while queue:
        path_len, v = heappop(queue)
        if A[v] is None: # v is unvisited
            A[v] = path_len
            for w, edge_len in graph[v].items():
                if A[w] is None:
                    heappush(queue, (path_len + edge_len, w))

    # to give same result as original, assign zero distance to unreachable vertices             
    return [0 if x is None else x for x in A]

shortest = dijkstra(graph, K)
#print(shortest)

questions = XY

for x,y in questions:
    ans = shortest[x] + shortest[y]
    print(ans)

Measured memory_bytes: 85856
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC108C
{
    static class MainClass
    {
        public static void Main(string[] args)
        {

            string[] input1 = Console.ReadLine().Split(' ');
            int N = int.Parse(input1[0]);
            int K = int.Parse(input1[1]);

            long cnt = 0;
            long ans = 0;
            long cntk2 = 0;
            long cntk0 = 0;
            if (K % 2 == 1)
            {
                cnt = N / K;

                ans = cnt * cnt * cnt;

            }
            else
            {
                //あまりがK/2のもののペア
                cntk2 = (long)Math.Pow((N + (K / 2)) / K,3);

                //あまりが0のもののペア
                cntk0 = (long)Math.Pow(N / K, 3);

                ans = cntk2 + cntk0;
            }

            Console.WriteLine(ans);
            return;

        }


        public static int Gcd(int a, int b){
            int tmp;
            // a<bにする
            if(a >=b){
                tmp = a;
                a = b;
                b = tmp;
            }

            if (a == 0){
                return b;
            }

            tmp = a;
            a = b % a;
            b = tmp;
            return Gcd(a, b);

        }


    }

}






Measured memory_bytes: 11092
#include <cstdio>

#define MOD 1000000007

using namespace std;

typedef long long ll;

ll x1, x2, x3, x4, x5, x6;
ll y1, y2, y3, y4, y5, y6;
ll factorials[2000001], inverses[2000001];

ll extendedEuclid(ll a, ll b, ll &x, ll &y) {
  if (a == 0) { x = 0; y = 1; return b; }
  ll x1, y1, d = extendedEuclid(b % a, a, x1, y1);
  x = y1 - (b / a) * x1; y = x1;
  return d;
}

ll multInv(ll n, ll p) {
  ll x, y;
  extendedEuclid(n, p, x, y);
  x = ((x % p) + p) % p;
  return x % p;
}

ll lattice(ll x, ll y) {
  return factorials[x + y] * inverses[x] % MOD * inverses[y] % MOD;
}

ll blockA(ll x, ll y) {
  ll res = 0;
  res += lattice(x - x1 + 1, y - y1 + 1);
  res -= lattice(x - x2, y - y1 + 1);
  res -= lattice(x - x1 + 1, y - y2);
  res += lattice(x - x2, y - y2);
  return ((res % MOD + MOD) % MOD);
}

ll blockC(ll x, ll y) {
  ll res = 0;
  res += lattice(x6 - x + 1, y6 - y + 1);
  res -= lattice(x6 - x + 1, y5 - y);
  res -= lattice(x5 - x, y6 - y + 1);
  res += lattice(x5 - x, y5 - y);
  return ((res % MOD + MOD) % MOD);
}

int main() {
  scanf("%lld %lld %lld %lld %lld %lld", &x1, &x2, &x3, &x4, &x5, &x6);
  scanf("%lld %lld %lld %lld %lld %lld", &y1, &y2, &y3, &y4, &y5, &y6);

  factorials[0] = 1;
  inverses[0] = 1;
  for (int i = 1; i <= 2000000; i++) {
    factorials[i] = (factorials[i - 1] * i) % MOD;
    inverses[i] = multInv(factorials[i], MOD);
  }

  ll res = 0;
  for (int i = x3; i <= x4; i++) {
    res -= (i + y3) * blockA(i, y3 - 1) % MOD * blockC(i, y3) % MOD;
    res += (i + y4 + 1) * blockA(i, y4) % MOD * blockC(i, y4 + 1) % MOD;
  }
  for (int i = y3; i <= y4; i++) {
    res -= (i + x3) * blockA(x3 - 1, i) % MOD * blockC(x3, i) % MOD;
    res += (i + x4 + 1) * blockA(x4, i) % MOD * blockC(x4 + 1, i) % MOD;
  }
  printf("%lld\n", (res % MOD + MOD) % MOD);
  return 0;
}


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

int main()
{
  ios::sync_with_stdio(false);
  int a, b, c, t = 0;
  cin >> a >> b >> c;

  while (t < c && b >= a)
  {
    t++;
    b -= a;
  }

  cout << t << "\n";
  return 0;
}

Measured memory_bytes: 256
def ketanowa(p):
    ans=0
    p=str(p)
    for i in p:
        ans+=int(i)
    return ans

def main():
    temp=input()
    n=int(temp)
    temp=input()
    a=int(temp)
    temp=input()
    b=int(temp)
    n=n-a
    k=int(n/b)
    n=n-b*k
    print(n)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(x) (((long long)x)%modulo)



int main(){
	int A,B;
	cin>>A>>B;
	string S;
	cin>>S;
	if(S[B-1]=='A')S[B-1]='a';
	else if(S[B-1]=='B')S[B-1]='b';
	else S[B-1]='c';
	
	cout<<S<<endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using U = unsigned int;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using std::cin; using std::cout;
using std::endl; using std::cerr;
using std::bitset; using std::map;
using std::queue; using std::priority_queue;
using std::set; using std::string;
using std::vector;
using std::pair; using std::make_pair;
using pii = std::pair<int, int>;
using pll = std::pair<LL, LL>;
#ifdef LOCAL
#include <ctime>
void displayTime() { cout << "Current time = " << clock() * 1e3 / CLOCKS_PER_SEC << "ms" << endl; }
#else
void displayTime() {}
#endif
#ifdef DEBUG
#define pass cerr << "[" << __FUNCTION__ << "] : line = " << __LINE__ << endl;
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n) { cerr << #a << " = {"; \
      for(int qwq = (st); qwq <= (n); ++qwq) cerr << a[i] << (qwq == n ? ' ' : '\n'); }
#else
#define pass ;
#define display(x) ;
#define displaya(a, st, n) {}
#endif

template<typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) { return a > b ? a = b, true : false; }
template<typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, true : false; }
#ifdef QUICK_READ
char pool[1<<15|1],*it=pool+32768;
#define getchar() (it>=pool+32768?(pool[fread(pool,sizeof(char),1<<15,stdin)]=EOF,*((it=pool)++)):*(it++))
#endif
inline int readint() {
  int a = 0; char c = getchar(), p = 0;
  while(isspace(c)) c = getchar();
  if(c == '-') p = 1, c = getchar();
  while(isdigit(c)) a = a*10 + c - '0', c = getchar();
  return p ? -a : a;
}
inline LL readLL() {
  LL a = 0; char c = getchar(), p = 0;
  while(isspace(c)) c = getchar();
  if(c == '-') p = 1, c = getchar();
  while(isdigit(c)) a = a*10 + c - '0', c = getchar();
  return p ? -a : a;
}

const int maxN = 2000 + 5;
const int maxK = 2000 + 5;
const LL P = 1000000007;
int n, m, k, len;
LL f[maxN * 2][maxN];

void inc(LL &a, const LL &b) {
  (a += b) >= P ? a -= P : a;
}
void dec(LL &a, const LL &b) {
  (a -= b) < 0 ? a += P : a;
}

LL solve() {
  LL ans = 0;
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for(int i = 0; i < len; ++i) {
    for(int j = std::max(0, i * (k - 1) - n - 1); j <= std::min(m, i * (k - 1)); ++j) {
      LL val = f[i][j];
      if(!val) continue;
//      printf("f[%d][%d] = %lld\n", i, j, f[i][j]);
      for(int t = 0; t < k && j + t <= m; ++t) {
        inc(f[i + 1][j + t], f[i][j]);
        int sum = j + t, com = (i + 1) * (k - 1) - sum;
      	if(t && sum <= m && com <= n - 1 && sum % (k - 1) == m % (k - 1) && com % (k - 1) == (n - 1) % (k - 1))
          inc(ans, f[i][j])/*, printf("t = %d\n", t)*/;
      }
    }
  }
  return ans % P;
}

int main() {
  cin >> n >> m >> k;
  len = (n + m - 1) / (k - 1);
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 63104
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

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

    
    int N;
    cin >> N;
    vector<string> W(N);
    REP(i, N) cin >> W[i];

    bool f = true;
    REP(i, N)REP(j, N){
        if(i != j && W[i] == W[j]){
            f = false;
            break;
        }
    }
    REP(i, N-1){
        if(W[i+1][0] != W[i][W[i].size()-1]){
            f=false;
            break;
        }
    }

    cout << ( f ? "Yes" : "No") << endl;
    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
    long long a1, a2, x, y, i;
    int amari;
     
    while(scanf("%lld%lld",&a1,&a2) != EOF){
        if(a1<=0 && a2==0) break;
        x=a1;
        y=a2;
     
        if(a1<a2){
            x = a2;
            y = a1;
        }
     
        for(i = 0; y > 0; i++){
            amari = x % y;
            x = y;
            y = amari;
     
        }
     	//lcm = a1*a2/x;
        printf("%lld %lld\n", x, a1*a2/x);
    }
        return 0;
}


Measured memory_bytes: 1980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

vector<ll> yakusu(ll n){
    vector<ll> ret;
    for(ll i = 1; i*i <= n; i++){
        if(n % i != 0) continue;
        ret.push_back(i);
        if(i*i != n) ret.push_back(n/i);
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main(){
    ll N, K;
    cin >> N >> K;
    VL A(N);
    rep(i, 0, N) cin >> A[i];
    ll sum = accumulate(ALL(A), 0);
    auto d = yakusu(sum);
    reverse(ALL(d));
    rep(i, 0, d.size()){
        VL r(N);
        rep(j, 0, N) r[j] = A[j]%d[i];
        sort(ALL(r));
        VL L(N+1, 0), R(N+1, 0);
        rep(j, 0, N) L[j+1] = L[j] + r[j];
        for(ll j = N-1; j >= 0; j--) R[j] = R[j+1] + (d[i] - r[j]);
        rep(j, 0, N+1){
            if(L[j] == R[j] && L[j] <= K){
                cout << d[i] << endl;
                return 0;
            }
        } 
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(3*10**5) # 大丈夫か？

N = int(input())
edge = [[] for i in range(N)]
# edge[i] : 頂点 i から出る経路の [距離,行先] の隣接リスト
for _ in range(N-1):
    a,b,c = map(int, input().split())
    edge[a-1].append([c,b-1])
    edge[b-1].append([c,a-1])

D = [-1]*N # K からの距離. 未訪問の場合 -1.
# 今回の問題の場合、木なので経路は 1 通りしか無く、
# K から頂点を順に辿りながらコストを足していくだけで良い
def dfs(src, cost):
    D[src] = cost
    for e in edge[src]:
        if D[e[1]] == -1:
            dfs(e[1], cost + e[0])

def main():
    Q,K = map(int, input().split())
    dfs(K-1, 0)

    for _ in range(Q):
        x,y = map(int, input().split())
        print(D[x-1] + D[y-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 137932
import sys
from collections import defaultdict

nesw = [[0, 1], [0, -1], [1, 0], [-1, 0]]
height, width = map(int, input().split(" "))
root = []
black = 0
for i in range(height):
    temp = [n for n in input()]
    root.append(temp)
    black += temp.count("#")
start_y, start_x = 0, 0
end_y, end_x = height - 1, width - 1

queue = [(start_y, start_x)]
used_white = 1
flag = 0
while queue:
    new_queue = []
    used_white += 1
    for q in queue:
        h, w = q
        for t in nesw:
            new_h, new_w = h + t[0], w + t[1]
            if 0 <= new_h < height and 0 <= new_w < width:
                if new_h == end_y and new_w == end_x:
                    flag = 1
                    break
                elif root[new_h][new_w] != "#":
                    root[new_h][new_w] = "#"
                    new_queue.append((new_h, new_w))
    if flag:
        break
    queue = new_queue
if flag:
    print(height * width - black - used_white)
else:
    print(-1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int a, b, c;
string res = "YES";

int main(){
  cin >> a >> b >> c;
  int fin = a % b;
  int num = (a * 2) % b;
  //cout << fin <<" "<< num <<endl;
  while(true){
    if(num == c){
      res = "YES";
      break;
    }
    if(num == fin){
      res = "NO";
      break;
    }
    num += a;
    num %= b;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import sys

s = sys.stdin.readline().rstrip('\r\n')
ss = ''

for ii in range(len(s)):
  if 'a' <= s[ii] <= 'z':
    ss += s[ii].upper()
  elif 'A' <= s[ii] <= 'Z':
    ss += s[ii].lower()
  else:
    ss += s[ii]

print(ss)



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

int main()
{
	int n;
	string act;
	int status[2];
	int pos=0;
	int count=0;
	status[0] =0;
	status[1] =0;
	/*0 jimen 1 dai*/
	cin >> n;
	while(n)
	{
	pos = 0;
	count =0;
	status[0] = 0;
	status[1] = 0;
	for(int i=0;i<n;++i)
	{
		cin >> act;
		if(act=="lu") status[0]=1;
		else if(act=="ru") status[1]=1;
		else if(act=="ld") status[0]=0;
		else if(act=="rd") status[1]=0;
		if(pos==0 && status[0]==1 && status[1]==1)
		{
			++count;
			pos=1;
		}
		else if(pos==1 && status[0]==0 && status[1]==0)
		{
			++count;
			pos=0;
		}
	}
	cout << count << endl;
	cin >> n;
	}
}
	
	
	

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

int main() {
 int n;
  cin>>n;
  vector<string> s(n);
  map<string,int> p;
  int memo=0;
  for(int i=0;i<n;i++){
    cin>>s[i];
   if(p[s[i]]>0) {p[s[i]]++; memo=max(memo,p[s[i]]) ;continue;}
    p[s[i]]=1;
    memo=max(memo,p[s[i]]);
  }
  vector<string> b;
  for(int i=0;i<n;i++){
    if(p[s[i]]==memo) {
      b.push_back(s[i]);
      p[s[i]]=0;
    }
  }
  sort(b.begin(),b.end());
  for(int i=0;i<b.size();i++){
    cout<<b[i]<<endl;
  }
}

Measured memory_bytes: 29300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  if (n == 1) {
    ans = 0;
  } else {
    ans = 1;
  }
  cout << ans << endl;
  return 0;
}


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

void Main()
{
    string t;
    cin >> t;
    int shisu = 0;
    for(int i = 0; i < t.size(); ++i){
        if(t[i] == '?') t[i] = 'D';
        // if(t[i] == 'D') shisu++;
        // if(i > 0){
        //     if(t[i] == 'D' && t[i-1] == 'P') shisu++;
        // }
    }
    cout << t << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3760
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program {
    internal static void Main(string[] args) {
        int N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => long.Parse(s)).ToList();
        var dic = new Dictionary<long, int>();

        for (int i = 0; i < N; i++) {
            if (dic.ContainsKey(A[i])) {
                dic[A[i]]++;    
            } else {
                dic.Add(A[i], 1);
            }
        }

        var max = dic.OrderByDescending(kvp => kvp.Key)
                     .Where(kvp => kvp.Value >= 4).ToArray();
        long sei = 0L;
        if (max.Length != 0) {
            sei = max[0].Key * max[0].Key;
        }

        var values = dic.OrderByDescending(kvp => kvp.Key)
                        .Where(kvp => kvp.Value >= 2)
                        .Select(kvp => kvp.Key).ToArray();
        if (values.Length < 2) {
            WriteLine(0);
            return;
        }
        long cho = values[0] * values[1];
        WriteLine(Math.Max(sei, cho));
    }
}

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

int main(void) {
  int n;
  cin >> n;
  int s = 0, sum = n;
  while (sum) {
    s += sum % 10;
    sum /= 10;
  }
  cout << (n % s == 0 ? "Yes" : "No") << '\n';
  return 0;
}

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

using namespace std;

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

    vector <int> A(no_of_elements + 1);
    for(int i = 1; i <= no_of_elements; i++)
        cin >> A[i];

    vector <int> sum_till(no_of_elements + 1, 0);
    for(int i = 1; i <= no_of_elements; i++)
        sum_till[i] = sum_till[i - 1] + A[i];

    int minimum_difference = sum_till[no_of_elements];
    for(int i = 1; i <= no_of_elements; i++)
    {
        minimum_difference = min(minimum_difference, abs(sum_till[no_of_elements] - 2*sum_till[i]));
    }

    cout << minimum_difference;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using llGraph = vector<vl>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

template<typename T>
bool CompareBySecond(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

template<typename T>
T GCD(T a, T b) {
  T c = a % b;
  while (c != 0) { a = b; b = c; c = a % b; }
  return b;
}

void solve() {
  int L; cin >> L;
  const int N = 32 - __builtin_clz(L);
  Graph ans;
  int edge = 1;
  rep1(i,N-1) {
    ans.push_back({i, i+1, 0});
    ans.push_back({i, i+1, edge});
    edge <<= 1;
  }
  rep(i,N-1) {
    if ((L>>i) & 1) {
      ans.push_back({i+1, N, edge});
      edge += (1<<i);
    }
  }
  cout << N << ' ' << ans.size() << endl;
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> w(n);

    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        w[i] = {b,a};
    }    
    sort(w.begin(),w.end());
    int now = 0;
    bool ans = true;
    for(int i = 0; i < n; i++){
        if(now+w[i].second > w[i].first) ans = false;
        now += w[i].second;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1792
n = int(input())
t, a = map(int, input().split())
H = input().split()
A = []
for i in H:
    if(((t - int(i) * 0.006)-a)<0):
        A.append(-1*((t - int(i) * 0.006)-a))
    else:
        A.append((t - int(i) * 0.006)-a)
print(A.index(min(A))+1)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;

int main() {
    string str;
    cin >> str;

    if (str.size() == 2) {
        cout << str;
    } else {
        cout << str[2] << str[1] << str[0];
    }

    return 0;
    


}

Measured memory_bytes: 256
from math import floor

# 入力値の取得
A, B = map(int, input().split())

# 問題の制約から、答えの候補としてあり得る範囲をチェック
# for _ in range(1010)で０〜１００９までのループが使える
for price in range(1010):
    if (floor(price * 0.08) == A) and (floor(price * 0.1) == B):
        # 条件を満たしたのでその金額を表示して終了
        # （小さい金額から順番にみていくので、最初に条件を満たしたものが、
        # 　条件を満たす金額のうちで最小の金額になる。）
        print(price)
        quit()

# 条件を満たすものが見つかっていれば、プログラムが終了するので、
# ここまで実行される時は、条件を満たす金額が存在しないということなので、
# 条件を満たす金額が存在しない時に表示すべき -1 を表示する。
# 最小行なので、quit()しなくてもプログラムが終了する
print(-1)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

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

    vector <int> idx(n, 0);
    vector <bool> removed(m+1, false);
    int mn = n;

    while (true) {
        map <int, int> mp;
        int mx = 0;
        int mx_team;
        for (int i = 0; i < n; i++) {
            int t = A[i][idx[i]];
            if (++mp[t] > mx) {
                mx = mp[t];
                mx_team = t;
            }
        }

        mn = min(mn, mx);
        removed[mx_team] = true;

        bool breaker = false;
        for (int i = 0; i < n; i++) {
            while (removed[A[i][idx[i]]]) {
                if (++idx[i] >= m) {
                    breaker = true;
                    break;
                }
            }
        }

        if (breaker) break;
    }

    cout << mn << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
void in_rectangle(int, int, int, int, int);
int main() {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  in_rectangle(w, h, x, y, r);
}
void in_rectangle(int w, int h, int x, int y, int r) {
  if ((x-r >= 0) && (x+r <= w) && (y-r >= 0) && (y+r <= h))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

#define lli long long
#define sz(A) (int)A.size()
#define lsz(A) (long long)A.size()
#define INT_INF (long long int)(1e18 + 7)


// Compiling command
// g++ -02 -Wall <question_name>.cpp -o <question_name>

int main(int argc, char const *argv[]){

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    lli a, b, c, d;
    cin >> a >> b >> c >> d;
    lli maxi = -(INT_INF);
    for(int i = 0 ; i < 2; i++){
        for(int j = 0; j < 2; j++){
            if(c + j <= d && a + i <= b && d - j >= c && b - i >= a){
                maxi = max((a + i) * (c + j), maxi);
                maxi = max((a + i) * (d - j), maxi);
                maxi = max((b - i) * (d - j), maxi);
                maxi = max((b - i) * (c + j), maxi);
            }
        }
    }
    
    cout << maxi << endl;
    
    return 0;
}



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

typedef long long ll;
typedef pair<ll, int> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(void) { 
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> R(N), L(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    L[0] = A[0];
    for (int i = 1; i < N; i++) {
        L[i] = GCD(L[i - 1], A[i]);
    }
    R[N - 1] = A[N - 1];
    for (int i = N - 2; i >= 0; i--) {
        R[i] = GCD(R[i + 1], A[i]);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if(i==0){
            ans = max(ans, R[i + 1]);
        }
        else if(i==N-1){
            ans = max(ans, L[i - 1]);
        }
        else{
            ans = max(ans, GCD(L[i - 1], R[i + 1]));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
import math
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  ci, si, fi = list(map(int, input().split()))
  c.append(ci)
  s.append(si)
  f.append(fi)

for i in range(n-1):
  t = s[i]
  for j in range(i, n-2):
    t = t + c[j]

    if t > s[j+1]:
      cycle = math.ceil((t - s[j+1]) / f[j+1])
      t = s[j+1] + cycle * f[j+1]
    else:
      t = s[j+1]
  t = t + c[n-2]
  print(t)
print(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define ll long long
#define int ll
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;
using cd = int;
const bool debug = 0;
const int mod = 1000000007;
struct Disjoint_Set_Union
{
#define V 201010
    int parent[V], size[V];
    Disjoint_Set_Union(int N = V-1)
    {
        init(N);
    }
    void init(int N)
    {
        for(int i=1;i<=N;i++)
        {
            parent[i]=i;
            size[i]=1;
        }
    }
    int Find(int K)
    {
        while(K!=parent[K])
        {
            parent[K]=parent[parent[K]];
            K=parent[K];
        }
        return K;
    }
    void unite(int x, int y)
    {
        int u=Find(x), v=Find(y);
        if(u==v)
            return;
        if(size[u]>size[v])
            swap(u, v);
        size[v]+=size[u];
        size[u] = 0;
        parent[u] = parent[v];
    }
} DSU;

int32_t main()
{
    usecppio
    int n, m; cin >> n >> m;
    DSU.init(n);
    for (int i = 0; i<m; i++)
    {
        int u, v; cin >> u >> v;
        DSU.unite(u, v);
    }
    int ans = 0;
    for (int i = 1; i<=n; i++)
        ans = max(ans, DSU.size[i]);
    cout << ans << '\n';
}


Measured memory_bytes: 6788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    vin h(n);
    rep(i,n)cin>>h[i];
    int max=0;
    int sum=0;
    rep(i,n-1){
        if(h[i]>=h[i+1])sum++;
        else sum=0;
        if(max<sum)max=sum;
    }
    cout<<max<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    char c;
    int x=0,M=0;
    for (int i = 0; i < n; i++)
    {
        cin >> c;
        if (c=='I')
        {
            x++;
        }
        else
        {
            x--;
        }
        M = max(x,M);
    }
    cout << M << endl;
}


Measured memory_bytes: 3596
/**
 * > Author : TISparta
 * > Date : 18-02-19
 * > Tags : DP
 * > Difficulty : 3 / 10
 */

#include <bits/stdc++.h>

using namespace std;

const int INF = INT_MAX;

int main () {
  int n, k;
  cin >> n >> k;
  vector <int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  vector <int> dp(n, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= i + k and j < n; j++) {
      dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n - 1] << endl;
  return (0);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bs binary_search
#define pb push_back
#define pp pair<ll,ll>
#define all(v) v.begin(),v.end()
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
int main() 
{
    fastio
    ll n,i,j,s=1; cin>>n;
    for(i=2;i<=n;i++)
    {
        for(j=i;j<=n;j+=i) s+=j;
        s+=i;
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <math.h>

int main(void){
    int n,i;
    int x[100],y[100];
    double p1,p2,p3,pinf;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&y[i]);
    }
    p1 = p2 = p3 = pinf = 0;
    for(i = 0;i<n;i++){
        p1 += fabs(x[i] - y[i]);
    }
    
    printf("%f\n",p1);
    for(i=0;i<n;i++){
        p2 += fabs(x[i] - y[i]) * fabs(x[i] - y[i]);
    }
    p2 = sqrt(p2);
    
    printf("%f\n",p2);
    for(i = 0;i<n;i++){
        p3 += fabs(x[i] - y[i]) * fabs(x[i] - y[i]) * fabs(x[i] - y[i]);
    }
    p3 = pow(p3,1.0 / 3.0);
    
    printf("%f\n",p3);
    pinf = fabs(x[0] - y[0]);
    for(i = 1;i<n;i++){
        if(fabs(x[i] - y[i]) > pinf){
            pinf = fabs(x[i] - y[i]);
        }
    }
    printf("%f\n",pinf);
    return 0;

}

Measured memory_bytes: 672
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    LL h;
    cin>>h;
    LL ans=1;
    int cnt=0;
    while(h>1){
        h=h/2;
        cnt++;
    }
    for(int i=0;i<cnt;i++){
        ans=ans*2+1;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> c(n, vector<int>(m+1));
    int res = -1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m+1; ++j) {
            cin >> c[i][j];
        }
    }
    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<vector<int>> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S.push_back(c[i]);
            }
        }

        vector<int> tmp(m+1);
        for (int i = 0; i < (int)S.size(); ++i) {
            for (int j = 0; j < m+1; ++j) {
                tmp[j] += S[i][j];
            } 
        }
        int flg = 0;
        for (int i = 1; i < m+1; ++i) {
            if (tmp[i] >= x) ++flg;
        }
        if (flg == m) {
            if (res == -1) {
                res = tmp[0];
            }
            else {
                res = min(res, tmp[0]);
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<ll, ll> P;
const int MAXN = 1e5 + 7;
const int LOG = 20;
const int INF = 0x3f3f3f3f;

bool check(string s) {
    int len = s.size();
    for(int i = 0,j = s.size()-1;i <= j;i++,j--){
        if(s[i] != s[j])
            return false;
    }
    return true;
}

void solve() {
    string s;
    cin >> s;
    if(!check(s)){
    	cout << "No" << endl;
    	return ;
	}
    int len = s.size();
    s.insert(0,1,' ');
    string ans1 = "", ans2 = "";
    for(int i = 1;i <= (len-1)/2;i++){
        ans1 += s[i];
    }
    for(int i = (len+3)/2;i <= len;i++)
        ans2 += s[i];
    //cout << ans1 << endl << ans2 << endl;
    if(check(ans1) && check(ans2))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int T;
    T = 1;
    while(T--) {
        solve();
    }
    return 0;
}


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

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

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	ll a, b, n;
	cin >> a >> b >> n;

	ll x = min(n, b-1);
	cout << a*x/b - 5 * (x/b) << endl;
	return 0;
}

Measured memory_bytes: 3652
import sys

MOD = 2019

l, r = map(int, sys.stdin.readline().split())

def main():
    if r - l >= MOD - 1:
        return 0
    lm = l % MOD
    rm = r % MOD
    if lm == 0 or lm > rm:
        return 0
    else:
        res = MOD - 1
        for i in range(l, r):
            for j in range(i+1, r+1):
                res = min(res, i % MOD * j % MOD)
        return res
        
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int N;
int main() {
	cin>>N;
	long long a[N];
	for(int i=0; i<N; i++){
		cin>>a[i];
	}
	sort(a, a+N);
	int l=a[N-1], r=a[N-1];
	int i=0, j=N-2;
	long long int sum=0;
	while(i<j){
        int li=abs(l-a[i]),ri=abs(r-a[i]);
        int lj=abs(l-a[j]),rj=abs(r-a[j]);
        if(li>ri||lj>rj){ 
                if(li>lj){
                        sum+=li; l=a[i++];
                }else{
                        sum+=lj; l=a[j--];
                }
        }else{
                if(ri>rj){
                        sum+=ri; r=a[i++];
                }else{
                        sum+=rj; r=a[j--];
                }
        }
	}
	sum+=max(abs(l-a[i]),abs(r-a[i]));
	cout<<sum<<endl;
}

Measured memory_bytes: 1024
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(N)]
c = 0
for i in range(N):
    if sum([A[i][j] * B[j] for j in range(len(B))]) + C > 0:
        c += 1
print(c)

Measured memory_bytes: 3064
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function

main :: IO ()
main = do
  getLine
  as <- map read . words <$> getLine :: IO [Int]
  print $ length $ filter even as



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

int main(){
    int cnt;
    int n,fig;
    int min,max,mid;
    while(1){
        cnt = 0;
        cin >> n;
        min = 0;
        max = n-1;
        int num[n];
        if(n == 0) break;
        for(int i=0;i<n;i++) cin >> num[i];
        cin >> fig;
        while(min <= max){
            mid = (min + max)/2;
            if(num[mid] == fig){
                cnt++;
                break;
            }
            else if(num[mid] < fig){
                min = mid + 1;
                cnt++;
            }
            else if(num[mid] > fig){
                max = mid - 1;
                cnt++;
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;

int main(){
    int S,W;
    cin>>S>>W;
    if(W>=S){
        cout<<"unsafe";
    }else{
        cout<<"safe";
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6;
ll a[N],sum,n,m;
int main() {
    int n;
    cin>>n;
    for(int i=2;i<=n;i++) {
        int x;cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++) printf("%lld\n",a[i]);

}


Measured memory_bytes: 5216
#include <iostream>
#include<cstdio>
#include <math.h>
using namespace std;
int main(void){

    
    int s=0;
    int x,i,amari,sum;
    cin>>x;
    i= x/100;
    sum=0;
    amari=x%100;

    for(int a=5;a>0;a--){
        sum+=amari/a;
        amari%=a;
        
      // cout<<sum<<" "<<amari<<endl;
    }
    if(i>=sum){
        cout<<"1"<<endl;
    }
       else cout<<"0"<<endl;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=310;
const int inf=2147483647;
const int mod=998244353;
const int inv=(mod+1)/2;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
void upd(int&x,int y){x+=y;if(x>=mod)x-=mod;}
int Pow(int x,int y)
{
	if(!y)return 1;
	int t=Pow(x,y>>1),re=(LL)t*t%mod;
	if(y&1)re=(LL)re*x%mod;
	return re;
}
int f[Maxn*Maxn],g[Maxn*Maxn],a[Maxn],n;
int main()
{
	memset(f,0,sizeof(f));
	memset(g,0,sizeof(g));
	n=read();
	f[0]=Pow(2,n);g[0]=1;int s=0;
	for(int i=1;i<=n;i++)
	{
		int x=read();s+=x;
		for(int k=s;k>=x;k--)
		upd(f[k],(LL)f[k-x]*inv%mod),upd(g[k],g[k-x]);
	}
	int ans=Pow(3,n);
	for(int j=(s+1)/2;j<=s;j++)
	if(f[j])upd(ans,mod-(LL)3LL*f[j]%mod);
//	printf("%d %d %d\n",i,j,f[i][j]);
//	printf("%d\n",ans);
	if(!(s&1))upd(ans,(LL)3LL*g[s/2]%mod);
	printf("%d",ans);
}

Measured memory_bytes: 1152