akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int N, Q;
string s;
char t[223456], d[223456];

bool left(int p) {
  for (int i = 0; i < Q; i++) {
    if (t[i] == s[p]) {
      p += ((d[i] == 'L') ? -1 : 1);
    }
    if (p < 0) return true;
  }

  return false;
}

bool right(int p) {
  for (int i = 0; i < Q; i++) {
    if (t[i] == s[p]) {
      p += ((d[i] == 'L') ? -1 : 1);
    }
    if (p >= N) return true;
  }

  return false;
}

int main(int argc, char *argv[])
{

  cin >> N >> Q;
  cin >> s;

  int ans = N;

  for (int i = 0; i < Q; i++) {
    cin >> t[i] >> d[i];
  }

  int ok = 0, ng = N;
  while (abs(ok-ng) > 1) {
    int mid = (ok + ng)/2;
    if (left(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  if (left(ok)) {
    ans -= (ok + 1);
  }

  ok = N-1, ng = -1;
  while (abs(ok-ng) > 1) {
    int mid = (ok + ng)/2;
    if (right(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  if (right(ok)) {
    ans -= N-(ok);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1028
/**
 🍪 the_hyp0cr1t3
 🍪 31.08.2020 20:26:17
**/
#ifdef W
#include "k_II.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define aylmao cin.tie(nullptr)->sync_with_stdio(false);
#endif
#define endl '\n'
#define pb emplace_back
// #define int int64_t
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()
#define Luv(...) [&](auto&& u, auto&& v) { return __VA_ARGS__; }
auto chmax = [](auto& A, auto&& B) { return B > A? A = B, true : false; };
auto chmin = [](auto& A, auto&& B) { return B < A? A = B, true : false; };

using ll = int64_t;
using pii = pair<int,int>;
const ll DESPACITO = 2e18;
const int INF = 2e9, MOD = 1e9+7;

template<class T>
struct Segtree {
    int N; vector<T> st;
    Segtree(int N): N(N) {
        int SZ = 1; for(SZ = 1; SZ < N; SZ <<= 1);
        st.resize(2*SZ+2);
    }
    template<class Iter> Segtree(Iter beg, Iter end): N(end-beg) {
        int SZ = 1; for(SZ = 1; SZ < N; SZ <<= 1);
        st.resize(2*SZ+2); build(1, 1, N, beg, end);
    }

    T Query(int node, int L, int R, int i, int j) {
        if(i > R or j < L) return T();
        if(i <= L and j >= R) return st[node];
        int M = L+R>>1;
        return T(Query(node*2, L, M, i, j), Query(node*2+1, M+1, R, i, j));
    } 

    void Update(int node, int L, int R, int pos, ll val) {
        if(L == R) return st[node] << val;
        int M = L+R>>1;
        pos <= M? Update(node*2, L, M, pos, val) : Update(node*2+1, M+1, R, pos, val);
        st[node] = T(st[node*2], st[node*2+1]);
    }

    auto query(int l, int r) { return Query(1, 1, N, l, r).val; }
    void update(int pos, ll val) { Update(1, 1, N, pos, val); }
};

struct Node {
    ll val;
    Node(ll val = 0) : val(val) {}    
    Node(const Node& l, const Node& r)
        : val(max(l.val, r.val)) {}
    void operator<<=(int init) { val = init; }
    void operator<<(ll delta) { chmax(val, delta); }
};

const int N = 2e5 + 5;
int a[N], h[N];

int32_t main() {
    aylmao
    int i, n;
    cin >> n;
    for(i = 0; i < n; i++) 
        cin >> h[i];
    for(i = 0; i < n; i++) 
        cin >> a[i];

    i = 0;
    map<int, int> coords;
    for(auto& x: h) 
        coords[x];
    for(auto& x: coords) 
        x.second = ++i;
    for(auto& x: h) 
        x = coords[x];

    Segtree<Node> st(n);
    for(int i = 0; i < n; i++) {
        auto x = st.query(1, h[i]-1);
        st.update(h[i], x+a[i]);
    }
    cout << st.query(1, n);
    return 0;
}

Measured memory_bytes: 18232
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {

			int n = scanner.nextInt();
			int m = scanner.nextInt();

			int[][] combination = combination();

			int N = 0;
			int M = 0;

			if (n >= 2) {
				N = combination[n][2] % 1000000007;
			}

			if (m >= 2) {
				M = combination[m][2] % 1000000007;
			}

			int RES = N + M;

			System.out.println(RES);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static int[][] combination() {
		int combination[][] = new int[1001][1001];
		for (int i = 0; i < 1001; i++)
			for (int j = 0; j <= i; j++) {
				if (j == 0 || j == i)
					combination[i][j] = 1;
				else
					combination[i][j] = combination[i - 1][j - 1] % 1000000007 + combination[i - 1][j] % 1000000007;
			}
		return combination;
	}
}

Measured memory_bytes: 26068
#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long

int take() {
    int n;
    scanf("%d",&n);
    return n;

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done {return 0;}
#define fr(n) for(int i=1;i<=n;i++)
#define FR(a,b,x) for(int i=(a);i<=(b);i+=(x))
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR {struct info}
#define debug(x) {cout<<"ekhane"<<x<<endl;}
#define  SS second
#define  FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int,int>
#define mil map<int,ll>
#define mll map<ll,ll>
#define msb map<string,bool>
#define M 100005
//////////////////////////////////////////


int main(){
    int n=Int,m=Int;
    string s;
    cin>>s;
    bool got=1;
    for(int i=0;i<n;i++){
        if(s[i]>=48 && s[i]<=57) continue;
        got=0;
    }

    for(int i=n+1;i<(n+m+1);i++){
         if(s[i]>=48 && s[i]<=57) continue;
        got=0;
    }

    if(s[n]!='-') got=0;

    if(got) printf("Yes\n");
    else printf("No\n");

    done;
}




Measured memory_bytes: 256
#include <iostream>
    #include<cmath>
    #include<string>
    using namespace std;
    int main()
    {
        int n,k;
      cin>>n;
      while(n!=0)
      {
       k=n%10;
        if(k==7)
        {cout<<"Yes";
        break;}
        else
        { n=n/10;
         if(n==0)
           cout<<"No";
        }
      }
    }

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

long long ta[399999];

int main()
{
  int n;
  int a;
  int b;
  long long k;
  std::cin >> n >> a >> b >> k;
  //  n = 4; a = 2; b = 1; k = 5;
  //printf("%d\t%d\t%d\t%lld\n", n, a, b, k);
  //system("pause");
  ta[0] = 1;
  long long q = 1;
  int m = (n + 1) / 2;
  long long answer = 0;

  for (int i = 1; i < m + 1; i++) {
    q = (q * (n - i + 1)) % 998244353;
    long long j = 998244353 - 2;
    long long ii = i;
    while (j > 0) {
      if (j % 2 == 1) {
        q = (q*ii) % 998244353;
      }
      ii = (ii*ii) % 998244353;
      j = j / 2;
    }
    ta[i] = q;
  }
  for (int i = m + 1; i < n + 1; i++) {
    ta[i] = ta[n - i];
  }
  for (int i = 0; i < n + 1; i++) {
    //printf("%d\t%lld\n", i, ta[i]);
  }
  for (int i = 0; i < n + 1; i++) {
    if ((k - i*a) % b == 0) {
      int j = (k - i*a) / b;
      if (j <= n && j >= 0) {
        long long pp = (ta[i])*(ta[j]);
        //printf("%d %d %lld %lld %lld\n", i, j, ta[i],ta[j],pp);
        answer += pp;
        answer = answer % 998244353;
      }
      else {
        continue;
      }
    }
  }




  //printf("%d\t%d\t%d\t%d\n", n, a, b, k);
  printf("%lld\n", answer);

}

Measured memory_bytes: 2560
/*
▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>


using namespace std;

#define ll long long
#define ld long double
#define null NULL
#define prev prev228
#define next next228
#define index index228
#define count count228


int a[228228];


signed main() {
	int n;
	scanf("%d", &n);
	n *= 2;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + n + 1);
	int i = n;
	ll res = 0LL;
	while (i >= 2) {
		res += a[i - 1];
		i -= 2;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;


ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}
string fun(ll n){
    string ans;
    while(n>0){
        ans+=(n%10)+'0';
        n/=10;
    }
    ll s=ans.size();
    if(s<3){
        int y=3-s;
        while(y--) ans+='0';
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 ll n;cin>>n;
  string s;
  cin>>s;
 ll fn=0;
  for(int i=0;i<1000;i++){
      string ans=fun(i);
      //123 124
      //unordered_map<ll,ll> m[2];
      //cout<<ans<<" ";
     char p1=ans[0],p2=ans[1];
     //cout<<p1<<p2;
     ll cnt1=0,cnt2=0;
     int f=0;
     ll m1[n],m2[n];
     int cnt=0;
     for(int j=0;j<n;j++){
         m1[j]=cnt;
         if(s[j]==ans[0]) cnt++;
     }
     cnt=0;
     for(int j=n-1;j>=0;j--){
         m2[j]=cnt;
         if(s[j]==ans[2]) cnt++;
     }
     for(int j=0;j<n;j++){
         if(s[j]==ans[1]){
             if(m1[j]&&m2[j]){
                 fn++;break;
             }
         }
     }
    
  }
  cout<<fn;
}



  

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

using namespace std;

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

int main(){
    string c;
    cin >> c;
    string a = "abcdefghijklmnopqrstuvwxyz";
    rep(i, 25){
        if (a[i] == c[0]){
            cout << a[i+1] << endl;
            return 0;
        }
    }
    
}

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

#define mx 50005
#define ll signed long long int

void IO()
{
     #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
}

int ar[mx],vis[mx];
ll cr[mx];
char ch[mx];

ll m,n,k,ii;


void solve()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    for(int i=1;i<=n;i++)cin>>cr[i];
    ll re=-2e18;
    for(int i=1;i<=n;i++)
    {
       
        vector<int>v;
        vis[ar[i]]=i;
        v.push_back(ar[i]);
        int cur=ar[i];
        while(vis[ar[cur]]!=i)
        {
            v.push_back(ar[cur]);
            cur=ar[cur];
            vis[cur]=i;
        }
        ll sz=v.size();
        //cout<<sz<<endl;
        if(k<=sz)
        {
            ll val1=-2e18,tot=0;
            for(int j=0;j<k;j++)
            {
                tot+=cr[v[j]];
                if(tot>=val1)val1=tot;
            }
            re=max(re,val1);
            continue;
        }
        ll koto=k/sz;
        ll ex=k%sz;
        ll val1=0,tot=0;
        ll maxi=-2e18;
       
        for(int j=0;j<sz;j++)
        {
           // cout<<v[j]<<" ";
            tot+=cr[v[j]];
            if(tot>=maxi)
            {
                maxi=tot;
                
            }
           
        }
        //cout<<endl;

        ll val=max(maxi,tot*koto);
        if(koto>1)
        {
            ll va=0;
            for(int j=0;j<sz;j++)
            {
                va+=cr[v[j]];
                val=max(val,va+(tot*(koto-1)));
            }
        }
        if(tot>0)
        {
        for(int j=0;j<ex;j++)
        {
             val1+=cr[v[j]];
             val=max(val,val1+(tot*koto));
        }
        }
       
        re=max(re,val);
    }
    cout<<re<<endl;
    //cout<<setprecision(2)<<re<<endl;
}

int main()
{
    IO();

    int t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <cmath>
using namespace std;
const long long INF = 1e18;

int main() {
    long long N;
    cin >> N;
    long long thresh = sqrt(N);
    long long stepMin = INF;
    for (long long i=1; i<=thresh; i++) {
        long long j = N / i;
        if ((i*j) == N) {
            long long step = i-1 + j-1;
            if (step < stepMin)
                stepMin = step;
        }
    }
    cout << stepMin << endl;
}



Measured memory_bytes: 256
import math
n = int(input())
while(n != 0):
    s = []
    s[:] = map(int,input().split())
    sigma2 = 0.0
    average = 0.0
    for _ in range(0,n):
        average += s[_]

    average = average / float(n)

    for _ in range(0,n):
        sigma2 += (s[_]-average)**2
    sigma2 = sigma2 / float(n)
    sigma = math.sqrt(sigma2)
    print(sigma)
    n = int(input())



Measured memory_bytes: 5700
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        char[] c = sc.next().toCharArray();

        // 赤：右から数える
        int[] red = new int[n];
        if (c[n-1] == 'R')
            red[n-1] = 1;
        for (int i = n-2; i >= 0; i--) {
            red[i] = red[i+1];
            if (c[i] == 'R')
                red[i]++;
        }

        // 白：左から数える
        int[] white = new int[n];
        if (c[0] == 'W')
            white[0] = 1;
        for (int i = 1; i < n; i++) {
            white[i] = white[i-1];
            if (c[i] == 'W')
                white[i]++;
        }

        int min = Math.min(red[0], white[0]);
        for (int i = 1; i < n; i++) {
            int tmp = Math.min(red[i], white[i]);
            if (min < tmp) {
                min = tmp;
            }
        }

        System.out.println(min);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 38196
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;

string s;

int main()
{
    int i,j,k;
    
    cin>>s;
    if(s.find("AC")==-1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[]A = new int[N];
		string S = Console.ReadLine();
		for(var i=0;i<N;i++){
			A[i] = int.Parse(S.Substring(i,1));
		}
		int ans = 0;
		int[]B = new int[3];
		for(var i=0;i<1000;i++){
			B[0] = i/100;
			B[1] = i/10%10;
			B[2] = i%10;
			int t = 0;
			int x = 0;
			while(t < N){
				if(A[t]==B[x]){
					x++;
					if(x==3){
						ans++;
						break;
					}
				}
				t++;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13152
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; 
  string s;
  cin >> n >> s;
  int result = 0;
  for(int i=0; i<n-2;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      result++;
    }
  }
  cout << result << endl;
}

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

int main() {
  string A, B;
  cin >> A >> B;

  int n = stoi(A + B);
  if (pow(floor(sqrt(n)), 2) == n) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k;
	cin>>n>>k;
	long long a[n];
	for(long long i=0;i<n;i++)
		cin>>a[i];
	long long dp[n+1];
	dp[1]=0;
	dp[2]=abs(a[0]-a[1]);
	for(long long i=3;i<=n;i++)
	{long long mi=LLONG_MAX;
		for(long long j=1;j<=k && i-j>0;j++)
		{
			if(dp[i-j]+abs(a[i-1]-a[i-j-1])<mi)
				mi=dp[i-j]+abs(a[i-1]-a[i-j-1]);
		}
	dp[i]=mi;
	}
	cout<<dp[n];
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

class UnionFind {
  public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

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

    int N, M;
    cin >> N >> M;
    int ans = 0;
    vector<int> a(M), b(M);
    rep(i, M) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    rep(i, M) {
        int aa = a[i], bb = b[i];
        UnionFind tree(N);
        rep(j, M) {
            if (i == j)
                continue;
            else {
                tree.merge(a[j], b[j]);
            }
        }

        if (!tree.issame(aa, bb))
            ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define rep(i,a) for(int i=0;i<(a);++i)

typedef std::pair<int, int> P;

int a, b, c, d, e, f;
P memo[31][3001];

double conc( const P &c )
{ return c.first == 0 ? 0 : (double)c.second/c.first; }

P maxConc( const P &a, const P &b )
{ return conc(a) > conc(b) ? a : b; }

P dfs( int water, int sugar )
{
  if( memo[water/100][sugar] != P(-1,-1) )
    return memo[water/100][sugar];

  P ret = P(water+sugar, sugar);
  
  if( water+100*a+sugar <= f )
    ret = maxConc( ret, dfs( water+100*a, sugar ) );
  if( water+100*b+sugar <= f )
    ret = maxConc( ret, dfs( water+100*b, sugar ) );
  if( water+sugar+c <= f && sugar+c <= water/100.0*e )
    ret = maxConc( ret, dfs( water, sugar+c ) );
  if( water+sugar+d <= f && sugar+d <= water/100.0*e )
    ret = maxConc( ret, dfs( water, sugar+d ) );

  return memo[water/100][sugar] = ret;
}

int main()
{
  scanf( "%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f );
  rep( i, 31 ) rep( j, 3001 )
    memo[i][j] = P(-1,-1);

  P ans = dfs( 0, 0 );
  printf( "%d %d\n", ans.first, ans.second );

  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define MAX 100

int main(void) {
  int n, m, X, Y, i, j, k, flag;
  int x[MAX], y[MAX];
  scanf("%d%d%d%d", &n, &m, &X, &Y);
  for (i = 0; i < n; i++) {
    scanf("%d", x + i);
  }
  for (i = 0; i < m; i++) {
    scanf("%d", y + i);
  }
  for (k = X + 1; k <= Y; k++) {
    flag = 1;
    for (i = 0; i < n; i++) {
      if (x[i] >= k) flag = 0;
    }
    for (i = 0; i < m; i++) {
      if (y[i] < k) flag = 0;
    }
    if (flag == 1) {
      printf("No War\n");
      return 0;
    }
  }
  printf("War\n");
  return 0;
}


Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define d(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


LL q,lenX,lenY,dp[1001][1001];
string X,Y;

int do_dp(){
    REP(i,lenX+1)dp[i][0]=0;
    REP(i,lenY+1)dp[0][i]=0;
    FOR(i,1,lenX+1)FOR(j,1,lenY+1){
        dp[i][j]=max(max(dp[i-1][j-1]+(X[i-1]==Y[j-1]?1:0),dp[i-1][j]),dp[i][j-1]);
    }
    return dp[lenX][lenY];
}

int main(void){
    cin>>q;
    REP(i,2*q){
        if(i%2==0){
            cin>>X;
        }
        else{
            cin>>Y;
        }
        lenX=X.size();
        lenY=Y.size();
        if(i%2==1){
            cout<<do_dp()<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 10976
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        ll h, w;
        cin >> h >> w;
        ll g = __gcd(h, w);
        h /= g;
        w /= g;
        if ((h+w)%2) {
            cout <<  "1 1" << endl;
        } else {
            ll mul = h*w;
            cout << (mul+1)/2 << " " << (mul-1)/2 << endl;
        }
    }
    return 0;
}

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

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    G[i].emplace_back(i + 1);
    G[i + 1].emplace_back(i);
  }
  G[X].emplace_back(Y);
  G[Y].emplace_back(X);
  vector<int> res(N, 0);
  for (int i = 0; i < N; i++) {
    vector<int> dist(N, 1 << 28);
    dist[i] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>,
                   greater<pair<int, int>>>
        que;
    que.push(make_pair(0, i));
    while (!que.empty()) {
      auto q = que.top();
      que.pop();

      int u = q.second, d = q.first;
      if (d > dist[u]) continue;

      for (int v : G[u]) {
        if (chmin(dist[v], dist[u] + 1)) {
          que.push(make_pair(dist[v], v));
          if (v > i) res[dist[v]]++;
        }
      }
    }
  }
  for (int i = 1; i < N; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;vector<vector<int> >a(11,vector<int>(330));void r(int n,int u,int s,int d){a[n][s]++;for(int i=10;i-->0;)if(!(u>>i&1))r(n+1,u^1<<i,s+d*i,d+1);}main(){r(0,0,0,1);for(int n,s;cin>>n>>s;)cout<<a[n][s]<<"\n";}

Measured memory_bytes: 808
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

typedef long long ll;

using namespace std;

int main(){

    double ans=0;
    ll n;
    cin>>n;
    vector<ll> x(n,0),y(n,0),a(n,0);
    double fact=1;
    for(ll i=0;i<n;i++){
        cin>>x[i]>>y[i];
        a[i]=i;
        fact*=(i+1);
    }

    vector<vector<double>> d(n,vector<double>(n,0.0));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            d[i][j]=sqrt((x[i]-x[j])* (x[i] - x[j])+(y[i]-y[j])* (y[i] - y[j]));
        }
    }

    double sum=0;

    do{
        for(ll i=0;i<n-1;i++){
            sum+=d[a[i]][a[i+1]];
        }
	}while(next_permutation(a.begin(),a.end()));
    
    ans=sum/fact;

    cout<< fixed << setprecision(10)<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long

int gcd(int a, int b){
    if (b==0)
        return a;
    else
        return gcd(b, a % b);
}

int gcd3(int a, int b, int c){
    return gcd(gcd(a, b), c);
}

int main()
{
    int k;
    cin >> k;
    int sum = 0;
    for(int a=1;a<k+1;a++){
        for(int b=1;b<k+1;b++){
            for(int c = 1;c<k+1;c++){
                sum += gcd3(a, b, c);
            }
        }
    }
    cout << sum << endl;
}

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

int main() {
	string s;
	cin >> s;
	int n = s.length();
	for (int i = 1; i < n; i++) {
		s = s.substr(0, s.length() - 1);
		if (s.length() % 2 == 1)continue;
		string sl, sr;
		sl = s.substr(0, s.length() / 2);
		sr = s.substr(s.length() / 2);
		if (sl == sr) {
			cout << s.length() << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m,t,p;
int a[70][70];
int main(){
	while(1){
		
		cin>>n>>m>>t>>p;
		if(n==0&&m==0&&t==0&&p==0)break;
		int nh=m,nw=n;
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				a[i][j]=1;
			}
		}
		for(int ppp=0;ppp<t;ppp++){
			int d,s;
			cin>>d>>s;
			if(d==1){
				if(s<=nw-s){
					for(int i=1;i<=s;i++){
						for(int j=0;j<nh;j++){
							a[j][s+i-1]+=a[j][s-i];
						}
					}
					for(int i=0;i<nw-s;i++){
						for(int j=0;j<nh;j++){
							a[j][i]=a[j][i+s];
						}
					}
					nw=nw-s;
				}else{
					for(int j=0;j<nh;j++){
						for(int i=1;s+i-1<nw;i++){
							a[j][s+i-1]+=a[j][s-i];
						}
						for(int i=2*s-nw-1;i>=0;i--){
							a[j][nw+(2*s-nw-1-i)]=a[j][i];
						}	
					}
					for(int i=0;i<s;i++){
						for(int j=0;j<nh;j++){
							a[j][i]=a[j][s+i];
						}
					}
					nw=s;
				}
			}else{
				if(s<=nh-s){
					for(int i=1;i<=s;i++){
						for(int j=0;j<nw;j++){
							a[s+i-1][j]+=a[s-i][j];
						}
					}
					for(int i=0;i<nh-s;i++){
						for(int j=0;j<nw;j++){
							a[i][j]=a[i+s][j];
						}
					}
					nh=nh-s;
				}else{
					for(int j=0;j<nw;j++){
						for(int i=1;s+i-1<nh;i++){
							a[s+i-1][j]+=a[s-i][j];
						}
						for(int i=2*s-nh-1;i>=0;i--){
							a[nh+(2*s-nh-1-i)][j]=a[i][j];
						}	
					}
					for(int i=0;i<s;i++){
						for(int j=0;j<nw;j++)
						a[i][j]=a[s+i][j];
					}
					nh=s;
				}
			}
			
			
			

			
		}
			/*for(int i=0;i<nh;i++){
				for(int j=0;j<nw;j++){
					cout<<a[i][j];
				}
				cout<<endl;
			}*/
			int ans=0;
			for(int i=0;i<p;i++){
				int xx,yy;
				cin>>xx>>yy;
				cout<<a[yy][xx]<<endl;
			}
		

		
	}
	return 0;
}
				
				
					

					
				


Measured memory_bytes: 3096
// luogu-judger-enable-o2
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <string>
#include <string.h>
#include <cmath>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <fstream>
#include <sstream>
#include <assert.h>
#define SIZE 200010
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
void io() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}
inline long long qpow(long long base, long long x, long long p) {
	long long res = 1;
	while (x) {
		if (x & 1) res *= base, res %= p;
		base *= base, base %= p;
		x >>= 1;
	}
	return res;
}
ll n, m, k;
bool c0 = false, f0 = false;
int posc = 0, posf = 0;
string s;
int main() {
	io(); cin >> s;
	rep(i, 0, s.length() - 1) {
		if (s[i] == 'C' && !c0) {
			c0 = true;
			posc = i + 1;
		}
		if (s[i] == 'F') {
			f0 = true;
			posf = i + 1;
		}
	}
	if (posc && posf) {
		if (posc < posf) cout << "Yes\n";
		else cout << "No\n";
	}
	else cout << "No\n";
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    
    for h in range(H) :
        for w in range(W) :
            if (h + w) % 2 == 0 :
                print("#", end="")
            else :
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7004
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define endl "\n"
#define loop(i,s,e) for(int i=s;i<e;i++)
#define int long long
#define mp make_pair
#define pii pair<int,int>
#define mset(a,f)  memset(a , f , sizeof(a))
#define pb push_back
const int N = 2e6 + 6;
const int inf = 1e18;
const int M = 1e9 + 7;
int A[N];
int dp[N][6][2];
int n , k = 0 , l = 0;

int alpha(int id , int cnt , int ok)
{
      if(id == n && n%2 && ok)return 0;
      if(id > n)return 0;
      int &abs = dp[id][cnt][ok];
      if(abs != -1)return abs;
      int ans = 0,a1 = -inf,a2 = -inf;
      if(cnt < k)
      {
            a1 = alpha(id+1,cnt+1,0);
            a2 = A[id] + alpha(id+2,cnt,ok); 
      }
      if(cnt == k)
      {
            a1 = A[id] + alpha(id+2,cnt,ok);
      }
      ans  = max(a1,a2);
      return abs = ans;
}

void solve()
{
      cin >> n;

      mset(dp,-1);

      loop(i,1,n+1)cin >> A[i];

      k = n%2;
      k++;
      int a1 = alpha(1,0,n%2);
      k--;
      int a2 = alpha(2,0,n%2);

      cout << max(a1,a2);
}
 
int32_t main()
{
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
    

       
       int t = 1;
       // cin >> t;
       while(t--)solve();
        
}


Measured memory_bytes: 198964
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007

typedef long long ll;

int W,H,A,B;
ll D[200010],R[200010];
ll ans = 0;

ll power(ll a,ll b)
{
    if(b == 0)return 1;
    ll res = power(a * a % mod,b / 2);
    if(b & 1)res = res * a % mod;
    return res;
}

ll con(int a,int b)
{
    if(a < b)return 0;
    return (D[a] * R[b] % mod) * R[a - b] % mod;
}

int main()
{
    scanf("%d%d%d%d",&H,&W,&A,&B);
    ll now = 1;
    for(int i = 0; i < H + W + 2; i++){D[i] = now;now *= i + 1;now %= mod;}
    for(int i = 0; i < H + W + 2; i++){R[i] = power(D[i],mod - 2);}
    for(int i = B + 1; i <= W; i++)
    {
        ll res = (con(i - 1 + H - A - 1,i - 1) * con(W - i + A - 1,A - 1)) % mod;
        ans += res;ans %= mod;
    }
    printf("%lld\n",ans);
    return 0;
}


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

#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;

void solve(void) {

	int n;
	cin >> n;
	vi A(n);

	for(int& x : A) cin >> x;

	vector<vector<ll>> dp(n, vector<ll>(n));
	// dp[i][j] = ans for A[i, .. , j]
	for(int l = n - 1; l >= 0; l--) {
		for(int r = l; r < n; r++) {
			bool turn = (n - (r-l+1)) % 2 == 0;

			if(l == r) {
				dp[l][r] = A[l]*(turn ? 1 : -1);
			} else if(turn) {
				dp[l][r] = max(dp[l+1][r] + A[l], dp[l][r-1] + A[r]);
			} else {
				dp[l][r] = min(dp[l+1][r] - A[l], dp[l][r-1] - A[r]);
			}
		}
	}

	cout << dp[0][n-1] << '\n';

}

int main(void) {

	solve();
	return 0;
}


Measured memory_bytes: 70656
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int N;
    cin >> N;
    vector<int> v(N);
    v.push_back(-1);
    rep(i, 0, N) cin >> v[i];

    int seq = 0;
    int ans = 0;
    for (int i = 0; i < v.size(); i++) {
        seq++;
        if (v[i] == v[i + 1]) {
        } else {
            ans += seq / 2;
            seq = 0;
        }
    }

    cout << ans << endl;


    return 0;
}


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

using namespace std;

int main() {
    int k;
    string s;
    cin>>k>>s;
    if(s.length()<=k) cout<<s<<endl;
    else {
        for(int i=0;i<k;i++) {
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
}


Measured memory_bytes: 3604
def sq(a, b, mod):#aのb乗を剰余,kは初期値#20191116-D-Knight
    if b==0:
        return 1
    elif b%2==0:
        return sq(a, b//2, mod)**2%mod
    else:
        return sq(a, b-1, mod)*a%mod

def nCk(n, k, mod=10 ** 9 + 7):
    x=max(k, n-k)
    y=min(k, n-k)
    kkai=1
    for i in range(2, y+1):
        kkai=(kkai*i)%mod
    nkkai=1
    for i in range(x+1, n+1):
        nkkai=(nkkai*i)%mod
    answer=sq(kkai, mod-2, mod)*nkkai%mod
    return answer
    
import math
c    = [list(map(int, input().split())) for _ in range(1)]
aa=(2*c[0][1]-c[0][0])
bb=(2*c[0][0]-c[0][1])
k=10**9+7

if aa%3!=0 or bb%3!=0:
    print(0)
elif aa<0 or bb<0:
    print(0)
else:
    a=aa//3
    b=bb//3
    answer=nCk(a+b,a)%k
    print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int a, b;
	cin >> a >> b;

	bool ok = false;
	for(int c = 1; c <= 3; c++) {
		if (a * b * c & 1)
			ok = true;
	}
	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

	solve();
}


Measured memory_bytes: 256
k,n=map(int,input().split())
a=list(map(int,input().split()))

long=0

for i in range(n-1):
  if long< a[i+1]-a[i]:
    long=a[i+1]-a[i]

if k+a[0]-a[n-1]>long:
  long=k+a[0]-a[n-1]

print(k-long)

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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n; cin >> n;
    ll row = n;

    vector<int> ans;
    vector<bool> v(n, false);
    for(int i = 2; i * i <= n; ++i) {
        if (v[i]) continue;

        while(n % i == 0) {
            n /= i;
            ans.pb(i);
        }

        for(int j = i; j * j <= n; j += i) v[j] = true;
    }

    if (n > 1) ans.pb(n);

    cout << row << ":";
    REP(i, ans.size()) {
        cout << " " << ans[i];
    }

    cout << endl;
}


Measured memory_bytes: 124800
defmodule Main do
  def main do
    case IO.gets("") |> String.trim() |> String.to_integer() |> Integer.digits() |> List.last() do
      2 ->
        IO.puts("hon")

      4 ->
        IO.puts("hon")

      5 ->
        IO.puts("hon")

      7 ->
        IO.puts("hon")

      9 ->
        IO.puts("hon")

      0 ->
        IO.puts("pon")

      1 ->
        IO.puts("pon")

      6 ->
        IO.puts("pon")

      8 ->
        IO.puts("pon")

      3 ->
        IO.puts("bon")
    end
  end
end

Measured memory_bytes: 30760
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

#define LL long long



int main() {
	int n;
	int p[25];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int ans = 0;
	for (int i = 2; i < n; i++) {
		if (((p[i - 2] < p[i - 1]) && (p[i - 1] < p[i]))
			|| ((p[i - 2] > p[i - 1]) && (p[i - 1] > p[i]))) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define mem(a,b) memset(a,b,sizeof(a))
#define shutdown ios::sync_with_stdio(false)
#define MAX 10e18+1000
#define INF 0x3f3f3f3f
#define MAR 10e5+100

int c[10][10];
int a[300][300];
int main(){
    shutdown;
    int h,w;
    LL sum=0;
    cin>>h>>w;
    for(int i=0;i<10;i++)
        for(int j=0;j<10;j++)
            cin>>c[i][j];
    for(int k=0;k<10;k++)
        for(int i=0;i<10;i++)
            for(int j=0;j<10;j++)
                if(c[i][j]>c[i][k]+c[k][j])
                    c[i][j]=c[i][k]+c[k][j];
    for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++){
        cin>>a[i][j];
    }
    for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++){
        if(a[i][j]!=-1)
            sum+=c[a[i][j]][1];
    }
    cout<<sum<<endl;
    return 0;
}


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

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

int main() {
    int n;
    cin >> n;
    int t[n], a[n];
    for (int i = 0; i < n; i++) {
        cin >> t[i] >> a[i];
    }
    
    ll totalT = t[0];
    ll totalA = a[0];
    for (int i = 1; i < n; i++) {
        ll cof = max((totalA + a[i] - 1) / a[i], (totalT + t[i] - 1) / t[i]);
        totalT = cof * t[i];
        totalA = cof * a[i];
    }
    
    cout << (ll)(totalA + totalT) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,ans = LLONG_MAX;
void check(ll sum[],ll i,ll j,ll k){
	if(i<0 || i>j || j>k || k>n-1){
		return;
	}
	ll a = sum[i];
	ll b = sum[j]-sum[i];
	ll c = sum[k]-sum[j];
	ll d = sum[n-1]-sum[k];
	ll mx = max(max(a,b),max(c,d));
	ll mn = min(min(a,b),min(c,d));
	if(ans > (mx-mn)){
		//cout<<ans<<" ";
		ans = mx-mn;
		//cout<<ans<<"\n";
	}
}
 
int main()
{
	cin>>n;
	ll seq[n];
	ll sum[n];
	for(int i=0;i<n;i++){
		cin>>seq[i];
		if(i==0){
			sum[i] = seq[i];
		}
		else sum[i] = sum[i-1] + seq[i];
	}
 
	for(int j=1;j<n-1;j++){
		ll i = lower_bound(sum,sum+n,(sum[j]+1)/2)-sum;
		ll k = lower_bound(sum,sum+n,(sum[n-1]+sum[j]+1)/2)-sum;
		//cout<<i<<" "<<j<<" "<<k<<"\n";
		check(sum,i-1,j,k-1);
		check(sum,i,j,k-1);
		check(sum,i-1,j,k);
		check(sum,i,j,k);
	}
 
	cout<<ans<<endl;
 
}

Measured memory_bytes: 3456
#include<stdio.h>
int main()
{
    int A, B;
    scanf("%d %d", &A, &B);
    if((A==1)&&(B==2))
        printf("3\n");
    else if((A==1)&&(B==3))
        printf("2\n");
    else if((A==2)&&(B==3))
        printf("1\n");
    else if((A==3)&&(B==2))
        printf("1\n");
    else if((A==3)&&(B==1))
        printf("2\n");
    else if((A==2)&&(B==1))
        printf("3\n");
    else
        printf("out of order\n");
    return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
  val (N, M) = readLine()!!.split(" ").map{it.toInt()}
  val vv = Array(8) {mutableListOf<Long>()}
  val tf = listOf(false, true)
  for (i in 1..N) {
    val (x, y, z) = readLine()!!.split(" ").map{it.toLong()}
    for (i in 0..1) {
      for (j in 0..1) {
        for (k in 0..1) {
          var v = 0L
          if (i==0) v += x else v -= x
          if (j==0) v += y else v -= y
          if (k==0) v += z else v -= z
          vv[i + j*2 + k*4].add(v)
        }
      }
    }
  }
  println(vv.map{it.sortedDescending().take(M).sum()}.max())
}

Measured memory_bytes: 41420
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define ll long long
#define INF 1e9
const ll MOD = 1e9 + 7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll count = 0;
        ll count_low = 0, count_upper = 0;
        for (int j = 0; j < N; j++) {
            if (a[i] > a[j]){
                if (j < i) count_low++;
                else count_upper++;
            }
        }
        ll sum = 0;
        // 1/2 (MOD)の逆元を考える
		sum = (count_upper % MOD + count_upper % MOD + (count_upper + count_low) % MOD  * (K - 1) % MOD) % MOD  * K   % MOD;
      	sum = sum  * 500000004 % MOD;
      
        ans += sum;
        ans %= MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14

int main(){
	ll a, b, c, d, e; cin >> a >> b >> c >> d >> e;
	cout << (c-a)*60+(d-b)-e << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(int i=0;i<(int)n;++i)
#define _rep1(i,k,n) for(int i=k;i<(int)n;++i)
#define _rep2(i,k,n,d) for(int i=k;d>0?i<(int)n:i>(int)n;i+=d)
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

void solve(){
    ll n, T; cin >> n >> T;
    ll res = 0;
    ll now = 0;
    rep(_, n){
        ll next; cin >> next;
        if(next - now < T){
            res += next - now;
        } else {
            res += T;
        }
        now = next;
    }
    res += T;
    cout << res << endl;
}

Measured memory_bytes: 256