akhauriyash/Code-Regression huggingface dataset:
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n;
	cin>>n;
	ll a,b;
	cin>>a>>b;
	ll ans = n/(a+b);
	ans *= a;
	ll rem = n%(a+b);
	rem = min(rem,a);
	cout<<ans+rem;
	return 0;
}

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

int main(void)
{
	string search, str;
	int n, res = 0;
	
	cin >> search >> n;
	int len = search.size();
	
	for (int i = 0; i < n; i++){
		cin >> str;
		str += str;
		for (int j = 0; j < 20; j++){
			if (str.substr(j, len) == search){
				res++; break;
			}
		}
	}
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 0
N, K = map(int, input().split())

if K == 0:
    print(N*N)
    exit()
ans = 0
for i in range(N - K):
    b = K + 1 + i
    n1 = N // b
    if n1 > 0:
        n2 = max(0, N % b - K + 1)
        ans += (i + 1) * n1 + n2
print(ans)


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

using namespace std;

string s;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> s;
    int n = s.length();
    if(n == 2 && s[0] == s[1]){
        cout << 1 << " " << 2 << '\n';
        return 0;
    }
    for(int i = 0; i <= n - 3; i++){
        string k = s.substr(i, 3);
        sort(k.begin(), k.end());
        if(k[0] == k[1] || k[1] == k[2]){
            cout << i + 1 << " " << i + 3 << '\n';
            return 0;
        }
    }
    cout << -1 << " " << -1 << '\n';
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,d=0,e,f,g=0;
  cin>>a;
  vector<int> b(a+1),c(a);
  fo(i,a+1)
    cin>>b[i];
  fo(i,a+1)
    g+=b[i];
  fo(i,a)
    cin>>c[i];
  for(int i=0;i<a;i++){
    e=b[i];
    f=c[i];
    b[i]=max<int>(b[i]-c[i],0);
    b[i+1]=max<int>(0,b[i+1]-max<int>(f-e,0));
  }
  fo(i,a+1)
    d+=b[i];
  cout<<g-d<<endl;
}


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

using namespace std;

int main()
{
   long int n;
   cin>>n;
   long long int A[n],sol[n];
   sol[0]=0;
   for(long int i=0;i<n;i++){
       cin>>A[i];
   }
   for(long int i=0;i<n-1;i+=2){
        sol[0]+=(A[i]-A[i+1]);
   }
   sol[0]+=A[n-1];
   for(long int i=0;i<n-1;i++){
       sol[i+1]=2*(A[i])-sol[i];
   }
   for(long int i=0;i<n;i++){
       cout<<sol[i]<<" ";
   }
       
   
}


Measured memory_bytes: 2816
#include<stdio.h>
int main(void){
	long a,b,c,k;
	scanf("%ld %ld %ld %ld",&a,&b,&c,&k);
	if(k<=a+b&&k>=a) printf("%ld\n",a);
	else if(k<a) printf("%ld\n",k);
	else {
		printf("%ld\n",(k-(a+b))*(-1)+a);
	}
	return 0;
}

Measured memory_bytes: 1720
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int K = sc.nextInt();

            int c = 0;
            while (N > 0) {
                N = (N / K);
                c++;
            }

            System.out.println(c);
        }
    }

}


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

