akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

long long N, M, L[309], R[309], X[309], dp[309][309][309], mod = 1000000007; vector<pair<long long, long long>>E[309];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> L[i] >> R[i] >> X[i]; E[R[i]].push_back(make_pair(L[i], X[i]));
	}
	dp[0][0][0] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= j; k++) {
				if (dp[i - 1][j][k] == 0) continue;
				for (int l = 0; l < 3; l++) {
					int I[3] = { i - 1,j,k };
					I[l] = i; sort(I, I + 3); reverse(I, I + 3);
					dp[i][I[1]][I[2]] += dp[i - 1][j][k];
					dp[i][I[1]][I[2]] %= mod;
				}
			}
		}
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= N; k++) {
				if (dp[i][j][k] == 0) continue;
				bool OK = true;
				for (int l = 0; l < E[i].size(); l++) {
					int LL = E[i][l].first;
					if (E[i][l].second == 1) {
						if (!(LL > j)) OK = false;
					}
					if (E[i][l].second == 2) {
						if (!(LL <= j && LL > k)) OK = false;
					}
					if (E[i][l].second == 3) {
						if (!(LL <= k)) OK = false;
					}
				}
				if (OK == false) dp[i][j][k] = 0;
			}
		}
	}
	long long sum = 0;
	for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) sum += dp[N][i][j]; }
	cout << sum%mod << endl;
	return 0;
}

Measured memory_bytes: 223488
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    double t,x; cin>>t>>x;
    printf("%.10f\n",t/x);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    double a, b, c, d, e, f;
    double x, y;
    
    while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
        y = (a * f - c * d) / (a * e - b * d);
        x = (c - b * y) / a;
        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

Measured memory_bytes: 652
import sys
from collections import defaultdict
from queue import deque

readline = sys.stdin.buffer.readline


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


sys.setrecursionlimit(10**5)


def main():
    n, d, a = geta(int)
    mon = []
    ans = 0

    for _ in range(n):
        x, h = geta(int)
        mon.append([x, (h + a - 1) // a])

    mon.sort()

    bom = deque()
    cur = 0
    for i, mi in enumerate(mon):

        while len(bom) != 0 and bom[0][0] < mi[0]:
            b = bom.popleft()
            cur -= b[1]

        if mi[1] <= cur:
            continue
        else:
            b1 = mi[1] - cur
            bom.append((mi[0] + 2 * d, b1))
            cur += b1
            ans += b1

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 71512
#include <bits/stdc++.h>
# include <string>
# include <math.h>
using namespace std;
typedef long long int ll;
//typedef .push_back pb;

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

	int n; cin >> n;
	int a = n%10;
	if(a==2 || a== 4 || a==5 || a==7 || a==9){
		cout << "hon" <<endl;
	}
	else if( a==3){
		cout << "bon" <<endl;
	}
	else cout << "pon" <<endl;	
	
}


Measured memory_bytes: 3616
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

int n, a, b;

const int mod = 1e9 + 7, N = 2e5 + 5;

ll inv[N];

ll fast_pow(ll b, ll p)
{
	if (p == 0)
		return 1;

	ll ret = fast_pow(b, p / 2);
	ret = (ret * ret) % mod;

	if (p & 1)
		ret = (ret * b) % mod;

	return ret;
}

ll get(int x)
{
	ll num = 1;

	for(ll i = n; i > n - x; i--)
		num = (num * 1ll * i) % mod;
	return (num * inv[x]) % mod;
}

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    ll res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}
ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}

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

	cin >> n >> a >> b;

	ll res = fast_pow(2, n), aa = modBinomial(n, a, mod), bb = modBinomial(n, b, mod);
	res = mod(res - 1, mod);

	res = mod(res - aa, mod);
	res = mod(res - bb, mod);
	cout << res << endl;

	return 0;
}


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

