akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define U 10050
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#define sp
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
bool is[U];
int w[U];
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, n;
	cin>>x>>n;
	rep(i, 0, n) cin>>w[i], is[w[i]] = 1;
	rep(i, 0, 55)
	{
		int l = x+i, r = x-i;
		if (is[r] == 0) { cout<<r<<endl; return 0; }
		if (is[l] == 0) { cout<<l<<endl; return 0; }
		
	}
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main(){

	string b,ans;

	cin >> b;

	if(b == "A")
		ans = 'T';
	else if (b == "T")
		ans = 'A';
	else if(b == "C")
		ans = 'G';
	else if (b == "G")
		ans = 'C';

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  if(s[0] == '9' || s[1] == '9') cout << "Yes\n";
  else cout << " No\n";
}


Measured memory_bytes: 3604
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define PUT(x) cout << x << endl;
#define DPUT(x) printf("%.15lf\n",x);
#define GET(x,y) std::get<x>(y) 


using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

int main(void) {

	ll r, g;
	cin >> r >> g;

	cout << 2*g-r << endl;


	return 0;

}

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

int n, s[100];

int main(void){
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> s[i];
  }
  sort(s, s + n);
  cout << s[n - 1] - s[0] << endl;
}


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

#define int long long

const int mod = 1e9 + 7;

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

  vector<int> t(n), a(n);

  for (int i = 0; i < n; i++) cin >> t[i];
  for (int i = 0; i < n; i++) cin >> a[i];

  int ans = (a[0] == t[n - 1] ? 1 : 0);
  for (int i = 1; i < n - 1; i++){
    if (t[i] > t[i - 1] && t[i] <= a[i]){
      continue;
    }
    if (a[i] > a[i + 1] && a[i] <= t[i]){
      continue;
    }
    if ((t[i] == t[i - 1]) && (a[i] == a[i + 1])){
      ans *= min(t[i], a[i]);
      ans %= mod;
      continue;
    }
    ans *= 0;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/6 21:58:12
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 55, MAX = 5000;

int n, m, S;
int C[N], D[N];
struct Edge{
    int v, A, B, next;   
}e[N << 2];
ll dis[N][MAX];
struct Dijkstra{
    struct node{
        ll d;
        pii f;
        bool operator < (const node &A) const {
            return d > A.d;
        }   
    };
    int head[N], tot;
    bool vis[N][MAX];
    void init() {
        memset(head, -1, sizeof(head)); tot = 0;   
    }
    void adde(int u, int v, int A, int B) {
        e[tot] = Edge {v, A, B, head[u]};
        head[u] = tot++;   
    }
    void dij(int s) {
        priority_queue <node> q;
        memset(dis, INF, sizeof(dis));
        memset(vis, 0, sizeof(vis));
        dis[s][S] = 0;
        q.push(node{0, MP(s, S)});
        while(!q.empty()) {
            node cur = q.top(); q.pop();
            int u = cur.f.fi, sta = cur.f.se;
            ll d = cur.d;
            if(vis[u][sta]) continue;
            vis[u][sta] = 1;
            int to = min(MAX - 1, sta + C[u]);
            if (dis[u][to] > dis[u][sta] + D[u]) {
                dis[u][to] = dis[u][sta] + D[u];  
                q.push(node{dis[u][to], MP(u, to)});
            }
            for(int i = head[u]; i != -1; i = e[i].next) {
                int v = e[i].v, A = e[i].A, B = e[i].B;
                if(sta >= A && dis[v][sta - A] > dis[u][sta] + B) {
                    dis[v][sta - A] = dis[u][sta] + B;
                    q.push(node{dis[v][sta - A], MP(v, sta - A)});   
                }
            }   
        }
    }
}solver;

void run() {
    cin >> n >> m >> S;
    S = min(S, MAX - 1); 
    solver.init();
    for (int i = 1; i <= m; i++) {
        int u, v, A, B; cin >> u >> v >> A >> B;
        solver.adde(u, v, A, B); 
        solver.adde(v, u, A, B);   
    }
    for (int i = 1; i <= n; i++) {
        cin >> C[i] >> D[i];
    }
    solver.dij(1);
    for (int i = 2; i <= n; i++) {
        ll ans = 1e18;
        for (int j = 0; j < MAX; j++) {
            ans = min(ans, dis[i][j]);
        }   
        cout << ans << '\n';
    }
}

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

Measured memory_bytes: 9808
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;


// mod. m での a の逆元 a^{-1} を計算する
//ただしmとaが互いにその時のみ
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    ll sum=0;
    for(auto p: A){sum+=p;sum%=MOD;}
    sum%=MOD;
    ll sum2=0;
    for(auto p: A){
        sum2+=p*p;
        sum2%=MOD;
    }
    sum=sum*sum%MOD;
    ll ans=sum-sum2+MOD;
    ans%=MOD;
    ans*=modinv(2,MOD);
    ans%=MOD;
    prt(ans);
    

    return 0;
}



