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

// using namespace std;



// const int N = 100000, MAXI = 10000;

// int getRandom(int l, int r) {
//     return l + rand() % (r - l + 1);
// }



// // Driver code to test above functions
// int main() 
// {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
   
//     srand(time(nullptr));
   
//     int tc = 30;
//     cout << tc << "\n";
//     //int n = 2;
//     while (tc--)
//     {
//         int n = getRandom(99900, 100000);
//         cout << n << "\n";
//         int a[n+1];
//         for(int i=1;i<=n;i++)
//         {
//             if(i==1)
//                 a[1] = getRandom(2, n);
//             else if(i==n)
//                 a[n] = getRandom(1, n-1);
//             else
//             {
//                 int x = getRandom(1, i-1);
//                 int y = getRandom(i+1, n);

//                 int flag = rand()%2;

//                 if(flag==0)
//                     x = y;

//                 a[i] = x;
//             }
//             cout << a[i] << " ";
//         }
//         cout << "\n~\n";
//     }

//     return 0;
// }








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


 

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



// int main()
// {
//     freopen("input.txt","r", stdin);
//     freopen("output.txt","w", stdout);

//     ios_base::sync_with_stdio(0);
//     cin.tie(NULL);
//     cout.tie(NULL);

//     int t;
//     cin >> t;
//     while(t--)
//     {
        
//     }
   
//     return 0;
// }














//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#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);
 
    int n;
    cin >> n;
    map<int, int> mp;
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        sum += x;
        mp[x]++;
    }

    int q;
    cin >> q;
    while(q--)
    {
        int x, y;
        cin >> x >> y;
        int k = mp[x];
        mp[x] = 0;
        mp[y] += k;

        sum += k*(y-x);
        cout << sum << endl;
    }

    
    return 0; 
}



Measured memory_bytes: 9320
#include <iostream>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


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


Measured memory_bytes: 504
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))
#define pi 3.14159265358979323846264338327950288419716939937510
int main()
{
	fastio;
	ll r;
	cin>>r;
	cout<<setprecision(18)<<2*pi*r<<endl;


	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    int n;
    cin >> n;
    vll a(n);
    cin >> a;
    vll rcum(n);
    rcum[n-1] = a[n-1];
    IREP(i, n-1) {
        rcum[i] = (a[i] + rcum[i+1]) % MOD;
    }
    ll ans = 0;
    REP(i, n-1) {
        ans = (ans + a[i]* rcum[i+1] % MOD) % MOD;
    }
    cout << ans << endl;
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



Measured memory_bytes: 6408
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<string>s(N);
	vector<pair<int, int>>p(N);
	priority_queue<pair<int, int>>plus;
	priority_queue<pair<int, int>>minus;
	int total = 0;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		int sum = 0;
		int m = 0;
		for (auto j : s[i]) {
			if (j == '(')sum++;
			else sum--;
			m = min(m, sum);
		}
		if (sum >= 0) {
			plus.emplace(m, sum);
		}
		else {
			minus.emplace(sum - m, sum);
		}
		p[i] = { m,sum };
		total += sum;
	}
	if (total) {
		cout << "No" << endl;
		return 0;
	}
	int sum = 0;
	while (!plus.empty()) {
		auto box = plus.top();
		plus.pop();
		if (sum + box.first < 0) {
			cout << "No\n";
			return 0;
		}
		sum += box.second;
	}
	while (!minus.empty()) {
		auto i = minus.top();
		minus.pop();
		if (sum - i.first + i.second < 0) {
			cout << "No\n";
			return 0;
		}
		sum += i.second;
	}
	cout << "Yes\n";
}


Measured memory_bytes: 50296
import sys
sys.setrecursionlimit(500000)
N = int(input())
A = [int(input()) for i in range(N-1)]
E = [[] for _ in range(N+1)]
for i, a in enumerate(A, 2):
    E[a].append(i)
#print(E)
def solve(v):
    if len(E[v])==0:
        return 0
    depth = []
    for u in E[v]:
        depth.append(solve(u))
    depth.sort(reverse=True)
    ma = 0
    for i, dep in enumerate(depth, 1):
        ma = max(ma, dep+i)
    return ma