int main()
{
    int N;
    int i, j;
    int count;
    int c;
    cin >> N;
    count = 0;
    for(i = 1; i <= N; i += 2) {
        c = 0;
        for(j = 1; j <= i; j += 2) {
            if(i%j == 0) {
                c += 1;
            }
        }
        if(c == 8) {
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int a[105];
int main () {
	int n ;
	cin>>n ;
	for(int i=0 ; i< n ; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int cnt = 1 ;
	for(int i= 1 ; i<n ; i++){
	   if(a[i-1]!=a[i])
	   cnt++;
	}
    cout<<cnt<<"\n";
	return 0 ;
}

Measured memory_bytes: 256
n, m = gets.split.map &:to_i
s = []
n.times do |i|
  s[i] = gets.chomp
end
t = []
m.times do |i|
  t[i] = gets.chomp
end
(n-m+1).times do |i|
  (n-m+1).times do |j|
    f=true
    m.times do |k|
      if s[i+k][j,m] != t[k]
        f=false
        break
      end
    end
    if f
      puts "Yes"
      exit
    end
  end
end
puts "No"

Measured memory_bytes: 1788
#include<iostream>
#include<vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> arr(n), dp(n+1) ;
    for(int i = 0; i < n; i++) cin >> arr[i];
    
    int ans = 0;
    for(int i = 0; i < n; i++)
{
    dp[arr[i]] = dp[arr[i] -1] + 1;
ans = max(ans, dp[arr[i]]);	//cout << dp[arr[i]] << " "; 
}
cout << n - ans ;

} 


Measured memory_bytes: 4804
import scala.io.StdIn._

object Main extends App {

  val Array(n,m,c) = readLine().split(" ").map(_.toInt)
  val B = readLine().split(" ").map(_.toInt)
  val A = Array.fill(n)(readLine().split(" ").map(_.toInt))

  def solve() = {
    A.map { list =>
      (0 until m).foldLeft(0) { (acc, i) =>
        acc + (B(i) * list(i))
      }
    }.count(_ + c > 0)
  }
  println(solve())

}



Measured memory_bytes: 54968
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x)(x)*(x)
#define fz1(i,n) for (i=1;i<=n;i++)
#define fd1(i,n) for (i=n;i>=1;i--)
#define fz0g(i,n) for (i=0;i<=n;i++)
#define fd0g(i,n) for (i=n;i>=0;i--)
#define fz0k(i,n) for (i=0;i<n;i++)
#define fd0k(i,n) for (i=(long long)(n-1);i>=0;i--)
#define fz(i,x,y) for (i=x;i<=y;i++)
#define fd(i,y,x) for (i=y;i>=x;i--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}}
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,int x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
long long n,m,i,j,num[500005],s1[500005],s2[500005],x,ans=1ll<<60;
vector<long long> a,b;
int main()
{
	scanf("%lld%lld",&n,&m);
	b.push_back(0);
	fz1(i,n)
	{
		scanf("%lld",&x);
		if (x<0) a.push_back(-x);
		else b.push_back(x);
	}
	a.push_back(0);
	reverse(a.begin(),a.end());
	for (i=0;i<a.size();i++)
	{
		if (m-i<b.size())
		{
			ans=min(ans,a[i]*2+b[m-i]);
			ans=min(ans,a[i]+b[m-i]*2);
			if (i==0||i==m) ans=min(ans,a[i]+b[m-i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1656
a, b = map(int, input().split())
ans = 0
for n in range(a, b+1):
    s = str(n)
    l = len(s)
    ok = True
    for i in range(l):
        if s[i] != s[l-1-i]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)

Measured memory_bytes: 39536
import java.util.Scanner;

//提出時にclass Main に書き換え
public class Main {
	public static void main(String[] args)  {
		// 標準入力を受け取る
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // int Nを受け取る
		int Y = sc.nextInt(); // int Yを受け取る
		sc.close(); // 標準入力を終了

		for(int a = 0; a <= N; a++) {
			// 10000円札の枚数
			for(int b = 0; b <= N - a; b++) {
				// 5000円札の枚数

				int c = N - a - b; // 1000円札の枚数

				if(10000*a + 5000*b + 1000*c == Y) {
					// 合計金額がY円になるなら、各金額の札の枚数の組を出力
					System.out.println(a + " " + b + " " + c);
					return; // プログラムを終了
				}
			}
		}

		// 合計金額がY円になる組み合わせが無い場合、-1 -1 -1を出力
		System.out.println(-1 + " " + -1 + " " + -1);
	}

}

Measured memory_bytes: 39392
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll MOD=1000000007;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

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

   vector<int> a(26,0);
      string s;
      cin>>s;

      rep(j,s.size()){
         a[s[j]-'a']++;
      }

      rep(i,n-1){
         string c;
         cin>>c;
         vector<int> b(26,0);
         rep(j,c.size()){
            b[c[j]-'a']++;
         }

         rep(j,26){
            a[j]=min(a[j],b[j]);
         }
      }

      string ans="";

      rep(i,26){
         rep(j,a[i]){
         ans+=(char)('a'+i);
         }
      }   
      cout<<ans;
   return 0;
}


Measured memory_bytes: 3620
def ispalindrome(str): return 1 if str == str[::-1] else 0
a = input()
l = len(a)
left = a[0:(l-1)//2]
right = a[(l-1)//2+1:]
if ispalindrome(left) and ispalindrome(right) and ispalindrome(a):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  
  int i;
  int a[N];
  for(i=0; i<N; i++)
    cin >> a[i];
  
  sort(a, a+N);
  int answer = a[0];
  i = 1;
  int temp;
  while(true){
    if(answer == 1) break;
    temp = a[i] % answer;
    if(temp < answer && temp != 0){
      a[i] = answer;
      answer = temp;
      i = 1;
    }else
      i++;
    
    if(i >= N) break;
  }
  
  cout << answer << endl;
    
  return 0;
}

Measured memory_bytes: 640
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N = lread();
    long[] red_x = new long[](N);
    long[] red_y = new long[](N);
    long[] bluex = new long[](N);
    long[] bluey = new long[](N);
    foreach (i; 0 .. N)
    {
        long x, y;
        scan(x, y);
        red_x[i] = x;
        red_y[i] = y;
    }
    foreach (i; 0 .. N)
    {
        long x, y;
        scan(x, y);
        bluex[i] = x;
        bluey[i] = y;
    }
    zip(red_y, red_x).sort!"b<a"();
    zip(bluex, bluey).sort();
    // writeln(red_x);
    // writeln(red_y);
    // writeln(bluex);
    // writeln(bluey);
    long ans;
    auto used = new bool[](N);
    foreach (i; 0 .. N)
    {
        loop: foreach (j; 0 .. N)
            if (!used[j] && red_x[i] < bluex[j] && red_y[i] < bluey[j])
            {
                used[j] = true;
                ans++;
                break loop;
            }
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
ll v[101010];
unordered_map<ll, ll> ump_even, ump_odd; //number, count
int main() {
    cin>>n;
    REP(i, 0, n) cin>>v[i];

    REP(i, 0, n){
        if(i%2==0){
            ump_even[v[i]]++;
        }
        else{
            ump_odd[v[i]]++;
        }
    }

    vector<pair<ll, ll>> vp_even, vp_odd; // count, number
    for(auto itr:ump_even){
        vp_even.emplace_back(make_pair(itr.second, itr.first));
    }
    for(auto itr:ump_odd){
        vp_odd.emplace_back(make_pair(itr.second, itr.first));
    }
    sort(vp_even.begin(), vp_even.end());
    reverse(vp_even.begin(), vp_even.end());
    sort(vp_odd.begin(), vp_odd.end());
    reverse(vp_odd.begin(), vp_odd.end());

    if(vp_even[0].second!=vp_odd[0].second){
        cout<<n-vp_even[0].first-vp_odd[0].first<<endl;
    }
    else{
        if(vp_even.size()==1 && vp_odd.size()==1){
            cout<<vp_even[0].first<<endl;
        }
        else if(vp_even.size()==1){
            cout<<n-vp_even[0].first-vp_odd[1].first<<endl;
        }
        else if(vp_odd.size()==1){
            cout<<n-vp_odd[0].first-vp_even[1].first<<endl;
        }
        else{
            cout<<n-max(vp_even[0].first+vp_odd[1].first, vp_even[1].first+vp_odd[0].first)<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 7440
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    int n,m;
    cin >> n >> m;
    vec(a,m+1);
    UnionFind tree(m);
    REP(i,n){
        int s,t;
        cin >> t;
        cin >> s;
        a[s]++;
        REP(j,t-1){
            int u;
            cin >> u;
            tree.unite(s,u);
            a[u]++;
        }
    }
    bool ans = true;
    int ro = -1;
    REP(i,m+1){
        if(a[i]==0){
            continue;
        }
        else{
            if(ro==-1){
                ro = tree.root(i);
            }
            else if(ro != tree.root(i)){
                ans = false;
            }
        }
    }

    if(ans){
        cout << "YES";
    }
    else{
        cout << "NO";
    }


    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

vector<P> func(vector<P> t){
  sort(t.begin(),t.end());
  int size=t.size();
  vector<P> res;
  for(int i=0;i+1<size;i++){
    P a=t[i];
    P& b=t[i+1];
    if(a.second<b.first){
      res.push_back(a);
    }else{
      b.first=a.first;
      b.second=max(b.second,a.second);
    }
  }
  res.push_back(t[size-1]);
  return res;
}

vector<P> A,B;
int N,H,W;
int y,x,z;
int main(){
  while(cin>>N>>H>>W){
    A.clear();
    B.clear();
    for(int i=0;i<N;i++){
      cin>>y>>x>>z;
      A.push_back(P(max(0,y-z),min(H,y+z)));
      B.push_back(P(max(0,x-z),min(W,x+z)));
    }

    A=func(A);
    B=func(B);
    
    if(A[0]==P(0,H)||B[0]==P(0,W))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3700
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
  table.append((A[i],1))
for i in range(M):
  b,c = map(int, input().split())
  table.append((c,b))
table.sort()
count = 0
ans = 0
while True:
  c, b = table.pop()
  if b <= N - count:
    ans += c*b
    count += b
  else:
    ans += (N-count)*c
    break
print(ans)

Measured memory_bytes: 29304
#include <stdio.h>

int main( void ) {
  char s[3];
  int i, cnt;
  scanf( "%s", s );

  cnt = 0;
  for ( i = 0; i < 3; i++ ) {
    if ( s[i] == '1' ) {
      cnt++;
    }
  }

  printf( "%d\n", cnt );

  return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
N, W = map(int, input().split())
dp = defaultdict(int)
dp[0] = 0
for _ in range(N):
    w, v = map(int, input().split())
    for pw, pv in dp.copy().items():
        if pw + w <= W:
            dp[pw + w] = max(dp[pw + w], pv + v)

print(max(dp.values()))


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

using namespace std;

int64_t gcd(int64_t one, int64_t other) {
    if (one == 0) {
        return other;
    }
    if (other == 0) {
        return one;
    }
    int64_t tmp;
    while (one != 0) {
        tmp = one;
        one = other % one;
        other = tmp;
    }
    return other;
}

int main(int argc, char *argv[]) {
    int N;
    cin >> N;

    vector<int64_t> arr(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }

    //
    //  最大公約数は結合法則が成り立つので
    //  先頭と最後から最大公約数を計算し続け、ふたつの
    //  リストを作る。ひとつひとつの要素を消した時の
    //  最大公約数を計算し、最大値を求めれば良い
    //

    vector<int64_t> arr1(N);
    for (int j = 0; j < N; j++) {
        if (j == 0) {
            arr1[0] = arr[0];
        } else {
            arr1[j] = gcd(arr1[j - 1], arr[j]);
        }
    }

    vector<int64_t> arr2(N);
    for (int k = N - 1; k >= 0; k--) {
        if (k == N - 1) {
            arr2[k] = arr[N - 1];
        } else {
            arr2[k] = gcd(arr[k], arr2[k + 1]);
        }
    }

    int64_t ans = INT_MIN;
    for (int l = 0; l < N; l++) {
        if (l == 0) {
            ans = max(ans, gcd(0, arr2[l + 1]));
        } else if (l == N - 1) {
            ans = max(ans, gcd(arr1[l - 1], 0));
        } else {
            ans = max(ans, gcd(arr1[l - 1], arr2[l + 1]));
        }
    }

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


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, k, c; cin >> n >> k >> c;
	string s; cin >> s;
	vector<int> lf(n, -1), rg(n, -1);
	{
		int cur = 0;
		int ok = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'o' and ok <= i) {
				lf[i] = cur;
				cur++;
				ok = i + c + 1;
				if (cur == k) break;
			}
		}
	}
	{
		int cur = k - 1;
		int ok = n - 1;
		for (int i = n - 1; i < n; i--) {
			if (s[i] == 'o' and ok >= i) {
				rg[i] = cur;
				cur--;
				ok = i - (c + 1);
				if (cur < 0) break;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		//cout << lf[i] << " "<< rg[i]<<endl;
		if (lf[i] == rg[i] and lf[i] >= 0) {
			cout << i + 1 << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >>n;
    if(n%2 == 0) OUT(n);
    else OUT(n*2);

    return 0;
}



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

using namespace std;
int i,n,dp[100005],x,W,v,w,j;
const int inf=1e9+5;
int main()
{
    cin>>n>>W;
    for(i=1;i<=100000;i++)
        dp[i]=inf;
    for(j=1;j<=n;j++)
    {
        cin>>w>>v;
        for(i=100000;i>=0;i--)
            if(dp[i]+w<=W)
        dp[i+v]=min(dp[i+v],dp[i]+w);
    }
    for(i=100000;i>=0;i--)
        if(dp[i]!=inf)break;
    cout<<i;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}
int main(){
  int N, M;
  cin >> N >> M;
  int A[N];
  long all=0;
  double ok;
  for(int i=0;i<N;i++){ 
    cin >> A[i];
    all+=A[i];
  }
  qsort(A , N , sizeof( int ), desc );
  ok=(double)all/(double)(4*M); //こいつか
  for(int i=0;i<M;i++){
    if(A[i]<ok/*-1*/){ //なんで1引いとんねん
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    
    vvl v(26);
    rep(i, n) {
        v[s[i] - 'a'].pb(i);
    }
    
    ll now = -1;
    ll ans = 0;
    rep(i, t.size()) {
        ll x = t[i] - 'a';
        if(v[x].size() == 0) {
            out(-1);
            re0;
        }
        if(upper_bound(all(v[x]), now) == v[x].end()) {
            ans += n;
            now = *v[x].begin();
        }  
        else {
            now = *upper_bound(all(v[x]), now);
        }
    }

    ans += now;
    ans++;  // 1-indexに直す

    out(ans);
    re0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
string field[128];
int h, w;

void rec(int y, int x, char target)
{
	field[y][x] = '.';
	for (int i = 0; i < 4; i++){
		int ny = y + dy[i], nx = x + dx[i];
		if (0 > ny || 0 > nx || ny >= h || nx >= w) continue;
		if (field[ny][nx] == target) rec(ny, nx, target);
	}
	return;
}

int main(void)
{
	while (cin >> h >> w){
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++){
			cin >> field[i];
		}
		int ret = 0;

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				// cout << field[i][j] << " ";
				if (field[i][j] != '.'){
					ret++;
					rec(i, j, field[i][j]);
				}
			}
		}
		// puts("");
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 2160
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        StringBuilder sb = new StringBuilder();
        sb.append(s1.charAt(0));
        sb.append(s2.charAt(0));
        sb.append(s3.charAt(0));
        _out.println(sb.toString().toUpperCase());
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
import sys
import heapq
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readline_s = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

INF = 10 ** 10 + 7


def main():
    X, Y, Z, K = map(int, readline().split())
    A = sorted(list(map(int, readline().split())), reverse=True)
    B = sorted(list(map(int, readline().split())), reverse=True)
    C = sorted(list(map(int, readline().split())), reverse=True)

    ans = solve3(X, Y, Z, K, A, B, C)
    print('\n'.join(map(str, ans)))


def solve3(X, Y, Z, K, A, B, C):

    init_v = -(A[0] + B[0] + C[0])
    q = [(init_v, 0, 0, 0)]
    heapq.heapify(q)
    search = set()
    ans = []

    for k in range(K):
        v, a, b, c = heapq.heappop(q)
        ans.append(-v)
        if a + 1 < X and not ((a + 1, b, c) in search):
            nv = A[a + 1] + B[b] + C[c]
            heapq.heappush(q, (-nv, a + 1, b, c))
            search |= {(a + 1, b, c)}
        if b + 1 < Y and not ((a, b + 1, c) in search):
            nv = A[a] + B[b + 1] + C[c]
            heapq.heappush(q, (-nv, a, b + 1, c))
            search |= {(a, b + 1, c)}
        if c + 1 < Z and not ((a, b, c + 1) in search):
            nv = A[a] + B[b] + C[c + 1]
            heapq.heappush(q, (-nv, a, b, c + 1))
            search |= {(a, b, c + 1)}

    return ans


def solve2(X, Y, Z, K, A, B, C):

    ABC = []
    for i in range(X):
        if (i + 1) > K:
            break
        for j in range(Y):
            if (i + 1) * (j + 1) > K:
                break
            for k in range(Z):
                if (i + 1) * (j + 1) * (k + 1) > K:
                    break
                else:
                    ABC.append(A[i] + B[j] + C[k])

    return sorted(ABC, reverse=True)[:K]


def solve1(X, Y, Z, K, A, B, C):

    AB = []
    for i in range(X):
        for j in range(Y):
            AB.append(A[i] + B[j])

    AB.sort(reverse=True)
    AB = AB[:min(X * Y, K)]

    ABC = []
    for i in range(len(AB)):
        for j in range(Z):
            ABC.append(AB[i] + C[j])

    ABC.sort(reverse=True)

    return ABC[:K]


if __name__ == '__main__':
    main()


Measured memory_bytes: 4772
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {

	int N, D;
	cin >> N >> D;

	vector<vector<int>> points;

	for (int n = 0; n < N; n++) {
		vector<int> v;
		for (int d = 0; d < D; d++) {
			int num;
			cin >> num;
			v.push_back(num);
		}
		points.push_back(v);
	}

	int result = 0;
	for (size_t i = 0; i < points.size(); i++) {
		for (size_t j = i + 1; j < points.size(); j++) {
			int sum = 0;
			for (size_t k = 0; k < points[i].size(); k++) {
				sum += (points[i][k] - points[j][k]) * (points[i][k] - points[j][k]);
			}
			double num = sqrt(sum);
			if (ceil(num) == floor(num)) {
				result++;
			}
		}
	}
	cout << result;

}

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

int main(){
    int n,pm,pe,pj;
    while(cin>>n,n){
        while(n--){
            cin>>pm>>pe>>pj;
            if(pm==100||pe==100||pj==100||((pm+pe)/2>=90)||(pm+pe+pj)/3>=80)
               cout<<"A"<<endl;
            else if(((pm+pe+pj)/3>=70)||(((pm+pe+pj)/3>=50)&&(pm>=80||pe>=80)))
               cout<<"B"<<endl;
            else cout<<"C"<<endl;
        }
    }
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int n, pos;
vector<int> pre, in, post;

void reconstruction(int l, int r)
{
  if (l >= r)
    return;
  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  reconstruction(l, m);
  reconstruction(m + 1, r);
  post.push_back(root);
}

void solve()
{
  pos = 0;
  reconstruction(0, n);
  for (int i = 0; i < n - 1; i++)
    printf("%d ", post[i]);
  printf("%d\n", post[n - 1]);
}

int main()
{
  int tmp;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &tmp);
    pre.push_back(tmp);
  }
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &tmp);
    in.push_back(tmp);
  }

  solve();
  return 0;
}

Measured memory_bytes: 2792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

int main(){
      int n;
      cin>>n;
      ll a[n];
      rep0(i,n) cin>>a[i];
      ll accumgcd[n+2];
      ll accumgcdd[n+2];
      fill(accumgcd,accumgcd+n+2,0);
      fill(accumgcdd,accumgcdd+n+2,0);
      rep0(i,n){
            accumgcd[i+1]=__gcd(accumgcd[i],a[i]);
            accumgcdd[n-i]=__gcd(accumgcdd[n-i+1],a[n-i-1]);
      }
      ll ans=0;
      rep1(i,n){
            ll pos=__gcd(accumgcd[i-1],accumgcdd[i+1]);
            //cout<<accumgcd[i-1]<<" "<<accumgcdd[i+1]<<endl;
            ans=max(ans,pos);
      }
      cout<<ans<<endl;
      return 0;
}

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

#define PI 3.1415926535
const double radtodeg = 180.0/PI;
#define max(A,B) (A>B?A:B)
#define min(A,B) (A<B?A:B)
typedef long long int lli;

int main(){
  int a, b, x;
  double ans, l;
  scanf("%d%d%d",&a,&b,&x);
  l = ((double)x)/a/a;
  if (b/2.0 <= l){
    ans = radtodeg*atan((b-l)/(a*0.5)); 
  } else {
    ans = radtodeg*atan(((double)a*b*b)/2.0/x); 
  }
  printf("%.8lf",ans); 
}

Measured memory_bytes: 128
n,m=map(int,input().split())
A=0
W=0
li=[0]*n
w=[0]*n
for i in range(m):
    p,s=map(str,input().split())
    p=int(p)
    if s=="AC" and li[p-1]==0:
        li[p-1]+=1
        A+=1
        W+=w[p-1]
    else:
        w[p-1]+=1
print(A,W)
                  
            
            
        
        
        

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

int main()
{
	long long int n,i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int dp[n];
	dp[0]=0;
	for(i=1;i<n;i++)
	{
		int op1=INT_MAX;
		int op2=INT_MAX;
		if(i-2>=0)
		{
			if(a[i]>a[i-2])
			op1=dp[i-2]+a[i]-a[i-2];
		    else
		    {
		    	op1=dp[i-2]+a[i-2]-a[i];
		    }
		}
		if(a[i]>a[i-1])
		op2=dp[i-1]+a[i]-a[i-1];
	    else
	    op2=dp[i-1]+a[i-1]-a[i];
     	dp[i]=min(op1,op2);
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;
int main(){
	int n = 0, v = 0;
	int a = 0;
	int b = 0;
	int c = 0;
	int d = 0;
	int s[5][4][11] = {0};
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a >> b >> c >> d;
		s[a][b][c] = s[a][b][c] + d;
	}
	for (int j = 1; j <= 4; j++){
		for (int k = 1; k <= 3; k++){
			for (int l = 1; l <= 10; l++){
				cout << " ";
				cout << s[j][k][l];
			}
			cout << endl;
		}
		if (j != 4){
			for (int nj = 0; nj < 20; nj++){
				cout << "#";
			}
			cout << endl;
		}
	}
	return 0;
}

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

int Q;
int sum[100002]; // sum[i] -> iまでの数で2017に似た数の総数を格納する
vector<pair<int, int>> lr;

bool is_prime(int n) {
    bool flag = true;;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

void input() {
    cin >> Q;
    rep(i, Q) {
        int l, r; cin >> l >> r;
        lr.push_back({l, r});
    }
}

void solve() {
    memset(sum, 0, sizeof(sum));
    sum[0] = 0; sum[1] = 0; sum[2] = 0; sum[3] = 1; sum[4] = 1;

    for (int i = 5; i <= 100000; i++) {
        if (i % 2 == 0) {
            sum[i] = sum[i - 1];
            continue;
        }
        if (is_prime(i) && is_prime((i + 1) / 2)) {
            sum[i] = sum[i - 1] + 1;
        } else {
            sum[i] = sum[i - 1];
        }
    }


    for (auto query : lr) {
        printf("%d\n", sum[query.second + 1] - sum[query.first - 1]);
    }

}
int main() {
    input();
    solve();
    return 0;
}


Measured memory_bytes: 4456
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

struct edge {int from,to,cost;};
int N,M,S;
vector<edge> v;
int dist[100010];

void Bellman(){
    fill(dist,dist+100010,MM);
    dist[S] = 0;
    for(int i = 0; i < N; i++){
        int update = 0;
        for(int j = 0; j < M; j++){
            edge e = v[j];
            if (dist[e.from] != MM && dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                update = 1;
                if (i == N-1){
                    cout << "NEGATIVE CYCLE" << endl;
                    return;
                }
            }
        }
        if (!update) break;
    }
    for(int i = 0; i < N; i++){
        if (dist[i] == MM) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
    return;
}

int main(){
    cin >> N >> M >> S;
    for(int i = 0; i < M; i++){
        int a,b,c; cin >> a >> b >> c;
        v.push_back({a,b,c});
    }
    Bellman();
}


Measured memory_bytes: 3584
H = int(input())
list = []
for i in range(H): #因数注意！
    n = input()    
    m = n.split()
    p = [int(i) for i in m]
    q = [p[0]-p[1],p[0]+p[1]]
    list.append(q)
newlist = sorted(list)
z = [-1000000000000000000,-100000000000000000]
a = 0
for i in newlist:
    if i[0] >= z[1]:
        z = i
        a = a + 1
    else:
        if i[1] < z[1]:
            z = i

print(a)


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

int main() {
  long n,ans=99999999;
  cin >> n;
  vector<long> a(n/2);
  vector<long> b(n/2);
  map<long,long> aa;
  map<long,long> bb;
  vector<vector<long>> aakey;
  vector<vector<long>> bbkey;
  for(long i=0;i<n/2;i++) {
    cin >> a[i] >> b[i];
    aa[a[i]]++;
    bb[b[i]]++;
    if(aa[a[i]]==1) aakey.push_back({0,a[i]});
    if(bb[b[i]]==1) bbkey.push_back({0,b[i]});
  }
  for(long i=0;i<aakey.size();i++) {
    aakey[i][0]=aa[aakey[i][1]];
  }
  for(long i=0;i<bbkey.size();i++) {
    bbkey[i][0]=bb[bbkey[i][1]];
  }
  sort(aakey.begin(),aakey.end());
  sort(bbkey.begin(),bbkey.end());
  reverse(aakey.begin(),aakey.end());
  reverse(bbkey.begin(),bbkey.end());

  if(aakey[0][1]==bbkey[0][1]) {
    if(aakey.size()>1) ans=min(ans,(n/2-aakey[1][0])+(n/2-bbkey[0][0]));
    else ans=min(ans,(n/2)+(n/2-bbkey[0][0]));
    if(bbkey.size()>1) ans=min(ans,(n/2-aakey[0][0])+(n/2-bbkey[1][0]));
    else ans=min(ans,(n/2)+(n/2-aakey[0][0]));
  } else {
    ans=(n/2-aakey[0][0])+(n/2-bbkey[0][0]);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 12776
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(string, s);
    var(int, K);

    vector<string> a;
    a.reserve(s.length() * 2);

    const int N = s.length();
    rep(i, 0, N) {
        string subs = "";
        rep(k, i, N) {
            subs += s[k];
            a.emplace_back(subs);
            if (subs.length() > 100) break;
        }
    }

    sort(all(a));
    a.erase(unique(all(a)), a.end());
    dump(a);

    print(a[K-1]);

    return 0;
}


Measured memory_bytes: 61956
#include<bits/stdc++.h>
using namespace std;
int main(){
 int N;
 cin>>N;
 vector<int> points(N+1);

 for(int i=0;i<N;i++){
  cin>>points.at(i);
 }

 sort(points.begin(),points.end());
 reverse(points.begin(),points.end());

 int alice,bob;
 for(int i=0;i<N;i+=2){
  alice+=points.at(i);
  bob+=points.at(i+1);
 }

 cout<<alice-bob<<endl;
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;


int main(){
    string S;
    vector<int>v;
    cin>>S;
    REP(i,S.size()-1){
        if(S[i]=='1'&&S[i+1]=='0'){
           v.push_back(i+1);
        }
        if(S[i]=='0'&&S[i+1]=='1'){
           v.push_back(i+1);
        }
    }
    int ans=1e7;
    v.push_back(0);
    v.push_back(S.size());
    REP(i,v.size()){
        ans=min(ans,max(v[i]-0,(int)S.size()-v[i]));
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main(void){
    vector<int> P(3);
    for(int i = 0; i < 3; i++) cin >> P[i];
    cout << accumulate(P.begin(), P.end(), 0) - *max_element(P.begin(), P.end()) << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define MOD 1000000007


#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()å
#define rall(i) (i).begin(),(i).end(),greater<int>()


#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }
 
//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

 
signed main(){
 
    int x,y,z,k;
    cin>>x>>y>>z>>k;

    vector<int> a(x);
    vector<int> b(x);
    vector<int> c(x);

    rep(i,x){
        cin >> a[i];
    }
    rep(i,y){
        cin >> b[i];
    }
    rep(i,z){
        cin >> c[i];
    }

    sort(a.begin(),a.end(),greater<int>());
    sort(b.begin(),b.end(),greater<int>());
    sort(c.begin(),c.end(),greater<int>());

    
    vector<int> ans;
    
    rep(i,x){
        rep(j,y){
            rep(s,z){
                if((i+1)*(j+1)*(s+1)<=k){    
                    ans.pb(a[i]+b[j]+c[s]);                
                }
                else break;    
        
            }

        }
    }

    sort(ans.begin(),ans.end(),greater<int>());

    rep(i,k){
        cout << ans[i] << endl;
    }

    return 0;
 
}


Measured memory_bytes: 1404
#include <stdio.h>

int main(void){
	int hin, min, sin, hout, mout, sout, totalSec;
	int h,m,s;
	
	for (int i=0;i<3;i++){
		scanf("%d%d%d%d%d%d",&hin,&min,&sin,&hout,&mout,&sout);
		totalSec = (hout-hin)*3600+(mout-min)*60+(sout-sin);
		h = totalSec / 3600;
		totalSec-= h*3600;
		m = totalSec / 60;
		totalSec -= m*60;
		s = totalSec;
		printf("%d %d %d\n",h,m,s);
	}
	
	return 0;
}

Measured memory_bytes: 2612
from time import time
from random import random

limit_secs = 2
start_time = time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

def calc_satisfaction():
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
    return S

def solution():
    return [i % 26 for i in range(D)]

t = solution()
S = calc_satisfaction()
while time() - start_time < limit_secs * 0.9:
    d = int(random() * D)
    q = int(random() * 26)
    old = t[d]
    t[d] = q
    new_S = calc_satisfaction()
    if new_S < S:
        t[d] = old
        S = new_S

for e in t:
    print(e + 1)


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

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

#define ll long long
const int MOD = 1e9 + 7;


int main() {
    INIT();
    ll a,b  ;
    cin >> a >> b;
    for(ll i = 0; i <= 1000; i++) {
        if((ll)(i * .08) == a && (ll)(i * .1) == b) {
            cout << i;
            return 0;
        }
    }
    cout << -1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int n;cin >>n;
    set<ll > s;
    for(int i=0;i<n;i++){
        ll a;cin >>a;
        s.insert(a);
    }
    if(n==s.size())puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a=0,b,c,d;
  string s;
  cin >>s;
  cout <<"2018/01/"<<s[8]<<s[9]<<'\n';
  return (0);
}


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

int main() {

  int a,i,c,d=0,e=0;
  cin>>a;
  for(i=0;i<a;i++){
    cin>>c;
    d=0;
  while(c%2==0){
    
    d++;
    
    c=c/2;
  }
    if(e>d||i==0)
    e=d;
  }
cout<<e<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=305;
string s;
int dp[305][305][305],K;
int dfs(int l,int r,int x)
{
    if(r<l)return 0;
    if(l==r)return 1;
    if(dp[l][r][x]!=-1)return dp[l][r][x];
    int t=max(dfs(l+1,r,x),dfs(l,r-1,x));
    if(s[l]==s[r])t=max(t,dfs(l+1,r-1,x)+2);
    else if(x)t=max(t,dfs(l+1,r-1,x-1)+2);
    return dp[l][r][x]=t;
}
int main()
{
    cin>>s>>K;
    memset(dp,-1,sizeof(dp));
    cout<<dfs(0,s.size()-1,K)<<endl;
    return 0;
}

Measured memory_bytes: 111104
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a = [0]*M
b = [0]*M
c = [0]*M
for i in range(M):
    input_data = input().split()
    a[i], b[i], c[i] = map(int, input_data)
    a[i] -=1
    b[i] -=1

MAX = 10**10
dist = [[MAX for j in range(N)] for i in range(N)]
#dist += MAX

for i in range(N):
    dist[i][i] = 0

for i in range(M):
    dist[a[i]][b[i]] = c[i]
    dist[b[i]][a[i]] = c[i]

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

ans = 0
for i in range(M):
    if dist[a[i]][b[i]] < c[i]:
        ans += 1

print(ans)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

namespace
{
	ll GCD(ll a, ll b)
	{
		return a == 0 ? b : GCD(b % a, a);
	}


	ll LCM(ll a, ll b)
	{
		return a * b / GCD(a, b);
	}
}
void ABC148C()
{
	ll A, B;
	cin >> A >> B;
	cout << LCM(A, B) << endl;
}

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

Measured memory_bytes: 256