Measured memory_bytes: 4728
n = int(input())

data = []

for i in range(n):
  x, y = input().split()
  y = int(y)
  data.append((i+1, x, y))
  
data.sort(key=lambda x: x[2], reverse=True)
data.sort(key=lambda x: x[1])

for x in data:
  print(x[0])

Measured memory_bytes: 3060
from itertools import product
ci = "({["
co = ")}]"
while 1:
    p, q = map(int, input().split())
    if p == q == 0:
        break
    S = [input() for i in range(p)]
    T = [input() for i in range(q)]
    L = [set() for i in range(q)]

    for lens in product(range(1, 21), repeat=3):
        cnts = [0]*3
        ok = 1
        for s in S:
            idx = 0
            while s[idx] == '.':
                idx += 1
            if sum(c*l for c, l in zip(cnts, lens)) != idx:
                ok = 0
                break
            for c in s:
                if c in ci:
                    cnts[ci.index(c)] += 1
                elif c in co:
                    cnts[co.index(c)] -= 1
        if not ok:
            continue
        cnts = [0]*3
        for i, t in enumerate(T):
            idx = 0
            while t[idx] == '.':
                idx += 1
            L[i].add(sum(c*l for c, l in zip(cnts, lens)))
            for c in t:
                if c in ci:
                    cnts[ci.index(c)] += 1
                elif c in co:
                    cnts[co.index(c)] -= 1
    ans = [0]*q
    for i in range(q):
        if 1 < len(L[i]):
            ans[i] = -1
        else:
            v, = L[i]
            ans[i] = v
    print(*ans)

Measured memory_bytes: 7824
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned 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 lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };
ll csb(ll n){ ll count = 0;while (n){ count += n & 1; n >>= 1; } return count;}


int main()
{

fastIO;
ll test,t,i,j,k,n,m,a,b,x,y,u,temp;
// i=0;
// while(pow(i+1,5)-pow(i,5)<=1000000000)
//     i++;
// cout<<i;
cin>>x;
for (i = -121; i <= 121; i++)
{
    for (j = -121; j <= 121; j++)
    {
        if(pow(i,5)-pow(j,5)==x)
        {
            cout<<i<<" "<<j;
            exit(0);
        }
    }
}
cout<<i;
return 0;
}

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

