akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;
struct A {
	int a, b, c, d;
}a[51];
int n, m, q;
ll ans = 0;
vector<int> v;
void go(int x) {
	if (v.size() == n) {
		ll cnt = 0;
		for (int i = 0; i < q; i++) {
			ll t = v[a[i].b - 1] - v[a[i].a - 1];
			if (t == a[i].c) {
				cnt += a[i].d;
			}
		}
		if (ans < cnt) {
			ans = cnt;
		}
		return;
	}
	for (int i = x; i <= m; i++) {
		v.push_back(i);
		go(i);
		v.pop_back();
	}
}
int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++) {
		cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
	}
	go(1);
	cout << ans << '\n';



}

Measured memory_bytes: 3192
//解説コピー
//テスト用　自力では無い

#include <bits/stdc++.h>

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
const ll INF = 1LL<<60;

int main() {
    int N,M;
    cin>>N>>M;
    vector<pair<int,ll>> tonari[1001];
    for(int i = 0; i < M; ++i) {
        int a,b; ll w;
        cin>>a>>b>>w;
        tonari[a-1].push_back({b-1,-w});
    }

    bool heikei=false;
    vector<ll> dist(N,INF);
    dist[0]=0;
    for(int i=0;i< 2*N + 10;i++){
        for(int v=0;v<N;v++) {
            if (dist[v] >= INF/2) continue;
            for (auto next:tonari[v]) {
                if (dist[next.first] > dist[v] + next.second) {
                    dist[next.first] = dist[v] + next.second;
                    if (next.first == N - 1 &&i==2*N) heikei=true;
                }
            }
        }
    }
    if(heikei) cout<<"inf"<<endl;
    else cout<<-dist[N-1]<<endl;

    return 0;
}



Measured memory_bytes: 384
function Main(input){
  var N = input.split("\n")[0];
  var B = input.split("\n")[1].split(" ");


  var count = 0;
  for(i=0;i<=(N-2);i++){
    B[i] = parseInt(B[i],10);
    if(i===0){
      count += 2*B[i];
    }else{
      if(B[i-1]>B[i]){
        count -= B[i-1];
        count += 2*B[i];
      }else{
        count += B[i];
      }
    }
  }
  console.log(count);
}  

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 200005, C = 26;

ll n, odd, mid, ans;
vector<ll> id[C], q[N];
vector<pll> v;

char a[N];

struct segtree {
	ll a[4*N], l;
	void init () {
		for(l=1;l<=n;l<<=1);
	}
	void upd (ll P, ll V) {
		P += l;
		while(P) {a[P] += V; P /= 2;}
	}
	ll get (ll S, ll E) {
		S += l; E += l;
		ll R = 0;
		while(S<=E) {
			if(S%2 == 1) R += a[S++];
			if(E%2 == 0) R += a[E--];
			S /= 2; E /= 2;
		}
		return R;
	}
} seg;

