akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  vi A(N);
  int ma = 0;
  int sum = 0;
  rep(i,N) {
    cin >> A[i];
    ma = max(ma,A[i]);
    sum += A[i];
  }
  int ans = 1;
  for(int k = 1;k * k <= sum;k++) {
    if(sum % k != 0) continue;
    vi d(N);
    rep(i,N) {
      d[i] = A[i] % k;
    }
    sort(rng(d));
    vi s(N+1,0);
    rep(i,N) {
      s[i+1] = s[i]+d[i];
    }
    bool ok = false;
    rep(i,N+1) {
      int a = s[i];
      int b = k * (N-i) - (s[N]-s[i]);
      if(a == b && a <= K) ok = true;
    }
    if(ok) {
      ans = max(ans,k);
    }
    int k2 = sum / k;
    d = vi(N);
    rep(i,N) {
      d[i] = A[i] % k2;
    }
    sort(rng(d));
    s = vi(N+1,0);
    rep(i,N) {
      s[i+1] = s[i]+d[i];
    }
    ok = false;
    rep(i,N+1) {
      int a = s[i];
      int b = k2 * (N-i) - (s[N]-s[i]);
      if(a == b && a <= K) ok = true;
    }
    if(ok) {
      ans = max(ans,k2);
    }
  }
  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++)
using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end(),greater<int>());
    int cnt=1;
    rep(i,n-1){
        if(a[i]>a[i+1])++cnt;
    }
    cout<<cnt;

    return 0;
    }


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

int main() {
    int w[10],k[10];
    for(int i = 0; i < 10; i++){
    	cin >> w[i];
    }
    for(int j = 0; j < 10; j++){
    	cin >> k[j];
    }
    sort(w,w + 10);
    sort(k,k + 10);
    cout << w[7]+w[8]+w[9] << " " <<  k[7]+k[8]+k[9] << endl;
    return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
int n,k;
struct Star{
	int s,e,to;
}edge[4010];
int head[2010];
int d[2010];
int cnt=0,sum=0;
void dfs(int x,int fa){
	for(int i=head[x];~i;i=edge[i].to){
		int nxt=edge[i].e;
		if(nxt==fa) continue;
		d[nxt]=d[x]+1;
//		printf("%d\n",d[nxt]);
		if(d[nxt]>k/2) sum++;
		dfs(nxt,x);
	}
}
int main(){
	memset(head,-1,sizeof(head));
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		edge[++cnt].s=x,edge[cnt].e=y,edge[cnt].to=head[x];head[x]=cnt;
		edge[++cnt].s=y,edge[cnt].e=x,edge[cnt].to=head[y];head[y]=cnt;
	}
	int ans=0x7fffffff;
	if(k&1){
		for(int i=1;i<=2*n-2;i++){
			sum=0;
			int x=edge[i].s,y=edge[i].e;
			d[x]=d[y]=0;dfs(x,y);dfs(y,x);
			ans=min(ans,sum);
		}
	}
	else{
		for(int i=1;i<=n;i++){
			sum=0;
			d[i]=0;
			dfs(i,0);
			ans=min(ans,sum);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n;
    cin>>n;
 
    vector<int>A,B,C;
    B.push_back(-1);
    C.push_back(-1);
 
    int i,x;
 
    for(i=0;i!=n;i++)
    {
        cin>>x;
        A.push_back(x);
    }
 
    for(i=0;i!=n;i++)
    {
        cin>>x;
        B.push_back(x);
    }
 
    for(i=0;i!=n-1;i++)
    {
        cin>>x;
        C.push_back(x);
    }
 
    int s = B[A[0]];
    for(i=1;i!=n;i++)
    {
        s += B[A[i]];
 
        if(A[i] == A[i-1]+1)
            s += C[A[i-1]];
    }
 
    cout<<s;
 
    return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    float T, X;
    cin >> T >> X;

    printf("%f", T / X);
    return 0;
}

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

fn input<T:FromStr>() -> T {
  let mut line: String = String::new();
  io::stdin().read_line(&mut line);
  line.trim().parse().ok().unwrap()
}

fn main() {
  let n: f64 = input();
  if n as i32 % 2 == 0 {
    println!("0.5");
  } else {
    println!("{}", (n + 1f64) / 2f64 / n);
  }
}


Measured memory_bytes: 4352
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
inp = list(map(int, input().split()))
L = []
for i, l in enumerate(inp, 1):
    L.append([l, i])

L = sorted(L, key=lambda x: x[0])
ans = []
for _, l in L:
    ans.append(l)
print(" ".join(map(str, ans)))


Measured memory_bytes: 28092
#include<cmath>
#include<iostream>
using namespace std;
 int is_prime( long long int n)
{
    if(n==2){ return 1;}
    else{ for(int i=2;i*i<=n;i++)
        {
            if( n%i ==0){ return 0;
            break;
            }
        }
    }
    return 1;
}
int main()
{
    char a[3];
    cin>>a;
    int cnt=0;
    for(int i=0;i<3;i++)if(a[i]=='A')cnt++;
    if(cnt==0 || cnt==3)cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var ns = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = ns[0];
        var s = ns[1];
        var cs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var ds = cs.Select(x => Math.Abs(s - x)).ToArray();
        for (int i = 1; i < ds.Length; i++)
        {
            while (ds[i] != 0)
            {
                if (ds[i - 1] > ds[i])
                {
                    ds[i] += ds[i - 1];
                    ds[i - 1] = ds[i] - ds[i - 1];
                    ds[i] -= ds[i - 1];
                }

                ds[i] %= ds[i - 1];
            }
            ds[i] = ds[i - 1];
        }
        Console.WriteLine(ds.Last());
    }
}


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

using namespace std;

pair<int,int>a[100010];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        a[i]=make_pair(x+y,x-y);
    }
    sort(a+1,a+n+1);
    int nowr=-0x7f7f7f7f,ans=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i].second<nowr) continue;
        nowr=a[i].first;
        ans++;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 4376