int main(int argc, char const *argv[])
{
	int x,y,z,k;
	cin>>x>>y>>z>>k;
	long long a[x],b[y],c[z];
	for (int i = 0; i < x; ++i)
	{
		cin>>a[i];
		a[i]*=-1LL;
	}
	for (int i = 0; i < y; ++i)
	{
		cin>>b[i];
		b[i]*=-1LL;
	}
	for (int i = 0; i < z; ++i)
	{
		cin>>c[i];
		c[i]*=-1LL;
	}
	sort(a,a+x);
	sort(b,b+y);
	sort(c,c+z);
	multiset<long long> ans;
	long long mi=0LL;
	for (int i = 0; i < x; ++i)
	{
		if (mi<=a[i]+b[0]+c[0])
		{
			break;
		}
		for (int j = 0; j < y; ++j)
		{
			if (mi<=a[i]+b[j]+c[0])
			{
				break;
			}
			for (int l = 0; l < z; ++l)
			{
				ans.insert(a[i]+b[j]+c[l]);
				if (ans.size()>k)
				{
					auto itr=ans.end();
					--itr;
					mi=min(mi,*itr);
					ans.erase(itr);
					if (mi<=a[i]+b[j]+c[l])
					{
						break;
					}
				}
			}
		}
	}
	for (auto i = ans.begin(); i != ans.end(); ++i)
	{
		cout<<(*i)*-1LL<<endl;
	}
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> ii;

const ll INF=2e18;
const int MOD=10000007;

string s,t;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s>>t;
    int l=s.length(), m=0;
    for(int i=0; i<l; i++){
        s=s[l-1]+s.substr(0,l-1);
        if(s==t){
            printf("Yes"); return 0;
        }
    }
    printf("No");
    return 0;
}



Measured memory_bytes: 256
import sys
from collections import deque
stdin = sys.stdin

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

h, w = na()
s = h * w
mid_h = h // 2
mid_w = w // 2
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    ans = s
    for i in range(mid_w+1)[::-1]:
        s0 = h * i
        s1 = ((w - i) // 2) * h
        s2 = s - s0 - s1
        ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))
        s1 = (w - i) * mid_h
        s2 = s - s0 - s1
        ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))
    for i in range(mid_h+1)[::-1]:
        s0 = w * i
        s1 = ((h - i) // 2) * w
        s2 = s - s0 - s1
        ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))
        s1 = (h - i) * mid_w
        s2 = s - s0 - s1
        ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))
    print(ans)

Measured memory_bytes: 43376
package main

import "fmt"

func main() {
    var N, r, l int
    var str string
    fmt.Scan(&N)
    fmt.Scan(&str)
    for i := 0; i < N; i++ {
        if str[i] == '(' {
            r++
        } else if r > 0 {
            r--
        } else {
            l++
        }
    }
    for i := 0; i < l; i++ {
        fmt.Print("(")
    }
    fmt.Print(str)
    for i := 0; i < r; i++ {
        fmt.Print(")")
    }
    fmt.Printf("\n")
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	long long ANS = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 3 != 0 && i % 5 != 0) ANS += i;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 3632
N, M = map(int,input().split())
p =[]
S =[]
for i in range(M):
    p1, S1 = map(str,input().split())
    p.append(int(p1))
    S.append(S1)
    
wa = [0] * (N+1)
ac = [0] * (N+1)
answ = 0
for i in range(M):
    if S[i] == "AC" and ac[p[i]] == 0:
        answ += wa[p[i]]
        ac[p[i]] = 1
    else:
        wa[p[i]] += 1

ans = [str(sum(ac)), str(answ)]

print(" ".join(ans))

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