int main()
{
	scanf("%s",a+1);
	n = strlen(a+1);
	for(int i=1;i<=n;i++) {
		id[a[i]-'a'].push_back(i);
	}
	for(int i=0;i<C;i++) {
		int S = id[i].size();
		if(id[i].size() % 2 == 1) {
			odd++;
			mid = id[i][S/2];
		}
		for(int j=0;j<S/2;j++) {
			ll A = id[i][j], B = id[i][S-1-j];
			v.push_back({A, B});
			q[A].push_back(B+1);
			q[B].push_back(B+1);
		}
	}
	if(odd > 1) {puts("-1"); return 0;}
	if(mid) {
		for(auto &T : v) {
			if(mid < T.X || T.Y < mid) ans++;
		}
	}
	sort(v.begin(), v.end());
	seg.init();
	for(int i=n,j=(int)v.size()-1;i>=1;i--) {
		for(auto &T : q[i]) {
			ans += seg.get(T, n);
		}
		while(j >= 0 && v[j].X >= i) {
			seg.upd(v[j].Y, 1); j--;
		}
	}
	printf("%lld\n",ans);
}


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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    SPEED
    int N; cin >> N;
    vector<int> V(N+1),W(N+1);
    for(int i = 1; i <= N; ++i) cin >> V[i] >> W[i];

    //O(Q)
    int nl = 1<<9,nr=1<<9,L_max=100001;
    vector<int> msb(nl,0);
    for(int i = 1; i < nl; ++i) msb[i]=31-__builtin_clz(i);
    vector<int> bit_w_dp(nl,0);
    vector<int> bit_v_dp(nl,0);
    vector<vector<int>> dp(nl,vector<int>(L_max,0));

    //前計算
    for(int n = 1; n < min(nl,N+1); ++n) {
        int k = 2*n;
        vector<int> l;
        while(k/=2) l.push_back(k);
        int sz=l.size();
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i^(1<<msb[i])]+W[l[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i^(1<<msb[i])]+V[l[msb[i]]];
            if(bit_w_dp[i]<=L_max) chmax(dp[n][bit_w_dp[i]],bit_v_dp[i]);
        }
        //累積max
        for(int i = 1; i < L_max; ++i) {
            chmax(dp[n][i],dp[n][i-1]);
        }
    }

    int Q; cin >> Q;
    string ans_str="";

    //クエリ
    while(Q--) {
        int p,L; cin >> p >> L;
        vector<int> r;
        int k = 2*p,l=0;
        while(k/=2) {
            if(k<nl) chmax(l,k);
            else r.push_back(k);
        }
        int sz = r.size(),ans=dp[l][L];
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i^(1<<msb[i])]+W[r[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i^(1<<msb[i])]+V[r[msb[i]]];
            if(bit_w_dp[i]<=L) chmax(ans,dp[l][L - bit_w_dp[i]]+bit_v_dp[i]);
        }
        ans_str += to_string(ans)+"\n";
    }
    cout << ans_str;

    return 0;
}


Measured memory_bytes: 207516
from collections import deque
import math
    
def dfs(edges, s):
    stack = deque([s])
    used  = {s}
    while stack:
        x = stack.pop()
        for y in edges[x]:
            if y not in used:
                used.add(y)
                stack.append(y)
    return used


def bfs(edges, s):
    queue = deque([s])
    used  = {s}
    while queue:
        x = queue.popleft()
        for y in edges[x]:
            if y in used:
                continue
            used.add(y)
            queue.append(y)
    return used
    

def bellman(dist):  #負辺があるケースでの、スタートからゴールへの最短路を求めるアルゴ。
    cost = [float("inf")] * n
    cost[0] = 0
    for _ in range(n): #頂点の個数の分だけ回る
        updated = False
        for u,v,c in dist: #辺の個数の分だけ回る
            if cost[u] + c < cost[v]:
                cost[v] = cost[u] + c
                updated = True                
    #収束しない場合は負閉路があるため無限に小さくできる。
    if updated==True:
        return -1
    else:
        return max(0, cost[n-1]*-1)    
        

n,m,p = map(int, input().split())
dist  = []
edge1 = [[] for _ in range(n)]
edge2 = [[] for _ in range(n)]  # rev_edge
for _ in range(m):
    u,v,c = map(int, input().split())
    u -= 1
    v -= 1
    dist.append((u,v,(c-p)*-1))
    edge1[u].append(v)
    edge2[v].append(u)    
    
use = bfs(edge1, 0) & bfs(edge2, n-1)
dist2 = [(a,b,c) for a,b,c in dist if a in use and b in use]
print(bellman(dist2))

Measured memory_bytes: 5480
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>


