akhauriyash/Code-Regression huggingface dataset:
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%lld %lld",&n,&m);
	lo c=n*m;
	c/=__gcd(n,m);
	printf("%lld\n",c);
	return 0;
}



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

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

int main(void){
  int H, W;
  cin >> H >> W;

  for(int i=0; i<H; i++) cin >> S[i];

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j] == '.'){
        int cnt = 0;
        for(int k=0; k<8; k++){
          int x = i + dx[k];
          int y = j + dy[k];
          if(x >= 0 && x < H && y >= 0 && y < W && S[x][y] == '#'){
            cnt++;
          }
        }
        S[i][j] = '0' + cnt;
      }
    }
  }

  for(int i=0; i<H; i++) cout << S[i] << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll unsigned long long
#define ld long double
#define mkp make_pair
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;
const int N = 1e7;

ll n;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    cin >> n;
    cout << (n)*(n-1)/2;
}



Measured memory_bytes: 256
a, b = map(int, input().split())
ans = 0
for i in range(a, b+1):
    num = list(str(i))
    re = list(reversed(num))
    cnt = 0
    for i in range(len(num)):
        if num[i] == re[i]:
            cnt += 1
    if cnt == len(num):
        ans += 1

print(ans)

Measured memory_bytes: 3060
x, y = map(int, input().split()) # 横に2個

if abs(x) <= abs(y):
    ans = abs(y) - abs(x)
    if (x >= 0 and y < 0) or (x < 0 and y > 0):
        ans += 1
    elif x < 0 and y < 0:
        ans += 2
else:
    ans = abs(x) - abs(y)
    if (x > 0 and y <= 0) or (x < 0 and y > 0):
        ans += 1
    elif (x > 0 and y > 0):
        ans += 2

print(ans)

