akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}


signed main(){
	
	
	ll n,m,c,a,cnt = 0,memo = 0;
	cin >> n >> m >> c;
	
	ll b[m] = {0};
	
	rep(i,0,m) cin >> b[i];
	
	
	rep(i,0,n){
		memo = 0;
		
		rep(j,0,m){
			
			cin >> a;
			
			memo += a * b[j];
		}
		
		if(memo + c > 0)cnt++;
	}
	
	cout << cnt << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

int main()
{
	FAST;

	int n;
	cin >> n;

	ll ans = 0;

	while (1)
	{
		if (n <= 4)
			break;

		if (n / 500 >= 1)
		{
			int temp = n / 500;
			ans += 1000 * temp;
			n -= temp * 500;
		}

		if (n / 5 >= 1)
		{
			int temp = n / 5;
			ans += 5  * temp;
			n -= temp * 5;
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
h=[int(i) for i in input().split()]

l=[0]+[100000000000000000000000000000 for i in range(n-1)]

for i in range(n-1):
    if i<n-k:
        for j in range(k):
            l[i+j+1]=min(l[i+j+1],abs(h[i]-h[i+j+1])+l[i])
    else:
        for j in range(n-i-1):
            l[i+j+1]=min(l[i+j+1],abs(h[i]-h[i+j+1])+l[i])

print(l[-1])
        




Measured memory_bytes: 57440
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>

#define yes            cout<<"YES"<<endl
#define no             cout<<"NO"<<endl
#define sz(x)          x.size()
#define ll                    long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)       __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>())
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define deb(x)         cout << #x << ": " << x << endl;
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846;
typedef vector<ll> vll ;
typedef vector<int> vii ;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}
void solve()
{
    ll n;cin>>n;
    vector<ll>v(n+1,0);
    for(ll i=1;i<=n;i++)
    {
        for(ll j=0;j<=n;j=j+i)
        {
            v[j]++;
        }
    }
   ll ans=0;
   for(ll i=1;i<=n;i++)
   {
      ans=ans+(i*(ll)v[i]);
   }
   cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    ll test_case=1;
   // cin>>test_case ;
    while(test_case--)
	{
		 solve();
	}

	return 0;
}

Measured memory_bytes: 81308
#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>;

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 n, m;
  cin >> n >> m;
  vector<int> vec;
  int totalVote = 0;
  rep(i, n) {
    int val;
    cin >> val;
    vec.push_back(val);
    totalVote += val;
  }
  int cnt = 0;
  double v = (double)totalVote / 4 / m;
  rep(i, n) {
    if ((vec[i]) >= v) cnt++;
    if (cnt == m) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(n)]
b=[0]*((10**5)+1)
for i in a:
    b[i[0]]+=i[1]
x=0
for i in range(10**5+1):
    x+=b[i]
    if x>=k:
        print(i)
        exit()

Measured memory_bytes: 23892
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        static int N;
        static int M;
        static bool[][] graph;

        public static void Solve()
        {
            var NM = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            (N, M) = (NM[0], NM[1]);
            graph = new bool[N][].Select(x => x = new bool[N]).ToArray();
            for (var i = 0; i < M; i++)
            {
                var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                var a = ab[0] - 1;
                var b = ab[1] - 1;
                graph[a][b] = graph[b][a] = true;
            }
            var visit = new bool[N];
            visit[0] = true;
            Console.WriteLine(Dfs(0, visit));
        }

        public static int Dfs(int current, bool[] visit)
        {
            if (visit.All(x => x)) return 1;
            var count = 0;
            for (var i = 0; i < N; i++)
            {
                if (!graph[current][i]) continue;
                if (visit[i]) continue;
                visit[i] = true;
                count += Dfs(i, visit);
                visit[i] = false;
            }

            return count;
        }
    }
}


Measured memory_bytes: 28548
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

s = input_s

if s == "ABC"
  puts "ARC"
else
  puts "ABC"
end


Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main() { 
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll A = 1, B = 1;
	int t, a;
	rep(i, n){
		cin >> t >> a;
		ll x = max((t + A - 1) / t, (a + B - 1) / a);
		A = x * t;
		B = x * a;
	}
	cout << A + B << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int s=0;
	if(a>=b)
	s+=b;
	else
	s+=a;
	if(c>=d)
	s+=d;
	else
	s+=c;
	cout<<s;
	return 0;
}

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

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

    sort(n, n + 3);
    printf("%d %d %d\n", n[0], n[1], n[2]);
}