int main()
{
    // cout << "A.cpp" << endl;

    int N;

    // 入力
    scanf("%d", &N);

    N = N*N*N;

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, k;
string s;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k >> s;
	cout << s.substr(0, k - 1) << (char)(s[k - 1] - 'A' + 'a') << s.substr(k, s.length() - k) << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    int ans=0;
    vector<string> s;
    string tmp_s;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp_s;
        s.push_back(tmp_s);
    }
    sort(s.begin(),s.end());
    ans++;
    for(int i=1; i<n; i++){
        if(s[i]!=s[i-1]){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11600
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var r, g, b string
	fmt.Scan(&r, &g, &b)

	n, _ := strconv.Atoi(r + g + b)

	if n%4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A_dict = {}
    for a in A:
        if a in A_dict.keys():
            A_dict[a] += 1
        else:
            A_dict[a] = 1

    A_list = sorted(A_dict.keys())
    limit = A_list[-1]

    sieve = {i: True for i in A_dict.keys()}

    for a in A_list:
        if not sieve[a]:
            continue
        for i in range(2*a, limit+1, a):
            if i in sieve:
                sieve[i] = False

    print(sum([1 for i in sieve.keys() if sieve[i] and (A_dict[i]==1)]))
main()

Measured memory_bytes: 146484
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int main() {
	string s;
	while (cin >> s, s != "0") {
		int length = s.length(), ans = 0;
		
		vvi dp(length, vi(11, 0));
		REP(i, length) {
			int num = s[i] - '0';
			if (i != 0) {
				REP(j, 11) {
					dp[i][(j * 10 + num) % 11] += dp[i - 1][j];
				}
			}
			if (num != 0) {
				dp[i][num]++;
			}
			ans += dp[i][0];
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 8132
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n, i;
	cin >> n;
	int arr[n];
	fo(i, 0, n){
		cin >> arr[i];
	}
	arr[0]--;
	fo(i, 1, n){
		if(arr[i] > arr[i - 1])
		arr[i]--;
	}
	fo(i, 1, n){
		if(arr[i] < arr[i - 1]){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}

Measured memory_bytes: 640
def solve(arr,dp,N):
    dp[0][0],dp[0][1],dp[0][2]=matrix[0][0],matrix[0][1],matrix[0][2]
    for i in range(1,N):
        dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2])
        dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2])
        dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1])
    return max(dp[-1])
if __name__ == "__main__":
    N=int(input())
    matrix=[[0 for j in range(3)] for i in range(N)]
    dp=[[0 for j in range(3)] for i in range(N)]
    for i in range(N):
        matrix[i][0],matrix[i][1],matrix[i][2]=map(int,input().split())
    print(solve(matrix,dp,N))

Measured memory_bytes: 99468
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,s,g1,g2;
  while(cin>>n>>m>>s>>g1>>g2,n){
    int d[1001][1001]={};
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)if(i!=j)d[i][j]=1e8;
    for(int i=0,a,b,c;i<m;i++)
      cin>>a>>b>>c,d[a][b]=c;
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
	for(int k=1;k<=n;k++)d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
    int ans=1e9;
    for(int i=1;i<=n;i++)ans=min(ans,d[s][i]+d[i][g1]+d[i][g2]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 6980
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    String Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    String[] AlTable = Alphabet.split("",0);
    String ans = "";
    for(int i=0;i<S.length();i++){
      String tmp = S.substring(i,i+1);
      for(int j=0;j<26;j++){
        if(tmp.equals(AlTable[j])){
          int j2 = j + N;
          if(j2>=26){
            j2 = j2-26;
          }
          ans = ans + AlTable[j2];
        }
      }
    }
    System.out.println(ans);
  }
}

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

int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b && b< c)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
/*In the name of ALLAH, Most Gracious, Most Merciful*/

#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define setbits                 __builtin_popcount
#define zerobits                __builtin_ctzll
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)               __gcd(a,b)
#define lcm(a, b)               ((a)*(b))/gcd(a,b)
#define watch(x)                cout << (#x) << " is " << (x) << endl
#define FOR(x,n)                for (ll i=x,j=x,k=x;i<n,j<n,k<n;i++,j++,k++)
#define FORR(n,x)               for (ll i=n-1,j=n-1,k=n-1;i>=x,j>=x,k>=x;i--,j--,k--)
#define TEST_CASES()            ll t;cin>>t;while (t--)
#define PRECISION(a,x)          fixed<<setprecision(x)<<a<<endl;
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define FAST_IO()               ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FILE_IO()               freopen("output.txt", "w", stdout);freopen("input.txt", "r", stdin)
using namespace std;
ll tc=1;


void solve()
{
    ll n;
    cin>>n;
    cout<<n+(n*n)+(n*n*n)<<endl;
}

int32_t main()
{
    FAST_IO();
    //TEST_CASES()
        solve();
}

Measured memory_bytes: 3604
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.TreeMap;
import java.util.*;

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

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

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

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

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

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

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

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

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

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int a = fs.nextInt();
        int b = fs.nextInt();
        // int c = fs.nextInt();
        if (a > b * 2)
            System.out.println(a - b * 2);
        else
            System.out.println(0);
    }

}


