akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define Q_LEN 100005

typedef struct pp{
  char name[100];
  int time;
}PROCESS;

static PROCESS Q[Q_LEN+1];
static int head, tail, process_num;

void
enqueue(PROCESS process_data)
{
        Q[tail] = process_data;

        if (Q_LEN < (tail + 1))
                tail = 0;
        else
                tail++;
}

PROCESS
dequeue(void)
{
        PROCESS process_data;

        process_data = Q[head];

        if (Q_LEN < (head + 1))
                head = 0;
        else
                head++;
        return process_data;
}

void
initialize(void)
{
        head = tail = 0;
}


int
main(void)
{
        int quantum;
        PROCESS process;
        int current_time = 0;
        int i;

        initialize();

        scanf("%d %d", &process_num, &quantum);

        for ( i = 0; i <= (process_num - 1); i++) {
                scanf("%s", Q[i].name);
                scanf("%d", &Q[i].time);
                tail++;
        }

        i = 1;
        while (i <= process_num) {
                process = dequeue();
                process.time -= quantum;

                if (0 < process.time) {
                        current_time += quantum;
                        enqueue(process);
                } else if (process.time <= 0) {
                        current_time += (quantum + process.time);
                        printf("%s %d\n", process.name, current_time);
                        i++;
                }
        }
        return 0;
}



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

const int nm = 2e5;
int n, l = 0, r;
long long b[nm + 1], ans = 0;

int main() {
	cin >> n;
	r = n;
	for (int i = 0, a; i < n; i++) {
		cin >> a;
		b[i + 1] = b[i] + a;
	}
	sort(b, b + n + 1);
	for (int i = 0, c = 1; i < n + 1; i++) {
		if (i < n && b[i + 1] == b[i]) {
			c++;
		} else {
			ans += (long long) c * (c - 1) / 2;
			c = 1;
		}
	}
	cout << ans << endl;
}


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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
using pii = pair<int,int>;
constexpr int inf = 1ll<<30;

int main(){
  int n, k; cin >> n >> k;
  string s; cin >> s;

  vector<pii> pos; // 1が連続する半開区間[l,r)を格納
  int l, r; l = r = 0;
  while(r < n and s[r] == '1') r++;
  pos.emplace_back(l,r);
  l = r = 0;
  while(1){
    while(l < n and s[l] == '1') l++;
    while(l < n and s[l] == '0') l++;
    r = l;
    while(r < n and s[r] == '1') r++;
    pos.emplace_back(l,r);
    if(r >= n) break;
  }
  
  int ans = -inf;
  rep(i,pos.size()-k) ans = max(ans, pos[i+k].second - pos[i].first);
  if(k >= pos.size()) ans = max(ans, pos.back().second - pos.front().first);
  cout << ans << endl;
}


Measured memory_bytes: 1020
#include<iostream>
#include<string>
#include<vector>

using namespace std;