#include <stdio.h>

int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0) break;
    for(j=0; j<H; j++){
      for(i=0; i<W; i++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	int co=0;
	while(cin>>n,n){
		co++;
		vector<double>x,y,x1,x2,y1,y2;
		vvi in(210,vi(210));
		rep(i,n){
			double a,b,c;
			cin>>a>>b>>c;
			x.pb(a-c);x.pb(a+c);
			y.pb(b-c);y.pb(b+c);
			x1.pb(a-c);x2.pb(a+c);
			y1.pb(b-c);y2.pb(b+c);
		}
		sort(all(x));
		sort(all(y));
		x.erase(unique(all(x)),x.end());
		y.erase(unique(all(y)),y.end());
		rep(i,n){
			int a=find(all(x),x1[i])-x.begin();
			int b=find(all(x),x2[i])-x.begin();
			int c=find(all(y),y1[i])-y.begin();
			int d=find(all(y),y2[i])-y.begin();
			loop(j,a,b)loop(k,c,d)
				in[j][k]=true;
		}
		double sum=0;
		rep(i,210)rep(j,210)if(in[i][j])
			sum+=(x[i+1]-x[i])*(y[j+1]-y[j]);
		cout<<co<<" "<<shosu(2)<<sum<<endl;
	}
}

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

#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long 
const ll mod = 1e9+7;
const int MAX = 2e5+5;


ll maxx(ll a, ll b, ll c, ll d){
    ll x = max(a,b);
    ll y = max(x,c);
    ll z = max(y,d);
    return z;
}
int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll x = a * c, y = a * d, z = b * c, w = b * d;
    ll ans = maxx(x,y,z,w);
    cout << ans << "\n";
}






Measured memory_bytes: 3628
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import reduce
from operator import xor

N = int(readline())
A = [0] + list(map(int,read().split()))