Measured memory_bytes: 81748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 

const int mod = 1000000007;
const int inf = 1e9;

class UnionFind{
public:
    vll par;
    vll siz;

    UnionFind(ll n):par(n), siz(n, 1LL){
        rep(i,0,n){par[i] = i;}
    }

    ll root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool merge(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    ll size(int x){
        return siz[root(x)];
    }

};

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    int fri[n] = {0}, opp[n] = {0};
    UnionFind p(n);
    rep(i,0,m){
        int a, b;
        cin >> a >> b;
        a--;b--;
        fri[a]++;fri[b]++;
        p.merge(a, b);
    }
    rep(i,0,k){
        int c,d;
        cin >> c >> d;
        c--;d--;
        if(p.root(c) == p.root(d)){
            opp[c]++;opp[d]++;
        }      
    }
    rep(i,0,n){
        cout << p.size(i) - fri[i] - opp[i] - 1 << " ";
    }


}

Measured memory_bytes: 3200
import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N = int(input())
    A = np.array(list(map(int, input().split())))
    
    a, b = min(A), max(A)
    ans = float('inf')
    for i in range(a, b+1):
        ans = min(ans, ((A - i)**2).sum())

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 13424
from collections import deque
X = input()
Q = deque()
for i in range(len(X)):
    if X[i] == 'T':
        if len(Q) > 0 and Q[-1] == 'S':
            Q.pop()
        else:
            Q.append('T')
    else:
        Q.append('S')
print(len(Q))

Measured memory_bytes: 5092
n = int(input()) - 1

a = []
b = list('abcdefghijklmnopqrstuvwxyz')

if n <= 25:
    print(b[n])
    exit()
count = 0
for i in range(1,100):
    if n >= 26 ** i:
        n = n - 26 ** i
        count += 1
    else:
        break


#print(n,count,n // (26 ** A5))
count2 = 0


while 1:
    #print(n)
    #print(n,count,a)
    if count == 0:
        a.append(n)
        break
    count2 = n // (26 ** count)
    n = n % 26 ** count
    a.append(count2)
    count -= 1