int main() {
    int sx, sy, gx, gy;

    std::cin >> sx >> sy >> gx >> gy;

    sx += 1000;
    sy += 1000;
    gx += 1000;
    gy += 1000;

    std::string s;
    int c = std::abs(std::abs(sx) - std::abs(gx));
    if (sx < gx) {
        for (int i = 0; i < c; i++) {
            s += 'R';
        }
    } else {
        for (int i = 0; i < c; i++) {
            s += 'L';
        }
    }

    c = std::abs(std::abs(sy) - std::abs(gy));

    if (sy < gy) {
        for (int i = 0; i < c; i++) {
            s += 'U';
        }
    } else {
        for (int i = 0; i < c; i++) {
            s += 'D';
        }
    }

    c = s.length();
    for (int i = 0; i < c; i++) {
        if (s[i] == 'U') s += 'D';
        if (s[i] == 'D') s += 'U';
        if (s[i] == 'L') s += 'R';
        if (s[i] == 'R') s += 'L';
    }

    std::cout << s;

    s.clear();
    
    bool u = false;
    if (gy < sy) {
        s += 'U';
        u = true;
    } else {
        s += 'D';
    }

    c = std::abs(std::abs(sx) - std::abs(gx)) + 1;
    if (sx < gx) {
        for (int i = 0; i < c; i++) {
            s += 'R';
        }
    } else {
        for (int i = 0; i < c; i++) {
            s += 'L';
        }
    }

    c = std::abs(std::abs(sy) - std::abs(gy)) + 1;

    if (sy < gy) {
        for (int i = 0; i < c; i++) {
            s += 'U';
        }
    } else {
        for (int i = 0; i < c; i++) {
            s += 'D';
        }
    }

    if (gx < sx) {
        s += 'R';
    } else {
        s += 'L';
    }

    c = s.length();
    for (int i = 0; i < c; i++) {
        if (s[i] == 'U') s += 'D';
        if (s[i] == 'D') s += 'U';
        if (s[i] == 'L') s += 'R';
        if (s[i] == 'R') s += 'L';
    }

    std::cout << s << std::endl;
    return 0;
}

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

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    double ans;
    if(x > a*b/2){
        x = a*b - x;
        x = x * 2 / a;
        ans = atan2(a, x);
    } else{
        x = x * 2 / b;
        ans = atan2(x, b);
    }
    ans = ans * 180 / M_PI;
    ans = 90 - ans;
    cout << setprecision(20) << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N,M;
    cin>>N>>M;
    
    if(abs(N-M)>1){
        cout<<0;return 0;
    }
    
        ll t=1,r=1;
        REP1(i,N){
            t=(i*t)%1000000007;
        }
        REP1(i,M){
            r=(i*r)%1000000007;
        }
        if(N==M)cout<<(2*t*r)%1000000007;
        else cout<<(t*r)%1000000007;
    
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int64_t> A(N), S(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        A[i]--;
        S[i+1] = (S[i] + A[i] + K) % K;
    }

    map<int, int> mp;
    int64_t ans = 0;
    for(int i=0; i<=N; i++){
        if(i-K>=0) mp[S[i-K]]--;
        ans += mp[S[i]];
        mp[S[i]]++;
        
    }
    cout << ans << endl;
    return 0;
}


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

void solve(){
  long long n, m; cin >> n >> m;
  long long ans = 0;
  if(n*2 >= m) {
    cout << m/2 << endl;
    return;
  } else {
    ans += n;
    m -= 2 * n;
    ans += m/4;
    cout << ans << endl;
  }
}

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

Measured memory_bytes: 3652
#!python3