for n in range(N//2,0,-1):
    A[n] = reduce(xor,A[n::n],0)

I = [i for i,x in enumerate(A) if x]

print(len(I))
if len(I) > 0:
    print(' '.join(map(str,I)))

Measured memory_bytes: 18920
import sys
input = sys.stdin.readline
N=int(input())
P=list(map(int,input().split()))
count = 0
saisyouti = P[0]
for i in range(N):
    if P[i]<=saisyouti:
        count += 1
        saisyouti=P[i]
print(count)

Measured memory_bytes: 24436
#pragma GCC optimize "O3"

#include <bits/stdc++.h>

using namespace std;
// O( ( V + E ) * sqrt( V ) )
class BipartiteMatching {
 public:
  static const int N = 1e4 + 10;  // total number of nodes, n + m
  static const int NIL = 0;
  static const int INF = ( 1 << 28 );
  vector< int > G[ N ];
  int n, m, match[ N ], dist[ N ];
  // n: number of nodes on left side, nodes are numbered 1 to n
  // m: number of nodes on right side, nodes are numbered n+1 to n+m
  // G = NIL[0] ??? G1[G[1---n]] ??? G2[G[n+1---n+m]]
  bool BFS() {
    queue< int > Q;
    for (int i = 1; i <= n; i++ ) {
      if ( match[ i ] == NIL ) {
        dist[ i ] = 0;
        Q.push( i );
      }
      else
        dist[ i ] = INF;
    }
    dist[ NIL ] = INF;
    while ( !Q.empty() ) {
      int u = Q.front(); Q.pop();
      if ( u != NIL ) {
        for(int v : G[u]) {
          if ( dist[ match[ v ] ] == INF ) {
            dist[ match[ v ] ] = dist[ u ] + 1;
            Q.push( match[ v ] );
          }
        }
      }
    }
    return ( dist[ NIL ] != INF );
  }
  bool DFS( int u ) {
    if ( u != NIL ) {
      for(int v : G[u]) {
        if ( dist[ match[ v ] ] == dist[ u ] + 1 ) {
          if ( DFS( match[ v ] ) ) {
            match[ v ] = u;
            match[ u ] = v;
            return true;
          }
        }
      }
      dist[ u ] = INF;
      return false;
    }
    return true;
  }
  int Solve() {
    int matching = 0;
    for(int i = 0; i <= n + m; ++i) match[i] = NIL;
    while ( BFS() )
      for (int i = 1; i <= n; i++ )
        if ( match[ i ] == NIL && DFS( i ) ) matching++;
    return matching;
  }
  void AddEdge( int u, int v ) { G[ u ].push_back( n + v ); }
} ob;

int main() {
  int E; scanf("%d %d %d", &ob.n, &ob.m, &E);
  for(int i = 0; i < E; ++i) {
    int x, y; scanf("%d %d", &x, &y);
    ob.AddEdge(x+1, y+1);
  }
  printf("%d\n", ob.Solve());
}

Measured memory_bytes: 3520
def num2alpha(num):
    if num<=26:
        return chr(64+num+32)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90+32)
    else:
        return num2alpha(num//26)+chr(64+num%26+32)

n = int(input())
print(num2alpha(n))

Measured memory_bytes: 61812
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))
for i in range(2+n_a):
 for j in range(2+int((f-100*i*a)/(100*b))):
  for k in range(2+int((f-100*i*a-100*j*b)/c)):
   for l in range(2+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>=noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))


Measured memory_bytes: 3064
from fractions import gcd
a, b, c, d = map(int, input().split())
lcm = c * d // gcd(c, d)
# a-1以下でcでもdでも割り切れない
ans_a = a-1 - (a-1) // c - (a-1) // d + (a-1) // lcm
# b以下でcでもdでも割り切れない
ans_b = b - b // c - b // d + b // lcm
print(ans_b - ans_a)


Measured memory_bytes: 64108
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y << endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
 
using namespace std;
 
bool compare(ll &x, ll &y){
    return x>=y;
}
 
ll mode=pow(10,9)+7;

 
int main(){ 
    
    
    ios::sync_with_stdio(0);
    cin.tie(0);
 
 	ll n,k;
 	cin>>n>>k;
 	for (int i=k-n+1;i<=n+k-1;i++){
 		cout<<i<<" ";
	 }
	 cout<<endl;
             
    return 0; 
}
	

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

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

    int a, b;
    cin >> a >> b;

    int n   = b - a + 1;
    int ans = 0;
    REP(i, n) { ans += i; }
    ans -= b;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#define maxn 120