#print(n)
x = [b[a[i]]for i in range(len(a))]
print("".join(x))



Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define ll      long long int   
#define ld      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     1000000007
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     1000000000000000007
const int N=300006;
ll n,i,ans,a[N],b[N],c[N];
void run(){
	cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n;i++)
        cin>>b[i];
    for(i=1;i<=n-1;i++)
        cin>>c[i];
    for(i=1;i<=n;i++)
    {
        ans+=b[a[i]];
        if(i>=2 && a[i]==a[i-1]+1) ans+=c[a[i-1]]; 
    }
    cout<<ans;
 
}
 
 
void setup(){
    ios;
    //cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}

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

const int N = 3001;

int dp[N][N];

signed main() {
    std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
    
    std::string s, t;
    std::cin >> s >> t;

    int n = s.size();
    int m = t.size();
    s = '$' + s;
    t = '$' + t;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
            if (s[i] == t[j]) {
                dp[i][j] = std::max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }

    std::string ans = "";

    while (n > 0 || m > 0) {
        if (s[n] == t[m]) ans += s[n], --n, --m;
        if (m > 0 && dp[n][m - 1] == dp[n][m]) --m;
        if (n > 0 && dp[n - 1][m] == dp[n][m]) --n;
    }

    std::reverse(ans.begin(), ans.end());
    std::cout << ans;

    return 0;
}



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

int main(){
  int n;
  ll d;
  cin>>n>>d;
  int ans=0;
  for(int i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    if(a*a+b*b<=d*d){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
    string s;
    cin >>s;

    int split = 0;
    bool dual = false;
    string prev = "A";
    for(int current = 0; current < s.size(); current++){
        if(dual){
            prev += s[current];
            dual = false;
        }else{
            if(prev == s.substr(current,1)){
                if(current+1 < s.size()){
                    dual = true;
                    prev = s[current];
                    split++;
                }
            }else{
               // printf("DDDD %s\n", prev.c_str());
                prev = s[current];
                split++;
            }
        }
    }

    printf("%d\n", split);
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict


def main():

    blue = defaultdict(int)
    red = defaultdict(int)

    n = int(input())
    for i in range(n):
        blue[input()] += 1

    m = int(input())
    for i in range(m):
        red[input()] += 1

    ans = 0

    for word, cnt in blue.items():
        if word in red.keys():
            ans = max(ans, cnt - red[word])
        else:
            ans = max(ans, cnt)
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!p)
#define until(p) while(!p)

using ll = long long;
using P = std::tuple<int,int>;

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

int counter;
void ask(std::string n){
    std::cout << "? " << n << std::endl;
    ++counter;
}

char answer(){
    char c;
    std::cin >> c;
    return c;
}

char findDigit(std::string s, int start, std::string suffix){
    int64_t lb = 9, ub = start - 1;

    while(std::abs(ub - lb) > 1){
        int64_t mid = (lb + ub) / 2;

        ask(s + (char)(mid + '0') + suffix);
        char ans = answer();
        if(ans == 'Y'){
            lb = mid;
        }else{
            ub = mid;
        }
    }

    return (char)(lb + '0');
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    std::string res = "";    
    bool two = false;
    
    while(res.size() < 9 || (res.size() == 9 && !two)){
        char d = findDigit(res, res.size() == 0 ? 1 : 0, std::string(max<int>(0, 18 - 1 - res.size()), '9'));

        if(d > '0'){
            if(res.size() > 0){two = true;}
            res += d;
        }else{
            {
                ask(res + '9' + std::string(max<int>(0, 18 - 1 - 1 - res.size()), '0'));;
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                    continue;
                }
            }
            {
                ask(res + "1");
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                    continue;
                }
            }
            {
                ask(std::string(res.size(), '9'));
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                }
                break;
            }
        }
    }

    // std::cout << "(res, two) = " << "(\"" << res << "\", " << two << ")" << std::endl;    
    
    std::cout << "! " << res << std::endl;
    // std::cout << "ask count: " << counter << std::endl;
}


Measured memory_bytes: 632
import math

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

if x <= a*a*b/2: #三角形
  print(90-math.degrees(math.atan(2*x/(a*b*b))))
  
else:
  print(math.degrees(math.atan((-2*x/(a*a)+2*b)/a)))

Measured memory_bytes: 3060
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

var X: Int = 0

fun solve() {
    X = inf.readLine()!!.toInt()
    val k = inf.readLine()!!.toInt()
    val r = inf.readLine()!!.split(' ').map(String::toInt).toIntArray()
    val q = inf.readLine()!!.toInt()
    var cur = G(0, X, 0, X)
    var ri = 0
    var rPrev = 0
    for (i in 0 until q) {
        val (t, a) = inf.readLine()!!.split(' ').map(String::toInt)
        while (ri < r.size && r[ri] <= t) {
            cur = compute(cur, r[ri] - rPrev, ri % 2)
            rPrev = r[ri++]
        }
        println(compute(cur, t - rPrev, ri % 2).calc(a))
    }
}

fun compute(g: G, t: Int, sign: Int): G {
    if (sign == 1) {
        if (g.ansMin + t >= X) return G(X, X, X, X)
        if (g.ansMax + t <= X) return G(g.aMin, g.aMax, g.ansMin + t, g.ansMax + t)
        return G(g.aMin, X + g.aMin - g.ansMin - t, g.ansMin + t, X)
    } else {
        if (g.ansMax - t <= 0) return G(X, X, 0, 0)
        if (g.ansMin - t >= 0) return G(g.aMin, g.aMax, g.ansMin - t, g.ansMax - t)
        return G(t + g.aMin - g.ansMin, g.aMax, 0, g.ansMax - t)
    }
}