def resolve():
    N, A, B = map(int, input().rstrip().split())

    diff = B - A

    a = []
    if diff % 2 == 0:
        a.append(diff//2)

    a.append(diff//2 + A-1 + 1)
    a.append(diff//2 + N -B + 1)

    print(min(*a))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  ll n;
  cin >> n;
  ll a[n];
  ll ans = 1;
  ll x;
  rep(i,n){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i,n) {
    if(1000000000000000000 / ans < a[i]){
      ans = -1;
      break;
    }
    ans *= a[i];
  }
  cout << ans << endl;
      
  return 0;
}

Measured memory_bytes: 4356
list_2d=[]
for i in range(3):
    list_2d.append([int(i) for i in input().split()])

n=int(input())

b=[int(input()) for i in range(n)]
#print(list_2d)
#print(b)
 
#印をつける
for i in range(3):
    for j in range(3):
        if list_2d[i][j] in b:
            list_2d[i][j]="x"
            
#print(list_2d)

#ビンゴかどうかチェックする
#横
if list_2d[0]==["x","x","x"] or list_2d[1]==["x","x","x"] or list_2d[2]==["x","x","x"]:
    ans="Yes"
    
#縦
elif list_2d[0][0]==list_2d[1][0]==list_2d[2][0]=="x" or  list_2d[0][1]==list_2d[1][1]==list_2d[2][1]=="x" or  list_2d[0][2]==list_2d[1][2]==list_2d[2][2]=="x":
    ans="Yes"

#斜め
elif  list_2d[0][0]==list_2d[1][1]==list_2d[2][2]=="x" or  list_2d[0][2]==list_2d[1][1]==list_2d[2][0]=="x":
    ans="Yes"
    
else:
    ans="No"
    
print(ans)

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

n=int(input())
a= [list(map(int, input().split())) for i in range(n-1)]
b = [[] for i in range(n)]

for x,y in a:
    b[x-1].append(y-1)
    b[y-1].append(x-1)

# グラフでのbfs
import collections
from collections import deque
def tree(s):

    INF=-10**9
    dis = [INF for i in range(n)]
    dis[s]=0
    def bfs():
        d = deque()
        d.append(s)

        while len(d):
            x = d.popleft()

            for i in range(len(b[x])):
                y=b[x][i]
                if dis[y] == INF:
                    d.append(y)
                    dis[y]=dis[x]+1


        return dis
    return bfs()

fennec=tree(0)
snuke=tree(n-1)

# ans1:fennecの取り分
# ans2:sunukeの取り分
ans1=0
ans2=0
for i in range(n):
    if fennec[i]<=snuke[i]:
        ans1+=1
    else:
        ans2+=1

if ans1>ans2:
    print('Fennec')
else:
    print('Snuke')

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

int main()
{
    ll n;
    cin>>n;
    vector <int> vec1,vec2,seq;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        vec1.push_back(x);
    }
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        vec2.push_back(x);
    }

    for(int i=1; i<=n; i++)
        seq.push_back(i);
    set <vector < int> > lexico;
    do
    {
        vector <int>temp;
        for(int i=0; i<seq.size(); i++)
            temp.push_back(seq[i]);
        lexico.insert(temp);
    }
    while(next_permutation(seq.begin(),seq.end()));
    set < vector <int> > :: iterator itr;
    ll a,b,cnt=0;
    for(itr=lexico.begin(); itr!=lexico.end(); itr++)
    {
        cnt++;
        if((*itr)==vec1)
            a=cnt;
        if((*itr)==vec2)
            b=cnt;
    }
    cout << max(a,b)-min(a,b) << endl;
    return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;

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

    int n;
    cin >> n;
    int res = 0;
    int a = 0, b = 0, ab = 0;
    for( int i = 0; i < n; ++i ) {
        string s;
        cin >> s;
        for( int i = 0; i < s.size() - 1; ++i ) {
            if( s[i] == 'A' && s[i + 1] == 'B' ) ++res;

        }
        if( s[0] == 'B' && s[s.size() - 1] == 'A' ) ++ab;
        else if( s[0] == 'B' ) ++b;
        else if( s[s.size() - 1] == 'A' ) ++a;

    }

    if( ab == 0 ) res += min( a, b );
    else if( a == 0 && b == 0 ) res += ab - 1;
    else res += min( a, b ) + ab;
    cout << res << endl;

    return 0;
}



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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define ll  int
#define ld long double
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
#define pa pair<ll,ll>
//#define goodset tree<pa, null_type, less<pa>, rb_tree_tag, tree_order_statistics_node_update>
//#define FRE freopen("acm.in","r",stdin); freopen("acm.out","w",stdout);

const ll mod = 1e9+7 ;
const ll N = 1e4+2;

//vector<ll>dp[N];
vector<ll>v;
int main()
{
    ll i,j,k,tc;
    //cin>>tc;
    tc=1;
    while(tc--)
    {
       string s,t;
       cin>>s>>t;
       ll siz=t.size();
       ll ans=siz;
       for(i=0; i+siz<s.size()+1; i++)
       {
           string s1=s.substr(i,siz);
           ll cnt=0;
           for(j=0; j<siz; j++)
           {
               if(s1[j]!=t[j])
                cnt++;
           }
           ans=min(ans,cnt);
       }
       cout<<ans;
    }

    return 0;
}