Measured memory_bytes: 3296
from operator import itemgetter

n = int(input())
sp = []
for i in range(n):
    s, p = input().split()
    sp.append([s, int(p), i + 1])
sp = sorted(sorted(sp, key=itemgetter(1), reverse=True), key=itemgetter(0))
for i in sp:
    print(i[2])

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
	string s;
	cin>>s;
	if( s.length()==3 ) 
		reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
H, W = list(map(int, input().split()))
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]

flag = True
while flag:
    flag = False
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if c[i][k] + c[k][j] < c[i][j]:
                    c[i][j] = c[i][k] + c[k][j]
                    flag = True

result = 0
countNumber = []
for i in range(10):
    if i != 1:
        a = sum([A[h].count(i) for h in range(H) if i in A[h]])
        countNumber.append(a)
        if countNumber[-1] != 0:
            result += c[i][1] * countNumber[-1]
print(result)


Measured memory_bytes: 3444
N,M = map(int, input().split())
# tasks[i][j]
# i: 開始日
# j: 価値
tasks = [[] for _ in range(M)]
for _ in range(N):
    A,B = map(int, input().split())
    if A <= M:
        tasks[M - A].append(B)

from heapq import *

que = []
for day in range(M):
    for task in tasks[day]:
        if len(que) < day + 1:
            heappush(que, task)
        elif len(que) == day + 1:
            heappushpop(que, task)

print(sum(que))

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