data class G(val aMin: Int, val aMax: Int, val ansMin: Int, val ansMax: Int) {
    fun calc(a: Int) = when (a) {
        in 0..aMin -> ansMin
        in aMin..aMax -> a - aMin + ansMin
        else -> ansMax
    }
}

fun main(args: Array<String>) {
    solve()
    ouf.close()
}

val inf = BufferedReader(InputStreamReader(System.`in`))
val ouf = PrintWriter(System.out)

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

int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		bool a=false,b=false;
		string str;
		cin >> str;
		if(str[0] == '>' && str[1] == '\'' && str.size()%2==0 && str.size() >= 6){a = true;}
		if(str[0] == '>' && str[1] == '^' && str.size()%2==0 && str.size() >= 6){b = true;}
		if(a){
			for(unsigned j=2;j<str.size()-1;j++){
				if(j != (str.size()/2) && str[j] != '='){
					a = false;
					break;
				}
			}
			if(str[str.size()/2] != '#' || str[str.size()-1] != '~')
				a=false;
		}		
		if(b){
			for(unsigned j=2;j<str.size()-3;j+=2){
				if(str[j] != 'Q' || str[j+1] != '='){
					b = false;
					break;
				}
			}
			if(str[str.size()-2] != '~' || str[str.size()-1] != '~')
				b=false;
		}
		if(a)
			cout << "A" << endl;
		else if(b)
			cout << "B" << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int find(int *a,int x){
  if(a[x]==x) return x;
  a[x]=find(a,a[x]);
  return a[x];
}

int same(int *a,int x,int y){
  return find(a,x)==find(a,y);
}

void merge(int *a,int x,int y){
  x=find(a,x);
  y=find(a,y);
  if(x==y) return;
  a[x]=y;
  return;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int p[100001];
  int i;
  for(i=1;i<=n;i++) scanf("%d",p+i);
  int a[100001];
  for(i=1;i<=n;i++) a[i]=i;
  for(i=0;i<m;i++){
    int x,y;
    scanf("%d%d",&x,&y);
    merge(a,x,y);
  }
  int cnt=0;
  for(i=1;i<=n;i++){
    if(same(a,i,p[i])) cnt++;
  }
  printf("%d\n",cnt);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 896
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        int countZero = 0;
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
            if (a[i] == 0) {
                countZero++;
            }
        }
        sc.close();

        // 主処理
        Set<Integer> set = new HashSet<>(Arrays.asList(a));
        boolean judge;
        if (countZero == n) {
            judge = true;
        } else if (n % 3 == 0 && countZero == n / 3 && set.size() == 2) {
            judge = true;
        } else if (n % 3 == 0 && set.size() == 3) {
            Map<Integer, Integer> map = new HashMap<>();
            for (int num : set) {
                map.put(num, 0);
            }
            for (int i = 0; i < n; i++) {
                map.put(a[i], map.get(a[i]) + 1);
            }
            Set<Integer> valueSet = new HashSet<>();
            int xorSum = 0;
            for (int key : map.keySet()) {
                valueSet.add(map.get(key));
                xorSum ^= key;
            }
            judge = valueSet.size() == 1 && xorSum == 0;
        } else {
            judge = false;
        }
        String result = judge ? "Yes" : "No";

        long num = 10L;
        String numStr = Long.toBinaryString(num);
        Long.parseLong(numStr, 2);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 61088
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

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

    set <int> values;
    for(int i = 0; i < N; i++){
        values.insert(a[i]);
    }
    if(values.size() > 2){
        cout << "No" << endl;
        return 0;
    } 

    if(values.size() == 1){
        if(a[0] == (N - 1) || (a[0] <= N / 2)){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        return 0;
    }

    if(values.size() == 2){
        auto it = values.begin();
        int smaller = *it;
        it++;
        int bigger = *it;

        int smaller_num = 0;
        int bigger_num = 0;
        for(int i = 0; i < N; i++){
            if(a[i] == smaller){
                smaller_num ++;
            } else {
                bigger_num ++;
            }
        }
        int min_color_num = smaller_num + 1;
        int max_color_num = smaller_num + bigger_num / 2;
        //cout << min_color_num << " " << max_color_num << endl;
        if(smaller < min_color_num - 1 || bigger > max_color_num){
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
        return 0;
    }

    return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String x = input.nextLine();
		String ans = "";
		for (int i = 0; i < x.length(); i++) {
			if (x.charAt(i)==',') ans+=" ";
			else ans+=x.substring(i,i+1);
		}
		System.out.println(ans);
	}		
}