print(solve(1))


Measured memory_bytes: 122928
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = INF + 7;



int main(){
    int n, k;
    cin >> n >> k;
    cout << n - k + 1;
}

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

using namespace std;

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

	int N = S.size();
	const int len = 'z' - 'a' + 1;
	vector<string> s_table(len, "");
	vector<string> t_table(len, "");

	for (int i = 0; i < N; i++)
	{
		s_table[S[i] - 'a'].push_back(i);
		t_table[T[i] - 'a'].push_back(i);
	}

	bool flag = true;
	for (int i = 0; i < N; i++)
	{
		if (s_table[S[i] - 'a'].size() > 1
			&& s_table[S[i] - 'a'] != t_table[T[i] - 'a'])
		{
			flag = false;
			break;
		}

		if (t_table[T[i] - 'a'].size() > 1
			&& s_table[S[i] - 'a'] != t_table[T[i] - 'a'])
		{
			flag = false;
			break;
		}
	}

	if (flag)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 1416
#include <iostream>
using namespace std;
struct dice{
    int x[6];
    
    void roll(char c){
        int tmp;
        if(c == 'E'){
            tmp = x[0];
            x[0] = x[3];
            x[3] = x[5];
            x[5] = x[2];
            x[2] = tmp;
        }
        if(c == 'N'){
            tmp = x[0];
            x[0] = x[1];
            x[1] = x[5];
            x[5] = x[4];
            x[4] = tmp;
        }
        if(c == 'S'){
            tmp = x[0];
            x[0] = x[4];
            x[4] = x[5];
            x[5] = x[1];
            x[1] = tmp;
        }
        if(c == 'W'){
            tmp = x[0];
            x[0] = x[2];
            x[2] = x[5];
            x[5] = x[3];
            x[3] = tmp;
        }
        if(c == 'R'){
            tmp = x[1];
            x[1] = x[2];
            x[2] = x[4];
            x[4] = x[3];
            x[3] = tmp;
        }
    }
    int top(void){
        return x[0];
    }
    int right(void){
        return x[2];
    }
    int left(void){
        return x[3];
    }
    int front(void){
        return x[1];
    }
};
int main(void){
    int n;
    dice d[101];
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 6; j++){
            cin >> d[i].x[j];    
        }
    }
    
    int cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(d[j].left() == d[i].top())   d[j].roll('E');
            if(d[j].right() == d[i].top())  d[j].roll('W');
            for(int k = 0; k < 4; k++){
                if(d[j].top() != d[i].top())
                    d[j].roll('N');
            }
            for(int k = 0; k < 4; k++){
                if(d[j].front() != d[i].front())
                    d[j].roll('R');
            }
            if(d[i].x[0] == d[j].x[0] && d[i].x[1] == d[j].x[1] && d[i].x[2] == d[j].x[2] && d[i].x[3] == d[j].x[3] && d[i].x[4] == d[j].x[4] && d[i].x[5] == d[j].x[5]){
                cnt++;
                break;
            }
        }
        if(cnt > 0) break;
    }
    if(cnt > 0)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    
    return 0;
}


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


