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

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	int okIndex = -1;

	if (S.size() < T.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	for (size_t i = 0; i <= S.size() - T.size(); i++) {
		bool isOK = true;
		string sb = S.substr(i, T.size());
		for (size_t j = 0; j < T.size(); j++) {
			if (sb[j] == T[j]) {
				continue;
			} else if (sb[j] == '?') {
				sb[j] = T[j];
			} else {
				isOK = false;
			}
		}
		if (isOK) {
			okIndex = i;
		}
	}

	if (okIndex != -1) {
		for (size_t k = 0; k < S.size(); k++) {
			if ((size_t)okIndex <= k && k < okIndex + T.size()) {
				cout << T[k - okIndex];
			} else if (S[k] == '?') {
				cout << 'a';
			} else {
				cout << S[k];
			}
		}

		cout << "\n";

		return 0;
	}

	cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    line = input()
    n, T = [int(x) for x in line.split()]
    lista_tempos = []
    lista_custos = []
    for i in range(n):
        line = input()
        c, t = [int(x) for x in line.split()]
        if t <= T:
            lista_tempos.append(t)
            lista_custos.append(c)
    if lista_tempos:
        print(min(lista_custos))
    else:
        print('TLE')
main()

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   while (1) {
      string s;
      getline(cin, s);
      if (s == ".") break;

      int n = s.size();
      stack<char> stk;
      bool ng = false;
      for (int i = 0; i < n; i++) {
         if (s[i] == '(') stk.push(s[i]);
         if (s[i] == '[') stk.push(s[i]);
         if (s[i] == ')') {
            if (stk.size() == 0 || stk.top() != '(') {
               ng = true;
               break;
            }
            stk.pop();
         }
         if (s[i] == ']') {
            if (stk.size() == 0 || stk.top() != '[') {
               ng = true;
               break;
            }
            stk.pop();
         }
      }
      if (!ng && stk.empty()) {
         puts("yes");
      } else {
         puts("no");
      }
   }

   return 0;
}


Measured memory_bytes: 3220
s = [int(i) for i in list(input())]
n = len(s)
patA = [i % 2 for i in range(n)]
patB = [i % 2 for i in range(1,n+1)]
diffA = [0]*n
diffB = [0]*n
for i in range(n):
  diffA[i] = s[i] - patA[i]
  diffB[i] = s[i] - patB[i]
ans = [0,0]
ans[0] = len([i for i in diffA if i == 0])
ans[1] = len([i for i in diffB if i == 0])
print(min(ans))

Measured memory_bytes: 7708
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------