int main(){
	int n, a[101];
	while( cin >> n , n ){
		for(int i=0 ; i < n ; i++ )
			cin >> a[i];
		int ans = 0;
		for(int j=n-1 ; j > 0 ; j-- ){
			for(int i=1 ; i <= j ; i++ ){
				if( a[i-1] > a[i] ){
					swap( a[i-1] , a[i] );
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

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

int main()
{
  int x, y; cin >> x >> y;
  set<int> st1 = {1, 3, 5, 7, 8, 10, 12};
  set<int> st2 = {4, 6, 9, 11};
  set<int> st3 = {2};
  if((st1.count(x) && st1.count(y)) || (st2.count(x) && st2.count(y))) cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((int)2e7+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

ll ct[MAXN];
ll n;
ll ans = 0;

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

	cin >> n;

	for (ll i = 1; i <= n; ++i)
		for (ll j = i; j <= n; j += i)
			ct[j]++;
	for (ll i = 1; i <= n; ++i)
		ans += ct[i] * i;

	cout << ans << endl;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

Measured memory_bytes: 81768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{
	c_p_c(); int cnt = 0; int i = 0;
	vector<int> a; int x;
	while (cin >> x) {
		++i;
		if (x == 0) {cnt = i;}
		a.push_back(x);
	}
	cout << cnt;


	return 0;
}



Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int Q;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>Q;
	while(Q--){
		int c,a,n,ans=0;
		cin>>c>>a>>n;
		int n1 = min(c,min(a,n));
		ans+=n1;
		c-=n1;
		a-=n1;
		int n2 = min(c/2,a);
		ans+=n2;
		c-=n2*2;
		cout<<ans+c/3<<endl;
	}
}

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

int main(){
    int ans=0;
    string s,t;
    cin>>s>>t;
    if(s.size()>t.size())swap(s,t);
    
    for(int l=1;l<=s.size();l++){
        map<array<int,26>,bool> mp;
        array<int,26> a,b;
        rep(i,26)a[i]=b[i]=0;
        
        rep(i,l)a[s[i]-'a']++;
        mp[a]=true;
        
        rep(i,s.size()-l){
            a[s[i]-'a']--;
            a[s[i+l]-'a']++;
            mp[a]=true;
        }
        
        
        rep(i,l)b[t[i]-'a']++;
        if(mp.count(b))ans = max(ans,l);
        
        rep(i,t.size()-l){
            b[t[i]-'a']--;
            b[t[i+l]-'a']++;
            if(mp.count(b))ans = max(ans,l);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3688
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if (n % 2 != 0) {
            System.out.println(0);
            return;
        }
        n /= 2;

        long ans = 0;
        for (long five = 5; five <= n; five *= 5) {
            ans += n / five;
            // System.out.println(ans);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n, a, b, c, x;

int main() {
    while(1) {
        cin >> n >> a >> b >> c >> x;
        if(n == 0 && a == 0 && b == 0 && c == 0 && x ==0) break;
        vector<int> y(n, 0);
        for(int i = 0; i < n; ++i) cin >> y[i];
        int ans = -1;
        int now = 0;
        for(int i = 0; i <= 10000; ++i) {
            if(i == 0) {
                if(x == y[now]) now++;
            }else {
                int ch = (a*x + b) % c;
                if(ch == y[now]) now++;
                x = ch;
            }
            if(now == n) {
                ans = i;
                break;
            }
        }
        cout << ans << endl;
    }
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, T;
  cin >> n >> T;
  vector<int> t(n);
  for (int i = 0; i < n; i++) cin >> t[i];
  int pushed = t[0];
  int tot = 0;
  for (int i = 1; i < n; i++) {
    tot += min(T, t[i] - pushed);
    pushed = t[i];
  }
  tot += T;
  cout << tot << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
	if(a>b)
		swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
	char str[100];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
	sprintf(str,"%s.out",s);
	freopen(str,"w",stdout);
#endif
}
int rd()
{
	int s=0,c;
	while((c=getchar())<'0'||c>'9');
	do
	{
		s=s*10+c-'0';
	}
	while((c=getchar())>='0'&&c<='9');
	return s;
}
int upmin(int &a,int b)
{
	if(b<a)
	{
		a=b;
		return 1;
	}
	return 0;
}
int upmax(int &a,int b)
{
	if(b>a)
	{
		a=b;
		return 1;
	}
	return 0;
}
int a[310][310];
int n,m;
int b[310];
int c[310];
int d[310];
int main()
{
	scanf("%d%d",&n,&m);
	int i,j;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	for(i=1;i<=n;i++)
		c[i]=1;
	int ans=0x7fffffff;
	for(i=1;i<=m;i++)
	{
		int s=0,s2;
		for(j=1;j<=m;j++)
			d[j]=0;
		for(j=1;j<=n;j++)
		{
			while(c[j]<=m&&b[a[j][c[j]]])
				c[j]++;
			if(c[j]>m)
			{
				printf("%d\n",ans);
				return 0;
			}
			d[a[j][c[j]]]++;
			if(d[a[j][c[j]]]>s)
			{
				s=d[a[j][c[j]]];
				s2=a[j][c[j]];
			}
		}
		upmin(ans,s);
		b[s2]=1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
// atcoder/abc115/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }


int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  const int N = 100;
  ull P[N];
  ull PB[N];

  PB[0] = 1;
  P[0] = 1;
  for (int i = 1; i < N; ++i) {
    P[i] = P[i - 1] + 1 + P[i - 1];
    PB[i] = 1 + PB[i - 1] + 1 + PB[i - 1] + 1;
  }

  int n;
  ull x;
  while (cin >> n >> x) {
    ull sum = 0;
    while (true) {
      if (n == 0) {
        ++sum;
        break;
      }

      if (x == 1) {
        break;
      } else if (x <= 1 + PB[n - 1]) {
        --x;
        --n;
      } else if (x <= 1 + PB[n - 1] + 1) {
        sum += P[n - 1] + 1;
        break;
      } else if (x <= 1 + PB[n - 1] + 1 + PB[n - 1]) {
        sum += P[n - 1] + 1;
        x -= 1 + PB[n - 1] + 1;
        --n;
      } else {
        sum += P[n - 1] + 1 + P[n - 1];
        break;
      }
    }
    cout << sum << endl;
  }

  return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define ul unsigned long long

int main() {
  int N;
  cin >> N;
  ll A[N];
  rep(i,N){
    cin >> A[i];
    if(A[i] == 0){
      cout << "0" << endl;
      return 0;
    }
  }
  ll result =1;
  rep(i,N){
    if ((long double)result * A[i] > 2000000000000000000) {
      cout << "-1" << endl;
      return 0;
    }
    result *= A[i];
    if( result > 1000000000000000000 || result < 0){
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << result << endl;

}


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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

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

long long factorial(long long n){
    long long temp = 1;
    for (int i = 1; i <= n; i++) temp *= i, temp %= mod;
    return temp;
}

int main(){
    long long n, m;
    cin >> n >> m;
    
    if (abs(n-m) >= 2){
        cout << 0 << endl;
        return 0;
    }
    
    if (n - m == 1){
        cout << (factorial(n) * factorial(m)) % mod << endl;
    }
    else if (m - n == 1) {
        cout  << (factorial(n) * factorial(m)) % mod << endl;
    }
    
    if (n == m){
        cout << (2 * factorial(n) * factorial(m)) % mod << endl;
    }
}

Measured memory_bytes: 256
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

//char rbuf[]; int rbufl;
//#define getchar() rbuf[rbufl++]
#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void printint(int32_t x){ if(x<0){x=-x; putchar('-');}else if(x==0){putchar('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar(s[i]); putchar('\n'); }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

char s[1004];
int main(void){
	int n=nextstr(s);
	if(s[n-1]=='s'){
		s[n]='e';
		s[n+1]='s';
	}else{
		s[n]='s';
	}
	printf("%s\n", s);
}


Measured memory_bytes: 1496
# include <bits/stdc++.h>
# define il inline
# define fi first
# define se second
# define pb push_back
# define mem(x,v) memset(x,v,sizeof x)
# define rep(i,x,y) for(int i=x;i<=y;++i)
# define re(i,x,y) for (int i=x;i<y;++i)
using namespace std;
typedef long long ll;
il ll read(){
    ll x=0; char c=getchar();
    for(;c<'0'||c>'9';c=getchar());
    for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
    return x;
}
const int maxm = 100+10;
int n,m;
int a[maxm];
vector<int> b;
int main(){
    n=read(); m=read();
    rep(i,1,m) a[i]=read();
    if (m == 1){
        b.pb(1); b.pb(n-1);
    }
    else{
        int cnt = 0;
        rep(i,1,m) cnt += a[i] % 2;
        if (cnt > 2){
            puts("Impossible"); return 0;
        }
        rep(i,2,m-1)
            if (a[i]%2==1){
                if (a[1]%2==0)swap(a[1],a[i]);
                else swap(a[m],a[i]);
            }
        b.pb(a[m]+1);
        for (int i=m-1;i>1;--i) b.pb(a[i]);
        b.pb(a[1]-1);
    }
    rep(i,1,m) printf("%d ",a[i]); printf("\n");
    int bs=b.size();
    if (b[bs-1] == 0)--bs;
    printf("%d\n",bs);
    for (int i=bs-1;i>=0;--i) printf("%d ",b[i]); printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
/*    #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  ll r;
  cin>>r;
  cin>>r;
  if(r<1200)
    cout << "ABC" << endl;
  else if(r<2800)
    cout<< "ARC" << endl;
  else
    cout << "AGC" << endl;

  
  

}
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

int N;
vector<int> P;
map<int, int> mp;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  P.resize(N + 1);
  // 1-indexed
  for (int i = 1; i <= N; i++) {
    cin >> P[i];
    mp[P[i]] = i;
  }

  vector<int> dp(N + 1, 0);
  int prev_pos = 0;
  for (int i = 1; i <= N; i++) {
    int pos = mp[i];
    if (prev_pos < pos) {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = 1;
    }
    prev_pos = pos;
  }

  int max_len = 0;
  for (int i = 1; i <= N; i++) {
    max_len = max(max_len, dp[i]);
  }

  int ans = N - max_len;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define db double
#define ld long db
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}

int main()
{
	ri x=read(),y,a;
	rep(i,x,200000){
		y=sqrt(i);bool f=1;
		rep(j,2,y){
			if(i%j==0){f=0;break;}
		}
		if(f)return cout<<i,0;
	}
	return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<time.h>
#define ll long long
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define miin(a,b,c) min((a), min((b), (c)))
#define maax(a,b,c) max((a), max((b), (c)))

ll x;
main(){
    scanf("%lld", &x);
    printf("%lld\n", (x/500)*1000 + ((x%500)/5)*5 );
    return 0;
}

Measured memory_bytes: 128
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
// #define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }
  void solve()
  {
string s,t;
cin>>s>>t;
int ans=INT_MAX,dif=0;
for(int i=0;i+t.size()-1<s.size();i++)
{
	int cur=0;
	for(int j=0;j<t.size();j++)
	{

		cur+=(s[i+j]!=t[j]);
	}
	ans=min(ans,cur);
}
cout<<ans;

  }
  
  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
    #endif
int t=1;
while(t--)
{
  solve();
}

    return 0;
  }


Measured memory_bytes: 3660
#pragma GCC optimize(2,3)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define re register
#define int long long
using namespace std;
int n,m,k,a[200002],b[200002],cnt,cnt1,c[200002],cnt2;
inline int read(){
	re int t=0,f=0;
	re char v=getchar();
	while(v<'0')f|=(v=='-'),v=getchar();
	while(v>='0'){
	t=(t<<3)+(t<<1)+v-48;
	v=getchar();}
	return f?-t:t;
}
inline int check(re int x){
	int ans=0;
	if(x>0){
		ans+=cnt*cnt1+cnt*cnt2+cnt1*cnt2+cnt2*(cnt2-1)/2;
		int t=cnt;
		for(re int i=1;i<=cnt;++i){
			while(a[i]*a[t]>x&&t>=i)--t;
			if(t<=i)break;
			ans+=(t-i);
		}//cout<<ans<<endl;
		t=cnt1;
		for(re int i=1;i<=cnt1;++i){
			while(b[i]*b[t]>x&&t>=i)--t;
			if(t<=i)break;
			ans+=(t-i);
		}
		return ans;
	}
	else if(x==0){
		ans+=cnt*cnt1+cnt*cnt2+cnt1*cnt2+cnt2*(cnt2-1)/2;
		return ans;
	}
	else{
		x=-x;
		int t=1;
		for(re int i=cnt;i>=1;--i){
			while(a[i]*b[t]<x&&t<=cnt1)++t;
			ans+=cnt1-t+1;
		}
		t=1;
		for(re int i=cnt1;i>=1;--i){
			while(b[i]*a[t]<x&&t<=cnt)++t;
			ans+=cnt-t+1;
		}
		return ans/2;
	}
}
int x;
signed main(){
n=read();k=read();
for(re int i=1;i<=n;++i){
x=read();if(x>0)a[++cnt]=x;else if(x<0)b[++cnt1]=-x;else c[++cnt2]=x;
}
sort(a+1,a+cnt+1);
sort(b+1,b+cnt1+1);
int l=-1e18,r=1e18;
while(l<r){
	int mid=(l+r)/2;
	if(mid==r)--mid;
	if(check(mid)>=k)r=mid;
	else l=mid+1;
}
printf("%lld",l);
}

Measured memory_bytes: 3072
#include<stdio.h>
int main(){
  int W[10],K[10],w,k,hh,h,i,ii,j,jj,W_max,K_max,sum_W,sum_K;
 
  for(i=0;i<10;i++){scanf("%d",&W[i]);}
  for(i=0;i<10;i++){
    W_max=i;
    for(j=i;j<10;j++){
      if(W[j]>W[W_max]){W_max=j;}
      
    }
h=W[W_max];
      W[W_max]=W[i];
      W[i]=h;
  
  } 
    sum_W=W[0]+W[1]+W[2];
  
   for(ii=0;ii<10;ii++){scanf("%d",&K[ii]);}
   for(ii=0;ii<10;ii++){
     K_max=ii;
     for(jj=ii;jj<10;jj++){
       if(K[jj]>K[K_max]){K_max=jj;}
      
     }
 hh=K[K_max];
       K[K_max]=K[ii];
       K[ii]=hh;
    
   }
    sum_K=K[0]+K[1]+K[2];
  
   printf("%d %d\n",sum_W,sum_K);

   return 0;
}

Measured memory_bytes: 0
S = input()
ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        if S[i:j+1][-1] not in ['A', 'C', 'G', 'T']:
            break
        else:
            ans = max(ans, len(S[i:j+1]))
print(ans)

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

namespace AtCoder
{
    class Abc167F
    {
        struct Bracket
        {
            public long BraN;
            public long KetN;
        }

        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());

            long braN = 0;
            long ketN = 0;

            long m = 0;
            var bra = new List<Bracket>();
            var ket = new List<Bracket>();

            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine();
                m += s.Length;
                var x = new Bracket { BraN = 0, KetN = 0 };
                for (int j = 0; j < s.Length; j++)
                {
                    x.BraN += s[j] == '(' ? 1 : -1;
                    if (x.KetN > x.BraN)
                        x.KetN = x.BraN;
                }
                x.KetN = -x.KetN;
                x.BraN += x.KetN;
                if (x.BraN == 0)
                    ketN += x.KetN;
                else if (x.KetN == 0)
                    braN += x.BraN;
                else if (x.BraN >= x.KetN)
                    bra.Add(x);
                else
                    ket.Add(x);
            }
            foreach (var item in bra.OrderBy(x => x.KetN))
            {
                braN -= item.KetN;
                if (braN < 0)
                {
                    Console.WriteLine("No");
                    return;
                }
                braN += item.BraN;
            }
            foreach (var item in ket.OrderBy(x => x.BraN))
            {
                ketN -= item.BraN;
                if (ketN < 0)
                {
                    Console.WriteLine("No");
                    return;
                }
                ketN += item.KetN;
            }
            Console.WriteLine(braN == ketN ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 45804
N = int(input())
S = input()

cnt=0
l = []
b = 1 if S[0] == "." else 0

for i in range(1, N):
    if S[i]==S[i-1]:
        cnt += 1
        if i == N-1:
            l.append(cnt+1)
    else:
        l.append(cnt+1)
        if i == N-1:
            l.append(1)
        cnt = 0

if len(l)<=1:
    print("0")
    exit()

s = 0
q = 0
q2 = 0
for c in S:
    if c=="#":
        q += 1
    else:
        q2 += 1

for j in range(abs(b-1), len(l), 2):
    #print(j, l[j])
    s += l[j]

m = min(q,q2,s)
#print(s)
for j in range(b, len(l), 2):
    #print(j-2,l[j-2], j-1, l[j-1])
    if j-2 >= 0:
        s += l[j-2]-l[j-1]
    elif j-1 >= 0:
        s += -l[j-1]
    m = min(s, m)


#print(l)
print(m)

Measured memory_bytes: 5220
#include <cstdio>
#define MAX 9999
#define NIL -1

struct Node {
  int parent, left, right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
  if ( u == NIL ) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if ( T[u].left != NIL )
    h1 = setHeight(T[u].left) + 1;
  if ( T[u].right != NIL )
    h2 = setHeight(T[u].right) + 1;
  return H[u] = ( h1 > h2 ? h1 : h2 );
}

int getSibling(int u) {
  if ( T[u].parent == NIL ) return NIL;
  if ( T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if ( T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].left != NIL ) deg++;
  if ( T[u].right != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].parent == NIL ) {
    printf("root\n");
} else if ( deg > 0 ) {
    printf("internal node\n");
  } else {
    printf("leaf\n");
  }
}

int main() {
  int v, l, r, root = 0;
  scanf("%d", &n);

  for ( int i = 0; i < n; i++ ) T[i].parent = NIL;

  for ( int i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if ( l != NIL ) T[l].parent = v;
    if ( r != NIL ) T[r].parent = v;
  }

  for ( int i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;

  setDepth(root, 0);
  setHeight(root);

  for ( int i = 0; i < n; i++ ) print(i);

  return 0;
}

Measured memory_bytes: 2724
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		System.out.println( reverse_str( sc.nextLine() ) );
		sc.close();
	}

	private static String reverse_str(String nextLine) {
		String str = nextLine;
		StringBuffer sb = new StringBuffer();

			for (int i = 0; i < str.length(); i++) {
				sb.append( str.charAt(str.length() - ( 1 + i ) ) );
			}

		String rev_str = sb.toString();

		return rev_str;
	}
}


Measured memory_bytes: 25976
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, ans;
signed main() {
	cin >> n;
	rep(i, n) {
		int a; cin >> a;
		if (i + 1 != a)ans++;
	}
	if (ans >= 3)cout << "NO" << endl;
	else cout << "YES" << endl;
}

Measured memory_bytes: 256
N = int(input())
t = []
a = []
for i in range(0,N):
	tokuhyousuu = list(map(int,input().split()))
	t.append(tokuhyousuu[0])
	a.append(tokuhyousuu[1])

T = 1
A = 1

for j in range(0,N):
	if(T<=t[j] and A<=a[j]):
		T = t[j]
		A = a[j]

	elif(T>t[j] and A>a[j]):
		if(T%t[j] == 0):
			r_1 = T//t[j]
		else:
			r_1 = T//t[j] + 1

		if(A%a[j] == 0):
			r_2 = A//a[j]
		else:
			r_2 = A//a[j] + 1

		r = max(r_1,r_2)

		T = t[j]*r
		A = a[j]*r


	elif(T>t[j]):
		if(T%t[j]==0):
			r = T//t[j]
		else:
			r = T//t[j]+1
		
		T = t[j]*r
		A = a[j]*r

	elif(A>a[j]):
		if(A%a[j] == 0):
			r = A//a[j]
		else:
			r = A//a[j]+1			
		T = t[j]*r
		A = a[j]*r

print(T+A)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll N;
    cin >> N;
    map<ll, ll> m;
    Rep (i, N) {
        ll a;
        cin >> a;
        m[a]++;
    }

    string ans = "No";

    if (m.size() == 2) {
        auto itr = m.begin();
        ll c = (*itr).first, a = (*itr).second;
        itr++;
        if ((*itr).first == c+1) {
            c++;
            ll b = (*itr).second;
            if (c-a > 0 && 2*(c-a) <= b) ans = "Yes";
        }

    } else if (m.size() == 1) {
        ll c = (*m.begin()).first;
        if (c == N-1 || 2*c <= N) ans = "Yes";
    }

    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

ll lcm (ll a, ll b){
    return (a*b)/gcd(a,b);
}

vi a;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cout.precision(10); 
    cout<<fixed;  // prints x digits after decimal in val

    cin>>n;
    x = 1;
    in(a,n);
    for(int i=0;i<n;i++){
        x = lcm(x,a[i]);
    }
    y = 0;
    for(int i=0;i<n;i++){
        y+=(x/a[i]);
    }
    cout<<1.0*x/y;
    
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int rooms[4][3][10] = {};
    int N;
    std::cin >> N;
    for (int i = 0; i < N; i++) {
        int b, f, r, v;
        std::cin >> b >> f >> r >> v;
        rooms[b-1][f-1][r-1] += v;
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 10; k++){
                std::cout << " " << rooms[i][j][k];
            }
            std::cout << std::endl;
        }
        if (i < 3) {
            std::cout << "####################" << std::endl;
        }
    }
}



Measured memory_bytes: 3092
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;

class Program
{
  static int n;
    static void Main(string[] args)
    {
      //入力を受け取る
      n = int.Parse(Console.ReadLine());
      Node[] T = new Node[n+1];
      
      //各ノードを初期化
      for(int i = 1; i < n+1 ; i++){
        var ukv = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var u = ukv[0];
        var k = ukv[1];
        T[i] = new Node(u,k);
        for(int j = 2;j < k+2; j++){
          T[i].RegistAdjacency(ukv[j]);
        }
      }
      
      //キューにノード1を入れる
      NodeQueue MyQ = new NodeQueue();
      T[1].d = 0;
      MyQ.enque(T[1]);
      //キューが空になるまで探索をする
      while(MyQ.IsNotEmpty()){
        //キューからノードを取り出す
        var extract = MyQ.deque();
        //Console.WriteLine("aaa");
        //取り出したノードの子ノードの深さを登録
        foreach(int child in extract.adjacency){
          //深さが未登録であったらキューに入れる
          if(T[child].d == -1){
            T[child].d = extract.d+1;
            MyQ.enque(T[child]);
          }
          //親の次数と子の次数の差が1以上あったら最短経路の方を登録
          if(extract.d+1 < T[child].d){
            T[child].d = extract.d+1;
          }
        }
      }
      
     // Console.WriteLine(string.Join(", ",T[1].adjacency));
      
      for(int i = 1;i < n+1;i++){
        Console.WriteLine(T[i].id+" "+T[i].d);
      }
    }

}

class Node{
  public int id;
  public int d = -1;
  public int[] adjacency;
  private int point = 0;
  
  public Node(int id,int depth){
    this.id = id;
    this.adjacency = new int[depth];
  }
  
  public void RegistAdjacency(int child){
    this.adjacency[point] = child;
    point++;
  }
}

class NodeQueue{
  Node[] Nodes = new Node[100];
  int head = 0;
  int tail = 0;
  
  public void enque(Node N){
    Nodes[tail] = N;
    tail++;
  }
  
  public Node deque(){
    Node res = Nodes[head];
    head++;
    return res;
  }
  
  public bool IsNotEmpty(){
    if(tail != head){
      return true;
    }else{
      return false;
    }
  }
}


Measured memory_bytes: 16316
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template <typename T> void _dbarr(T* a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
template <typename T> void _dbarr(vector<T> a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
#define dbarr(x, n) {cerr << #x << ": "; _dbarr((x),(n));}
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second

int main()
{
	cin.tie(0)->sync_with_stdio(0);
    int n,x,t;
    cin >> n >> x >> t;

    cout << (int)(t * ceil((double)n/x)) << "\n";
}


Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if(a == 1){
    if(b == 2){
      cout << 3 << endl;
    }else{
      cout << 2 << endl;
    }
  }else{
    if(a == 2){
      if(b == 1){
        cout << 3 << endl;
      }else{
        cout << 1 << endl;
      }
    }else{
      if(b == 1){
        cout << 2 << endl;
      }else{
        cout << 1 <<endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, M, A, B;
	map<int, vector<int> > PartTimeJob;
	priority_queue<int> PQ;
	ll ans = 0;

	cin >> N >> M;
	rep(i, N) {
		cin >> A >> B;
		PartTimeJob[A].push_back(B);
	}

	for (int daysLeft = 1; daysLeft <= M; daysLeft++) {
		rep(i, PartTimeJob[daysLeft].size()) PQ.push(PartTimeJob[daysLeft][i]);
		if (PQ.empty()) continue;
		ans += (ll)PQ.top(); PQ.pop();
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10880