Measured memory_bytes: 22612
#include <stdio.h>
   int main(void)
   {
   int a,b;
   scanf("%d",&a);
   scanf("%d",&b);
   if(a+b<=16)
   { if((a<=8)&&(b<=8))
      printf("Yay!\n");
   else  printf(":(\n");}
  else  printf(":(\n");
  return 0;
  }


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void ABC138E()
{
	string s, t;
	cin >> s >> t;

	int n1 = s.length();
	int n2 = t.length();
	set<char> subT;
	subT.insert(t.begin(), t.end());
	set<char> subS;
	subS.insert(s.begin(), s.end());

	for (auto& x : subT)
	{
		if (subS.find(x) == subS.cend())
		{
			cout << -1 << endl;
			return;
		}
	}

	vector<long long int> locs[26];
	long long int ct = 0;
	for (auto& x : s)
	{
		int i = x - 'a';
		locs[i].push_back(ct);
		++ct;
	}

	long long int wh = 0;
	long long int n = 0;
	auto y = t.cbegin();
	int i = *y - 'a';
	auto p = lower_bound(locs[i].begin(), locs[i].end(), wh);
	wh = *p;
	++y;
	while (y != t.cend())
	{
		int i = *y - 'a';
		auto p = upper_bound(locs[i].begin(), locs[i].end(), wh);
		if (p == locs[i].cend())
		{
			++n;
			wh = locs[i].front();
		}
		else
			wh = *p;
		++y;
	}
	wh += 1;
	n *= s.length();
	long long int x = wh + n;
	cout << x << endl;
}

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

Measured memory_bytes: 1724
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;


const i64 MAXN = 300005;

i64 n;
i64 a[MAXN];
int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

    for (i64 i = 0; i < n; i++) {
        cin >> a[i];
    }


    i64 m = inf;
    i64 R = 0;
    for (i64 i = 0; i < n; i++) {
        if (a[i] < m) {
            R += 1;
        }
        m = min(m, a[i]);
    }
    cout << R << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	//for(int i=0;i<N;i++) {}
	static int a[]=new int[51];
	static int b[]=new int[51];
	static int c[]=new int[51];
	static int d[]=new int[51];
	
	
	static int N,M,Q;
	
	public static void main(String[] args) {
		N=sc.nextInt();
		M=sc.nextInt();
		Q=sc.nextInt();
		
		for(int i=0;i<Q;i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			c[i]=sc.nextInt();
			d[i]=sc.nextInt();
		}
		
		int a[]=new int[N+1];
		a[N]=M;
		for(int i=0;i<N;i++) {
			a[i]=M;
		}
		
		
		dfs(a,N-1);
		p(ans);
		
		
	}
	static int ans=0;
	
	static void dfs(int g[],int i) {
		if(i==-1) {
			int sum=0;
			for(int cc=0;cc<Q;cc++) {
				if(g[b[cc]-1]-g[a[cc]-1]==c[cc]) {
					sum+=d[cc];
				}
				ans=Math.max(ans, sum);
			}
		}
		else {
			for(int v=1;v<=g[i+1];v++) {
				g[i]=v;
				dfs(g,i-1);
			}
		}
		
		
	}
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

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

int main(){
  ll X,ans;
  cin>>X;
  ans=0;
  ans+=1000*(X/500);

  ll amari = X%500;
  amari = amari/5;

  ans+=5*amari;

















  cout<<ans<<endl;


}


Measured memory_bytes: 256