int main(){
	int a,p; cin >> a >> p;
	int ret = (a*3+p)/2;
	cout << ret;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL  INF=1<<31;
const LL MOD=1000000007;



int main(){
     int k,s;
     cin>>k>>s;
     int ans=0;
     for(int i=0;i<=k;++i){
          for(int j=0;j<=k;++j){
               int z=s-i-j;
               if(0<=z&&z<=k){
                    ans++;
               }
          }
     }
     cout<<ans<<endl;
}
     

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

const int INF=1001001001;
vector<int> to[100005];

int main(){
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n,INF);//距離
    vector<int> pre(n,-1);
    dist[0]=0;
    q.push(0);
    while(!q.empty()){
        int v=q.front(); q.pop();
        for(int u: to[v]){
            if(dist[u]!=INF) continue;
            dist[u]=dist[v]+1;
            pre[u]=v;
            q.push(u);
        }
    }
    cout<<"Yes"<<endl;
    rep(i,n){
        if(i==0)continue;
        int ans=pre[i];
        ++ans;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 10520
#include<stdio.h>
#include<string.h>
#define LEN 500001
#define NIL -1

int trance_command(char []);
void insert(int);
int find(int, int);
int minimum(int);
int successor(int);
void delete(int);
void print();
void inorder(int);
void preorder(int);

int P[LEN], L[LEN], R[LEN], Key[LEN];
int root=NIL;

int main()
{
  char command[10];
  int n, id;
  int z=0;
  int i, j, k;

  //intelization
  for(i=0; i<LEN; i++)
    {
      P[i]=NIL;
      L[i]=NIL;
      R[i]=NIL;
      Key[i]=NIL;
    }

  //read
  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%s", command);
      //insert
      if(trance_command(command)==0)
	{
	  scanf("%d", &id);
	  Key[z]=id;
	  insert(z);
	  z++;
	}
      //print
      else if(trance_command(command)==1)
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
      //find
      else if(trance_command(command)==2)
	{
	  scanf("%d", &id);
	  j=find(root, id);
	  if(j!=NIL)printf("yes\n");
	  else printf("no\n");
	}
      //delete
      else if(trance_command(command)==3)
	{
	  scanf("%d", &id);
	  delete(find(root, id));
	}
    }

  return 0;
}


//-------------------------
//this method is trancing command.
int trance_command(char c[])
{
  if(strcmp(c, "insert")==0)return 0;
  else if(strcmp(c, "print")==0)return 1;
  else if(strcmp(c, "find")==0)return 2;
  else if(strcmp(c, "delete")==0)return 3;
}

void insert(int z)
{
  int y=NIL;
  int x=root;

  while(x!=NIL)
    {
      y = x;
      if(Key[z]<Key[x])x = L[x];
      else x = R[x];
    }
  P[z]=y;

  if(y==NIL)root=z;
  else if(Key[z]<Key[y])L[y]=z;
  else R[y]=z;
}

int find(int x, int key)
{
  while(x!=NIL && key!=Key[x])
    {
      if(key < Key[x])x=L[x];
      else x=R[x];
    }
  return x;
}

int minimum(int x)
{
  while(L[x]!=NIL)x = L[x];
  return x;
}
int successor(int x)
{
  int y;
  if(R[x]!=NIL)return minimum(R[x]);
  y=P[x];
  while(y!=NIL && x==R[y])
    {
      x=y;
      y=P[y];
    }
  return y;
}

void delete(int z)
{
  int y;
  int x = z;
  if(L[x]==NIL || R[x]==NIL)y=z;
  else y=successor(z);

  if(L[y]!=NIL)x=L[y];
  else x=R[y];

  if(x!=NIL)P[x]=P[y];
  if(P[y]==NIL)root=x;
  else if(y==L[P[y]])L[P[y]]=x;
  else R[P[y]]=x;

  if(y!=z)Key[z]=Key[y];
  //return y;
}

void inorder(int t)
{
  if(t!=NIL)
    {
      inorder(L[t]);
      printf(" %d", Key[t]);
      inorder(R[t]);
    }
}

void preorder(int t)
{
  if(t!=NIL)
    {
      printf(" %d", Key[t]);
      preorder(L[t]);
      preorder(R[t]);
    }
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
ll x[maxn], y[maxn];



//1-indexed DSU
struct DSU {
    int n;
    vector<int> siz, par;
    int init_calls;
    DSU() {
	init_calls = 0;
    }
    void init(int n) {
	assert(++init_calls == 1);
	this->n=n;
	siz.resize(n+10, 1);
	par.resize(n+10);
	for (int i=1; i<=n; i++) par[i] = i;
    }
    int parent(int x) {
	assert(init_calls == 1);
	assert(x>=1 && x<=n);
	if (x == par[x]) return x;
	return par[x] = parent(par[x]);
    }
    bool join(int x, int y) {
	assert(init_calls == 1);
	x = parent(x);
	y = parent(y);
	if (x == y) return false;
	if (siz[x]<siz[y]) swap(x,y);
	par[y] = x;
	siz[x] += siz[y];
	return true;
    }
    void clear() {
	init_calls = 0;
	n = 0;
	siz.clear();
	par.clear();
    }
};


ll dist(pair<int,int> p) {
    int i = p.first;
    int j = p.second;
    return min(abs(x[i]-x[j]), abs(y[i]-y[j]));
}





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

    cin>>n;

    for (int i=1; i<=n; i++) {
	cin>>x[i]>>y[i];
    }

    DSU dsu;
    dsu.init(n);
    vector<pair<ll,pair<ll,ll>>> edges;

    {   
	vector<pair<ll,ll>> v;
	for (int i=1; i<=n; i++) {
	    v.push_back({x[i],i});
	}
	sort(v.begin(), v.end());
	for (int i=1; i<n; i++) {
	    ll a = v[i-1].second;
	    ll b = v[i].second;
	    ll wei = v[i].first-v[i-1].first;
	    edges.push_back({wei,{a,b}});
	}
    }

    {
        vector<pair<ll,ll>> v;
	for (int i=1; i<=n; i++) {
	    v.push_back({y[i],i});
	}
	sort(v.begin(), v.end());
	for (int i=1; i<n; i++) {
	    ll a = v[i-1].second;
	    ll b = v[i].second;
	    ll wei = v[i].first-v[i-1].first;
	    edges.push_back({wei,{a,b}});
	}
    }


    sort(edges.begin(), edges.end());
    ll res=0;
    for (auto p: edges) {
	int a = p.second.first;
	int b = p.second.second;
	if (dsu.join(a,b)) {
	    res += p.first;
	}
    }

    out(res);

    return 0;
}


Measured memory_bytes: 18128
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    while(1){
        int n, m; cin>>n>>m;
        if(n == 0) return 0;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin>>a[i];

        int ans = 0;
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                int price = a[i] + a[j];
                if(m < price) continue;
                chmax(ans, price);
            }
        }

        if(ans == 0) cout << "NONE" << endl;
        else cout << ans << endl;
    }
}


Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int main(){
    std::string s;
    std::cin >> s;
    
    int res = 0;
    REP(i, s.size()/2){
        char a = s[i], b = s[s.size()-1-i];
        if(a > b){std::swap(a, b);}
        if((std::isalpha(a) && std::isalpha(b) && a == b) || (a == '(' && b == ')'));
        else{
            // printf("%c, %c\n", a, b);
            res++;
        }
    }

    if(s.size() % 2 == 1 && !(s[s.size()/2] == 'i' || s[s.size()/2] == 'w')){
        res++;
    }
    
    std::cout << res << std::endl;
}