int main(){

  int N;
  cin >> N;

  int n = N;
  int digitSum = 0;

  while(n>0){
    digitSum += n%10;
    n /= 10;
  }

  if(N % digitSum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0; 
}

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

class Program
{
  
  int[] dx = new int[] {0, 1, 0, -1};
  int[] dy = new int[] {-1, 0, 1, 0};
  static void Main(string[] args) =>
    new Program().solve();

  void solve()
  {
    var param = ReadLine().Split(' ').Select(int.Parse).ToArray();
    var h = param[0];
    var w = param[1];
    var tar = Enumerable.Range(0, h).Select(_ => ReadLine().ToCharArray()).ToArray();
    var grid = new bool[h, w];

    for(int y = 0; y < h; y++)
    {
      for(int x = 0; x < w; x++)
      {
        if(tar[y][x] == '#')
        {
          grid[y, x] = 
            Enumerable.Range(0, 4)
              .Where(i =>
                (x + dx[i]) >= 0 &&
                (x + dx[i])  < w &&
                (y + dy[i]) >= 0 &&
                (y + dy[i])  < h)
              .Select(i => tar[y + dy[i]][x + dx[i]])
              .Any(ch => ch == '#');

          if(!grid[y, x])
          {
            WriteLine("No");
            return;
          }
        }
      }
    }
    WriteLine("Yes");
  }
}

Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math
INF = 500000
mod = 10**9+7

N = int(input())
C = [int(x) for x in input().split()]
C.sort(reverse = 1)
x = 0
for i, c in enumerate(C, 1):
    x += c * (i+1)
    x %= mod
print(x * pow(4, N-1, mod) % mod)


Measured memory_bytes: 87500
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<bool> ac(N);
    map<int, int> mp;
    ll ans = 0;
    ll cnt = 0;
    REP(i,M){
        int p;
        string S;
        cin >> p >> S;
        p--;
        if(ac[p]) continue;
        if(S == "AC" && !ac[p]){
            ac[p] = true;
            ans += mp[p];
            cnt++;
        }
        else{
            mp[p]++;
        }
    }
    cout << cnt << " " << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int64_t N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    int64_t X = min({A, B, C, D, E});
    int64_t through = ceil(N / floor(X));
    cout << through + 4 << endl;
    return 0;
}

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

long long H, W;
int main() {
	scanf("%lld %lld", &H, &W);
	if (H == 1 || W == 1) {
		printf("1\n");
		return 0;
	}
	printf("%lld\n", (H * W + 1) / 2);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"

const int inf = (int)1e18 + 10;

int a[3003];
int dp[3003][3003];
signed main(){
  fast;
  
 int n , sum = 0;
 cin >> n;
 for(int i = 1 ; i <= n ; i++){
 	cin >> a[i];
 	sum += a[i];
 }

 for(int l = 1 ; l <= n ; l++ ){
 	for(int i = 1 ; i<= n - l + 1 ; i++){
 		if(l == 1) dp[i][i] = a[i];
 		else if(l == 2) dp[i][i+1] = max(a[i] , a[i+1]);
 		else{
 			dp[i][i+l-1] = max(a[i] + min(dp[i+1][i+l-2] , dp[i+2][i+l-1]) ,
 			                      a[i+l-1] + min(dp[i+1][i+l-2] , dp[i][i+l-3]));

 			// cout << i << " "<< (i + l-1) << " " << dp[i][i+l-1]<<endl;
 		}
 	}
 }
 
 
 int ans = dp[1][n]  - (sum - dp[1][n]);
 cout << ans << endl; 

}	

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int debt = 100000;
  int n;
  cin >> n;
  for (int i = 0; i < n; i ++) {
    debt = (int)ceil(((double)debt * 1.05) / 1000) * 1000;
  }
  cout << debt << endl;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
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; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int N;
    cin >> N;
    vector<int> A(81);
    bool ans = false;
    REP(i,9){
        REP(j,9){
            if(N == (i+1) * (j+1) ) ans = true;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    lld N;
    lld a[200001];
    cin >> N;
    lld sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum = sum ^ a[i];
    }
    for (int i = 0; i < N; i++) {
        lld ans = sum ^ a[i];
        cout << ans;
        if(i == N-1){
            cout << endl;
        } else {
            cout << " ";
        }
    }
    
}

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

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)
#define sz(x) (int)(x).size()

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;
constexpr ll mod = 1000000007;

ll powMod(ll a, ll b, ll n) {
        if (b == 0) return 1;
        ll res = 1;
        while (b > 1) {
                if (b & 1) res = (a * res) % n;
                a = (a * a) % n;
                b /= 2;
        }
        return (a * res) % n;
}