using namespace std;
int a[maxn]={0},N;
int read(){
	int w=0;char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') w=w*10+c-48,c=getchar();
	return w;
}
int main(){
	int i,ans=0;
	N=read();
	for(i=1;i<=N;i++){
		a[i]=read();
	}
	sort(a+1,a+N+1);
	for(i=N;i>0;i=i-2){
		ans+=a[i]-a[i-1];
//		printf("ans:%d\n",ans);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

ans = 0
hands = []
for i in range(N):
    t = T[i]
    if t == 'r':
        if i < K or hands[i-K] != 'p':
            ans += P
            hands.append('p')
        else:
            if i+K >= N:
                hands.append('r')
            else:
                if T[i+K] == 'r':
                    hands.append('r')
                elif T[i+K] == 's':
                    hands.append('s')
                elif T[i+K] == 'p':
                    hands.append('p')
    elif t == 's':
        if i < K or hands[i-K] != 'r':
            ans += R
            hands.append('r')
        else:
            if i+K >= N:
                hands.append('s')
            else:
                if T[i+K] == 'r':
                    hands.append('r')
                elif T[i+K] == 's':
                    hands.append('s')
                elif T[i+K] == 'p':
                    hands.append('p')
    elif t == 'p':
        if i < K or hands[i-K] != 's':
            ans += S
            hands.append('s')
        else:
            if i+K >= N:
                hands.append('p')
            else:
                if T[i+K] == 'r':
                    hands.append('r')
                elif T[i+K] == 's':
                    hands.append('s')
                elif T[i+K] == 'p':
                    hands.append('p')
print(ans)

Measured memory_bytes: 49264
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char s[15];
inline int ask(R int x){
	printf("%d\n",x-1);fflush(stdout);
	scanf("%s",s+1);if(s[1]=='V')exit(0);
	return s[1]=='M';
}
int n;
void query(int l,int r,int cl,int cr){
	if(l>=r-1)assert(false);
	int mid=(l+r)>>1,c=ask(mid);
	if((c^cl)!=((mid-l)&1))query(l,mid,cl,c);
	if((c^cr)!=((r-mid)&1))query(mid,r,c,cr);
	assert(false);
}
int main(){
	scanf("%d",&n);
	query(1,n,ask(1),ask(n));
	return 0;
}

Measured memory_bytes: 852
def main():
    N, X = map(int, input().split())
    M = [
        int(input())
        for _ in range(N)
    ]

    ans = 0
    for i in range(N):
        ans += 1
        X -= M[i]
    ans += X // min(M)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
	int W[10];
	int K[10];
	for(int i=0;i<10;i++)
		cin>>W[i];
	for(int i=0;i<10;i++)
		cin>>K[i];
	sort(W,W+10);
	sort(K,K+10);
	cout<<W[7]+W[8]+W[9]<<" "<<K[7]+K[8]+K[9]<<endl;
	return 0;
}

Measured memory_bytes: 1184
# -*- coding: utf-8 -*-

S = input()
K = int(input())

S2 = ""
for i in range(len(S)):
    if S[i] == "1":
        S2 += "1"
    else:
        S2 += S[i] * 100
        break

if K <= 100:
    print(S2[K-1])
else:
    print(S2[-1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a[200009];
int vis[200009];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
memset(vis,0,sizeof(vis));
        for(int i=n;i>0;i-=2)
        {
            cout<<a[i]<<" ";
            vis[i]=1;
        }
        for(int i=1;i<=n;i++)
        {
            if(vis[i]==0)
            {
                cout<<a[i]<<" ";
            }
        }


}


Measured memory_bytes: 3712
/// Find the maximum product of subsequences  of size k
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
using namespace std;
signed main()
{
    ll i,j,k,n,s=0;
    cin>>n;
    cin>>k;
    ll K=k;
    vector<ll>neg,pos,zero;
    vector<pair<ll,ll> >vec;
    ll arr[n];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
        if(arr[i]>0)
        {
            pos.pb(arr[i]);
            s=1;
        }
        else if(arr[i]<0)
        {
            neg.pb(abs(arr[i]));
            s=-1;
        }
        else
        {
            zero.pb(arr[i]);
            s=1;
        }
        vec.pb(make_pair(abs(arr[i]),s));
    }
    ll idp=pos.size()-1;
    ll idn=neg.size()-1;
    sort(pos.begin(),pos.end());
    sort(neg.begin(),neg.end());
    sort(vec.begin(),vec.end());
    ll ans=1;
    if(k%2)
    {
        if(pos.size()>0)
        {
            ans=((ans*pos[idp])%mod+mod)%mod;
            idp--;
            k--;
        }
    }
    /// as k is even so k will be zero if enough positive or negative pair is present here
    while(k&& (idp>0||idn>0))
    {
        ll a=-inf;
        ll b=-inf;
        if(idp>=1)
            a=pos[idp]*pos[idp-1];
        if(idn>=1)
            b=neg[idn]*neg[idn-1];
        if(a>b)
        {
            ans=((a+mod)%mod*(ans+mod)%mod)%mod;
            idp=idp-2;
            k=k-2;
        }
        else
        {
            ans=((b+mod)%mod*(ans+mod)%mod)%mod;
            idn=idn-2;
            k=k-2;
        }
    }
    if(k)
    {
        if(zero.size())
            ans=0;
        else
        {
            ans=1;
            for(i=0; i<K; i++)
                ans=((ans%mod*((vec[i].first*vec[i].second)%mod))%mod+mod)%mod;
        }
    }
    cout<<ans;
    return 0;

}


Measured memory_bytes: 10868
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il print(T x){
	if(x/10) print(x/10);
	putchar(x%10+'0');
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x%mod;
	while(m){
		if(m&1) res=(res*bas)%mod;
		bas=(bas*bas)%mod,m>>=1;
	}
	return res%mod;
}
int n,m,ans;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m);
	for(ri i=1;i<=n;++i)
		for(ri j=1;j<=m;++j)
			if(j%10>=2&&j/10>=2&&j/10*(j%10)==i)
				ans++;
	print(ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int watch = sc.nextInt();
        int time = sc.nextInt();
        if (watch < time) {
            System.out.println(0);
        } else {
            System.out.println(watch-time);
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  ll ans = 0;
  rep(i, n) {
    ans += A[i]/2;
    A[i] %= 2;
    if(i+1<n) {
      ll tmp = min(A[i], A[i+1]);
      ans += tmp;
      A[i+1] -= tmp;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3964
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  string S;
  cin >> S;
  if(S.size()==3){
    reverse(ALL(S));
  }
  cout << S << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
mod = 10 ** 9 + 7
h = 1
t = set()
while h * h <= N:
  t.add(N // h)
  t.add(h)
  h += 1
t = sorted(t)
#print(len(t))
tt = []
for x in t:
  tt.append(N // x)

dp = [[0] * len(t) for _ in range(K + 1)]
dp[0][0] = 1
for i in range(K):
  for j in range(len(t)):
    k = len(t) - j - 1
    dp[i + 1][k] += dp[i][j]
    dp[i + 1][k] %= mod
  #print(dp)
  for k in range(len(t) - 1, 0, -1):
    dp[i + 1][k - 1] += dp[i + 1][k]
    dp[i + 1][k - 1] %= mod
    rng = (t[k] - t[k - 1]) % mod
    dp[i + 1][k] *= rng
    dp[i + 1][k] %= mod

  #print(dp)
res = 0
#print(dp)
for j in range(len(t)):
  res += dp[-1][j]
  res %= mod
print(res)

Measured memory_bytes: 96632
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int main()
{
  vector<int> degree(4);
  for (int i = 0; i < 3; ++i) {
    int a, b;
    cin >> a >> b;
    degree[a - 1]++;
    degree[b - 1]++;
  }
  sort(degree.begin(), degree.end());
  bool ok = degree[0] == 1 && degree[1] == 1 && degree[2] == 2 && degree[3] == 2;
  cout << (ok ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
//
// Created by 10034 on 2020/7/29.
//

#include <iostream>
using namespace std;
int n,a[1000010];
int st[1000010];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%d",&a[i]),st[a[i]]++;
    int cnt=n;
    for(int i=1;i<=n;++i){
        for(int j=1;j*j<=a[i];++j){
            if(a[i]%j==0){
                int x=a[i]/j,y=j;
                if(st[x]&&(x!=a[i]||st[x]>1)){
                    cnt--;
                    break;
                }
                if(st[y]&&(y!=a[i]||st[y]>1)){
                    cnt--;
                    break;
                }
            }
        }
    }
    cout<<cnt<<endl;


    return 0;
}

Measured memory_bytes: 7792
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr, sort)
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn :: IO Int
  xs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let r = length $ filter id $ zipWith (/=) xs $ sort xs
  if r <= 2
    then putStrLn "YES"
    else putStrLn "NO"


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

int main()
{
    int N, M;
    cin >> N >> M;
    pair<int, int> c[M];
    int a, b;
    for (int i = 0; i < M; i++)
    {
        cin >> c[i].second >> c[i].first;
    }
    sort(c, c + M);
    int ans = 1;
    int latest_bridge = c[0].first - 1;
    for (int i = 1; i < M; i++)
    {
        if (c[i].second > latest_bridge)
        {
            ans++;
            latest_bridge = c[i].first - 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
s = input()

if len(s) == 1:
  print(s)
  exit()

a = 0
di = len(s) - 1
m = 2 ** di
for i in range(m):
  b = format(i, 'b').zfill(di)
  fs = ''
  for c, d in zip(s, b):
    fs += c
    if d == '1':
      fs += '+'
  fs += s[-1]
  a += eval(fs)

print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
typedef pair<int, int> P;

void queue_to_vector(queue<P>& stk, vector<P>& v){
  while(!stk.empty()){
    v.push_back(stk.front());
    stk.pop();
  }
}

int main(){
  int N, M, p, q, r;
  while(cin >> N >> M >> p >> q >> r){
    vector<P> card;
    card.push_back(P(1, N));
    while(M-- > 0){
      int x, y;
      cin >> x >> y;
      int C = 0;
      queue<P> bottom, mid, top;
      for(int i = 0; i < card.size(); i++){
        int num = card[i].second - card[i].first + 1;
        if(C < x){
          if(C + num <= x){
            bottom.push(card[i]);
            C += num;
          }else{
            bottom.push(P(card[i].first, card[i].second - (C + num - x)));
            card.insert(card.begin() + i + 1, P(card[i].second - (C + num - x) + 1, card[i].second));
            C = x;
          }
        }else if(C < y){
          if(C + num <= y){
            mid.push(card[i]);
            C += num;
          }else{
            mid.push(P(card[i].first, card[i].second - (C + num - y)));
            card.insert(card.begin() + i + 1, P(card[i].second - (C + num - y) + 1, card[i].second));
            C = y;
          }
        }else{
          top.push(card[i]);
        }
      }
      card.clear();
      queue_to_vector(top, card);
      queue_to_vector(mid, card);
      queue_to_vector(bottom, card);
    }
    int C = 0;
    int ans = 0;
    p--;
    for(int i = 0; i < card.size(); i++){
      int num = card[i].second - card[i].first + 1;
      if(C < p){
        if(C + num <= p){
          C += num;
        }else{
          card.insert(card.begin() + i + 1, P(card[i].second - (C + num - p) + 1, card[i].second));
          C = p;
        }
      }else if(C < q){
        if(C + num <= q){
          ans += max(0, min(card[i].second, r) - card[i].first + 1);
          C += num;
        }else{
          int E = card[i].second - (C + num - q);
          ans += max(0, min(E, r) - card[i].first + 1);
          break;
        }
      }else{
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

    int num[6];
    int tmp;
    for (int i = 0; i < 6; i++) {
        cin >> tmp;
        num[i] = tmp;
    }
    bool flag = true;
    for (int i = 5; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (num[i] - num[j] > num[5]) {
                flag = false;
                break;
            }
        }
    }

    string out = flag ? "Yay!" : ":(";

    cout << out << "\n";

    return 0;
}

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

namespace ABC168A
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int num = N.Length;
            string A = N.Substring(num - 1, 1);
            string ans = "ans";
            if (A == "3")
            {
                ans = "bon";
            }
            else if (A == "0" | A == "1" | A == "6" | A == "8")
            {
                ans = "pon";
            }
            else
            {
                ans = "hon";
            }
            Console.WriteLine(ans);


        }
    }
}


Measured memory_bytes: 25788
#include <stdio.h>

int main() {
  int A, B, C, D;
  int time = 0;
  int sw = 0;
  
  scanf("%d %d %d %d", &A, &B, &C, &D);
  for(int i = 0; i < 100; i++) {
    if(i == A) sw += 1;
    if(i == C) sw += 1;
    if(i == B) sw -= 1;
    if(i == D) sw -= 1;
    if(sw == 2) time++;
  }
  
  printf("%d\n", time);
  
  return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	n := readInt()
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			a[i][j] = readInt()
		}
	}

	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if a[i][k] == 0 || a[k][j] == 0 {
					continue
				}
				if a[i][k]+a[k][j] < a[i][j] {
					println("-1")
					return
				}
				if a[i][k]+a[k][j] == a[i][j] {
					a[i][j] = 0
					a[j][i] = 0
				}
			}
		}
	}

	var ans int64
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			ans += int64(a[i][j])
		}
	}
	println(ans)
}


Measured memory_bytes: 2816
#include <iostream>

using namespace std;

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

    int H, W;
    cin >> H >> W;

    string picture[H];
    for (int i = 0; i < H; ++i) {
        cin >> picture[i];
    }

    int dx[4] = {-1, 0, 0, 1};
    int dy[4] = {0, 1, -1, 0};
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (picture[i][j] == '.') continue;
            bool flag = false;
            for (int k = 0; k < 4; ++k) {
                int ny = i + dy[k];
                int nx = j + dx[k];
                if (0 <= ny && ny < H && 0 <= nx && nx < W && picture[ny][nx] == '#') {
                    flag = true;
                }
            }
            if (!flag) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

idx = [i+1 for i in range(n)]
s = []
p = []

for i in range(n):
    _s, _p = input().split()
    s.append(_s)
    p.append(int(_p))

for i in range(n-1):
    for j in range(i+1, n):
        if s[i] > s[j] or (s[i] == s[j] and p[i] < p[j]):
            idx[i], idx[j] = idx[j], idx[i]
            s[i], s[j] = s[j], s[i]
            p[i], p[j] = p[j], p[i]

for i in idx:
    print(i)

Measured memory_bytes: 3064
require 'pp'
require 'prime'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
N, P = gets_i_list

factors = Prime.prime_division(P)

max = 1
factors.each do |num, count|
  max *= num ** (count / N)
end

puts max

Measured memory_bytes: 2812
#include<stdio.h>

int a,b,c,i;
int d=0;
int main(void){
  scanf("%d %d %d",&a,&b,&c);
  //printf("%d %d %d",a,b,c);
  for(i=a;i<=b;i++){
    if(c%i==0){
    d++;}
    else;
}
      printf("%d\n",d);
return 0;
}


Measured memory_bytes: 2100
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		InputStream in = System.in;

		sc = new Scanner(in);

		String N = sc.next();
		int answer = 0;

		for(int i = 0; i < 3; i++){
			if(N.charAt(i) == '1'){
				answer++;
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 19796
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if p[i] != max(p[i-1], p[i], p[i+1]) and p[i] != min(p[i-1], p[i], p[i+1]):
        ans += 1

print(ans)


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

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

  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, 0, n) {
    int v;
    cin >> v;
    a[i] = v;
    b[i] = v;
  }

  sort(b.rbegin(), b.rend());
  int m1 = b[0], m2 = b[1];
  rep(i, 0, n) {
    if (a[i] == m1)
      cout << m2 << endl;
    else
      cout << m1 << endl;
  }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int n,a[100005],g;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    fort (i,n)
    {
        cin >> a[i];
        g=__gcd(g,a[i]);
    }
    cout << g;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#define MN 2100001
using namespace std;
int n,m,a[MN];
long long sum1=0,sum2=0,mmh=1e18;
long long _abs(long long x){return x<0?-x:x;}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum2+=a[i];
    for (int i=1;i<n;i++) 
		if (sum1+=a[i],_abs(sum2-sum1-sum1)<mmh) mmh=abs(sum2-sum1-sum1);
    printf("%lld\n",mmh);
}

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

long long modmul(long long a, long long b, long long mod){
	return a*b%mod;
}

long long modnjo(long long a, long long n, long long mod){
	if(n==0)return 1;
	if(n%2==1)return a*modnjo(a, n-1, mod)%mod;
	return modnjo(a*a%mod, n/2, mod);
}

long long modinv(long long a, long long mod){
	return modnjo(a, mod-2, mod);
}

long long moddiv(long long a, long long b, long long mod){
	return modmul(a, modinv(b, mod), mod);
}

int SosuNum = 10;
int Sosu[10] = {
1000000007,
1000000009,
1000000021,
1000000033,
1000000087,
1000000093,
1000000097,
1000000103,
1000000123,
1000000181};
int isVisit[114514];
int cst[114514][10];

vector<vector<pair<int, long long> > > edges;

void dfs(int p){
	for(int i=0;i<edges[p].size();i++){
		if(!isVisit[edges[p][i].first]){
			isVisit[edges[p][i].first] = 1;
			for(int j=0;j<SosuNum;j++){
				if(edges[p][i].second > 0)cst[edges[p][i].first][j] = modmul(cst[p][j], edges[p][i].second, Sosu[j]);
				else cst[edges[p][i].first][j] = moddiv(cst[p][j], -edges[p][i].second, Sosu[j]);
			}
			dfs(edges[p][i].first);
		}
	}
}


int main(){
	int N,M;
	scanf("%d%d", &N, &M);
	//int isVisit[N];
	for(int i=0;i<N;i++)isVisit[i]=0;
	edges.assign(N, vector<pair<int,long long> >(0));
	for(int i=0;i<M;i++){
		long long a,b,x;
		scanf("%lld%lld%lld", &a, &b, &x);
		a--;b--;
		edges[a].push_back(make_pair(b, x));
		edges[b].push_back(make_pair(a, -x));
	}

	//long long cst[N][SosuNum];
	for(int i=0;i<N;i++)for(int j=0;j<SosuNum;j++)cst[i][j]=0;
	for(int i=0;i<N;i++)if(cst[i][0]==0){
		for(int j=0;j<SosuNum;j++)cst[i][j]=1;
		dfs(i);
	}
	//for(int i=0;i<N;i++)printf("%d %d\n", i, cst[i][0]);
	bool isOK = true;
	for(int i=0;i<N;i++)for(int j=0;j<edges[i].size();j++){
		if(edges[i][j].second > 0){
			for(int k=0;k<SosuNum;k++)if(modmul(cst[i][k], edges[i][j].second, Sosu[k]) != cst[edges[i][j].first][k]) /*printf("NG!!(%d, %d)\n", i, edges[i][j].first); */isOK = false;
		}
	}
	printf(isOK?"Yes\n":"No\n");
	return 0;
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    deque<char> dq;
    rep(i, s.size()) {
        dq.push_back(s[i]);
    }
    int q; cin >> q;
    int cnt_rev = 0;
    // reverseの回数が偶数の時は，元どおりなのでそのまま，奇数の時は逆側に追加すればよい
    rep(i, q) {
        int t; cin >> t;
        if (t == 1) {
            cnt_rev++;
            continue;
        } else {
            int f; cin >> f;
            char c; cin >> c;
            if (f == 1) {
                if (cnt_rev % 2 == 0) {
                    dq.emplace_front(c);
                } else {
                    dq.emplace_back(c);
                }
            } else {
                if (cnt_rev % 2 == 0) {
                    dq.emplace_back(c);
                } else {
                    dq.emplace_front(c);
                }
            }
        }
    }
    // if (cnt_rev % 2 != 0) reverse(ALL(s));
    if (cnt_rev % 2 == 0) {
        rep(i, dq.size()) {
            cout << dq[i];
        }
        cout << endl;
    } else {
        for (int i=dq.size()-1; i>=0; --i){
            cout << dq[i];
        }
        cout << endl;
    }

    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
#define MAX_N 51
ll all[MAX_N];
ll patty[MAX_N];


ll solve(ll l, ll e){
  if(e == 0)
    return 0;

  else if(l == 0 && e == 1)
    return 1;

  else if(1 <= e && e <= all[l-1]+1)
    return solve(l-1, e-1);

  else if(e == all[l-1]+2)
    return patty[l-1]+1;

  else if(all[l-1] + 3 <= e && e <= 2*all[l-1] + 2)
    return patty[l-1]+1+solve(l-1, e-(all[l-1] + 2));

  else
    return 2*patty[l-1]+1;



}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, x;
  cin >> n >> x;

  all[0] = 1;
  patty[0] = 1;
  REP1(i, MAX_N){
    all[i] = 3+2*all[i-1];
    patty[i] = 1+2*patty[i-1];
  }


  ll ans = solve(n, x);

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=100000000000000LL;
const int MAX=100001;
const double EPS=1e-10;
int main() {
    int n;ll x;
    cin>>n>>x;
    ll a[2020];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll b[2020][2020]={};
    ll ans=INF;
    for(int i=0;i<n;i++){
        b[i][0]=a[i];
        for(int j=1;j<n;j++){
            int idx=i-j;
            if(idx<0){
                idx=n+idx;
            }
            b[i][j]=min(b[i][j-1],a[idx]);
        }
    }
    for(int i=0;i<n;i++){
        ll m=x*i;
        for(int j=0;j<n;j++){
            m+=b[j][i];
        }
        ans=min(ans,m);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 32128
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int main()
{
  int n,h[100005];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>h[i];
  }
  dp[1]=0;
  dp[2]=abs(h[2]-h[1]);
  for(int i=3;i<=n;i++){
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
  }
  cout<<dp[n]<<"\n";
  return 0;
}


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

#define SIZE 1001

int Char_Change_Int( char c );

int main()
{
	char num;
	string str;
	int sum = 0;
	
	while( 1 )
	{
		//cout << "??\??????????????????" << endl << ">";
		cin >> str;
		
		num = str[0];
		if( num == '0' && str.size() == 1 )
		{
			//cout << "????????°???????????????????????????" << endl;
			break;
		}
		
		//cout << "??\?????????????????????" << str << endl;
		
		for( int i = 0; i < str.size(); i++ )
		{
			sum += Char_Change_Int(str[i]);
		}
		
		cout /* << "??\????????????" */ << sum << endl;
		str.clear();
		sum = 0;
	}
	return 0;
}

int Char_Change_Int( char c )
{
	int tmp;
	char zero = '0';
	
	tmp = (int)c - (int)zero;
	
	return tmp;
}

Measured memory_bytes: 1184
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

# [a, b].min が遅いので
def min(a, b)
  return a < b ? a : b
end

A, B, M = gets_i_list
a_list = gets_i_list
b_list = gets_i_list

total = a_list.min + b_list.min
M.times do
  x, y, c = gets_i_list
  total = min(a_list[x - 1] + b_list[y - 1] - c, total)
end

puts total

Measured memory_bytes: 20452
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n = int(input())
    a = Input()
    count = 0
    for i in range(1, n-1):
        if a[i] == sorted((a[i-1], a[i], a[i+1]))[1]:
            count += 1

    print(count)

main()

Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint n;
llint k;
string s;
llint cnt=0;
llint l;


void solve(){
	cin >>n;
	cin >> s;
  llint r=count(s.begin(),s.end(),'R');
  llint g=count(s.begin(),s.end(),'G');
  llint b=count(s.begin(),s.end(),'B');
  llint cnt=r*g*b;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=n;j++){
      if(j*2-i>=n)continue;
      set<char>st;
      st.insert(s[i]);
      st.insert(s[j]);
      st.insert(s[j*2-i]);
      if(st.size()==3)cnt--;
    }
  }

  cout << cnt << endl;
}

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


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

int main(void)
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, 0, n) cin >> h[i];
    int ans = 0;
    int mx = 0;
    rep(i, 0, n) if (mx <= h[i]) ans++, mx = h[i];
    cout << ans << endl;
}


Measured memory_bytes: 3600