Measured memory_bytes: 1184
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

long long COMB[2008][2008];
long long MOD = 1000000007;
long long comb(long long a, long long b) {
  if (b < 0) return 0;
  if (b > a) return 0;
  return COMB[a][b];
}

int main() {
  long long N, K;
  cin >> N >> K;

  COMB[0][0] = 1;
  for (long long i = 1; i < N + 5; i++) {
    for (long long j = 0; j <= i; j++) {
      COMB[i][j] = 0;
      if (j > 0) COMB[i][j] += COMB[i - 1][j - 1];
      COMB[i][j] += COMB[i - 1][j];
      COMB[i][j] %= MOD;
    }
  }


  for (long long i = 0; i < K; i++) {
    long long ans = comb(K - 1, i) * comb(N - K + 1, N - K - i);
    ans = (ans % MOD + MOD) % MOD;
    cout << ans << endl;
  }

  return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,r;
  cin >> n >> r;
  if(n >= 10){
    ANS(r);
  }else{
    ANS(r + 100 * (10 - n));
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
long long Array[10];

int main(){
    long long N , Min = 1e18;
    int i , index = 0;
    scanf( "%lld\n" , &N );

    for( i = 1 ; i <= 5 ; ++i ){
        scanf( "%lld" , Array + i );

        if( Array[i] < Min ){
            Min = Array[i];
            index = i;
        }
    }

    long long Ans = (long long)ceil( (long double)N / Array[index] ) + 4;
    printf( "%lld\n" , Ans ); 
    return 0;
}

Measured memory_bytes: 256
n=int(input())
hl=list(map(int,input().split()))
count=0
temp_count=0
for i in range(n-1):
    if hl[i]>=hl[i+1]:
        temp_count+=1
    else:
        if count<temp_count:
          count=temp_count
        temp_count=0
if count<temp_count:
    count=temp_count
print(count)

Measured memory_bytes: 15760
n,z,w = map(int,input().split())

al = list(map(int,input().split()))
if len(al) == 1:
    print(abs(al[-1] - w))
    exit()
ans1 = abs(al[-1] - al[-2])
ans2 = abs(al[-1] - w)

print(max(ans1, ans2))


Measured memory_bytes: 38640
n,k,q = map(int,input().split())
a = [0] * q

member = [k] * n

for i in range(q):
    a[i] = int(input())
    member[a[i]-1] = member[a[i]-1] + 1

for j in range(n):
    if member[j] - q <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 10432
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<string> vs(N);
  FOR(i,0,N) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    vs[i] = s;
  }
  sort(vs.begin(), vs.end());
  ll ans = 0;
  ll cnt = 1;
  FOR(i,0,N-1) {
    if (vs[i] == vs[i+1]) {
      cnt++;
    } else {
      if (cnt > 1) {
        ans += cnt * (cnt - 1) / 2;
      } 
      cnt = 1;
    }
  }
  if (cnt > 0) {
    ans += cnt * (cnt - 1) / 2;
  }
  cout << ans << endl;
}



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

using namespace std;

long long power(int x, int y){
  long long n = 1;
  for(int i = 0; i < y; i++)
    n *= x;
  return n;
}

int log(int x, int y){
  int cnt = 0;
  while(y > 1){
    y /= x;
    cnt++;
  }
  return cnt;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n-1);
  for(int i = 0; i < n-1; i++)
    cin >> b.at(i);
  a.at(0) = b.at(0);
  a.at(n-1) = b.at(n-2);
  for(int i = 1; i <= n-2; i++)
    a.at(i) = min(b.at(i),b.at(i-1));
  
  int ans;
  for(int i = 0; i < n; i++)
    ans += a.at(i);
  
  cout << ans << endl;
}


Measured memory_bytes: 256
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i + 1, f + '+' + s[i + 1], sum + int(s[i + 1]))
        dfs(i + 1, f + '-' + s[i + 1], sum - int(s[i + 1]))


s = input()
dfs(0, s[0], int(s[0]))


Measured memory_bytes: 3060
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define INFLL 1000000000000000000LL
#define MOD 1000000007
#define PI acos(-1)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>

using namespace std;

// clang-format on