ll inv(ll a) {
        return powMod(a, mod - 2, mod);
}

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

        int n;
        cin >> n;
        vector<ll> a(n);
        fora(i, n) cin >> a[i];

        vector<ll> pl(n), pr(n), wpl(n), wpr(n);

        pl[0] = a[0], wpl[0] = 0;
        for (int i = 1; i < n; ++i) {
                pl[i] = (pl[i - 1] + a[i]) % mod;
                wpl[i] = (wpl[i - 1] + i * a[i]) % mod;
        }

        pr[n - 1] = a[n - 1], wpr[n - 1] = 0;
        for (int i = n - 2; i >= 0; --i) {
                pr[i] = (pr[i + 1] + a[i]) % mod;
                wpr[i] = (wpr[i + 1] + (n - i - 1) * a[i]) % mod;
        }

        ll fac = 1;
        forb(i, n) fac = (i * fac) % mod;

        ll res = (pl[n - 1] * fac) % mod;
        //cout << dbgs(res) << endl;
        for (int len = 1; len < n; ++len) {
                ll w = (fac * inv(len + 1)) % mod;
                ll l = (w * pl[len - 1]) % mod;
                ll r = (w * pr[n - len]) % mod;
                //if (len == n) r = 0;
                //cout << dbgs4(len, w, l, r) << endl;

                res = (res + l + r) % mod;

                ll w2 = (fac * inv((((ll)(len + 1) * (ll)(len + 2)) / 2) % mod)) % mod;
                int mi = n - 2;
                if (mi < len) continue;
                ll dist = max(0, min(len, mi - len));
                //cout << dbgs2(mi, dist) << endl;
                ll l2 = (w2 * wpl[dist]) % mod;
                ll r2 = (w2 * wpr[n - dist - 1]) % mod;
                //ll len_mid = mi - 2 * dist;
                ll max_overlap = min(len, mi - len + 1);
                ll mid_area = (pl[n - dist - 2] - pl[dist] + mod) % mod;
                ll m2 = (((w2 * max_overlap) % mod) * mid_area) % mod;
                //cout << dbgs4(w2, l2, r2, m2) << endl;
                res = (res + l2 + r2 + m2) % mod;
        }
        cout << res << endl;

}


Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int main(void) {
	int n, k;
	char s[100001] = { 0 };
	int cnt = 0;
	int flip = 0;
	int flag = 0;

	scanf("%d %d", &n, &k);
	scanf("%s", s);

	for (int i = 0; i < n; i++) {
		if (i == 0 && s[0] == 'R' && s[1] == 'R')cnt++;
		else if (i == n - 1 && s[n - 2] == 'L' && s[n - 1] == 'L')cnt++;
		else if (s[i] == 'L' && s[i - 1] == 'L')cnt++;
		else if (s[i] == 'R' && s[i + 1] == 'R')cnt++;	
	}
	for (int i = 1; i < n; i++) {
		if (flag == 0 && s[i] != s[0]) flag = 1;
		else if (flag == 1 && s[i] == s[0]) {
			cnt += 2, flip++,flag=0;
		}
		if (flip == k)break;
		else if (i == n - 1 && s[n - 1] != s[0])cnt++;
	}
	printf("%d", cnt);
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
	int n;
	cin >> n;
	
	string s;
	set<string> st;
	
	f(i,n)
	{
		cin >> s;
		st.insert(s);
	}
	
	cout << st.size();
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

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

int main() {
	int w, a, b;
	cin >> w >> a >> b;

	int aw, bw;
	aw = a + w;
	bw = b + w;

	if (abs(max(aw,bw)-min(a,b))<=w*2) {
		cout << 0 << endl;
	}
	else {
		cout << abs(min(aw, bw) - max(a, b)) << endl;
	}
}


Measured memory_bytes: 256
/**
 *      ABC 85 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-01 04:30:16
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string S; cin >> S;
    
    cout << S[0] << S[1] << S[2] << '8';
    cout << '\/' << S[5] << S[6] << '\/' << S[8] << S[9];

    return 0;
}


Measured memory_bytes: 256
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a, b = map(int, input().split())
if a <= 1:
  basea = 0
else:
  basea = comb(a,2)
if b <= 1:
  baseb = 0
else:
  baseb = comb(b,2)
print(basea + baseb)

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


int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n)
    cin >> d[i];
  ll ans = 0;
  rep(i, n - 1)
    for (int j = i + 1; j < n; j++)
      ans += d[i] * d[j];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    string s1;
    string s2;

    cin >> s1;
    cin >> s2;

    int min_diff = s2.length();

    for(int i = 0; i < s1.length(); i++){
        int diff = s2.length();
        for(int j = 0; j < s2.length(); j++){
            if(i + j >= s1.length()){
                diff = s2.length();
                break;
            }
            if(s1[i + j] == s2[j]){
                diff -= 1;
            }
        }

        if(diff < min_diff){
            min_diff = diff;
        }
    }

    cout << min_diff << endl;

    return 0;
}

Measured memory_bytes: 3628
N = int(input())
xy = set(tuple(map(int, input().split())) for _ in range(N))

if len(xy) == 1:
    print(0)
else:
    plus = [x+y for x, y in xy]
    diff_plus = max(plus) - min(plus)

    minus = [x-y for x, y in xy]
    diff_minus = max(minus) - min(minus)

    print(max(diff_minus, diff_plus))

Measured memory_bytes: 143720
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

#define Tcmp(X, Y) (abs(aryvec[i]->x) == X && abs(aryvec[i]->y) == Y)

template<typename T> void input(T *data, int n){
	For(i, n){
		cin >> data[i];
	}
}

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

struct Vec{
	int x, y;
	Vec():
	x(0), y(0){}
};

int main(){

	int a, b, t;

	cin >> a >> b >> t;

	int cookie = (int)(((double)t + 0.5) / a) * b;

	out(cookie);
	
	return 0;

}

Measured memory_bytes: 256
import itertools

num = int(input())
w_arr = [int(i) for i in input().split()]

w_div_arr = []
for i in range(num-1):
  former = sum(w_arr[:i+1])
  later = sum(w_arr[i+1:])
  div = abs(former - later)
  w_div_arr.append(div)

print(min(w_div_arr))

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
using namespace std;
int h[100005];
int dp[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>h[i];
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++)
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 4364
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    int t[102], v[102];
    int l[102], r[102];
    int pt[102];
    int d[40003];
    l[0] = 0;
    pt[0] = 0;
    for(int i = 1; i <= n; i++){
        cin >> t[i];
        t[i] *= 2;
        pt[i] = pt[i - 1] + t[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> v[i];
        v[i] *= 2;
        l[i] = min(l[i - 1], v[i] - pt[i]);
    }
    r[n] = 0;
    for(int i = n - 1; i >= 0; i--){
        r[i] = min(r[i + 1], v[i + 1] - (pt[n] - pt[i]));
    }
    for(int i = 1; i <= n; i++){
        for(int j = pt[i - 1]; j <= pt[i]; j++){
            d[j] = min(l[i - 1] + j, r[i] + (pt[n] - j));
            d[j] = min(d[j], v[i]);
        }
    }
    double ans = 0;
    for(int i = 0; i < pt[n]; i++){
        ans += d[i] + d[i + 1];
    }
	printf("%.15f\n", ans / 8.0);
}

Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <numeric>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vec>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    ll a=in(),b=lin();
    ll n = min(lin(),b-1);
    cout<<a*n/b<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v) cout << i << ' ' << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vin2(v, w) for (ll i = 0; i < v.size(); ++i) cin >> v[i] >> w[i];
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 (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(18);

	int X, N;
	cin >> X >> N;
	vi p(N); vin(p);
	sort(all(p));
	
	if(N == 0){
		cout << X;
		return 0;
	}

	rep(i, N){
		int flag = 0;
		rep(j, N){
			if(p.at(j)==X-i && X-i >= 0){
				flag = 1;
			}
		}
		if(flag == 0){
			cout << X-i;
			return 0;
		}
		flag = 0;
		rep(j, N){
			if(p.at(j)==X+i && X+i <= 100){
				flag = 1;
			}
		}
		if(flag == 0){
			cout << X+i;
			return 0;
		}
	}

	cout << 0;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>

using namespace std;

int main() {
	string week[] = {  "SUN","MON","TUE","WED","THU","FRI","SAT" };
	string s;

	cin >> s;

	for (int i = 0; i < 7; i++) {
		if (s == week[i]) {
			cout << 7 - i << endl;
			break;
		}
	}


	return 0;
};


Measured memory_bytes: 888
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        //String s = sc.next();
        
        
        int k = Integer.parseInt(sc.next());
        int count =0;
        int i=b+1;
        while(count<k){
            i--;
            if((a%i==0)&&(b%i==0)) count++;
        }
        
        System.out.println(i);
    }
}

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

int main(){
//	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	if(s[0] == '0' || s[n - 1] == '1'){
		cout << "-1\n";
		return 0;
	}
	for(int i = 0; i < n - 1; ++i){
		if(s[i] != s[n - 2 - i]){
			cout << "-1\n";
			return 0;
		}
	}

	int r = 1;
	for(int i = 0; i < n - 1; ++i){
		cout << r << ' ' << i + 2 << '\n';
		if(s[i] == '1'){
			r = i + 2;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(void)
{
  int in[5];
  int i,j;
  for(i=0;i<5;i++)
    scanf("%d",&in[i]);
  for(i=1;i<5;i++){
    for(j=0;j<i;j++){
	  if(in[i]>in[j]){
	    int tmp=in[i];
		in[i]=in[j];
		in[j]=tmp;
	  }
	}
  }
  printf("%d %d %d %d %d\n",in[0],in[1],in[2],in[3],in[4]);

  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> pii;

int main(){
	while(true){
		int N;
		cin >> N;
		if(N == 0){ break; }
		map<string, pii> programs;
		set<pii> times;
		for(int i = 0; i < N; ++i){
			string name;
			pii t;
			cin >> name >> t.first >> t.second;
			if(t.second % 100 >= 60){ t.second = 59; }
			programs.insert(make_pair(name, t));
			times.insert(t);
		}
		int M;
		cin >> M;
		multiset<pii> favs;
		for(int i = 0; i < M; ++i){
			string name;
			cin >> name;
			favs.insert(programs[name]);
		}
		bool invalid = false;
		pii prev(0, 0);
		for(multiset<pii>::iterator it = favs.begin(); it != favs.end(); ++it){
			prev.second += 30;
			if(prev.second % 100 >= 60){ prev.second += 100 - 60; }
			if(*it < prev){ invalid = true; break; }
			prev = *it;
		}
		if(invalid){
			cout << "-1" << endl;
			continue;
		}
		int answer = 0;
		pii curTime(0, 600);
		set<pii>::iterator it;
		while((it = times.lower_bound(curTime)) != times.end()){
			++answer;
			curTime = *it;
			multiset<pii>::iterator jt = favs.lower_bound(curTime);
			curTime.second += 30;
			if(curTime.second % 100 >= 60){ curTime.second += 100 - 60; }
			if(jt != favs.end() && *jt < curTime){
				curTime = *jt;
				curTime.second += 30;
				if(curTime.second % 100 >= 60){ curTime.second += 100 - 60; }
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 992
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void){

	int n;
	int day[1000];
	
	cin >> n;
	
	for( int i = 0; i < n; i++ ){
    	cin >> day[i];
	}
	
	for( int i = n - 1; i >= 0; i--){
		if(i == 0){
			cout << day[i] ;
		}else{
		
		cout << day[i] << " ";
		}
	}
	cout << endl;





return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<unsigned long long> a(n);
  rep(i, n) cin >> a[i];
  vector<double> l(n);
  rep(i, n) l[i] = log10(a[i]);
  if((double)accumulate(ALL(l), 0.0) > 18) {
    cout << -1 << endl;
    return 0;
  }
  unsigned long long ans = 1;
  rep(i, n) ans *= a[i];
  if(ans > (unsigned long long)pow(10, 18)) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 4904
S = str(input())
i = 0
left = 0
cnt = 1

while i < len(S):
    tmp = S[i]
    j = i + 1
    if j >= len(S):
        break
    right = S[j]
    while j < len(S):
        if tmp != left: 
            if tmp != right:
                if len(tmp) != len(S) - j or j == len(S) - 1:
                    cnt += 1
                    break
                elif tmp == S[j:]:
                    tmp += S[j]
                    j += 1
                    if j < len(S):
                        right = S[j]
                else:
                    cnt += 1
                    break


            else:
                j += 1
                if j < len(S):
                    right += S[j]
        else:
            tmp += S[j]
            j += 1
            if j < len(S):
                right = S[j]
    i += len(tmp)
    left = tmp
print(cnt)

Measured memory_bytes: 3500
import math

n, d = map(int, input().split())
xs = []
for i in range(n):
    xs.append([int(x) for x in input().split()])

count = 0
for a in range(n):
    x1 = xs[a]
    for b in range(n):
        if a == b:
            continue
        x2 = xs[b]
        r = 0
        for ii in range(d):
            r += abs(x1[ii] - x2[ii])**2
        r = math.sqrt(r)
        if r.is_integer():
            count += 1
print(int(count / 2))


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

using namespace std;

typedef long long ll;
ll n, k, cnt, ans;

int main() {

	cin >> n >> k;

	cnt = n / k;
	ans = cnt * cnt * cnt;

	if (k % 2 == 0) {
		cnt = (n + k / 2) / k;
		ans += cnt * cnt * cnt;
	}

	cout << ans<< "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
  ll a;
  double b;
  cin >> a >> b;
  if(a == 0 || b == 0.00){
    cout << 0 << endl;
    return 0;
  }
  
  ll b2 = b*100+0.5;
  
  ll ans = a*b2/100;
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(){
	int n;
	char a[10001];
	scanf("%d %s",&n,a);
	char b[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N',
	'O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	for(int i=0;i<strlen(a);i++){
		for(int j=0;j<26;j++){
			if(a[i]==b[j]){
				if(j+n>=26)
					printf("%c",b[j+n-26]);
				else
					printf("%c",b[j+n]);
			}
		}
	}
	puts("");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    ll a = 0, b = 1000;
    rep(i, N-1){
        if(A[i] < A[i+1]) a += b/A[i], b %= A[i];
        if(A[i] == A[i+1]) continue;
        if(A[i] > A[i+1]) b += A[i]*a, a = 0;
    }
    b += A[N-1]*a, a = 0;
    cout << b << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define s second
ll power(ll x, ll y){ ll ans = 1;x %= MOD;while(y){if(y&1)ans = (x * ans) % MOD;x = (x * x) % MOD;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
using namespace std;


int main() {
    fastio;
    ll n, k;
    cin >> n >> k;
    ll arr[n + 1];
    for(int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    
    int visited[n + 1];
    int index[n + 1];
    memset(visited, 0, sizeof(visited));
    vector<ll> circle (n + 1);
    int i = 0;
    int curr = 1;
    ll start;
    while(true) {
        if(visited[curr]) {
            start = index[curr];
            break;
        }
        visited[curr] = 1;
        index[curr] = i;
        circle[i++] = curr;
        curr = arr[curr];
    }
    
    //cout << start << " " << i << endl;
    
    if(k < i) {
        cout << circle[k] << endl;
    } else {
        k -= start;
        ll temp = k % (i - start);
        
        cout << circle[start + temp] << endl;
    }
    
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;

const int Q = 303;
const ll INF = 0x3f3f3f3f3f3f3f3f;

pair<ll, ll> dist[Q][Q];
int N, M, L;
ll co[Q][Q];
int taken[Q];

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> N >> M >> L;
  for (int i=0; i<Q; ++i) {
    for (int j=0; j<Q; ++j) {
      dist[i][j] = {INF, INF};
      co[i][j] = INF;
    }
    dist[i][i] = {0, -L};
  }
  for (int i=1; i<=M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (c > L) {
      continue;
    }
    co[a][b] = c;
    co[b][a] = c;
  }
  for (int i=1; i<=N; ++i) {
    int u = i;
    memset(taken, 0, sizeof taken);
    while (u != 0) {
      //cerr << " " << i << "->" << u << " :: " << dist[i][u].first << "," << dist[i][u].second << endl;
      taken[u] = 1;
      for (int v=1; v<=N; ++v) {
        if (co[u][v] == INF) {
          continue;
        }
        auto va = dist[i][u];
        va.second += co[u][v];
        if (va.second > 0) {
          va.second = -L+co[u][v];
          va.first++;
        }
        dist[i][v] = min(dist[i][v], va);
      }
      dist[i][0] = {INF, INF};
      int nxt = 0;
      for (int v=1; v<=N; ++v) {
        if (dist[i][v] < dist[i][nxt] && !taken[v]) {
          nxt = v;
        }
      }
      u = nxt;
    }
  }
  int q;
  cin >> q;
  for (int i=1; i<=q; ++i) {
    int s, t;
    cin >> s >> t;
    auto a = dist[s][t];
    if (a.first == INF) {
      cout << -1 << "\n";
    } else {
      cout << a.first << "\n";
    }
  }
  return 0;
}


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

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u,int k){
    while(u != NIL && k != u->key){
        if(k < u->key){
            u = u->left;
        }
        else u = u->right;
    }
    return u;
}

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

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }
        else{
            x = x->right;
        }
    }
    z->parent = y;
    if(y == NIL){
        root = z;
    }
    else{
        if(z->key < y->key){
            y->left = z;
        }
        else{
            y->right = z;
        }
    }
}

void inorder(Node u){
    if(u == NIL){
        return;
    }
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node u){
    if(u == NIL){
        return;
    }
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,i,x;
    char com[20];
    Node t;
    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%s",com);
        if(com[0] == 'f'){
            scanf("%d",&x);
            t = treeSearch(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }
        else if(com[0] == 'i'){
            scanf("%d",&x);
            insert(x);
        }
        else if(com[0] == 'p'){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 20608
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<cstring>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t,o;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
typedef double dob;
bitset<60> fr[60];
int a[60],b[60],vis[60],n,m;
bool judge(){
	rep(i,0,m) fr[i].reset();
	per(i,m,0){
		fr[i][i]=1;
		rep(j,1,i) if (vis[j]) fr[i%j]|=fr[i];
	}
	bool flag=1;
	rep(i,1,n) if (!fr[b[i]][a[i]]) flag=0;
	return flag;
}
void dfs(int d){
	if (!d) return;
	vis[d]=0;
	if (!judge()) vis[d]=1;
	dfs(d-1);
}
int main(){
	scanf("%d",&n);
	m=50;
	rep(i,1,n) scanf("%d",a+i);
	rep(i,1,n) scanf("%d",b+i);
	rep(i,1,m) vis[i]=1;
	dfs(m+1);
	LL ans=0;
	rep(i,1,m) if (vis[i]) ans+=1ll<<i;
	printf("%lld\n",vis[m+1]?-1:ans);
	return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	string s;
	cin >> s;
	cout << string(s.size(), 'x') << endl;



	return 0;
}

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

int main(){
  int n; cin >> n;
  int sum[100010]={0};
  int a[100010]; cin >> a[0];
  int pos = 0;
  int cnt = 1;
  for(int i=1;i<n;i++){
    cin >> a[i];
    if(a[i] == a[i-1]){
      sum[pos] = cnt;
      cnt = 1;
      pos++;
    }
    else cnt++;
  }
  sum[pos] = cnt;
  pos++;
  int ans = 0;
  for(int i=0;i<pos;i++){
    ans = max(ans,sum[i]+sum[i+1]+sum[i+2]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1948
ceilDiv :: Integral a => a -> a -> a
ceilDiv t s = (t + s - 1) `div` s

main :: IO ()
main = do
    [n,a,b] <- map read . words <$> getLine :: IO [Int]
    print $ (n `div` (a+b)) * a + min (n `mod` (a+b)) a

Measured memory_bytes: 508