int main(){
  int m=1000000,e;
  
  while(1){
    cin>>e;
    m=1000000;
    if(e==0)break;
    for(int z=0;z*z*z<=e;z++){
      for(int y=0;y*y<=(e-z*z*z);y++){
	int x=e-y*y-z*z*z;
	if(e==x+y*y+z*z*z) m=min(m,(x+y+z));	
      }
    }
    cout<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
count=1
if a[0]==2:
    print(1)
    exit()
b=a[a[0]-1]
while count<=n:
    if b==2:
        print(count+1)
        exit()
    else:
        count +=1
        b=a[b-1]
print(-1)

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

using namespace std;

int main() {

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

	string s, t;
	cin >> s >> t;
	if (t.length() - s.length() == 1 && t.substr(0, s.length()) == s) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

int main()
{
	int n;
	while(cin>>n)
	{
		int sum=0;
		for(int a=0;a<10;a++)
			for(int b=0;b<10;b++)
				for(int c=0;c<10;c++)
					for(int d=0;d<10;d++)
						if(a+b+c+d==n)
							sum++;
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1160
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

ll get_path_len(ll x, ll y){
    if(x < y){swap(x, y);}
    ll ret = (x / y) * 2 * y;
    if(x%y == 0){
        ret -= y;
    }
    else{
        ret += get_path_len(y, x%y);
    }
    return ret;
}

int main(){
    ll n, x; cin >> n >> x;
    cout << get_path_len(n-x, x) + x + n-x << endl;
    return 0;
}

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

class Program
{

	//Main
	static void Main(string[] args)
	{
		//読み込む
		double R = double.Parse(Console.ReadLine());
		double ans = 2 * R * Math.PI;

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


Measured memory_bytes: 18624
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;
using ll = long long int;

int main() {
	string s;
	cin >> s;
	ll num = 0;
	ll total = 0;
	ll total2 = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			total++;
			total2 += total;
			num += s.size() - i;
		}
	}
	cout << num - total2;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec[i];
	}

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

	double ans = vec[0];

	for (int i = 1; i < n; i++) {
		ans = (ans + vec[i]) / 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

struct wyr
{
    ll a, nowe_a, nr;
};

bool porownanie(wyr a, wyr b)
{
    if (a.a < b.a) return true;
    else return false;
}

bool porownanie2(wyr a, wyr b)
{
    if (a.nr < b.nr) return true;
    else return false;
}

vector<ll> T;
int l, size;

void Stworz(int n)
{
    int p = 1;
    while (p < n) p *= 2;
    l = p;
    size = 2 * p - 1;
    for (int i = 0; i <= size; ++i) T.push_back(0);
}

void Dodaj(int a)
{
    a += l;
    while (a != 0)
    {
        ++T[a];
        a /= 2;
    }
}

ll Pyt(int a, int b)
{
    a += l;
    b += l;
    ll s = T[a];
    if (a != b) s += T[b];
    while (a / 2 != b / 2)
    {
        if (a % 2 == 0) s += T[a + 1];
        if (b % 2 == 1) s += T[b - 1];
        a /= 2;
        b /= 2;
    }
    return s;
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    vector<wyr> A(n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &A[i].a);
        A[i].a -= k;
        A[i].nr = i;
        if (i != 0) A[i].a += A[i - 1].a;
    }
    sort(A.begin(), A.end(), porownanie);
    A.push_back({10000000000, 0, 0});
    ll akt = 0;
    for (int i = 0; i < n; ++i)
    {
        A[i].nowe_a = akt;
        if (A[i].a != A[i + 1].a) ++akt;
    }
    A.pop_back();
    sort(A.begin(), A.end(), porownanie2);
    Stworz(akt + 1);
    ll wyn = 0;
    Dodaj(A[0].nowe_a);
    if (A[0].a >= 0) ++wyn;
    for (int i = 1; i < n; ++i)
    {
        wyn += Pyt(0, A[i].nowe_a);
        if (A[i].a >= 0) ++wyn;
        Dodaj(A[i].nowe_a);
    }
    printf("%lld", wyn);
    return 0;
}


Measured memory_bytes: 15024
a, b = map(int, input().split())

def small(a, b):
    return a < b
    
def big(a, b):
    return a > b

def equal(a, b):
    return a == b

if small(a, b):
    print('a < b')
elif big(a, b):
    print('a > b')
elif equal(a, b):
    print('a == b')


Measured memory_bytes: 5596
#include <iostream>
#include <stack>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    stack<char> S;
    for (int i = 0; i < nap.size(); ++i)
    {
        if (nap[i] == 'S')
            S.push('S');
        else
        {
            if (S.size() != 0 && S.top() == 'S')
                S.pop();
            else
                S.push('T');
        }
    }
    cout << S.size();
    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>
#include <cstring>
#include <cctype>
#include <random>

using namespace std;
typedef long long  ll;
const ll INF = 1000000007;
const ll mod = 998244353;

vector<ll> dp(2 * 100000 + 1, -1);
vector<ll> popcount(2 * 100000 + 1, 0);

int pcnt(int x) {
	return __builtin_popcount(x);
}

int f(int x) {
	if (x == 0) return 0;
	return f(x % pcnt(x)) + 1;
}

int main()
{
	ll n;
	cin >> n;
	string s;
	cin >> s;
	vector<ll> x(n);
	for (ll i = 0; i < n; i++)
	{
		x[i] = s[i] - '0';
	}
	ll pc = 0;
	for (ll i = 0; i < n; i++)
	{
		pc += x[i];
	}
	vector<ll> ans(n);
	for (ll b = 0; b < 2; b++)
	{
		ll npc = pc;
		if (b == 0) npc++; else npc--;
		if (npc <= 0) continue;
		ll r0 = 0;
		for (ll i = 0; i < n; i++)
		{
			r0 = (r0 * 2) % npc;
			r0 += x[i];
		}
		ll k = 1;
		for (ll i = n - 1; i >= 0; --i) {
			if (x[i] == b) {
				int r = r0;
				if (b == 0) r = (r + k) % npc;
				else r = (r - k + npc) % npc;
				ans[i] = f(r) + 1;
			}
			k = (k * 2) % npc;
		}
	}
	for (ll i = 0; i < n; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 9928
import numpy as np
n,d = map(int,input().split())
x = [[0 for _ in range(d)] for _ in range(n)]

for i in range(n):
	X = list(map(int,input().split()))
	x[i] = X
	
c = 0
for i in range(n):
	for j in range(i+1,n):
		if(i == j):continue
		
		dist = 0.0
		for k in range(d):
			dist += (x[i][k] - x[j][k]) ** 2.0
		dist = np.sqrt(dist)
		if(dist % 1.0 < 0.001):c+=1
print(c)

Measured memory_bytes: 12448
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		String s=nextLine();
		int cnt[]=new int[128];
		for(int i=0;i<s.length();i++)
			cnt[s.charAt(i)]++;
		if(cnt['N']*cnt['S']==0 && cnt['N']+cnt['S']>0 || cnt['E']*cnt['W']==0 && cnt['E']+cnt['W']>0)
			out.println("No");
		else
			out.println("Yes");
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
bool dame[10];
int main(void) {
  int n, k;
  int d;
  cin >> n >> k;
  for(int i = 0;i < k; i++) {
    cin >> d;
    dame[d] = true;
  }
  for(int i = n; ; i++) {
    int j = i;
    bool flag = false;
    while(j && !flag) {
      if(dame[j%10]) flag = true;
      j /= 10;
    }
    if(!flag) {
      cout << i << endl;
      exit(0);
    }
  }
}


Measured memory_bytes: 256
n, *S = open(0)
n = int(n)
a = b = ba = c = 0
for i in range(n):
  S[i] = S[i].strip()
  if S[i][-1]=='A' and S[i][0]=='B':
    ba += 1
  else:
    a += S[i][-1]=='A'
    b += S[i][0]=='B'
  c += S[i].count('AB')
if ba == 0:
  print(c + min(a, b))
elif a+b == 0:
  print(c + ba-1)
else:
  print(c + ba + min(a, b))

Measured memory_bytes: 9612
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <bitset>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <assert.h>
using namespace std;
#define e exp(1.0)
typedef long long ll;
#define MAXN 100005
#define mod 998244353
#define INF 0x3f3f3f3f3f3f3f
#define fe(i,st,en) for(i = (st);i <= (en);++i)
#define fne(i,st,en) for(i = (st);i < (en);++i)
#define ri register int
#define db double
int a[MAXN], tr[MAXN];
int main() {
	int n, m, l, r;
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", &l, &r);
		for (int j = l; j <= n + 1; j += (j&(-j)))tr[j]++;
		for (int j = r+1; j <= n + 1; j += (j&(-j)))tr[j]--;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int s = 0;
		for (int j = i; j; j -= (j&(-j))) s += tr[j];
		
		if (s == m) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

// DAME:

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int g_cnt = 0;
    int p_cnt = 0;
    int ans = 0;;
    for(int i=0; i<n; i++){
        if(g_cnt-p_cnt>0){
            // p
            if(s[i]=='g'){
                ans++;
            }
            p_cnt++;
        }else{           
            // g
            if(s[i] == 'p'){
                ans--;
            }
            g_cnt++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2*1e5+10;
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;


void printVector(vector<int> s){
    for(int &x:s){
        cout<<x<<" ";
    }
    cout<<endl;
}



void solve(){
    int n;
    cin>>n;
    vector<int> h(n+1);
    for(int i = 1 ; i<= n ; i++) cin>>h[i];
    vector<int> dp(n+1 , INF);
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for(int i = 3 ; i <= n; i++){
        dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1] , abs(h[i] - h[i-2]) + dp[i-2]);
    }
//    printVector(dp);
    cout<<dp[n]<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
//    cin>>t;
    t = 1;
    for(int i = 0 ; i < t ; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>
#include<math.h>
int main(void)
{
    int r,d,x,i,j;
    scanf("%d %d %d",&r,&d,&x);
    for(i=1;i<=10;i++)
    {
        j=r*x-d;
        printf("%d\n",j);
        x=j;
    }
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define debug(x_) cerr << #x_ << ":" << x_ << endl;
#define debug2(x__) for(auto a__ : x__) cerr << a__ << " "; cerr << endl;
#define debug3(x___ , sx___) rep(i, sx___) cerr << x___[i] << " "; cerr << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> odd, even;
    int Max_o = 0, Max_e = 0;
    set<int> used_odd,used_even;

    rep(i, n) {
        int a;
        cin >> a;
        if (i % 2 == 0) {
            odd[a]++;
            used_odd.insert(a);
        } else {
            even[a]++;
            used_even.insert(a);
        }
    }

    vector<pii> po, pe;
    po.push_back(MP(0, -1)), pe.push_back(MP(0, -2));
    for (auto a : used_odd) po.push_back(MP(odd[a], a));
    for (auto a : used_even) pe.push_back(MP(even[a], a));
    sort(all(po));
    sort(all(pe));
    reverse(all(po));
    reverse(all(pe));
    int ans;
    if (po[0].second == pe[0].second) {
        ans = po[0].first + pe[1].first;
        ans = max(ans, po[1].first + pe[0].first);
    } else {
        ans = po[0].first + pe[0].first;
    }
    cout << n - ans << endl;
    return 0;
}



Measured memory_bytes: 10748
#include<bits/stdc++.h>
using namespace std ;
int main () {
  char str[1001] ;
  while(1){
    scanf("%s",str);
    if(str[0]=='0') break ;
    int sum = 0 ;
    for(int i = 0 ; i < strlen(str) ; i++ ){
      sum += str[i] -'0' ;
    }
    cout << sum << endl ;
  }
}


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

int main(void){

    char S[100001];
    int i,N,ans=1;

    scanf("%d",&N);
    scanf("%s",S);

    for(i = 0;i < N-1;i++){
        if(S[i] != S[i + 1]){
            //strcpy(tmp[0],S[i]);
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int N;
    cin >> N;
    int arr[N];
    for (int i = 0 ; i < N ; i++)
        cin >> arr[i];
    long long ans = 1000;
    for (int i = 0 ; i < N ;){
        int mini = 1e8;
        while(i < N && arr[i] <= mini)
            mini = arr[i++];
        int maks = 0;
        while(i < N && arr[i] >= maks)
            maks = arr[i++];
        if (maks)
            ans += ans / mini * (maks - mini);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n;
	cin>>n;
	vector<LL> s(n);
	LL ans=0;
	FOR(i,0,n)cin>>s[i];
	FOR(i,1,n/2){
		LL t=0;
		int l=i,r=n-1-i;
		set<LL> st;
		FOR(j,0,n){
			if(l>=n-1||r<=0)break;
			if(st.find(l)!=st.end()||st.find(r)!=st.end()||l==r)break;
			if((n-1)%i==0&&l>=r)break;
			if(r-i<=0)break;
			st.insert(l);
			st.insert(r);
			t+=s[l]+s[r];
			ans=max(t,ans);
			l+=i;
			r-=i;
		}
	}

	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7424
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = getInt(sc);
		int b = getInt(sc);
		int c = getInt(sc);
		int d = getInt(sc);

		if (a + b > c + d) {
			System.out.println("Left");
		} else if (a + b == c + d) {
			System.out.println("Balanced");
		} else {
			System.out.println("Right");
		}
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int dp[100001];
int find_dp(int h[],int k,int n,int count){
	if(dp[count]!=-1)
	   return dp[count];
	   dp[count]=INT_MAX;
     for(int idx = 1;idx<=k&&count+idx<=n;idx++){
     	dp[count]=min(dp[count],abs(h[count]-h[count+idx])+find_dp(h,k,n,count+idx));
	 }
	 return dp[count];
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  int n,k;
  cin>>n>>k;
  int vec[n+1];
    for(int idx = 1;idx<=n;idx++)
      cin>>vec[idx];
  
   memset(dp,-1,sizeof(dp));
   dp[n]=0;
   dp[n-1]=abs(vec[n]-vec[n-1]);
  cout<<find_dp(vec,k,n,1);
   
  
  return 0;
}

Measured memory_bytes: 8832
import java.util.*;
import java.text.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static LinkedList<Pair> list;
    public static void main(String[] args) throws Exception {
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) break;
            String s = sc.next();
            for (int i = 0; i < n; i++) {
                list = new LinkedList<>();
                for (int j = 0; j < s.length(); j++) {
                    String c = s.substring(j, j+1);
                    if (!list.isEmpty()) {
                        Pair p = list.getLast();
                        if (!p.s.equals(c)) {
                            list.add(new Pair(c, 1));
                        } else {
                            list.getLast().i++;
                        }
                    } else {
                        list.add(new Pair(c, 1));
                    }
                }
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < list.size(); j++) {
                    Pair p = list.get(j);
                    sb.append(p.i).append(p.s);
                }
                s = sb.toString();
            }
            System.out.println(s);
        }
    }
}

class Pair {
    public String s;
    public int i;
    public Pair(String s, int i) {
        this.s = s;
        this.i = i;
    }
}

Measured memory_bytes: 40620
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

a, b = 0, 0
for i in range(N):
    if i % 2 == 0:
        a += A.pop(0)
    else:
        b += A.pop(0)

print(a-b)

Measured memory_bytes: 61828
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(Int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(Int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);

const string YES = "Yes";
const string NO = "No";
void yn(bool ok){
  cout << (ok ? YES : NO) << endl;
}

void solve(std::vector<std::vector<long long>> c){
  bool ok = true;
  rep(k, 1){
    rep(i, 2){
      REP(j, 1, 3) ok &= (c[i+1][j] - c[i][j] == c[i+1][0] - c[i][0]);
    }
    vvi c2 = c;
    rep(i, 3) rep(j, 3) c2[i][j] = c[j][i];
    swap(c2, c);
  }
  yn(ok);
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  std::vector<std::vector<long long>> c(3, std::vector<long long>(3));
  for(int i = 0 ; i < 3 ; i++){
    for(int j = 0 ; j < 3 ; j++){
      scanf("%lld",&c[i][j]);
    }
  }
  solve(std::move(c));
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
int main() {
  int a,b;scanf("%d%d", &a, &b);
  int res = 0;
  if (a > b) {
    res += a;
    a--;
  } else {
    res += b;
    b--;
  }
  if (a > b) {
    res += a;
    a--;
  } else {
    res += b;
    b--;
  }
  printf("%d\n", res);
}

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

const int N = 2e5+7, M = 1e9+7;
typedef long long LL;

LL power(LL a, LL p) {
    if (p == 0) return 1;
    LL ans = power(a, p/2);
    ans = (ans * ans)%M;
    if (p%2)    ans = (ans*a)%M;
    return ans;
}

LL fac[N], invfac[N], p2[N];
void pre() {
    fac[0] = 1;
    for(int i=1; i<N; i++)  fac[i] = (i*fac[i-1])%M;
    invfac[N-1] = power(fac[N-1], M-2);
    for (int i=N-2; i>=0; i--)  invfac[i] = (invfac[i+1]*(i+1))%M;
    p2[0] = 1;
    for(int i=1; i<N; i++)  p2[i] = (2*p2[i-1])%M;
}

int sz[N];
LL dp[N], invprod[N], dpprod[N];
vector<int> adj[N];


void dfs1(int u, int p) {
    sz[u] = 1;
    dpprod[u] = invprod[u] = 1;
    for (int v: adj[u]) {
        if (v == p)   continue;
        dfs1(v, u);
        sz[u] += sz[v];
        invprod[u] = (invprod[u] * invfac[sz[v]])%M;
        dpprod[u] = (dpprod[u] * dp[v])%M;
    }
    dp[u] = (dpprod[u] * invprod[u])%M;
    dp[u] = (dp[u] * fac[sz[u]-1])%M;
}

LL ans[N], over[N];
int n;

void dfs2(int u, int p) {
    if (p == -1)    ans[u] = dp[u];
    else {
        LL dpp = (dpprod[p] * power(dp[u],M-2))%M;
        LL invp = (invprod[p] * fac[sz[u]])%M;
        over[u] = (dpp*invp)%M;
        over[u] = (over[u] * fac[n-sz[u]-1])%M;
        dpprod[u] = (dpprod[u] * over[u])%M;
        invprod[u] = (invprod[u] * invfac[n-sz[u]])%M;
        ans[u] = (dpprod[u] * invprod[u])%M;
        ans[u] = (ans[u] * fac[n-1])%M;
    }
    for (int v: adj[u]) {
        if (v == p) continue;
        dfs2(v, u);
    }
}

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

    cin>>n;
    for (int i=1; i<n; i++) {
        int u, v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs1(1, -1);
    dfs2(1, -1);

    for (int i=1; i<=n; i++)    cout<<ans[i]<<"\n"; cout<<endl;
}



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

typedef long long ll;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll M = 1000, K = 0;
    rep(i, N) {
        M += K * A[i];
        K = 0;
        if (i < N - 1 && A[i] < A[i + 1]) {
            K = M / A[i];
            M -= K * A[i];
        }
    }
    cout << M << "\n";
}

Measured memory_bytes: 3624
/*
2017_02_25_AC
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

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

const int INF = 1000000000;
int w, h, cost[4], grid[35][35], dp[35][35][4];

void dfs(int y, int x, int dir, int currentcost){
  if(!CH(y,0,h) || !CH(x,0,w)) return;
  if(dp[y][x][dir] <= currentcost) return;
  dp[y][x][dir] = currentcost;
  if((x == w-1 && y == h-1)/* || grid[y][x] == 4*/) return;
  REP(k,0,5){
    if(k == 0){ //????????????
      int d = grid[y][x];
      if(0<=d && d<=3){ //grid[y][x]==4 (halt) ??????????????????
        dfs(y + dy[(dir + d) % 4], x + dx[(dir + d) % 4], (dir + d) % 4, currentcost);
      }
      /*
      switch (grid[y][x]) {
        case 0:
          dfs(y + dy[dir], x + dx[dir], dir, currentcost);
          break;
        case 1:
          dfs(y + dy[(dir + 1) % 4], x + dx[(dir + 1) % 4], (dir + 1) % 4, currentcost);
          break;
        case 2:
          dfs(y + dy[(dir + 2) % 4], x + dx[(dir + 2) % 4], (dir + 2) % 4, currentcost);
          break;
        case 3:
          dfs(y + dy[(dir + 3) % 4], x + dx[(dir + 3) % 4], (dir + 3) % 4, currentcost);
          break;
        case 4:
          //return;
          break;
        }
        */
    }else{  //???????????????tk: 0 ~ 3????????????4(halt)???????????????
      int tk = k - 1;
      if(tk == grid[y][x]) continue;
      dfs(y + dy[(dir + tk) % 4], x + dx[(dir + tk) % 4], (dir + tk) % 4, currentcost + cost[tk]);
      /*
      switch (tk) {
        case 0:
          dfs(y + dy[dir], x + dx[dir], dir, currentcost + cost[tk]);
          break;
        case 1:
          dfs(y + dy[(dir + 1) % 4], x + dx[(dir + 1) % 4], (dir + 1) % 4, currentcost + cost[tk]);
          break;
        case 2:
          dfs(y + dy[(dir + 2) % 4], x + dx[(dir + 2) % 4], (dir + 2) % 4, currentcost + cost[tk]);
          break;
        case 3:
          dfs(y + dy[(dir + 3) % 4], x + dx[(dir + 3) % 4], (dir + 3) % 4, currentcost + cost[tk]);
          break;
        }
      */
    }
  }
  return;
}

int main() {

  while(1){
    cin>>w>>h;
    if(w==0 && h==0) break;
    REP(i,0,h){
      REP(j,0,w){
        cin>>grid[i][j];
      }
    }
    REP(k,0,4) cin>>cost[k];
    //memset(dp, INF, sizeof(dp));
    REP(i,0,h)REP(j,0,w)REP(k,0,4) dp[i][j][k] = INF;

    dfs(0, 0, 0, 0);

    cout<<*min_element(dp[h-1][w-1], dp[h-1][w-1]+4)<<endl;
  }

  return 0;
}

Measured memory_bytes: 3236
def main():
    n =  int(input())
    ls = []
    for _ in range(n):
        a, b = map(int, input().split())
        ls.append([b,a])
    ls.sort()
    t=0
    for i in ls:
        t += i[1]
        if t > i[0]:
            print('No')
            exit(0)
    print('Yes')
if __name__ == '__main__':
    main()

Measured memory_bytes: 38060
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    using ll = long long;
    using P = pair<int,int>; 
    
    int main() {
   
     int n;
     string s;
     cin >> n >> s;
     ll sum;
     ll r = 0;
     ll g = 0;
     ll b = 0;
     
     rep(i,n){
     	if(s[i]=='R') r++;
     	if(s[i]=='G') g++;
     	if(s[i]=='B') b++;
     }
     
     sum = r*g*b;
     int get = 0;
     
     for(int i = 0; i < n; i++){
     	for(int j = i+1; j < n; j++){
     		if(s[i]==s[j]) continue;
     			int k = (2*j) - i;
     			if( k>=n ||s[i]==s[k] || s[k]==s[j])	continue;
     			else	get++;
     	}
     }
     
     	cout << sum -get<<'\n';
     
     return 0;
    }

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
ll sm(int i,int j,vector<ll>&pref,vector<ll>&arr){
	if (i==j)return arr[i];
	else if (i==0)return pref[j];
	else return pref[j]-pref[i-1];
}
int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	int n;
	cin>>n;
	vector<ll> arr(n);
	rep(i,0,n)cin>>arr[i];
	vector<vector<ll>>dp(n,vector<ll>(n,LONG_MAX));
//	vector<vector<ll>>sm(n,vector<ll>(n,0));
	vector<ll>pref(n);
	pref[0]=arr[0];
	rep(i,1,n)pref[i]=arr[i]+pref[i-1];
	
	rep(i,0,n)dp[i][i]=0;
	rep(l,2,n+1){
		rep(i,0,n-l+1){
			int j=i+l-1;
			rep(k,i,j){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sm(i,j,pref,arr));
			}
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    int count =0;
    int ans[n];
    for (int i=0;i<n;i++){
        cin >> ans[i];
    }
    int j=0;
    
    while (ans[j]%2==0){
        ans[j] = ans[j]/2;
        if (j ==(n-1)){
            count++;
            j=0;
            continue;
        }
        j++;
    }  
    cout << count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int x[4], y[4], xh, yh;
	for (int i = 0; i < 2; ++i)
	{
		cin >> x[i] >> y[i];
	}
	xh = x[1] - x[0];
	yh = y[1] - y[0];
	y[2] = y[1] + xh;
	x[2] = x[1] - yh;
	y[3] = y[2] - yh;
	x[3] = x[2] - xh;
	cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>   
#define ll long long
#define sz size
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define int long long    
#define rc(s) return cout<<s,0
using namespace std;

int n,m;

signed main(){
    ios_base::sync_with_stdio(0);  cin.tie(); cout.tie();
    cin >> n >> m;
    string s,t;
    cin >> s >> t;
    double a=n;
    double b=m;
    int ans=(m*n)/(__gcd(m,n));
    for(double i=0;i<=s.size()-1;i++){
        double y=(b/a)*i;
        if(y==floor(y)){
            if(s[i]!=t[y]){ rc(-1); }
        }
        
    }
    rc(ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e5+10, mod=1e9+7;

int main ()
{
    FASTIO
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout << "Yes" << endl;

    }

    else cout << "No" << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

K = int(input())

d = {
    "0": [0, 1],
    "1": [0, 1, 2],
    "2": [1, 2, 3],
    "3": [2, 3, 4],
    "4": [3, 4, 5],
    "5": [4, 5, 6],
    "6": [5, 6, 7],
    "7": [6, 7, 8],
    "8": [7, 8, 9],
    "9": [8, 9],
}

cand = set(i for i in range(1, 10))
while True:
    if len(cand) >= K:
        ans = sorted(list(cand))[K - 1]
        break
    K -= len(cand)
    new = set()
    for s in cand:
        val = d[str(s)[-1]]
        for v in val:
            new.add(s * 10 + v)
    cand = new


print(ans)

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

int main()
{
  ll x;
  cin >> x;

  ll yen = 100;
  int ans = 0;
  while(yen < x){
    yen *= 1.01;
    ans++;
  }
  
  cout << ans << endl;

  return 0; 
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int x;
	cin >> x;
	int ans = 360 / __gcd(x, 360LL);
	cout << ans;
	return 0;
}

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

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a/GCD(a,b)*b; }

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

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

  cout << 2 * R * pi << endl;


  return 0;
}


Measured memory_bytes: 3784
#include<stdio.h>

#define INF 1000001

#define maxi(a,b) ((a>b)?a:b)
#define mini(a,b) ((a<b)?a:b)

int main(void){
    int max=-INF,min=INF,a,i,n;
    long long int sum=0LL;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d",&a);
        max = maxi(a,max);
        min = mini(a,min);
        sum+=a;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 1028
a = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#ab = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))

for i in range(5):
    if a[i] == 0:
        print(i+1)


Measured memory_bytes: 9028
// https://atcoder.jp/contests/abc164/tasks/abc164_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  string S;
  cin >> S;

  ll N = S.size();
  ll MOD = 2019;
  VL mods(N + 1);

  rep(i, N) mods[i + 1] = (mods[i] * 10 + (S[i] - '0')) % MOD;

  {
    ll ten_mod = 1;
    repr(i, N + 1) {
      mods[i] = (mods[i] * ten_mod) % MOD;
      ten_mod = ten_mod * 10 % MOD;
    }
  }

  ll res = 0;

  map<ll, ll> m;

  rep(i, N + 1) {
    res += m[mods[i]];
    m[mods[i]]++;
  }

  cout << res << "\n";
}


Measured memory_bytes: 5168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ans;
ll n,m;
ll mod=1e9+7;
int main()
{
	cin>>n>>m;
	if(abs(n-m)>1)
	{
		puts("0");return 0;
	}
	ans=1;
	{
		for(ll i=1;i<=n;i++) {ans*=i;ans=ans%mod;}
		for(ll i=1;i<=m;i++){ans*=i;ans=ans%mod;}
	}
	if(n==m) ans*=2;
	ans=ans%mod;
	cout<<ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    //input
    int n; cin >> n;
    vector<int> a(n + 1,0);
    for(int i = 1; i < n + 1; i++) cin >> a[i]; 

    //compute
    vector<pair<int,int>> p(n + 1);
    for(int i = 1; i < n + 1; i++){
        p[i] = make_pair(a[i] , i);
    } 
    sort(p.begin() + 1 , p.end());

    //output
    for(int i = 1; i < n + 1;i++){
        cout << p[i].second << " ";
    }

}

Measured memory_bytes: 4292
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<String> select = new ArrayList<String>();
      select.add("Sunny");
      select.add("Cloudy");
      select.add("Rainy");
      String s = next();
      int index = select.indexOf(s) + 1;
      index %= 3;
      myout(select.get(index));
	}
	//Method addition frame start



	//Method addition frame end
}


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

int main(void) {
    //code goes 
	int a,b,mul,root,bdig;
	scanf("%d %d",&a,&b);
	if(b<10)    bdig=10;
	else if(b<100)  bdig=100;
	else bdig=1000; 
	mul=a*bdig+b; 
	root = (int) sqrt(mul);
	if(root*root==mul) 
	    printf("Yes");
	else       
	    printf("No");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;
int n,a[2000005];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int x=1;
    for(int i=0;i<n;i++)
    {
        if(a[i]==x)
        {
            x++;
        }
    }
    if(x==1)cout<<"-1"<<endl;
    else
    cout<<n-(x-1)<<endl;;
    return 0;
}


Measured memory_bytes: 1024