main {
  int h, w;
  cin >> h >> w;
  cout << string(w + 2, '#') << endl;
  rep(i, h) {
    string a;
    cin >> a;
    cout << '#' << a << '#' << endl;
  }
  cout << string(w + 2, '#') << endl;
}


Measured memory_bytes: 256
// #include "testlib.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<ll,ll>
#define se second
#define double long double
#define mod 1000000007
#define popcount __builtin_popcountll
const double PI = acos(-1.0);
using namespace std;
#define MXN 3005
int n, m;
int a[88][88];
int b[88][88];
int dp[80][80][15626];
int cal(int i, int j, int s){
    if(i==n || j==m || s>=15626)return 1e8;
    if(i==n-1 && j==m-1){
        int d = a[i][j]-b[i][j];
        return min(abs(s+d), abs(s-d));
    }
    int &ret = dp[i][j][s];
    if(ret!=-1)return ret;
    ret = 1e8;
    int d = a[i][j]-b[i][j];
    ret = cal(i+1, j, abs(s+d));
    ret = min(ret, cal(i+1, j, abs(s-d)));
    ret = min(ret, cal(i, j+1, abs(s+d)));
    ret = min(ret, cal(i, j+1, abs(s-d)));
    return ret;
}
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d", &a[i][j]);
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d", &b[i][j]);
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<cal(0,0, 0)<<endl;
}


Measured memory_bytes: 390912
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;

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