void Main()
{
    int A, B;
    cin >> A >> B;

    int result = A - B * 2;
    if (result < 0) {
        cout << 0;
    } else {
        cout << result;
    }

}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	while(1){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		vector<ll> a(n);
		rep(snip_i, n) cin >> a.at(snip_i);
		vector<ll> w(m);
		rep(snip_i, m) cin >> w.at(snip_i);
		sort(w.begin(), w.end());
		map<ll, int> mp;
		mp.clear();
		rep(i, pow(3, m)){
			ll sum = 0;
			int ii = i;
			rep(j, m){
				if(ii % 3 == 0) sum += w.at(j);
				if(ii % 3 == 1) sum -= w.at(j);
				ii /= 3;
			}
			mp[sum] = i;
		}
		vector<ll> nf;
		rep(i, n){
			ll now = a.at(i);
			if(mp.count(now) == 0){
				nf.push_back(now);
			}
		}
		if(nf.size() == 0){
			cout << 0 << endl;
			continue;
		}
		ll fst = nf.at(0);
		ll ans = 1e18;
		for(auto p : mp){
			ll add =fabs(fst - p.first);
			bool flag = true;
			rep2(j, 1, nf.size()){
				ll now = nf.at(j);
				if(mp.count(now-add) == 0 && mp.count(now+add) == 0){
					flag = false;
					break;
				}
			}
			if(flag == true){
				ans = min(ans, add);
			}
		}
		if(ans == 1e18) ans = -1;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 6968
N = int(input())
 
S = list(map(str, input().split()))
 
color = [0, 0, 0, 0]
 
for s in S:
  if (color.count(0) == 0):
    print("Four")
    break
  
  if (s == "P"):
    color[0] += 1
  elif (s == "G"):
    color[1] += 1
  elif (s == "W"):
    color[2] += 1
  else:
    color[3] += 1
  
if (color.count(0) == 1):
  print("Three")

Measured memory_bytes: 3064
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> X(N);
  vector<Pair> Y(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> X[i];
    Y[i].first = X[i];
    Y[i].second = i;
  }
  sort(Y.begin(), Y.end());
  int64_t left = Y[(N - 1) / 2].second;
  int64_t right = Y[(N - 1) / 2 + 1].second;
  for (int64_t i = 0; i < N; ++i) {
    if (i != 0) {
      cout << " ";
    }
    if (X[i] <= X[left]) {
      cout << X[right];
    } else {
      cout << X[left];
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 7948
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll digit_sum(ll x){
  ll ret=0;
  while(x){
    ret+=x%10;
    x/=10;
  }
  return ret;
}

int main(){
  ll n;cin>>n;
  if(n%digit_sum(n)==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int poww(int a,int b){
    if(b==0)return 1;
    int ans=poww(a,b/2);
    ans=ans*ans%MOD;
    if(b&1)ans=ans*a%MOD;
    return ans;
}

signed main(){
    FASTER;
    int n,k;cin>>n>>k;
    int dp[k+1],ans=0;
    for(int g=k;g>=1;g--){
        dp[g]=poww(k/g,n);
        for(int j=2*g;j<=k;j+=g){
            dp[g]=(dp[g]-dp[j]+MOD)%MOD;
        }
        ans=(ans+dp[g]*g%MOD+MOD)%MOD;
    }
    cout<<ans;
    
}

Measured memory_bytes: 4428
until(n,m=gets.split.map(&:to_i)).all?(&:zero?)do
r,p,a=[],[],[]
n.times{r.unshift(gets.gsub("?",".").split)}
m.times{p<<gets.split}
p.each{|p|r.each{|r|if p[0]=~/#{r[1]}/&&p[1]=~/#{r[2]}/
a<<p*" "if r[0]=~/p/
break
end}}
puts a.size,a
end

Measured memory_bytes: 9396
/*
 * ABC093_A.cpp
 *
 *  Created on: May 21, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}



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

	string S;
	cin >> S;
	if(S[0]+S[1]+S[2] == 'a'+'b'+'c') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}






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

string solve(vector<int> a){
    sort(a.begin(), a.end());
    vector<int> dp(k+1,0);
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-a[j]<0)
                break;
            if(dp[i-a[j]]==0){
                dp[i] =1;
                break;
            }
        }
    }
    if(dp[k]==0)
        return "Second";
    return "First";
}

int main(){

    cin>>n>>k;
    vector<int> a(n,0);
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<solve(a)<<endl;
    return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int b[200001];

int main() {
  int n,a;
  cin >> n;
  for(int i=1;i<n;i++){
    cin >> a; b[a]++;
  }
  for(int i=1;i<=n;i++) cout << b[i] << endl;
}


Measured memory_bytes: 4336
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
using dl = long double;
int main()
{
    dl l;
    cin>>l;
    l  = l/3;
    dl answer = l*l*l;
    cout<<fixed<<setprecision(7)<<answer;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>

long long cost[50][50];
long long minutes[50][50];
long long ans[50][50 * 50 * 50];
long long exchange[50];
long long minutes_exchange[50];

int main() {
    int n, m; long long s; std::cin >> n >> m >> s;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cost[i][j] = -1;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) minutes[i][j] = -1;
    long long sum = 0;
    for (int i = 0; i < m; i++) {
        long long a, b, c, d; std::cin >> a >> b >> c >> d;
        a--; b--;
        cost[a][b] = cost[b][a] = c;
        minutes[a][b] = minutes[b][a] = d;
        sum += c;
    }
    if (sum <= s) s = sum;

    constexpr long long INIT = 1e18;
    for (int i = 0; i < n; i++) {
        std::cin >> exchange[i] >> minutes_exchange[i];
    }
    using Node = std::pair<long long, std::pair<long long, long long>>;
    std::priority_queue<Node, std::vector<Node>, std::greater<Node>> que;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < sum + 2; j++) {
            ans[i][j] = INIT;
        }
    }
    que.push({ 0, { 0, s } });
    while (!que.empty()) {
        auto node = move(que.top());
        que.pop();
        long long dist = node.first;
        long long pos = node.second.first;
        long long coin = node.second.second;
        if (ans[pos][coin] != INIT) continue;
        ans[pos][coin] = dist;

        for (int i = 0; i < n; i++) {
            if (cost[pos][i] == -1) continue;
            long long nxtcoin = coin - cost[pos][i];
            if (nxtcoin < 0) continue;
            if (ans[i][nxtcoin] != INIT) continue;
            que.push({ dist + minutes[pos][i], { i, nxtcoin } });
        }

        if (coin < sum) {
            long long nxtcoin = std::min(sum, coin + exchange[pos]);
            long long nxtdist = dist + minutes_exchange[pos];
            if (ans[pos][nxtcoin] != INIT) continue;
            que.push({ nxtdist, {pos, nxtcoin} });
        }
     }
    for (int i = 1; i < n; i++) {
        std::cout << *std::min_element(ans[i], ans[i] + sum + 1) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 10756
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

int main()
{
	LL x, y;
	cin >> x;
	y = x;
	--x;
	int ans = 1;
	for(LL i = 2; i*i <= x; ++i) if(x % i == 0) {
		int cnt = 1;
		while(x % i == 0) x /= i, ++cnt;
		ans *= cnt;
	}
	if(x > 1) ans *= 2;
	x = y;
	for(LL i = 2; i*i <= x; ++i) if(x % i == 0) {
		LL t = x;
		while(t % i == 0) t /= i;
		if(t % i == 1) ++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int d[n];
    for (int i=0;i<n;i++){
        scanf("%d",&d[i]);
    }
    int store; 
    for (int i=n-1;i>0;i--){
        for (int j=0;j<i;j++){
            if (d[j]<d[j+1]){
                store=d[j];
                d[j]=d[j+1];
                d[j+1]=store;
            }
        }
    }
    int sum=1,mochi=d[0];
    for (int i=1;i<n;i++){
        if (mochi>d[i]){
            sum++;
            mochi=d[i];
        }
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
  long long int k,a,b,num=1;
  scanf("%lld%lld%lld",&k,&a,&b);
  while(k>0)
  {
    if(k==1)
    {
      num++;
      k--;
     //printf("a");
    }
    else if(b<=a)
    {

      num=num+k;
      k=0;
      //printf("b");
    }
    else if(((num/a)*b-(num/a)*a)<3)
    {
      if((b-a)==1)
      {
        if(k>=(3*a-num))
        {
        
        k=k-(3*a-num);
          num=3*a;
        }
        else 
        {
          num=num+k;
      k=0;
        }
        
      }
      else if((b-a)==2)
      {
        if(k>=(2*a-num))
        {
          
          k=k-(2*a-num);
          num=2*a;
        }
         else 
        {
          num=num+k;
      k=0;
        }
      }
      else
      {
        if(k>=(a-num))
        {
          
          k=k-(a-num);
          num=a;
        }
        else 
        {
          num=num+k;
      k=0;
        }
      }
      
      
    // printf("C");
    }
    else
    {
      num=num+((num/a)*b-(num/a)*a)*(k/2);
      k=k-(k/2)*2;
     //printf("d");
    }
  }
  printf("%lld",num);
  return 0;
}

Measured memory_bytes: 128
N=int(input())
dp=[0]*100
for i in range(N):
    s=str(i+1)
    dp[int(s[0])*10+int(s[-1])]+=1
ans=sum(dp[i*10+j]*dp[j*10+i] for i in range(1,10) for j in range(1,10))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	string s;cin>>s;
	int n=s.size();

	for(int i=1;i<n;i++){
		if((n-i)%2==1) continue;
		else{
			bool chk=1;
			for(int j=0;j<(n-i)/2;j++){
				if(s[j]!=s[j+(n-i)/2]){
					chk=0;
					break;
				}
			}
			if(chk){
				cout<<n-i<<"\n";
				return 0;
			}
			else continue;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, d; scanf("%d%d", &n, &d);
	d = 2 * d + 1;
	
	printf("%d\n", (n + d - 1) / d);	
	return 0;
}


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

int main() {
  int N;
  scanf("%d", &N);

  std::vector<std::vector<int>> A(N, std::vector<int>(N));
  intmax_t res=0;
  for (int i=0; i<N; ++i)
    for (int j=0; j<N; ++j) {
      scanf("%d", &A[i][j]);
      res += A[i][j];
    }

  std::vector<std::vector<int>> B=A;
  for (int k=0; k<N; ++k)
    for (int i=0; i<N; ++i)
      for (int j=0; j<N; ++j)
	A[i][j] = std::min(A[i][j], A[i][k]+A[k][j]);

  if (A != B)
    return !printf("-1\n");

  for (int k=0; k<N; ++k)
    for (int i=0; i<N; ++i) {
      if (i == k) continue;
      for (int j=0; j<N; ++j) {
	if (j == k) continue;
	if (j == i) continue;
	if (A[i][j] == A[i][k] + A[k][j]) {
	  res -= A[i][j];
	  A[i][j] = 2e9;
	}
      }
    }

  printf("%jd\n", res>>1);
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

int main()
{
  std::string str;
  std::cin >> str;
  std::sort(str.begin(), str.end());
  if ( str[0] == str[1] && str[2] == str[3] && str[1] != str[2])
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;

  return 0;
}



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

int main() {
    long long x, y; cin>>x>>y;
    if(x<y) swap(x, y);
    while(y){
        long long temp;
        temp = y;
        y = x%y;
        x = temp;
    } 
    cout << x <<endl;
    return 0;
}


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

int main(){

 int N,P;
 cin >> N;
 string s;
 pair<pair<string,int>,int> p[110];

 for(int i=0;i<N;i++){
 cin>>s>>P;
 p[i]=make_pair(make_pair(s,-P),i);
 }

 sort(p,p+N);

 for(int i=0;i<N;i++){
 printf("%d\n",p[i].second+1);
}
 return 0;
}

Measured memory_bytes: 256
//template
import java.util.*;
import java.util.stream.*;
import java.io.*;
public class Main{
	static BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	
	private static final int HUNDRED = 100;
	public static void main(String[] args) throws IOException{
		
		String s=in.readLine();
		int ans=0;
		for(int i=0;i<4;i++) {
			if(s.charAt(i)=='+') ans++;
			else ans--;
		}
		out.append(ans+"");
		
		out.flush();
		in.close();
		out.close();
	}
	private static int modulo(int S, int N) { return ((S) & (N - 1)); } // returns S % N, where N is a power of 2
	private static int isPowerOfTwo(int S) { return (S & (S - 1)) == 0 ? 1 : 0; }
	private static int[] readInts() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
	}
	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}
	private static long[] readLongs() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
	}
	private static long readLong() throws IOException {
		return Long.parseLong(in.readLine());
	}
	 
}
class Team{
	int id;
	LinkedList<Team> weekAdj;
	LinkedList<Team> strongAdj;
	public Team(int id) {
		this.id=id;
		weekAdj=new LinkedList<Team>();
		strongAdj=new LinkedList<Team>();
	}
	public void add(Team team) {
		if(weekAdj.remove(team))
			strongAdj.add(team);
		else
			weekAdj.add(team);
	}
}

Measured memory_bytes: 36616
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int p[10000];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	vi ps;
	for(int i = 2; i < 10000; i++) if(!p[i]){
		ps.pb(i);
		for(int j = i * i; j < 10000; j += i) p[j] = 1;
	}
	
	int n; cin >> n;
	const int N = 501;
	vector<vector<ll>> ans(N, vector<ll>(N, 1));
	rep(i, N) rep(j, 2 * i + 1){
		int y = j, x = 2 * i - j;
		if(x < 0 || x >= N || y < 0 || y >= N) continue;
		ans[y][x] *= ps[i];
		ans[y][N - x - 1] *= ps[i + N];
	}
	set<ll> used;
	rep(i, N) rep(j, N) used.insert(ans[i][j]);
	
	//dbg(used.size());
	//rep(i, N) rep(j, N) cerr<<ans[i][j]<<(j==N-1?"\n":" ");
	
	rep(i, N) rep(j, N) if(ans[i][j] == 1){
		ll pd = 1;
		for(int dy = -1; dy < 2; dy++) for(int dx = -1; dx < 2; dx++){
			if(!dy && !dx) continue;
			if(abs(dy) + abs(dx) > 1) continue;
			if(i + dy < 0 || i + dy >= N || j + dx < 0 || j + dx >= N) continue;
			ll g = __gcd(ans[i + dy][j + dx], pd);
			pd = pd / g * ans[i + dy][j + dx];
		}
		for(ll x = pd + 1; ; x += pd){
			if(!used.count(x)){
				used.insert(x);
				ans[i][j] = x;
				break;
			}
		}
	}
	rep(i, N) rep(j, N) assert(ans[i][j] > 0 && ans[i][j] < 1e15);
	rep(i, n) rep(j, n) cout << ans[i][j] << (j==n-1?"\n":" ");
	
	return 0;
}

Measured memory_bytes: 16896
t = input()
s = "AKIHABARA"
posA = [0, 4, 6, 8]
ok = 0
pos = [0, 3, 4, 5]
for i in range(2 ** 4):
    tmp = ""
    now = 0
    for j in range(9):
        if j == posA[now]:
            if i >> now & 1:
                tmp = tmp + s[j]
            now += 1
        else:
            tmp = tmp + s[j]

    if t == tmp:
        ok = 1
        break

if ok == 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }



int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    //累積和
    vector<ll> sum(n+1);
    
    rep(i,n){
        sum.at(i+1) = sum.at(i) + a.at(i);
    }
        

    ll ans=1e20;
    rep(i,n){ //i番目で区切った時に何回操作が必要になるか
        ans = min(ans,abs(2*sum[i+1]-sum[n]));
    }

    cout << ans << endl;
   

}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
class Dice{
  private:

  vector<int> num;

  public:

  Dice(vector<int> input):num(input){};

  void operate(int cmd){
    vector<int>ret = num;
    if(cmd == 0){ //E方向
      ret[0] = num[3]; 
      ret[2] = num[0]; 
      ret[5] = num[2]; 
      ret[3] = num[5]; 
    }
    if(cmd == 1){ // N方向
      ret[0] = num[1];
      ret[1] = num[5];
      ret[5] = num[4];
      ret[4] = num[0];
    }
    if(cmd == 2){// S方向
      ret[1] = num[0];
      ret[5] = num[1];
      ret[4] = num[5];
      ret[0] = num[4];
    }
    if(cmd == 3){ // W方向
      ret[3] = num[0]; 
      ret[0] = num[2]; 
      ret[2] = num[5]; 
      ret[5] = num[3]; 
    }
    num = ret;
  }
  static int dir(char c){
    if(c == 'E')return 0;
    if(c == 'N')return 1;
    if(c == 'S')return 2;
    if(c == 'W')return 3;
  }
  int top(){
    return num[0];
  }
  void print(){
    for(int i = 0; i < 6; i++){
      cout << num[i] << " ";
    }
    cout << endl;
  }
};

int main(){
  vector<int>a(6);
  for(int i = 0; i < 6; i++)cin >> a[i];
  string cmd;
  cin >> cmd;
  Dice dice(a);
  for(int i = 0; i < cmd.size(); i++){
    dice.operate(Dice::dir(cmd[i]));
    //dice.print();
  }
  cout << dice.top() << endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  ll cnt = 0;

  map<ll, int> m;
  REP(i, N) {
    cnt += m[i - A[i]];
    m[i + A[i]]++;
  }

  REP(i, N) {
    
  }

  cout << cnt << endl;
}


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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int sum = 0, tmp;
    vector<int> list(5);
    for (int i = 0; i < 5; i++)
    {
        cin >> tmp;
        sum += ((tmp + 9) / 10) * 10;
        list[i] = tmp % 10;
        if (list[i] == 0)
            list[i] = 10;
    }
    sort(list.begin(), list.end());
    cout << sum - 10 + list[0];
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
ll pow_mod(ll a, ll n, ll MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 0x01) { 
            res *= a;
            res %= MOD;
        }
        a = a * a;
        a %= MOD;
        n >>= 1LL;
    }
    return res;
}

ll combi_mod(ll n, ll k, const ll MOD) {
    if (k == 0) return 1;
    if (k == 1) return n%MOD;

    ll nume = 1, denom = 1;
    FOR(i, 1, k + 1) {
        nume *= i;
        nume %= MOD;
        denom *= i;
        denom %= MOD;
    }
    nume %= MOD;
    denom %= MOD;
    FOR(i, 1, n-k+1) {
        nume *= k + i;
        nume %= MOD;
        denom *= i;
        denom %= MOD;
    }
    nume %= MOD;
    denom %= MOD;

    ll res = nume * pow_mod(denom, MOD - 2, MOD);
    res %= MOD;
    return res;
}
#endif 


int main_D() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M; cin >> N >> M;

    const ll MOD = 1e9 + 7;

    ll ans = 1;
    ll q = M;
    for(int i = 2; i*i <= q; i++) {
        if (q%i == 0) {
            int cnt = 0;
            while(q%i==0) {
                cnt++;
                q /= i;
            }
            ans *= combi_mod(cnt + N - 1, N - 1, MOD);
            ans %= MOD;
        }
    }
    if (q > 1) {
        ans *= combi_mod(1 + N - 1, N - 1, MOD);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int len = s.length(),count=0;
  for(int i=0;i<len/2;i++)
  {
    if(s[i] == s[len-1-i])
      continue;
    else
      count++;}
  cout<<count;
  return 0;}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }

}

use std::cmp::{max, min};

fn main() {
    let n: usize = read();
    let m: usize = read();

    let mut keys: Vec<(i64, i64)> = vec![];

    for _ in 0..m {
        let a: i64 = read();
        let b: usize = read();
        let b_vec: Vec<usize> = read_n(b);
        let mut s = 0;

        for i in b_vec {
            s += 1 << (i - 1)
        }
        keys.push((a, s));
    }

    // println!("n:{}, m: {}", n, m);
    // println!("{:?}", keys);

    let mut dp: Vec<i64> = vec![1000000007; (1 << n) + 5];
    dp[0] = 0;

    for j in 0..(1 << n) {
        // println!("j: {}", j);
        for key in &keys {
            let news = j | key.1;
            dp[news as usize] = min(dp[news as usize], dp[j as usize] + key.0)
        }
    }
    if dp[(1 << n) - 1] == 1000000007 {
        println!("{}", -1);
    } else {
        println!("{}", dp[(1 << n) - 1]);
    }

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
const ll mod  = 1e9 + 7;
const int INF = 2e9;
using pint = pair <int, int>;

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (60 * h2 + m2) - (60 * h1 + m1) - k << endl;
  return 0;
}


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

#define MAX_LEN 10

int main()
{
  string s; cin >> s;
  int slen = s.length();
  
  int64_t sum = 0;
  for (int i = 0; i < (1 << MAX_LEN); i++) {
    bitset<MAX_LEN> bit(i);
    string num = "";
    for (int j = 0; j < slen; j++) {
      if (bit.test(j)) {
        // ビットが立っていたら連結する
        num += s.at(j);
      } else if (num != "") {
        // 101のように離れている場合、例えば入力が125のとき1+5となるようにする
        sum += stoll(num);
        num = "";
      }
    }
    // ループを抜けたときに連結されている数を足す
    if (num != "") {
      sum += stoll(num);
    }
    if (bit.count() == slen) {
      // 入力された文字列長まで調べ終わったので抜ける
      break;
    }
  }
  
  cout << sum << endl;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] mozi = Console.ReadLine().Split(' ');
            string A = mozi[0];
            string B = mozi[1];
            string C = mozi[2];

            if (A.Substring(A.Length - 1, 1) == B.Substring(0,1) && 
                B.Substring(B.Length - 1, 1) == C.Substring(0,1))
            {
                Console.WriteLine("YES");
                
            } else
            {
                Console.WriteLine("NO");
            }

            
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        String S = sc.next();

        System.out.println(solve(N, S));
    }

    private static long solve(int N, String S) {
        long count = 0;

        int[][] hit = new int[N+1][3];
        char[] RGB = {'R', 'G', 'B'};
        for (int i=N-1; i>=0; i--) {
            for (int j=0; j<3; j++) {
                hit[i][j] = S.charAt(i) == RGB[j] ? 1 : 0;

                if (i != N-1) {
                    hit[i][j] += hit[i + 1][j];
                }
            }
        }

        for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                if (S.charAt(i) == S.charAt(j)) {
                    continue;
                }

                int chidx = 0;
                for (int k=0; k<3; k++) {
                    if (S.charAt(i) != RGB[k] && S.charAt(j) != RGB[k]) {
                        chidx = k;
                        break;
                    }
                }

                count += hit[j+1][chidx];
                if (j+j-i < N && S.charAt(j + (j-i)) == RGB[chidx]) {
                    count--;
                }
            }
        }

        return count;
    }
}

Measured memory_bytes: 37068
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {

		Scanner sc= new Scanner(System.in);
		int a,b =0;
		double h,g;


			a = sc.nextInt();
			b = sc.nextInt();

			int d = a / b;
			int r = a % b;
			h = a;
			g = b;
			double f = h / g;
			System.out.println(d+" " + r + " " + String.format("%.5f", f));
	}
}


Measured memory_bytes: 26512
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
#define int long long
#define double long double
#define fst first
#define snd second
#define fr(s,n,i) for(int i=s;i<n;i++)
#define times(n) for(int i=0;i<n;i++)
#define fr_(s,n,i) for(int i=s;i>=n;i--)
#define srt(v) sort(v.begin(), v.end());
#define upr(v, aim, ind) int ind; ind=(int)distance(v.begin(), upper_bound(v.begin(),v.end(), aim))
#define sz(v) (int)v.size()
#define ers(v, i) v.erase(v.begin() + i)
#define last(v) v[sz(v) - 1]
#define swp(v, i, j) int buf = v[j]; v[j] = v[i]; v[i] = buf
#define shout(a) cout << a << endl
#define dshout(a) printf("%.16Lf\n", a)
#define pr pair<int, int>
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vd vector<double>
#define vdd vector<vd>
#define mx(a, b) a = max(a, b)
#define mn(a, b) a = min(a, b)
#define mulM(a,b,c) a = a * b % c
#define squM(a,b) a = a * a % b
#define mpr(a,b) make_pair(a,b)
#define iinp(a) int a; cin >> a
#define sinp(a) string a; cin >> a
#define dinp(a) double a; cin >> a
#define ios() ios_base::sync_with_stdio(0);cin.tie(0)

int MOD = 1000000007;
int INF = ~(1LL << 63);

int powM(int base, int exp){
    int ret = 1;
    int buf = base;
    while(exp > 0){
        if(exp & 1){
            ret *= buf;
        }
        squM(buf, MOD);
        exp >>= 1;
    }
    return ret;
}
int combM(int a, int b){
    if(b == 0){
        return 1;
    }
    if(a-b < b){
        return combM(a, a-b);
    }
    int ans = 1;
    fr(1,b+1,i){
        ans *= a + 1 - i;
        ans /= i;
    }
    return ans;
}
void solve();
signed main() {
    ios();
    solve();
    return 0;
}

int calc(int num, int l, int r){
    if(r < 0){
        return calc(num, abs(r), abs(l));
    }
    if(l > 0){
        return (r+l)*num/2;
    }
    return calc(abs(l), 1, l) + calc(r, 1, r);
}

struct Task{
    int place, time;
    bool operator>(const Task & an) const{
        return time > an.time;
    }
};






void solve(){
    int N,M,C;
    cin >> N >> M >> C;
    vi bs(M);
    fr(0,M,i){
        cin >> bs[i];
    }
    int cnt = 0;
    fr(0,N, _){
        int buf = 0;
        fr(0,M,i){
            int inp;
            cin >> inp;
            buf += bs[i] * inp;
        }
        if(buf + C > 0){
            cnt++;
        }
    }
    shout(cnt);
}


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

int main() {
  int N, M;
  cin >> N >> M;
  bool path[N][N];
  memset(path,false,sizeof(path));
  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    path[a][b]=true;
    path[b][a]=true;
  }
  int vertex[N];
  for (int i=0; i<N; i++) {
    vertex[i]=i;
  }
  int ans=0;
  do {
    if (vertex[0]!=0) {
      continue;
    }
    for (int i=0; i<N-1; i++) {
      if (!path[vertex[i]][vertex[i+1]]) {
        break;
      }
      if (i==N-2) {
        ans++;
      }
    }
  } while (next_permutation(vertex,vertex+N));
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,h,w
    integer(8)::a,b,c,d
    character(10000),allocatable::x(:),y(:)
  
    read(*,*) h,w
    allocate(x(h),y(2*h))  
    do i=1,h
        read(*,*)s
        write(*,*)s
        write(*,*)s
        !y(i*2-1)=x(i)
        !y(i*2)=x(i)
    end do
    
    stop
end program sample
  



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

ll i,j,z;
static ll C,N,K,H,W,M;
ll min_ite=0;
ll *pt;
ll A[100000];
ll B[100000];
ll ans=0;
string S,T;

int main()
{

cin>>N>>M;
      int a = 1;
     for(i=0;i<M;i++){
          a*=2;
     }
	printf("%lld\n",(1900*a*M)+(100*((N-M)*a)));

	
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            boolean[] exists = new boolean[123];
            for (int i = 0; i < s.length(); i++) {
                exists[s.charAt(i)] = true;
            }
            for (char c = 'a'; c <= 'z'; c++) {
                if (!exists[c]) {
                    out.print(s + c);
                    return;
                }
            }
            for (int i = s.length() - 1; i >= 0; i--) {
                for (char c = (char) (s.charAt(i) + 1); c <= 'z'; c++) {
                    if (!exists[c]) {
                        out.print(s.substring(0, s.length() - 1) + c);
                        return;
                    }
                }
                exists[s.charAt(i)] = false;
                s = s.substring(0, s.length() - 1);
            }
            out.print(-1);
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 23252
def inc3(i):
    if i - (i // 10)*10 == 3:
        return(True)
    elif i//10==0:
        return(False)
    else:    
        return(inc3(i//10))

n = int(input())
for i in range(1,n+1):
    if i%3==0 or inc3(i):
        print(" " + str(i),end="")
print()

Measured memory_bytes: 7980
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

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

  deque<int> q;
  for (int i = 0; i < N; ++i) {
    int b;
    cin >> b;
    q.push_back(b);
  }

  vector<int> ret;
  while (!q.empty()) {
    int last_index = -1;
    int just_index = -1;
    for (int i = 1; i <= q.size(); ++i) {
      if (q[i - 1] < i && last_index != -1)
        last_index = i;
      if (q[i - 1] == i)
        just_index = i;
    }
    if (just_index != -1)
      last_index = just_index;
    else if (last_index == -1) {
      cout << -1 << endl;
      return 0;
    }
    ret.push_back(q[last_index - 1]);
    q.erase(q.begin() + last_index - 1);
  }

  for (int i = N - 1; i >= 0; --i) {
    cout << ret[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include <deque>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
using namespace std;
typedef pair<int,int> pii;
#define f first
#define s second

int main() {
	int n,m;
	scanf("%d %d",&n,&m);
	vector<pair<int,pii> > v;
	for (int i = 0 ; i < m ; ++i) {
		int x,y; scanf("%d %d",&x,&y);
		v.pb(make_pair(x,pii(1,i)));
		v.pb(make_pair(y,pii(0,i)));
	}
	sort(all(v));
	int ans = 0;
	set<int> cord;
	REP(i,v) {
		if (v[i].s.f) {
			cord.insert(v[i].s.s);
		} else {
			if (cord.find(v[i].s.s) != cord.end()) {
				//wind = 0;
				cord.clear();
				++ans;
			}
		}
	}
	cout << ans << "\n";

}


Measured memory_bytes: 4980
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
//#define int long long
#define INF 10000000
using namespace std;
int main(){
    int T,P,R;
    while(1){
        cin >> T >> P >> R;
        if(T == 0 && P == 0 && R == 0) break;
        int time_table[T][P] = {};
        int flag_table[T][P] = {};
        rep(i,R){
            int team,program,t;
            string flag;
            cin >> team >> program >> t >> flag;
            team--; program--;
            if(flag == "CORRECT"){
                time_table[team][program] = flag_table[team][program]*1200+t;
            }
            else if(flag == "WRONG"){
                flag_table[team][program]++;
            }
        }
        int top = -1;
        vector<pair<pair<int,int> , int> > ans(T);
        rep(i,T){
            int correct = 0;
            int fail = 0;
            rep(j,P){
                if(time_table[i][j] != 0) correct++;
                fail += time_table[i][j];
            }
            ans[i].first.first = -correct;
            ans[i].first.second = fail;
            ans[i].second = i+1;
        }
        sort(ans.begin(),ans.end());
        rep(i,ans.size()){
            cout << ans[i].second << " " << -ans[i].first.first << " " << ans[i].first.second << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
typedef int INT;
#define int long long
using namespace std;

const int MAX = 1e5 + 10;

INT main()
{
	int n; cin>>n;
	int a[MAX],c[MAX]={0};

	for(int i=1;i<=n;i++) cin>>a[i];

	for(int i=1;i<n;i++){
		if(i%2){
			c[i]--;
			c[i+1]++;
		}
		else{
			c[i]++;
			c[i+1]--;
		}
	}

	int ans1=0;
	sort(a+1,a+n+1);
	sort(c+1,c+n+1);
	for(int i=n;i>0;i--) ans1 += a[i]*c[i];
	for(int i=1;i<=n;i++) c[i]=0;
	for(int i=1;i<n;i++){
		if(i%2){
			c[i]++;
			c[i+1]--;
		}
		else{
			c[i]--;
			c[i+1]++;
		}
	}
	int ans2=0;
	sort(c+1,c+n+1);
	for(int i=n;i>0;i--) ans2 += a[i]*c[i];

	cout<<max(ans2,ans1)<<endl;	

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 1<<30
int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  rep(i,N) cin >> h.at(i);
  vector<int> dp(N, INF);
  dp.at(0) = 0;
  int x;
  rep(i, N) {
    if(i > 0) {
      x  = dp.at(i-1)+abs(h.at(i)-h.at(i-1));
      if(dp.at(i) > x) dp.at(i) = x;
    }
    if(i > 1) {
      x = dp.at(i-2)+abs(h.at(i)-h.at(i-2));
      if(dp.at(i) > x) dp.at(i) = x;
    }
  }
  cout << dp.at(N-1) << endl;
}

Measured memory_bytes: 1024
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String in = br.readLine();
		double x = Math.pow(Integer.parseInt(in), 3);
		System.out.println((int)x);
		br.close();
	}
}

Measured memory_bytes: 16896
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <deque>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int h, w;
int w_ans[2001][2001];
int h_ans[2001][2001];

vector<string> sw;
vector<string> sh;

bool grid_inside(int y, int x) {
  if(0 <= y && y < h && 0 <= x && x < w) return true;
  else return false;
}

int rec_h(int i, int j, int c) {
  if(!grid_inside(i, j)) return c;
  if(sh[i][j] == '#') return c;
  sh[i][j] = '#';
  c++;
  h_ans[i][j] = rec_h(i + 1, j, c);
  return h_ans[i][j];
}

int rec_w(int i, int j, int c) {
  if(!grid_inside(i, j)) return c;
  if(sw[i][j] == '#') return c;
  sw[i][j] = '#';
  c++;
  w_ans[i][j] = rec_w(i, j + 1, c);
  return w_ans[i][j];
}

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

  cin >> h >> w;
  REP(i, h) {
    string s;
    cin >> s;
    sw.push_back(s);
    sh.push_back(s);
  }

  REP(i, h) {
    REP(j, w) {
      if(sh[i][j] == '.') rec_h(i, j, 0);
      if(sw[i][j] == '.') rec_w(i, j, 0);
    }
  }

  int ans = 0;
  REP(i, h) REP(j, w) {
    ans = max(ans, h_ans[i][j] + w_ans[i][j] - 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 42500
from functools import reduce
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
B = 0
div = 10**9+7

lcm_A = lcm_list(A)

for item in A:
    B+=(lcm_A//item)

print(B%div)


Measured memory_bytes: 6080
#include <stdio.h>

int gcd(int x, int y)
{
	return (y ? gcd(y, x % y) : x);
}
int lcm(int x, int y)
{
	return (x / gcd(x, y) * y);
}

int main(void)
{
	int x, y;

	while (~scanf("%d %d", &x, &y)){
		if (x > y) printf("%d %d\n", gcd(x, y), lcm(x, y));
		else printf("%d %d\n", gcd(y, x), lcm(y, x));
	}

	return (0);
}

Measured memory_bytes: 596
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
const static int N=1000;
ll f[N][10];
ll p[N][11];
int n;



int main(){
    cin>>n;
    rep(i,n){
        rep(j,10){
            cin>>f[i][j];
        }
    }
    rep(i,n){
        rep(j,11){
            cin>>p[i][j];
        }
    }
    
    int mi=-(1<<30);
    for(int b=1;b<(1<<10);b++){
        
        int cc=0;
        for(int i=0;i<n;i++){
            ll a=0;
            for(int j=0;j<10;j++){
                if ((b>>j&1)) {
                    if(f[i][j]){a++;}
                }
            }
            cc+=p[i][a];
        }
        mi=max(mi,cc);
    }
    cout<<mi<<endl;
  
    
    return 0;
}


Measured memory_bytes: 256