Measured memory_bytes: 3064
s=list(input())
ans="Yes"
l=len(s)
for i in range(l//2):
    if(s[i*2+1]=="R"):
        ans="No"
for i in range((l//2)+(l%2)):
    if(s[i*2]=="L"):
        ans="No"
print(ans)
        
        
        

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
set<pair<int, int> >xx[10];
set<pair<int, int> >have;
int h, w;
void add(int x, int y)
{
	int cnt = 0;
	for (int i = x; i <= x + 2; i++)
	{
		for (int j = y; j <= y + 2; j++)
		{
			if (i <= 0 || i > h || j <= 0 || j > w) return;
			cnt += have.count(make_pair(i, j));
		}
	}
	//cerr << x << " " << y << " " << cnt << endl;
	xx[cnt].insert(make_pair(x, y));
}
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n;
	scanf("%d %d %d", &h, &w, &n);
	vector<pair<int, int> >p;
	for (int i = 1; i <= n; i++)
	{
		int x, y;
		scanf("%d %d", &x, &y);
		have.insert(make_pair(x, y));
		p.push_back(make_pair(x, y));
	}
	for (int i = 0; i < (int)p.size(); i++)
	{
		for (int x = p[i].first - 2; x <= p[i].first; x++)
		{
			for (int y = p[i].second - 2; y <= p[i].second; y++)
			{
				add(x, y);
			}
		}
	}
	ll total = 1LL * (h - 2) * (w - 2);
	for (int i = 1; i <= 9; i++)
	{
		total -= (int)xx[i].size();
	}
	printf("%lld\n", total);
	for (int i = 1; i <= 9; i++)
	{
		printf("%d\n", (int)xx[i].size());
	}
	return 0;
}


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

using namespace std;

int n, l;
int arr[100100];

int main() {
    int i;

    scanf("%d%d",&n,&l);
    for (i=0;i<n;i++) scanf("%d",&arr[i]);
    for (i=1;i<n;i++) {
        if (arr[i]+arr[i-1]>=l) {
            printf("Possible\n");
            int j;
            for (j=1;j<i;j++) printf("%d\n",j);
            for (j=n-1;j>i;j--) printf("%d\n",j);
            printf("%d\n",i);
            return 0;
        }
    }
    printf("Impossible\n");

    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <complex>
#include <set>
#include <vector>
#define x(p) p.real()
#define y(p) p.imag() 

namespace std{
	bool operator < (const complex<int> &a,const complex<int> &b){
		return x(a) != x(b) ? x(a) < x(b) : y(a) < y(b);
	}
};
using namespace std;
typedef complex<int> P;
typedef pair<P,int> node;

P size[10];
P pos[10];

vector<int> used;

void search(set<node> K){
	while(!K.empty()){
		node get = *K.begin();
		K.erase(get);
		used.push_back(get.second);
		y(get.first) += y(size[get.second]);
		while(x(get.first) != 501){
			bool f = false;
			for(set<node>::iterator it = K.begin(); it != K.end() ; ++it){
				if( y((*it).first) < y(get.first) && y(get.first) < y((*it).first) + y(size[(*it).second]) && x((*it).first) == x(get.first) ){
					f = true; break;
				}
			}
			if(f) break;
			x(get.first)++;
		}
		set<node> R;
		for(set<node>::iterator it = K.begin(); it != K.end() ; ++it){
			if( y(get.first) >= y((*it).first) + y(size[(*it).second]) && x((*it).first)+x(size[(*it).second]) <= x(get.first) ){
				R.insert(*it);
			}
		}
		for(set<node>::iterator it = R.begin(); it != R.end() ; ++it)
			K.erase(*it);
		search(R);
	}
}
int main(){
	int n;
	int cnt = 0;
	while(cin >> n , n){
		used.clear();
		if(cnt++)cout << endl;
		for(int i = 0 ; i < n ; i++){
			int x1 , x2 , y1 , y2;
			cin >> x1 >> y1 >> x2 >> y2;
			if(x1 > x2) swap(x1,x2);
			if(y1 > y2) swap(y1,y2);
			pos[i]  = P(x1,y1);
			size[i] = P(x2-x1,y2-y1);
		}
		set<node> L;
		
		for(int i = 0 ; i < n ; i++)
			L.insert(make_pair(pos[i],i));
		
		search(L);
		
		int view[10] = {0};
		for(int i = 0 ; i < n ; i++)
			view[used[i]] = i+1;
		for(int i = 0 ; i < n ; i++)
			cout << view[i] << endl;
	}
}

Measured memory_bytes: 0
from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
q=[0]*10**5
v=[[]for _ in q]
z=0
for a,b in t:v[a-1]+=b,
for i in v[:M]:
 for j in i:heappush(q,-j)
 z-=heappop(q)
print(z)

Measured memory_bytes: 58468
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  int a;
  int b;

  cin >> a >> b;

  string strA = to_string(a);
  string strB = to_string(b);

  string strC = strA + strB;

  int c = stoi(strC);

  for (int i = 1; i <= 1000; i++) {
    if (c == i*i) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
a,b,m = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
x_y_c_list=[list(map(int,input().split())) for _ in range(m)]

ans = min(a_list) + min(b_list)

for i in range(m):
    if ans > a_list[x_y_c_list[i][0] - 1] + b_list[x_y_c_list[i][1] - 1] - x_y_c_list[i][2]:
        ans = a_list[x_y_c_list[i][0] - 1] + b_list[x_y_c_list[i][1] - 1] - x_y_c_list[i][2]

print(ans)

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

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")
}

fn gen_csum_vec<T: std::ops::Add<Output=T> + Copy>(ai: Vec<T>, zero: T) -> Vec<T> {
    let mut si: Vec<T> = Vec::new();
    si.push(zero);
    for a in ai {
        let s_last = *si.last().unwrap();
        si.push(s_last + a);
    }
    return si;
}

fn calc_e(n: u64) -> f64 {
    return ((n as f64) + 1.0) / 2.0
}

fn main() {
    let n: u64 = read();
    let k: usize = read();
    let pi: Vec<u64> = (0..n).map(|_| read()).collect();
    let ei: Vec<f64> = pi.into_iter().map(|p| calc_e(p)).collect();
    let si: Vec<f64> = gen_csum_vec(ei, 0.0);

    let mut ans: f64 = 0.0;
    for i in 0..si.len()-k {
        let tmp_ans: f64 = si[i+k] - si[i];
        if tmp_ans > ans {
            ans = tmp_ans;
        }
    }

    println!("{:.12}", ans);
}


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

const int maxn = 2e5, maxm = 19;
const int mod = 924844033, gen = 5;

int n;
vector<int> g[maxn];
int size[maxn], cnt[maxn];
int fact[maxn + 1], ifact[maxn + 1];
int a[1 << maxm], b[1 << maxm];

void Dfs(int u, int p) {
  size[u] = 1;
  for (int v : g[u]) {
    if (v == p) continue;
    Dfs(v, u);
    size[u] += size[v];
    ++cnt[size[v]];
    ++cnt[n - size[v]];
  }
}

inline int Mul(int a, int b) {
  return (long long)a * b % mod;
}

inline int Add(int a) {
  return a >= mod ? a - mod : a;
}

inline int Sub(int a) {
  return a < 0 ? a + mod : a;
}

int Pow(int a, int b) {
  int c = 1;
  for (; b; b >>= 1) {
    if (b & 1) c = Mul(c, a);
    a = Mul(a, a);
  }
  return c;
}

void FFT(int *a, int n) {
  for (int i = 0; i < 1 << n; ++i) {
    int j = 0, x = i;
    for (int k = 0; k < n; ++k) {
      j = (j << 1) | (x & 1);
      x >>= 1;
    }
    if (i < j) {
      swap(a[i], a[j]);
    }
  }
  for (int i = 0; i < n; ++i) {
    int root = Pow(gen, (mod - 1) / (2 << i));
    for (int j = 0; j < 1 << n; j += 2 << i) {
      int *l = a + j, *r = l + (1 << i), w = 1;
      for (int k = 0; k < 1 << i; ++k, w = Mul(w, root)) {
        int t = Mul(w, r[k]);
        r[k] = Sub(l[k] - t);
        l[k] = Add(l[k] + t);
      }
    }
  }
}

void IFFT(int *a, int n) {
  reverse(a + 1, a + (1 << n));
  FFT(a, n);
  int inv = Pow(1 << n, mod - 2);
  for (int i = 0; i < 1 << n; ++i) {
    a[i] = Mul(a[i], inv);
  }
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b); --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  Dfs(0, -1);
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = Mul(fact[i - 1], i);
  }
  ifact[n] = Pow(fact[n], mod - 2);
  for (int i = n; i >= 1; --i) {
    ifact[i - 1] = Mul(ifact[i], i);
  }
  for (int i = 0; i < n; ++i) {
    a[i] = ifact[i];
  }
  for (int i = 1; i < n; ++i) {
    b[i] = Mul(cnt[n - i], fact[n - i]);
  }
  int m = 0;
  while (1 << m < n << 1) {
    ++m;
  }
  FFT(a, m);
  FFT(b, m);
  for (int i = 0; i < 1 << m; ++i) {
    a[i] = Mul(a[i], b[i]);
  }
  IFFT(a, m);
  for (int k = 1; k <= n; ++k) {
    int t = Mul(a[n - k], ifact[k]);
    int c = Mul(fact[n], Mul(ifact[k], ifact[n - k]));
    printf("%d\n", Sub(Mul(n, c) - t));
  }
  return 0;
}


Measured memory_bytes: 30976
n=int(input())
A=list(map(int,input().split()))
A.sort()
judge=0
if n%2==1:
    for i in range(n):
        if A[i]!=2*((i+1)//2):
            judge+=1
            break
else:
    for i in range(n):
        if A[i]!=2*(i//2)+1:
            judge+=1
            break
if judge==1:
    print(0)
else:
    print((2**(n//2))%(10**9+7))

Measured memory_bytes: 20436
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int a,b,c; cin >> a >> b >>c;
  if (a==b){cout<<c;}
  else if (b==c){cout <<a;}
  else {cout << b;}

  return 0;
}


Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    ll a[n];
    map<ll, ll> freq;
    for(int i = 0;  i< n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ans += freq[i-a[i]];
        freq[a[i]+i]++;
    }
    cout << ans << "\n";
}


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

int main(void){
  int A, B, C;
  int K;
  int i, j, k;
  int max;
  int buf;
  scanf("%d %d %d %d", &A, &B, &C, &K);
  max = A;
  if(B > max){
    max = B;
  }
  if(C > max){
    max = C;
  }
  buf = A + B + C + max*(((int) pow(2, (double) K)) - 1);
  printf("%d\n", buf);
  return 0;
}


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

using namespace std;

#define ll long long

string rev(string s) {
	reverse(s.begin(),s.end());
	return s;
}
int main(){
	int A,B,C,D;
	scanf("%d%d%d%d",&A,&B,&C,&D);
	if(D<=A || B<=C) puts("0");
	else printf("%d",min(B,D)-max(A,C));
	return 0;
}




Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	inline char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=gc();}
	}
};
using io::gi;
struct qwq{
	int a,b;
	inline bool operator<(const qwq &x)const{
		return a<x.a;
	}
};
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
const ll p=998244353ll,inf=1000000000000000000ll;
const int N=200005;

int main(){
	int a,b,i,x,y,t=0;
	scanf("%d%d",&a,&b);
	for(i=1;i<=b;++i){
		x=i/10;
		y=i%10;
		if(x>1&&y>1&&x*y<=a)++t;
	}
	printf("%d",t);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
vector<int> E[400000];
int flag[400000];
int N,M;
bool dfs(int x){
    if(flag[x]==1) return true;
    flag[x]=1;
    for(int &to : E[x]){
        if(flag[to]>=0&&dfs(to)) return true;
    }
    flag[x]=-1;
    return false;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>M;
    string s;
    cin>>s;
    rep(i,0,M){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        if(a==b){
           E[N+a].pb(b);
        }
        else if(s[a]==s[b]){
            E[N+a].pb(b);
            E[b+N].pb(a);
        }
        else{
            E[a].pb(b+N);
            E[b].pb(a+N);
        }
    }
    rep(i,0,2*N){
        if(flag[i]==0){
            if(dfs(i)){
                cout <<"Yes"<<"\n";
                return 0;
            }
        }
    }
    cout <<"No"<<"\n";
}

Measured memory_bytes: 24912
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

using Graph = vector<vector<int>>;

// O(|V| + |E|)
struct SCC
{
    int V, K;
    Graph G, rG;
    vector<int> vs;
    vector<bool> used;
    vector<int> cmp;
    SCC(int _V) : V(_V), G(_V), rG(_V), used(_V, false), cmp(_V) {}
    void add_edge(int from, int to)
    {
        G[from].push_back(to);
        rG[to].push_back(from);
    }
    void dfs(int cur)
    {
        used[cur] = true;
        for (const auto &v : G[cur])
        {
            if (!used[v])
                dfs(v);
        }
        vs.push_back(cur);
    }
    void rdfs(int cur, int k)
    {
        used[cur] = true;
        cmp[cur] = k;
        for (const auto &v : rG[cur])
        {
            if (!used[v])
                rdfs(v, k);
        }
    }
    vector<int> scc()
    {
        for (int i = 0; i < V; i++)
            used[i] = false;
        vs.clear();
        for (int v = 0; v < V; v++)
        {
            if (!used[v])
                dfs(v);
        }
        for (int i = 0; i < V; i++)
            used[i] = false;
        int k = 0;
        for (int i = (int)vs.size() - 1; i >= 0; i--)
        {
            if (!used[vs[i]])
                rdfs(vs[i], k++);
        }
        K = k;
        return cmp;
    }
    Graph buildGraph()
    {
        scc();
        vector<set<int>> s(K);
        Graph ret(K);
        for (int v = 0; v < V; v++)
        {
            for (const auto to : G[v])
            {
                s[cmp[v]].insert(cmp[to]);
            }
        }
        for (int i = 0; i < K; i++)
        {
            for (auto j : s[i])
            {
                if (i != j)
                    ret[i].push_back(j);
            }
        }
        return ret;
    }
};

int N, M;

ll dfs(const Graph &g, int cur)
{
    ll res = 1;
    for (const auto &v : g[cur])
    {
        res *= (dfs(g, v) + 1);
        res %= MOD;
    }
    return res;
}

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

    cin >> N >> M;
    SCC scc(N);
    for (int i = 0; i < M; i++)
    {
        int s, d;
        cin >> s >> d;
        s--;
        d--;
        scc.add_edge(d, s);
    }
    Graph g = scc.buildGraph();
    ll res = 1;
    int K = g.size();
    vector<int> in(K, 0);
    for (int i = 0; i < K; i++)
    {
        for (const auto &v : g[i])
        {
            in[v]++;
        }
    }
    for (int i = 0; i < K; i++)
    {
        if (in[i])
            continue;
        res *= (dfs(g, i) + 1LL);
        res %= MOD;
    }
    cout << res << endl;
}



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

int main() {
  ll q,h,s,d;
  cin >> q >> h >> s >> d;
  ll n;
  cin >> n;
  vector<ll> vec={q*4,h*2,s};
  sort(vec.begin(), vec.end());
  ll one=vec.at(0);
  if(one*2<d || n==1)
    cout << one*n << endl;
  else{
    if(n%2==0)
      cout << d*n/2 << endl;
    else
      cout << d*(n-1)/2+one << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 1000010
char s[MAXN];
int a[MAXN],sum,n,t,k;
int main()
{
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i-1]=s[i]-'0';
	for(int i=0;i<n;i++)
	{
		t+=a[i]*9;
		a[i]=t%10;
		sum+=a[i];
		t/=10;
		if(i==n-1&&t) n++;
	}
	for(k=1;k<=20*n;k++)
	{
		a[0]+=9;
		sum+=9;
		t=0;
		for(int j=0;j<n;j++)
		{
			t+=a[j];
			sum-=a[j];
			a[j]=t%10;
			sum+=a[j];
			t/=10;
			if(!t) break;
			if(j==n-1) n++;
		}
		if(sum<=k*9) break;
	}
	printf("%d\n",k);
}

Measured memory_bytes: 4480
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<int> dijk(int s, int v, vector<vector<pair<int, int>>> adjlist){
    priority_queue <pair<int, int>> wait;
    vector<int> result(v, INF);

    result[s] = 0;
    wait.push(make_pair(0,s));

    while(!wait.empty()){
        int nowpoint = wait.top().second;
        int nowcost = -wait.top().first;
        wait.pop();

        if(result[nowpoint] < nowcost) continue;

        for(int i = 0; i < adjlist[nowpoint].size(); i++){
            int nextpoint = adjlist[nowpoint][i].second;
            int nextcost = nowcost + adjlist[nowpoint][i].first;
            if(result[nextpoint] > nextcost){
                result[nextpoint] = nextcost;
                wait.push(make_pair(-nextcost, nextpoint));
            }
        }
    }
    return result;
}



signed main(){
    

    while(1){
    int c, n, m, s, t; cin >> c >> n >> m >> s >> t;
    s--;
    t--;
    if(!n) break;
    vector<vector<int> > toNode(n, vector<int> (c + 1));
    int num = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= c; j++){
            toNode[i][j] = num;
            num++;
        }
    }

    vector<vector<pair<int, int>>> adj(num);

    for(int i = 0; i < m; i++){
        int a, b, f; cin >> a >> b >> f;
        a--;
        b--;

        for(int iii = 0; iii < 2; iii++){

            for(int j = 0; j <= c; j++){
                    
                int cur = toNode[a][j];
                // 使わない
                int nxt = toNode[b][j];
                adj[cur].push_back({f, nxt});
                
                nxt = toNode[b][j + 1];
                // 使う
                if(j != c){
                    adj[cur].push_back({f / 2, nxt});
                }
            }
            swap(a, b);
        }
    }

    
    int ans = INF;
    int S = toNode[s][0];
    vector<int> result = dijk(S, num, adj);
    for(int j = 0; j <= c; j++){
        int G = toNode[t][j];
        ans = min(ans, result[G]);
    }

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



Measured memory_bytes: 3452
use v5.18; # strict say state
use warnings;

chomp (my $n = <STDIN>);
my @x;
for my $i (0..$n-1) {
  chomp (my $in = <STDIN>);
  my @in = split(' ', $in);
  $x[$i] = [$in[0]-$in[1], $in[0]+$in[1]];
}
@x = sort {$$a[1] <=> $$b[1]} @x;
my $ans = 0;
my $cur = -1e9;
for my $i (0..$n-1) {
  next if $cur > ${$x[$i]}[0];
  $ans++;
  $cur = ${$x[$i]}[1];
}
say $ans;

Measured memory_bytes: 18816
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var s = next();
  var output = [];
  var now = N;
  while(true){
  	var isOK = false;
  	var nextMove = 0;
  	var count = 0;
  	for(var i = now - 1; i > (now - M - 1) && i >= 0; i--){
  		count++;
  		if(s[i] == "0"){
  			isOK = true;
  			nextMove = count;
  		}
  	}
  	now -= nextMove;
  	if(!isOK){
  		myout(-1);
  		return;
  	}else{
  		output.push(nextMove);
  	}
  	if(now == 0){
  		break;
  	}
  }
  output.sort(function(){return -1});
  myout(myconv(output, 8));
}


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

using namespace std; 

int main(){ 
  int64_t n;
  cin>>n;
  for(int64_t i=0;i<pow(n,0.5)+2;i++){
      if(i*i>n){
    cout<<(i-1)*(i-1);
      break;
      }
  }
}

Measured memory_bytes: 384
from itertools import product

m = input()
n = m[0] + 'x' + m[1] + 'y' + m[2] + 'z' + m[3]

for i in product([0,1], repeat=3):
    if i[0] == 0:
        l = n.replace('x', '+')
    elif i[0] == 1:
        l = n.replace('x', '-')

    if i[1] == 0:
        l = l.replace('y', '+')
    elif i[1] == 1:
        l = l.replace('y', '-')

    if i[2] == 0:
        l = l.replace('z', '+')
    elif i[2] == 1:
        l = l.replace('z', '-')

    if eval(l) == 7:
        print(l + '=7')
        exit()


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

const int inf = 1e9;
int s,r,a,b,q,c,d,u,v,w;
vector<pii> g[100100];
vector<int> ming[100100];
int dis[100100];
bool vis[100100];

bool dfs(int now,int goal){
  if(now == goal)return true;
  if(vis[now])return false;
  vis[now] = true;

  rep(i,ming[now].size()){
    if(dfs(ming[now][i],goal))return true;
  }
  return false;
}

int main(){
  scanf("%d%d",&s,&r);
  rep(i,r){
    scanf("%d%d%d",&u,&v,&w); u--; v--;
    g[u].push_back(pii(w,v));
    g[v].push_back(pii(w,u));
  }
  
  scanf("%d%d%d",&a,&b,&q); a--; b--;
  memset(dis,-1,sizeof(dis));
  dis[a] = 0;
  priority_queue<pii,vector<pii>,greater<pii> > que;
  que.push(pii(0,a));

  while(que.size()){
    pii p = que.top(); que.pop();
    int cost = p.first, pos = p.second;
    if(dis[pos]<cost)continue;

    rep(i,g[pos].size()){
      int ncost = cost + g[pos][i].first, npos = g[pos][i].second;
      if(dis[npos]< 0 || dis[npos] > ncost){
	dis[npos] = ncost;
	que.push(pii(ncost,npos));
      }
    }
  }

  memset(vis,0,sizeof(vis));
  vis[b] = true;
  queue<int> state;
  state.push(b);

  while(state.size()){
    int p = state.front(); state.pop();

    rep(i,g[p].size()){
      int np = g[p][i].second, nc = g[p][i].first;
      if(dis[p] == dis[np] + nc){
	ming[np].push_back(p);
	if(!vis[np]){
	  state.push(np);
	  vis[np] = true;
	}
      }
    }
  }

  map<pii,bool> memo;
  rep(i,q){
    scanf("%d%d",&c,&d); c--; d--;

    bool f;
    if(memo.find(pii(c,d))!=memo.end())f = memo[pii(c,d)];
    else{
      memset(vis,0,sizeof(vis));
      memo[pii(c,d)] = f = dfs(c,d);
    }

    if(f)printf("Yes\n");
    else printf("No\n");
  }
}

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

typedef long long ll;

int main()
{
    ll h;
    cin >> h;
    ll ans = 0;
    ll it = 1;
    while(true){
        if(h == 1){
            ans += it;
            break;
        }else{
            h /= 2;
            ans += it;
            it *= 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 1001000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll X,Y; cin>>X>>Y;
    COMinit();
    if((X+Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }

    cout << COM((X+Y)/3, X-((X+Y)/3)) << endl;
 

}

Measured memory_bytes: 23680
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if (n == 2) {
            System.out.println(1);
            return;
        }
        int count = 2;
        for (long i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                if (getMod(n, i) == 1) {
                    count++;
                }
                if (i * i != n) {
                    if (getMod(n, n / i) == 1) {
                        count++;
                    }
                }
            }
            if ((n - 1) % i == 0 && i * i <= n - 1) {
                count++;
                if (i * i != n - 1) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
    
    static long getMod(long x, long y) {
        while (x % y == 0) {
            x /= y;
        }
        return x % y;
    }
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  string s,t;
  ll i,c,j;
  c=0;
  cin>>s>>t;
  for(i=0;i<s.length();i++)
  {
    if(s[i]!=t[i])
      c++;
  }
  if(c>0 || t.length()!=s.length()+1)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll K;
int main(){
	cin>>K;
	int n=50;
	printf("%d\n",n);
	ll a=K/(ll)n; ll b=K%(ll)n;
	int cnt=0;
	for(int i=1;i<=(int)b;++i){
		++cnt;
		cout<<49ll+a+((ll)n-(b-1ll))<<(cnt==n ? '\n' : ' ');
	}
	for(int i=1;i<=n-(int)b;++i){
		++cnt;
		cout<<49ll+a-b<<(cnt==n ? '\n' : ' ');
	}
	return 0;
}

Measured memory_bytes: 256
# 2019/04/29
# AtCoder Beginner Contest 085 - C

# Input
n, y = map(int,input().split())

cashl = [10000, 5000, 1000]
ansl = [-1, -1, -1]
eflg = False

# Search AC and make Accumed sum
for i in range(n+1):
    for j in range((n+1)-i):
        subt = i * cashl[0] + j * cashl[1]
        k = int((y - subt) / 1000)

        total = subt + k * cashl[2]
        bcnt = i + j + k

        if total == y and bcnt == n:
            ansl[0] = i
            ansl[1] = j
            ansl[2] = k
            eflg = True
            break

    if eflg == True:
        break

# Output
print(ansl[0], ansl[1], ansl[2])


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n, k;

int limit;

vector<pair<int, int>> ans;

void calc() {
  int cnt = 0;
 
  for (int i = 2; i < n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      if (cnt == (limit - k)) {
        return;
      }
      ans.push_back(make_pair(i, j));
      cnt += 1;
    }
  }
}

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &k);

  limit = n * (n - 1) / 2 - (n - 1);

  if (k > limit) {
    printf("%d\n", -1);
    return 0;
  }

  for (int i = 2; i <= n; ++i) {
    ans.push_back(make_pair(1, i));
  }

  calc();

  printf("%d\n", ans.size());

  for (auto &e: ans) {
    printf("%d %d\n", e.first, e.second);
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    if(n%2 == 0){
        cout << n/2 -1 <<endl;
    }else{
        cout << n/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("AC")
    else:print("WA")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#n = ip()                              #入力整数1つ
#x,y= (int(i) for i in input().split())      #入力整数横2つ
a,b,k = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
c = [ i for i in range(a,min(b,a+k))]
d = [ i for i in range(max(b-k+1,a),b+1)]
e = set()
for i in range(len(c)):
    e.add(c[i])
for i in range(len(d)):
    e.add(d[i])
e = list(e)
e.sort()
for i in range(len(e)):
    print(e[i])

Measured memory_bytes: 5788
#include <bits/stdc++.h>
using namespace std;
vector<int>v[200000];
int t[200000];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	queue<int>q;
	q.push(1);
	q.push(n);
	t[1]=1;
	t[n]=2;
    int f=0,s=0;
	while(!q.empty())
	{
		int a=q.front();
		q.pop();
		for(int i=0;i<v[a].size();i++)
		{
			int b=v[a][i];
			if(t[b]==0)
			{
				q.push(b);
				t[b]=t[a];
				if(t[b]==1)
					f++;
				else
					s++;
			}
		}
	}
	if(f>s)
		cout<<"Fennec";
	else
		cout<<"Snuke";

	return 0;
}

Measured memory_bytes: 8576
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int INF=1<<30;
int main(){
  int n,m;
  int min_cost[100005];
  int from[100005];
  vector<int>node[100005];
  cin>>n>>m;
  for(int i=0;i<=n;i++){
    min_cost[i]=INF;
    from[i]=i;
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    node[a].push_back(b);
    node[b].push_back(a);
  }
  
  queue<int>que;
  que.push(1);
  min_cost[1]=0;
  from[1]=1;
  while(!que.empty()){
    int pos=que.front();que.pop();
    for(int i=0;i<node[pos].size();i++){
      int next=node[pos][i];
      if(min_cost[pos]+1<min_cost[next]){
	min_cost[next]=min_cost[pos]+1;
	from[next]=pos;
	que.push(next);
      }
    }
  }
  
  for(int i=2;i<=n;i++){
    if(from[i]==i){
      cout<<"No"<<endl;
      return(0);
    }
  }
  cout<<"Yes"<<endl;
  for(int i=2;i<=n;i++){
    cout<<from[i]<<endl;
  }
  
  return(0);
}


Measured memory_bytes: 10888
using System;
using System.IO;
using System.Linq;

namespace Tree
{
    class Rooted_Trees
    {
        struct Node
        {
            public int id;
            public int parent;
            public int depth;
            public int[] childlen;
            public int type;
            public string Type { get { switch (type) { case 0: return "root"; case 1: return "internal node"; case 2: return "leaf"; default: return null; } } }
        }

        static void Main(string[] args)
        {
            int size = int.Parse(Console.ReadLine());
            var nodes = new Node[size];

            for (int i = 0; i < size; i++)
                nodes[i].parent = -1;

            for (int i = 0; i < size; i++)
            {
                var token = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var id = token[0];
                nodes[id].id = id;

                var k = token[1];
                if (k == 0) nodes[id].type = 2;
                else nodes[id].type = 1;
                nodes[id].childlen = new int[k];
                for (int j = 0; j < k; j++)
                {
                    nodes[id].childlen[j] = token[2 + j];
                    nodes[token[2 + j]].parent = id;
                }
            }

            for (int i = 0; i < size; i++)
                if (nodes[i].parent == -1)
                {
                    nodes[i].type = 0;
                    SetDepth(nodes, i, 0);
                    break;
                }

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            for (int i = 0; i < size; i++)
            {
                Console.Write("node {0}: parent = {1}, depth = {2}, {3}, [", nodes[i].id, nodes[i].parent, nodes[i].depth, nodes[i].Type);
                Console.Write(string.Join(", ", Array.ConvertAll(nodes[i].childlen, n => n.ToString())));
                Console.WriteLine("]");
            }

            Console.Out.Flush();
        }

        static void SetDepth(Node[] nodes, int id, int depth)
        {
            nodes[id].depth = depth;
            for (int i = 0; i < nodes[id].childlen.Length; i++)
                SetDepth(nodes, nodes[id].childlen[i], depth + 1);
        }
    }
}

Measured memory_bytes: 22952
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let s = read_as_string().chars().collect::<Vec<char>>();
    let t = read_as_string().chars().collect::<Vec<char>>();

    println!("{}", s.into_iter().zip(t.into_iter()).filter(|x| x.0 == x.1).count());

}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

string red(string s) {
	stack<char> st;
	for(auto i: s)
		if(i=='(')
			st.push('(');
		else if(i==')' && (st.size()==0 || st.top()==')'))
			st.push(')');
		else
			st.pop();
	string ans="";
	while(st.size())
		ans+=st.top(),st.pop();
	reverse(all(ans));
	return ans;
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
	
	ll n;
	cin>>n;
	vll A(n),B(n);
	vll C(n);
	for(int i=0;i<n;i++)
		cin>>A[i];
	for(int i=0;i<n;i++)
		cin>>B[i];
	for(int i=0;i<n;i++)
		C[i]=i+1;
	ll a=0,b=0,c=0;
	do{
		c++;
		bool ok = true;
		for(int i=0;i<n;i++)
			if(C[i]!=A[i])
				ok=false;
		if(ok) a=c;
		ok = true;
		for(int i=0;i<n;i++)
			if(C[i]!=B[i])
				ok = false;
		if(ok) b=c;
	}while(next_permutation(all(C)));
	cout<<abs(a-b);


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<pair<int, int> > LR(N);
    for (auto & lr : LR) {
        cin >> lr.first >> lr.second;
    }
    sort(LR.begin(), LR.end());
    vector<int> MIN(N), MINR(N);
    MIN[0] = LR[0].second;
    MINR[N-1] = LR[N-1].second;
    for (int i = 1; i < N; ++i) {
        MIN[i] = min(MIN[i-1], LR[i].second);
        MINR[N-1-i] = min(MINR[N-i], LR[N-1-i].second);
    }
    int ans = 0;
    for (int i = 1; i < N; ++i) {
        ans = max(ans, max(0, MIN[i-1]-LR[i-1].first+1) + max(0, MINR[i]-LR[N-1].first+1));
        if (i < N-1) ans = max(ans, max(0, MIN[N-1]-LR[N-1].first+1) + max(0, LR[i].second-LR[i].first+1));
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    int ans = 100000;
    long a;
    REP(i,n) {
        cin >> a;
        int cnt = 0;
        while (a % 2 == 0) {
            a = a >> 1;
            cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//69行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

//Simple Array Input
#define SAI int n;cin >> n;vi a(n);ain(a)
//Simple Graph Input
#define SGI(m) for(int i=0;i<m;i++){int a,b;cin >> a >> b;g[--a].pb(--b);g[b].pb(a);}
//Simple Tree Input
#define STI SGI(n-1)

typedef long long ll;
typedef long long integer;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){
    for(int i=0;i<a.size();i++)cout << a[i] << (i < a.size()-1 ? ' ' : '\n');
}
///////////////////////////////////////////////////////////

const int mod = 2019;
int main(void){
	string s;cin >> s;
	int n = s.size();

	reverse(s.begin(),s.end());

	vector<int> a(n); // (10^i * s[i]) mod 2019;
	int now = 1;
	rep(i,n){
		a[i] = (now * (s[i] - '0')) % mod;
		now = (now * 10) % mod;
	}		
	vector<int> c(n+1,0);
	rep(i,n){
		c[i+1] = (c[i] + a[i]) % mod;
	}

	vector<ll> cnt(2020,0);
	rep(i,n+1){
		cnt[c[i]]++;
	}
	ll ans = 0;
	rep(i,2020){
		ll c = cnt[i];
		ans += c * (c - 1) / 2; 
	}
	cout << ans << '\n';
}

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

int main(){
  int i,j,cnt=0;
  int a,b;
  cin>>a>>b;
  if(a+b==15)cout<<'+';
  else if(a*b==15)cout<<'*';
  else cout<<'x';
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


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

const int MOD = 1e9 + 7;



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}
/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return (x / tmp) * y;
}


/******************************************************************************************/


int main() {

	
	int n, l;
	cin >> n >> l;

	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		sum += l + i - 1;
	}

	int mini = INF;

	int ans = 0;

	for (int i = 1; i <= n; i++)
	{
		int tmp = sum - (l + i - 1);
		int diff = abs(sum - tmp);
		if (diff < mini) {
			mini = diff;
			ans = sum - (l + i - 1);
		}
	}
	cout << ans << endl;








	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[100000];
int main() {
	int n, k;
	while (cin >> n >> k&&n != 0 && k != 0) {
		int sum = 1, c = 0;
		fill(a, a + n, false);
		for (int i = 0; i < k; i++) {
			cin >> sum;
			if (sum == 0)
				c++;
			else a[i - c] = sum;
		}
		sum = 0;
		sort(a, a + k - c);
		for (int i = 0; i < k - c; i++) {
			int b = c, ne = a[i], e = i + 1;
			ne++;
			while (ne == a[e]) {
				e++;
				ne++;
			}
			if (c == 1) {
				ne++;
				while (ne == a[e]) {
					ne++;
					e++;
				}
			}
			sum = max(sum, ne - a[i]);
		}
		cout << sum << endl;
	}
}

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

int main()
{
    int a, b;
    char op;

    while(true){
        cin >> a >> op >> b;

        if(op == '?'){
            break;
        }else if(op=='+'){
            cout << a + b << endl;
        }else if(op=='-'){
            cout << a - b << endl;
        }else if(op=='*'){
            cout << a*b << endl;
        }else if(op=='/'){
            cout << a/b << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3096
#include<cstdio>
#include<algorithm>
#define MN 200001
using namespace std;
 
const int MOD=1e9+7;
int n,m,a[MN],b[MN],A=0,B=0;
int main(){
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);sort(a+1,a+1+n);
    for (int i=1;i<=m;i++) scanf("%d",&b[i]);sort(b+1,b+1+m);
    for (int i=1;i<n;i++) A=(1LL*(a[i+1]-a[i])*i%MOD*(n-i)+A)%MOD;
    for (int i=1;i<m;i++) B=(1LL*(b[i+1]-b[i])*i%MOD*(m-i)+B)%MOD;
    printf("%lld\n",1ll*A*B%MOD);
}

Measured memory_bytes: 896