Measured memory_bytes: 3592
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


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

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}







/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  vector<ll> nums;
  if(s[0]=='0') nums.push_back(0);
  for(ll i=0;i<s.size();){
    ll j=i;
    while(j<s.size() && s[i]==s[j]) j++;
    nums.push_back(j-i);
    i=j;
  }
  if(s.back()=='0') nums.push_back(0);
  vector<ll> sums(nums.size()+1,0);
  rep(i,nums.size()) sums[i+1]=sums[i]+nums[i];
  ll res=0;
  for(ll left=0;left<sums.size();left+=2){
    ll right=left+k*2+1;
    if(right>=sums.size()) right=(ll)sums.size()-1;
    res=max(res,sums[right]-sums[left]);
  }
  cout<<res<<endl;
  
  
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 1;i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int n;
    int m;
    cin >> n >> m;
    int a;
    int sum =0;
    rep(i,m){
        cin >> a;
        sum += a;
    } 
    if(n<sum){
        cout << -1 << endl;
    }else{
        cout << n-sum << endl; 
    }
    
}



Measured memory_bytes: 3636
#include<stdio.h>//
#define For(i,a,b) for(register long long i=a;i<=b;i++)
#define Rof(i,a,b) for(register long long i=a;i>=b;i--)
#define int long long
using namespace std;
const int maxn=1e5+10;
int fa[maxn<<1];
inline int findfa(int i){
	return i==fa[i]?i:fa[i]=findfa(fa[i]);
}
inline void uni(int i,int j){
	int a=findfa(i),b=findfa(j);
	if(a!=b) fa[a]=b;
}
inline bool wxp(int i,int j){
	return findfa(i)==findfa(j);
}
int n,m;
signed main(){
	scanf("%lld%lld",&n,&m);
	Rof(i,n<<1,1){
		fa[i]=i;
	}
	For(i,1,m){
		int u,v;
		scanf("%lld%lld",&u,&v);
		uni(u,v+n);
		uni(u+n,v);
	}
	For(i,1,n){
		if(wxp(i,i+n)){
			printf("%lld\n",n*(n-1)/2-m);
			return 0;
		}
	}
	int ls=1,rs=0;
	For(i,2,n){
		if(wxp(i,1)){
			++ls;
		}else{
			++rs;
		}
	}
	printf("%lld\n",ls*rs-m);
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int N, H;
int b[100001];

int main(int argc, char* argv[])
{
	scanf("%d%d", &N, &H);
	int A = 0;
	for (int i = 0; i < N; i++) {
		int a;
		scanf("%d%d", &a, &b[i]);
		A = max(A, a);
	}
	sort(b, b + N, greater<int>());
	for (int i = 0; i <= N; i++) {
		if (H <= 0) {
			printf("%d\n", i);
			break;
		} else if (b[i] <= A) {
			i += H % A == 0 ? H / A : H / A + 1;
			printf("%d\n", i);
			break;
		}
		H -= b[i];
	}

	return 0;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int A, B;
    cin >> A >> B;

    int ans;


    if (A > 12) { ans = B; }
    else if (A >= 6) { ans = B / 2; }
    else if (A < 6) { ans = 0; }


    cout << ans << endl;
}

Measured memory_bytes: 256
//
// Created on 2020/07/11.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>
#include <cmath>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;

bool is_integer( double x ){
    return std::floor(x)==x;
}
int main() {
    int n;
    cin>>n;
    vector<int>ans(n+10,0);

    for (int i = 1; i * i <= n ; ++i) {
        for (int j = 1; j * j <= n; ++j) {
            for (int k = 1; k * k <= n; ++k) {
                if(i*i+j*j+k*k+i*k+j*k+i*j > n)break;
                ans[i*i+j*j+k*k+i*k+j*k+i*j] += 1;
            }
        }
    }

    for (int l = 1; l <= n; ++l) {
        cout<<ans[l]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3632
n,l = map(int,input().split())

sum = 0
for i in range(1,int(n+1)):
  sum += l + i - 1

if l > 0:
  sum = sum - l
else:
  #0を含むとき
  if n>abs(l):
    sum = sum 
  else:
    sum = sum - (l+n-1)
    
print(sum)

Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        mut a: i32, b: i32, mut c: i32, d:i32
    }

    let ans;
    loop {
        c -= b;
        if c <= 0 {
            ans = true;
            break;
        }

        a -= d;
        if a <= 0 {
            ans = false;
            break;
        }
    }

    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2168
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c, d, ans;
	cin >> a >> b >> c >> d;
	ans = a + b + c + d;
	cin >> a >> b >> c >> d;
	cout << max(ans, a + b + c + d) << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    string s;
    cin >> s;

    string ans;

    
    if(s == "Sunny") ans = "Cloudy";
    if(s == "Cloudy") ans = "Rainy";
    if(s == "Rainy") ans = "Sunny";

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

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

int main(){
        int n;
        cin >> n;
        ll res = 1;
        for(int i = 0; i < n; i++) {
                ll t;
                cin >> t;;
                res = lcm(res, t);
        }
        cout << res << endl;
        return 0;
}


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

int main(){
	int n;	cin>>n;
	vector<int> a(n);	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(), a.end());

	long long b[2];	 b[0]=b[1]=0;
	int p=0;

	int i=n-1;
	while(i-1>=0){
		if(a[i]==a[i-1]){
			b[p]=a[i];
			++p;

			if(p>=2) break;
			else{
				i-=2;
				continue;
			}
		}else{
			i--;
		}
	}


	long long ans=b[0]*b[1];
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,m;
struct Node{
	int x,y,num;
}Edge[100005];

bool cmp(Node a,Node b){
	if(a.x == b.x){
		return a.y < b.y;
	}
	return a.x < b.x;
}

bool cmp1(Node a,Node b){
	return a.num < b.num;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&Edge[i].x,&Edge[i].y);
		Edge[i].num = i;
	}
	sort(Edge,Edge+m,cmp);
	int num = 1;
	for(int i=0;i<m-1;i++){
		if(Edge[i].x == Edge[i+1].x){
			Edge[i].y = num++;
		}
		else{
			Edge[i].y = num;
			num = 1;
		}
	}
	if(Edge[m-1].x == Edge[m-1].x) Edge[m-1].y = num;
	else Edge[m-1].y = ++num;
	sort(Edge,Edge+m,cmp1);
	for(int i=0;i<m;i++){
		printf("%06d%06d\n",Edge[i].x,Edge[i].y);
	}
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

int		main(void)
{
	string s;
	cin >> s;
	if (s == "Sunny")
		cout << "Cloudy";
	else if (s == "Cloudy")
		cout << "Rainy";
	else
		cout << "Sunny";
	cout << endl;
}


Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }

fn main() {
    input! {
        n: usize,
        l: usize,
        mut s: [String; n],
    }
    s.sort();
    println!("{}", s.concat());
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main(){
  int n; cin >> n;
  int G[n][n];
  FOR(i,0,n) FOR(j,0,n) G[i][j] = 0;
  FOR(i,0,n){
    int u,k;
    cin >> u >> k;
    u--;
    FOR(j,0,k){
      int v;
      cin >> v;
      v--;
      G[u][v] = 1;
    }
  }
  FOR(i,0,n){
    FOR(j,0,n){
      printf("%d%c", G[i][j], j == n - 1 ? '\n' : ' ');
    }
  }
  return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
const ll MOD=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin>>N>>K;
    int MA=(N-1)*(N-2)/2;
    if(MA<K){cout<<-1<<endl;exit(0);}
    cout<<MA-K+N-1<<endl;
    for(int i=2;i<=N;i++){
        cout<<"1 "<<i<<endl;
    }
    int count=0;
    for(int i=2;i<=N-1;i++){
        for(int j=i+1;j<=N;j++){
            if (MA-count==K){exit(0);}
            cout<<i<<" "<<j<<endl;
            count++;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+5;

bool bz[50][N];
int n,k;

void dfs(int x,int v){
	if (x>45||bz[x][v])return;
	bz[x][v]=1;
	fo(i,0,9){
		int u=(v*10+i)%n;
		dfs(x+i,u);
	}
}

int main(){
	n=get();
	dfs(0,0);
	int ans=0;
	fo(i,1,45){
		if (bz[i][0]){ans=i;break;}
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

using ll = long long;

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

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

map<ll,ll> Divs_all(ll N)
{
    map<ll,ll> ret_map;
    for(ll i=1;i*i<=N;i++)
    {
        if(N%i==0)
        {
            ret_map[i]++;
            ret_map[N/i]++;
        }
    }
    return ret_map;
}

ll tri(ll N)
{
    return N*(N+1)/2;
}

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

    ll ans = 0;
    for(ll i=1;i<=N;i++)
    {
        ans += i * tri((N/i));
    }

    OUT0(ans);

    return 0;
}

Measured memory_bytes: 3604
from functools import reduce
N = int(input())
T = [0]*N
for i in range(N):
    T[i] = int(input())
def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x
def lcm(x, y):
    return x*y//gcd(x, y)
print(reduce(lcm, T))

Measured memory_bytes: 3572
#include <iostream> 
#include <string> 
using namespace std; 
  int main(){
    string s; 
  cin>>s; 
    if(s=="Sunny"s) cout<<"Cloudy"<<endl; 
    if(s=="Cloudy"s) cout<<"Rainy"<<endl; 
      if(s=="Rainy"s) cout<<"Sunny"<<endl; 
             return 0; 
            }


Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 1000000001

int main(void)
{
    long min,max,a;
    int n,i;

    min=SIZE;
    max=-SIZE;
    scanf("%d",&n);
    //printf("scan n=%d\n",n);

    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        //printf("scan %d\n",a);
        if(min!=SIZE&&a-min>max)
        {
            //printf("max=%d\n",a-min);
            max=a-min;
        }
        if(a<min)
        {
            min=a;
            //printf("min=%d\n",min);
            continue;
        }

    }

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

}


Measured memory_bytes: 1992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m; cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;

    return 0;
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0022
# Kadane
module Kadane
  def self.max_subarray(a)
    max_so_far = max_ending_here = -1.0 / 0
    a.each do |i|
      max_ending_here = [i, max_ending_here + i].max
      max_so_far = [max_so_far, max_ending_here].max
    end
    max_so_far
  end
end

while n = gets.to_i
  break if n == 0
  a = []
  n.times { a << gets.to_i }
  puts Kadane.max_subarray(a)
end

Measured memory_bytes: 6128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
//#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << (x) << "\n"
constexpr int mod = 1000000007;
using namespace std;
string f() { string t; cin >> t; return t; }
map<string, int>m;
signed main() {
	int n; cin >> n;
	for1(i, n)m[f()]++;
	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int N, Q; cin >> N >> Q;
    string str; cin >> str;
    vector<int> s(N+1,0);
    for (int i = 0; i < N; i++) {
      if (i+1 < N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
      else s[i+1] = s[i];
    }
    for (int q = 0; q < Q; q++) {
        int l, r; cin >> l >> r;
      --l, --r;
      cout << s[r] - s[l] << endl;
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int>P(N),I(N);
  for(int i=0;i<N;i++){
    cin>>P[i];P[i]--;I[P[i]]=i;
  }
  int M=0,tmp=1;
  for(int i=0;i<N;i++){
    if(i==N-1||I[i+1]<I[i]){M=max(M,tmp);tmp=1;}
    else tmp++;
  }
  cout<<N-M;
}



Measured memory_bytes: 1792
using System;

namespace ABC87_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            Console.WriteLine((X - A) % B);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}



int main()
{
  int N,a,b;
  cin>>N;
  a=N/100;
  b=N%100;
  if(a==0)
  {
    cout<<0<<endl;
    return 0;
  }
  if(a==1)
  {
    if(b<6)
    {
      cout<<1<<endl;
      return 0;
    }
    else
    {
      cout<<0<<endl;
      return 0;
    }
  }
  else
  {
    if(5*a>=b)
    {
      cout<<1<<endl;
      return 0;
    }
    else
    {
      cout<<0<<endl;
      
    }
  }

}

Measured memory_bytes: 256
N = int(input())

zoro = 0

for i in range(N):
    D1, D2 = list(map(int, input().split()))

    if (D1 == D2):
        zoro += 1
    else:
        zoro = 0

    if (zoro == 3):
        print("Yes")
        exit(0)

print("No")


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

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

using namespace std;

//v.push_back(123);
//sort(v.begin(), v.end(),greater<int>());
//for(int x : v) {cout << x << endl;}

//for(int x: v) cout << x << endl;
//vector<vector<char>> v(H, vector<char>(W));
//vector<int> v(1000);

signed main(){
  int N;
  cin>>N;
  int W[N];
  rep(i, N) cin >> W[i];

  int sum1;
  int sum2;
  int sa;
  int minsa=100000;
  //sort(W, W+N);
  rep(i, N){
    sum1 = 0;
    sum2 = 0;
    rep(j, N){
      if(j>i){
        sum1+=W[j];
      }else{
        sum2+=W[j];
      }
    }
    if(sum1>sum2){
      sa = sum1 - sum2; 
    }else{
      sa = sum2 - sum1;
    }
    if(minsa>sa){
      minsa=sa;
    }
  }

  cout << minsa << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int  N,K;
  int L=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    	int x;
    	cin>>x;
    	if(x<=K/2){
          L+=2*x;
        }else if(x<=K){
          L+=2*K-2*x;
        }else{
          L+=2*x-2*K;
        }
  }
  cout<<L<<endl;
}
          

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

int p[200000];

int main() {
    int n;
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; i++) {
            int x;
            scanf("%d", &x);
            x--;
            p[x] = i;
        }

        int best = 1;
        for (int i = 1, cur = 1; i < n; i++) {
            if (p[i] > p[i - 1])
                best = max(best, ++cur);
            else
                cur = 1;
        }

        printf("%d\n", n - best);
    }
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>  // std::greater<T>()

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから

// func declaration
template <class T> void printVec(vector<T>);
template <class T> void calcVec(vector<T>&, int, char);
bool checkMultiple(vector<int>&, int);

// const
const int INF = 10000000;

/*MEMO
辞書順
abc < abcd, atcoder < atlas
*/

int main() {
    string str;
    cin >> str;

    size_t idx_A = str.find('A');
    size_t idx_Z = str.rfind('Z');
    cout << (int)idx_Z - (int)idx_A + 1 << endl;

    return 0;
}


// function
template <class T> void printVec(vector<T> vec) {
    // 1要素ずつ、空白・改行なしで出力
    REP(i, vec.size()) {
        cout << vec.at(i);
    }
    cout << endl;
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    if (ch == '+') {
        REP(i, vec.size()) {
            vec.at(i) += num;
        }
    } else if (ch == '-') {
        REP(i, vec.size()) {
            vec.at(i) -= num;
        }
    } else if (ch == '*') {
        REP(i, vec.size()) {
            vec.at(i) *= num;
        }
    } else if (ch == '/'){
        REP(i, vec.size()) {
            vec.at(i) /= num;
        }
    } else if (ch == '%') {
        REP(i, vec.size()) {
            vec.at(i) %= num;
        }
    }
}

bool checkMultiple(vector<int> &vec, int num) {
    // vecの中身が、numの倍数かどうかのチェック
    int count = 0;
    REP(i, vec.size()) {
        if (vec.at(i)%num != 0) count++;
    }
    return (count == 0);
}


Measured memory_bytes: 640
/*
Author : N_o_o_B
Created : April 26 2020 17:32:36 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    for(int i=0;;i++){
        if(i&1){
            if(a>d){
                a-=d;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }   
        else{
            if(c>b){
                c-=b;
            }
            else{
                cout << "Yes" << endl;
                return 0;
            }
        }
    }




    time_taken();
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

ll f(ll n){
    if(n%2==0){
        return n/2;
    }else{
        return 3*n+1;
    }
}

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

    ll now = s;
    map<ll,ll> p;
    p[now]++;
    int cnt = 1;
    while(1){
        ll next = f(now);
        p[next]++;
        cnt++;
        if(p[next]==2){
            break;
        }
        now = next;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256