int main() {
    string s; cin >> s;
    int Min = 1000;
    char word;

    vector<int> m(26,0),w(26,0);
    rep(i,s.length()){
        m[(int)(s[i]-'a')] = 1;
    }

    if(s.length() == 26){
        w[(int)(s[s.length()-1]-'a')] = 1;
        for(int i = s.length()-2; i >= 0; i --){
            if(s[i] < s[i+1]){
                rep(j,26){
                    if(w[j] == 1){
                        if(('a' + j) - s[i]> 0 && Min > abs(s[i] - ('a' + j))) {
                            Min = abs(s[i] - ('a' + j));
                            word = (char)('a' + j);
                        }
                    }
                }
                string r = s.substr(0,i);
                cout << r << word;
                return 0;
            }else{
                w[(int)(s[i]-'a')] = 1;
            }

            if(i == 0){
                cout << -1;
                return 0;
            }
        }
    }else{
        rep(i,26){
            if(m[i] == 0){
                cout << s << (char)('a' + i);
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff  first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 2e5+9;
const lli mod= 1000000007;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli digit(lli n){int res=(int)log10(n)+1;return res;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}
///=================== ALWAYS CHECK 1 or 0 base case=================================================================================///
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///
lli pre[maxn];
void solve()
{
    int n;cin>>n;
    lli lol[n];
    for(int i=0;i<n;i++)cin>>lol[i];
    pre[n-1]=lol[n-1];
    for(int i=n-2;i>=0;i--)
    {
        pre[i]=(lol[i]+pre[i+1])%mod;

    }
//    for(int i=0;i<n;i++)cout<<pre[i]<<" ";
//    cout<<endl;
    lli ans=0;

    for(int i=0;i<n;i++)
    {
        ans=(ans%mod+(((pre[i]-lol[i]+mod)%mod)*lol[i]%mod)%mod )%mod;
    }
    cout<<ans<<endl;
}
int main()
{
    solve();
}


Measured memory_bytes: 6800
S = list(input())
N = len(S)
K = int(input())
ans = []
for start in range(N):
    for end in range(K):
        if start + end >= N:
            break
        sentinel = min(N - 1 , start + end)
        ans.append(S[start:sentinel + 1])

i = 0
ans.sort()
answer = []
while len(answer) < K:
    if not ans[i] in answer:
        answer.append(ans[i])
    i += 1
print("".join(answer[K - 1]))

Measured memory_bytes: 5748
#include<iostream>
#include<vector>
using namespace std;
long long a[2000];
long long money=1000;
long long num=0;
int main() {
	int n;
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	vector<int>v;
	for(int i=0; i<n; i++) {
		if(a[i]!=a[i-1]) {
			v.push_back(a[i]);
		}
	}
	int len=v.size();
	int flag;


	if(v[1]>v[0]) flag=1;
	else flag=-1;

	if(flag==1) {
		num=1000/v[0];
		money=1000-num*v[0];
	}
	bool f=true;
	for(int i=1; i<len; i++) {
		int temp;
		if(v[i]>v[i-1]) {
			temp=1;
		} else {
			temp=-1;
		}
		if(temp!=flag) {
			f=false;
			if(flag==1) {//卖
				money+=num*v[i-1];
				num=0;
			}
			if(flag==-1) {//买
				num=money/v[i-1];
				money=money-num*v[i-1];
			}
			flag=-flag;
		}
	}
	if(f==true) {
		if(flag==1) cout<<1000-1000/v[0]*v[0]+1000/v[0]*v[len-1]<<endl;
		if(flag==-1) cout<<1000<<endl;
	} else {
		if(flag==1) money+=num*v[len-1];
		cout<<money<<endl;
	}

}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int N;
  int Y;
  cin >> N >> Y;
  Y /= 1000;
  for (auto i = 0; i <= N; ++i) {
    for (auto j = 0; j <= N-i; ++j) {
      int k = N - i - j;
      if (10 * i + 5 * j + k == Y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}


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


int main() {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> bs(m);
    for (int i = 0; i < m; i++) {
        cin >> bs.at(i);
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = 0; j < m; j++) {
            int num;
            cin >> num;
            sum += num * bs.at(j);
        }
        if (sum + c > 0) count++;
    }
    cout << count << endl;
    return 0;
}


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

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

			var S = Console.ReadLine();
			var Q = int.Parse(Console.ReadLine());

			var l = new LinkedList<string>();
			foreach (var item in S) {
				l.AddLast(item.ToString());
			}

			//反転フラグ
			Boolean hantenFlag = false;
			for (int i = 0; i < Q; i++) {
				var inputArray = Console.ReadLine().Split(' ');

				
				// 最初に与えられるのは1か2のみ
				if (int.Parse(inputArray[0]) == 1) {
					//1が与えられたときは反転フラグを逆にする
					hantenFlag = !hantenFlag;
				}
				else {
					//要素が足りない場合はエラーメッセージ
					if (inputArray.Length < 3) {
						Console.WriteLine("不正な入力");
						return;
					}

					//反転フラグがFlaseのときは、1の時に前にたす　trueのときは2の時まえにたす
					if ((int.Parse(inputArray[1]) == 1 & hantenFlag == false) | (int.Parse(inputArray[1]) == 2 & hantenFlag == true)) {
						l.AddFirst(inputArray[2]);
					}
					else {
						l.AddLast(inputArray[2]);
					}

				}

			}

		var fin = new List<string>();
			if (hantenFlag) {
				 fin =l.Reverse().ToList();
			}
			else {
				fin = l.ToList();
			}

			var sb = new StringBuilder();
			foreach (var item in fin) {
				sb.Append(item);
			}
		Console.WriteLine(sb.ToString());

		}

		
	}
}


Measured memory_bytes: 50592
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
int check(int num ){
    
    int num1 = pow(num , 0.2);
    
    int ans = num1;
    
    num1 = pow(num1,5);
    
    if(num1 == num){
        return ans;
    }
    
    return 0;
}
int32_t main(){
    
    int x;
    cin>>x;
    map<int,int>cn;
    
    int a,b;
    for(int j = -5000; j <= 5000 ; j++ ){
            int num = pow(j,5) + x;
            int a1 = check(num);
            
            // cout<<a1<<" "<<num<<endl;
            if(a1!=0){
             //   cout<<a1<<" "<<j<<endl;
                a=a1;
                b=j;
                break;
            }
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 4204
K = int(input())

ans = 0
ans2 = 0


import math

for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            tmp = math.gcd(i,j)
            ans += math.gcd(tmp,k)
            
for i in range(1,K+1):
    for j in range(i+1,K+1):
        for k in range(j+1,K+1):
            tmp3 = math.gcd(i,j)
            ans2 += math.gcd(tmp3,k)
      
tmp2 = 0

for i in range(1,K+1):
    tmp2 += i
    
print((ans - tmp2 - ans2)*3 + ans2*6 + tmp2)
            

Measured memory_bytes: 9224
// ABC169-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
//typedef pair<int, int> pair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

map<ll,ll> sosu;
void bunkai(ll x){
    ll num=x;
    for(int i=2;i<=ll(sqrt(x));i++){
        while(num%i==0){
            num/=i;
            if(sosu.count(i)==1) sosu[i]++;
            else sosu[i]=1;
        }
    }
    if(num!=1) sosu[num]=1;
}
vector<int> max_(100);
int count(ll x){
    for(int i=1;i<=50;i++){
        if(x<max_[i]) return i-1;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    ll n;
    cin>>n;
    //cout<<sqrt(n);
    bunkai(n);
    max_[1]=1;
    for(int i=2;i<=50;i++){
        max_[i]=max_[i-1]+i;
    }
    ll ans=0;
    for(auto p:sosu){
        ans+=count(p.second);
        //cout<<p.first<<" "<<p.second<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3700
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 100, MAXI = 100001, D = 9;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 100, flag = 1;
//     cout << tc << "\n";
//     int n = 1;

//     while (tc--)
//     {
    	
//     	int n = rand()%N + 1, m = rand()%N + 1;

//     	int a[n][m];
//     	for(int i=0;i<n;i++)
//     	{
//     		for(int j=0;j<m;j++)
//     		{
//     			int flag = rand()%4;
//     			if(flag==0)
//     				a[i][j] = -1;
//     			else
//     				a[i][j] = rand()%MAXI;
//     		}
//     	}

//     	a[n-1][0] = rand()%MAXI;

//     	cout << n << " " << m << "\n";
//     	for(int i=0;i<n;i++){
//     		for(int j=0;j<m;j++)
//     			cout << a[i][j] << " ";
//     		cout << "\n";
//     	}

//     	cout << "~\n";
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 

//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(3e17+10)
#define N 200005


// Driver code to test above functions
int32_t main()
{
   
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
	cout.tie(NULL);

	string s;
	cin >> s;

	int ans = 0;
	for(int i=0;i<s.size();i++)
		if(s[i]=='?')
			s[i] = 'D';

	

	cout << s;

    return 0;
 
} 


Measured memory_bytes: 3732
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using int64 = long long;
using vint = vector<int>;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, init, n) for (int i = (init); i < (n); ++i)
#define RepLong(i, n) for (int64 i = 0; i < (n); ++i)
#define InitRepLong(i, init, n) for (int64 i = (init); i < (n); ++i)
#define RepItr(it, itBegin, itEnd) for (auto it = (itBegin); it != (itEnd); ++it)


int main()
{
	int n, t;
	cin >> n >> t;
	vector<pair<int, int>> plates(n);
	Rep(i, n)
	{
		int a, b;
		cin >> a >> b;
		plates[i] = make_pair(a, b);
	}
	sort(plates.begin(), plates.end(), [](const pair<int, int>& x, const pair<int, int>& y) { return x.first < y.first; });

	vector<vint> dp(n + 1, vint(t));
	Rep(i, n)
	{
		Rep(j, t)
		{
			dp[i + 1][j] = dp[i][j];
			if (j >= plates[i].first)
			{
				dp[i + 1][j] = max(dp[i][j - plates[i].first] + plates[i].second, dp[i][j]);
			}
		}
	}
	
	vint afterMax(n);
	int curMax = 0;
	for (int i = n - 1; i >= 0; --i)
	{
		afterMax[i] = curMax;
		curMax = max(curMax, plates[i].second);
	}

	int valMax = 0;
	Rep(i, n)
	{
		int val = dp[i + 1][t - 1] + afterMax[i];
		valMax = max(valMax, val);
	}

	cout << valMax << endl;

	return 0;
}

Measured memory_bytes: 35584
def dfs(a):
    global ans
    if a>n:
        return
    if len(set(list(str(a))))==3:
        ans+=1
    for i in (3,5,7):
        a=a*10+i
        dfs(a)
        a//=10
    
n=int(input())
ans=0
dfs(0)
print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int tmp;
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int change = 0;
        for(int i=N;i>=1;i--){
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        }
        for(int i=0;i<N;i++){
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        }
        System.out.println();
        System.out.println(change);
    }
}


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

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    auto F = factorize(accumulate(A.begin(), A.end(), 0));
    sort(F.begin(), F.end(), greater<int>());

    for (const auto &f: F){
        vector<int> B(n);
        for (int i = 0; i < n; i++)
            B[i] = A[i] >= f ? A[i] % f : A[i];
        auto S = accumulate(B.begin(), B.end(), 0);
        auto i = S / f;
        nth_element(B.begin(), B.begin() + (n - i), B.end());
        if (max(accumulate(B.begin(), B.begin() + (n - i), 0), S - accumulate(B.begin() + (n - i), B.end(), 0)) <= k){
            printf("%d\n", f);
            return 0;
        }
    }

    puts("0");
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  long dfs(int depth, String str) {
    if (depth == str.length() - 1) {
      debug(str);
      String[] sp = str.split("\\+");
      long sum = 0;
      for (int i = 0; i < sp.length; ++i) {
        sum += Long.parseLong(sp[i]);
      }
      return sum;
    }
    long sum = 0;
    sum += dfs(depth + 1, str);
    str = str.substring(0, depth + 1) + "+" + str.substring(depth + 1);
    sum += dfs(depth + 2, str);
    return sum;
  }

  void run() {
    String str = sc.next();

    System.out.println(dfs(0, str));
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

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

Measured memory_bytes: 11344
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  const int MAX=100011;
  bool prime[MAX+1];
  rep(i,MAX+1)prime[i]=true;
  prime[0]=prime[1]=false;
  int q;
  cin>>q;
  int num[MAX];
  num[0]=0;
  for(int i=2;i<sqrt(MAX+1);i++){
    for(int j=i*2;j<MAX+1;j+=i){
      prime[j]=false;
    }
  }
  loop(i,1,MAX){
    if(i%2==0)num[i]=num[i-1];
    else{
      if(prime[i] && prime[(i+1)/2]){
	num[i]=num[i-1]+1;
      }else{
	num[i]=num[i-1];
      }
    }
  }
  int l,r;
  rep(i,q){
    cin>>l>>r;
    cout<<num[r]-num[l-1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10 ** 5)

N = int(input())

def check(p):
  return ("3" in p and "5" in p and "7" in p)
  
cnt = 0
def dfs(n):
  if int(n) > N:
    return
  global cnt
  if check(n):
    cnt += 1
  for c in ("3","5","7"):
    dfs(n + c)

dfs("0")
print(cnt)

Measured memory_bytes: 3064
import collections
N=int(input())
mod=10**9+7

def bunkai(n):
  a=[]
  while n%2==0:
    n//=2
    a.append(2)
  f=3
  while f*f<=n:
    if n%f==0:
      n//=f
      a.append(f)
    else:
      f+=2
  if n!=1:
    a.append(n)
  return(collections.Counter(a))
  
l=collections.Counter()
for n in range(1,N+1):
  l+=bunkai(n)
  
ans=1
for i in l.values():
  ans=(ans*(i+1)%mod)%mod
  
print(ans)

Measured memory_bytes: 3316
program sample
    implicit none
    character(len=50)::O, E
    character(len=100)::cha
    character(len=1)::p, f
    character, allocatable::C(:)
    integer:: i
    read(*,*) O
    read(*,*) E
    allocate(C(len_trim(O)+len_trim(E)))
    cha = ''

    if(len_trim(O)>len_trim(E))then
        do i = 1, len_trim(O)-1
            C(2*i-1) = O(i:i)
            C(2*i) = E(i:i)
        end do
        C(len_trim(O)+len_trim(E)) = O(i:i)
    else
        do i = 1, len_trim(O)
            C(2*i-1) = O(i:i)
            C(2*i) = E(i:i)
        end do
    end if 

    write(*,*) C
    deallocate(C)
    stop

end program sample

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }

        bool[] visited = new bool[n];
        var ans = 0;
        var k = 0;
        while (true)
        {
            if (visited[k])
            {
                ans = -1;
                break;
            }

            if (a[k] - 1 == 1)
            {
                ans++;
                break;
            }
            else
            {
                visited[k] = true;
                ans++;
                k = a[k] - 1;
            }
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 30848
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n - 1); 0 <= i; --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  string s;
  cin >> s;
  
  char c = s[0] + 1;
  cout << c << endl;
}


Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val letters = next().toList()
    println(when{
        letters[0] == letters[2] -> "Yes"
        else -> "No"
    })
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt()= listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31864
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

int nums[100001];
vector<int> adj[100001];

int main()
{
    int n,m,a,b;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>nums[i];
    }
    while(m--){
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int cnt = 0;
    for(int i=1;i<=n;i++){
        bool flag = true;
        if(adj[i].size()>0){
            for(int child:adj[i]){
                if(nums[child]>=nums[i]){
                    flag = false;
                    break;
                }
            }
        }
        if(flag){
            cnt++;
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 9144
require("fs").readFileSync("/dev/stdin",'utf8').trim().split(/\s/).map(function(i){j=i.split(',');for(n=m=s=0;m<10;m++)j[m]=s-=j[m];for(s*=j[10]/(-j[10]-j[11]);j[n]>-s;n++);console.log(++n)})

Measured memory_bytes: 7644
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main(){
 int n,k,x,y,z;
  cin>>n;
  
  vector<int> a;
  
  for(int i=0;i<n;i++){
   cin>>x;
    a.push_back(x);
  }
  
  cin>>k;
  for(int i=0;i<k;i++){
   cin>>y>>z;
    cout<<(accumulate(a.begin(), a.end(), 0))-a[y-1]+z<<endl;
    
  }
  
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    mod = 10**9 + 7

    # max_nCrまで調べられる
    max_n = 4*10**5
    fac, inv = [1]*(max_n+1), [0]*(max_n+1)
    for i in range(2, max_n+1):
        fac[i] = fac[i-1] * i % mod
    inv[-1] = pow(fac[-1], mod-2, mod)
    for i in range(max_n, 0, -1):
        inv[i-1] = inv[i] * i % mod
    
    # nCrを求める
    def ncr(n, r):
        return fac[n]*inv[r]*inv[n-r]%mod

    n,m,k = map(int, input().split())

    base = ncr(n*m-2, k-2)

    res = 0
    # x方向
    for i in range(1, m):
        res += n**2 * i * (m-i)
        res %= mod

    for i in range(1, n):
        res += m**2 * i * (n-i)
        res %= mod

    print(res*base%mod)

if __name__ == '__main__':
    main()

Measured memory_bytes: 45296
import collections

s = raw_input()
stack = collections.deque([])
i = 0
j = 0
while(j < len(s)):
	while(j < len(s) and s[i] == s[j]): j += 1	
	stack.append(j-i)
	i = j
n = len(s)
while(len(stack) > 1) :
	v = stack.pop()
	u = stack.pop()
	if v > u: 
		if stack:
			stack[-1] += v-u
		else:
			stack.append(v-u)
	elif v < u: stack.append( u - v)

print n - (stack[-1] if stack else 0)

Measured memory_bytes: 87868
n, k = map(int, input().split())
A = list(map(int, input().split()))
A = [-1] + A
memo = []
loop = []
visit = [0]*n
town = 1
while visit[town-1] < 2:
    if visit[town-1] == 0:
        memo.append(town)
    else:
        loop.append(town)
    visit[town-1] += 1
    town = A[town]
outlier = len(memo) - len(loop) 
T = len(loop)
if k <= outlier:
    print(memo[k])
else:
    print(loop[(k-outlier) % T])

Measured memory_bytes: 32252
use std::cmp::min;
use std::io::{BufRead, StdinLock};

fn read(stdin_lock: &mut StdinLock, buf: &mut Vec<u8>, delimiter: u8) -> i32 {
    buf.clear();
    let l = stdin_lock.read_until(delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap()
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a = read(&mut stdin_lock, &mut buf, b' ');
    let p = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(a, p));
}

fn solve(a: i32, p: i32) -> i32 {
    (a * 3 + p) / 2
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x;
  cin>>n>>x;
  vector<int> v(n);
  int i;
  for(i=0;i<n;i++)
  {
      cin>>v[i];
  }
  int sum=0;
  int ans=1;
  for(i=0;i<n;i++)
  {
    sum+=v[i];
    if(sum<=x)
        ++ans;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N;
	scanf("%d",&N);

	printf("%d\n",(N+1)/2);

	return 0;
}


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

int main(void){
  int count[4];
  int i,j,k,min;
  char str[512];
  memset(count,0,sizeof(count));
  scanf("%s",str);
  k=strlen(str);
  for(i=0;i<k;i++){
    switch(str[i]){
    case 'K':
      count[0]++;
      break;
    case 'U':
      count[1]++;
      break;
    case 'P':
      count[2]++;
      break;
    case 'C':
      count[3]++;
      break;
    }
  }
  min=count[0];
  for(i=1;i<=3;i++) if(count[i]<min) min=count[i];
  printf("%d\n",min);
  return 0;
}

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

signed main() {
  string a, b;
  cin >> a >> b;

  if (a.size() > b.size()) {
    cout << "GREATER" << endl;
    return 0;
  } else if (a.size() < b.size()) {
    cout << "LESS" << endl;
    return 0;
  }

  for (int i = 0; i < a.size(); i++) {
    if (a[i] > b[i]) {
      cout << "GREATER" << endl;
      return 0;
    } else if (a[i] < b[i]) {
      cout << "LESS" << endl;
      return 0;
    }
  }

  cout << "EQUAL" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = Integer.parseInt(scanner.nextLine());
        String inputLine =  scanner.nextLine();
        System.out.println(inputLine);
        String[] input = inputLine.split(" ");
        int[] numbers = new int[count];
        for (int i = 0; i < count; i++) {
            numbers[i] = Integer.parseInt(input[i]);
        }

// 1 insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
// 2   for i が 1 から N-1 まで
// 3     v = A[i]
// 4     j = i - 1
// 5     while j >= 0 かつ A[j] > v
// 6       A[j+1] = A[j]
// 7       j--
// 8     A[j+1] = v


        // sort
        for (int i = 1; i < count; i++) {
            int v = numbers[i];
            int j = i - 1;
            while ((j >= 0) && (numbers[j] > v)) {
                numbers[j + 1] = numbers[j];
                j--;
            }
            numbers[j + 1] = v;
            
            StringJoiner joiner = new StringJoiner(" ");
            Arrays.stream(numbers).forEach(n -> joiner.add(Integer.toString(n)));
            
            System.out.println(joiner.toString());
        }
    }
}



Measured memory_bytes: 32360
import numpy as np
n = int(input())
l = np.array([int(i) for i in input().split()])
mean = np.mean(l)

ans = 10 ** 9

for i in [int(mean),int(mean)-1,int(mean)+1]:
    ans = min(ans, np.sum(((l-i)*(l-i))))

print(ans)



Measured memory_bytes: 20644
#include<bits/stdc++.h>
using namespace std;
int n,h[100100],d[100100];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	} 
	for(int i=1;i<n;i++)
	{
		int b;
		int a=abs(h[i-1]-h[i]);
		b=abs(h[i-2]-h[i]);
		d[i]=d[i-1]+a;
		if(i>1 && d[i]>d[i-2]+b)
		{
			d[i]=d[i-2]+b;
		} 
	}
	cout<<d[n-1];
	return 0;
}

Measured memory_bytes: 1024