akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main(){
	string s;
	cin >> s;
	ll n = s.size();
	s = "#" + s;

	bool exist = true;
	if(s[1] == '0' || s[n] == '1'){
		exist = false;
	}
	exrep(i, 1, n-1) {
		if(s[i] != s[n - i]){
			exist = false;
		}
	}

	if(!exist){
		out(-1);
		re0;
	}
    
	s[n] = '1';
	queue<ll> Q;
	exrep(i, 1, n) {
		if(s[i] == '1'){
			Q.push(i);
		}
	}
    
	exrep(i, 1, n-1) {
		if(i == Q.front()) {
			Q.pop();
		}
		cout << i << " " << Q.front() << "\n";
	}

	re0;
}

Measured memory_bytes: 2300
#include<stdio.h>
#include<math.h>
 
 
int main(){
 
  int n, i;
  double x[100], y[100],s[100], max=0, d1=0, d2=0, d3=0,d22,d33;
  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%lf", &x[i]);
  for(i=0;i<n;i++) scanf("%lf", &y[i]);
 
  for(i=0;i<n;i++){
    s[i]=fabs(x[i]-y[i]);

    d1+=s[i];
    d2+=pow(s[i], 2);
    d3+=pow(s[i], 3);
    if(max<s[i]) max=s[i];
  }
  d22=sqrt(d2);
 d33=cbrt(d3);

  printf("%f\n%f\n%f\n%f\n", d1, d22, d33, max);
 
  return 0;
}


Measured memory_bytes: 2104
#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];
	}

	if(a[0]!=0)
		a[0]--;

	for(int i=1;i<n;i++){
		if(a[i]>a[i-1]){
			a[i]--;
		}
	}

	for(int i=1;i<n;i++){
		if(a[i-1] > a[i]){
			cout << "No" << "\n";
			return 0;
		}
	}

	cout << "Yes" << "\n";

	return 0;


}

Measured memory_bytes: 640
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vc vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

ll extgcd(ll a, ll b)
{
	ll x = 1, y = 0, u = 0, v = 1;
	while (b > 0) {
		ll q = a / b;
		ll tmp = u; u = x - q * u; x = tmp;
		tmp = v; v = y - q * v; y = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}
	return a;
}

ll gcd(ll m, ll n)
{
	if (!m || !n)
		return 0;
	while (m != n)
	{
		if (m > n) m = m - n;
		else n = n - m;
	}
	return m;
}

ll lcm(ll m, ll n)
{
	if (!m || !n)
		return 0;
	return ((m / extgcd(m, n)) * n);
}

int main()
{
	ll n, ans = 1;
	cin >> n;
	vc v(n);
	REP(i, n) cin >> v[i];
	REP(i, n)
	{
		ans = lcm(ans, v[i]);
	}
	cout << ans << endl;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (A >= 13) cout << B << endl;
    else if (A >= 6 && A <= 12) cout << B / 2 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int A[4];
int main()
{
    int a,b;
    cin>>a>>b;
    A[a]=1;
    A[b]=1;
    if(A[1]==0)
      cout<<1;
    else if(A[2]==0)
      cout<<2;
    else if(A[3]==0)
      cout<<3;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
	cin.sync_with_stdio(0);
	// cin.tie(0);

	ll k, x;
	cin >> k >> x;
	FOR(i,x-k+1,x+k) {
		cout << i << " ";
	}
	cout << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL N,a[300010],l[300010],r[300010];
multiset<LL> st;

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

    int i;
    for (i=1; i<=3*N; i++) cin >> a[i];

    st.clear(); LL sum=0;
    for (i=1; i<=3*N; i++){
        if (st.size()<N){
            sum+=a[i];
            st.insert(a[i]);
        }
        else{
            LL val=(*st.begin());
            if (val<a[i]){
                sum-=val,sum+=a[i];
                st.erase(st.begin());
                st.insert(a[i]);
            }
        }

        l[i]=sum;
    }

    st.clear(); sum=0;
    for (i=3*N; i>0; i--){
        if (st.size()<N){
            sum+=a[i];
            st.insert(a[i]);
        }
        else{
            multiset<LL>::iterator it =st.end();
            it--;
            LL val=*it;
            if (val>a[i]){
                sum-=val,sum+=a[i];
                st.erase(st.find(val));
                st.insert(a[i]);
            }
        }

        r[i]=sum;
    }

    LL res=-(1LL<<60);
    for (i=N; i<=2*N; i++)
        res=max(res,l[i]-r[i+1]);
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int dis[10000][10000];
int main() {
  int n,x,y;
  cin >> n >> x >> y;
  int a=y-x-1,c=(x+y)/2;
  vector<int> b(n+1,0);
  r2(i,n){
    for(int j=i+1; j<=n; j++) b.at(min(j-i,abs(x-i)+1+abs(y-j)))++;
  }
  r2(i, n) cout << b.at(i) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;

const int maxn = 1e6+6;
int fa[maxn];
int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
int id(int x,int y,int z) {
	return (x-1)*6 + y*3 + z;
}
int gcd(int a,int b) {
	return !b?a:gcd(b,a%b);
}
int n,m,q,mod;
int c[maxn],a[maxn],b[maxn];
void adg(int x,int y) {
	x = gf(x); y = gf(y);
	if(x!=y) fa[x] = y;
}
bool ycl[2][maxn];
int main() {
	scanf("%d%d%d%d",&n,&m,&q,&mod);
	for(int i=1;i<=maxn-5;i++) fa[i] = i;
	int g = 0;
	for(int i=1;i<=m;i++) {
		int x,y; scanf("%d%d%d",&x,&y,&c[i]);
		a[i] = x; b[i] = y;
		g = gcd(g,abs(c[i]-c[1]));
	}
	if(!g) g = mod;
	mod = gcd(mod,3*g);
	int z = c[1]%g;
	for(int i=1;i<=m;i++) {
		int x,y,o;
		x = a[i]; y = b[i];
		o = (c[i]-z)/g%3;
		for(int j=0;j<3;j++) {
			for(int k=0;k<2;k++) {
				adg(id(x,k,j),id(y,k^1,(2*j+o)%3));
				adg(id(y,k,j),id(x,k^1,(2*j+o)%3));
			}
		}
	}
	int j = z;
	for(int i=0;;i++,j = (j*2)%mod ) {
		if(ycl[i&1][j]) break;
		ycl[i&1][j] = 1;
	}
	for(int i=1;i<=q;i++) {
		int s,t,r; scanf("%d%d%d",&s,&t,&r);
		bool mk = 0;
		for(int j=0;j<3;j++) {
			for(int k=0;k<2;k++) {
				if(gf(id(t,0,0))==gf(id(s,k,j))) {
					if(ycl[k][(r+z+(3-j)*g)%mod]) {
						mk = 1; break;
					}
				}
			}
			if(mk) break;
		}
		if(mk) puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 13952
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ulong = unsigned long;
using ll = long long;
const int M = 1e9 + 7;
#pragma unused(M)

int main(){
	int n, x;
	cin >> n >> x;
	int s = x - n;
	if(x == 1 || x == 2*n-1){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for(int i=0;i<2*n-1;i++){
		cout << (s + i + 2*n-1) % (2*n-1) + 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
int cou(int x)
{
    int count=0;
    while(x%10!=0)
    {
        x++;
        count++;
    }
    return count;
}
    
    
using namespace std;
int main(void){
    long long int i=0,j,a,b,c,d,e,a1,b1,c1,d1,e1,m;
    string s;
    cin >> a >> b >> c >> d >> e;
    a1=cou(a);
    b1=cou(b);
    c1=cou(c);
    d1=cou(d);
    e1=cou(e);
    m=max({a1,b1,c1,d1,e1});
    cout << a+b+c+d+e+a1+b1+c1+d1+e1-m << endl;
    return 0;

}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n>>a;
  ll ar[n];
  rep(i,0,n) cin>>ar[i];
  rep(i,0,n)
  {
    m+=ar[i];
    if(m>a) break;
    k++;
  }
  //k=min(n+a,min(n+b,a+b));
  cout<<k+1;
  /*if(n<a) cout<<0;
  else cout<<10;*/
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
 //  cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3652
def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    ans = [[float("inf")] * (W) for _ in range(H)]
    if S[0][0] == "#":
        ans[0][0] = 1
    else:
        ans[0][0] = 0
    for i in range(H):
        for j in range(W):
            tmp = ans[i][j]
            if 0 < i:
                tmp = min(tmp, ans[i-1][j] +
                          (1 if S[i-1][j] == "." and S[i][j] == "#" else 0))
            if 0 < j:
                tmp = min(tmp, ans[i][j-1] +
                          (1 if S[i][j-1] == "." and S[i][j] == "#" else 0))
            ans[i][j] = tmp
    print(ans[H-1][W-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 42480
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
int const MOD = 1000000007;
#define END {cout<<END<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n';
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int n,m,q,_,x,y;
string s,t;
const char* sb;
bool ok;
char ch;

int main(){
  cin.tie(nullptr); ios::sync_with_stdio(false);
  
  cin>>n>>m; queue<pair<string,int>>op; int t=0;
  rep(i,n){
    string s; int x; cin>>s>>x;
    op.push(pair<string,int>(s,x));
  }
  pair<string ,int>p;
  while(!op.empty()){
    p=op.front(); op.pop();
    if(p.second>m){p.second-=m; t+=m; op.push(p);}
    else{t+=p.second; cout<<p.first<<' '<<t<<'\n';}
  }
}


Measured memory_bytes: 6292
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	long long  a[100005],b[100005];
	cin >> n;
	for(int i=0;i<=n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	long long cnt=0;
	for(int i=0;i<n;i++){
		if((a[i] + a[i+1]) <= b[i]){
			cnt=cnt+a[i]+a[i+1];
			a[i+1]=0;			
		}
		else{
			cnt=cnt+b[i];
			if(a[i] <= b[i]){
				b[i]=b[i]-a[i];
				a[i+1]=a[i+1]-b[i];
			}
		} 				
	}
	printf("%lld\n",cnt);
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int A;
  int B;
  cin >> A>> B;
  if(((A==1) && (B==3)) || ((A==3) && (B==1))) {
cout << 2<< endl;
  }
  else if(((A==1) && (B==2)) || ((A==2) && (B==1))) {
cout << 3<< endl;
  }
  else if(((A==2) && (B==3)) || ((A==3) && (B==2))) {
cout << 1<< endl;
  }
  
}


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

ll a(int i) {
    if(i == 0) {
        return 1;
    }

    return 2*a(i-1) + 3;
}

ll p(int i) {
    if(i == 0) {
        return 1;
    }

    return 2*p(i-1) + 1;
}

ll f(int n, ll x) {
    if(n == 0) {
        return 1;
    }
    if(x == 1) {
        return 0;
    }
    else if(x <= a(n-1) + 1) {
        return f(n-1, x-1);
    }
    else if(x == a(n-1) + 2) {
        return p(n-1) + 1;
    }
    else if(x <= 2*a(n-1) + 2) {
        return p(n-1) + 1 + f(n-1, x - 2 - a(n-1));
    }
    else if(x == a(n)) {
        return p(n);
    }
}

int main() {
    int n;
    ll x;
    cin >> n >> x;

    cout << f(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int x,a,b,c,d;
    scanf("%d%d%d",&x,&a,&b);
    c=sqrt((x-a)*(x-a));
    d=sqrt((x-b)*(x-b));
    if(c>d)
    {
        printf("B");
    }
    else
    {
        printf("A");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        Arrays.sort(s);
        Arrays.sort(t);
        String ts = new StringBuilder(new String(t)).reverse().toString();
        System.out.println(new String(s).compareTo(ts) < 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 21972
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << arr[k - 1] << '\n';
}


Measured memory_bytes: 888
#include <iostream>
#include<math.h>
 
int main()
{
    double A,B,H,M;
    double r;
    std::cin>>A>>B>>H>>M;
    H=(H*60+M)*.5;
    H > M*6 ? r = H - M*6 : r = M*6 - H;
    if(r>180)
    {
        r=360-r;
    }
    r = (double)((r  * M_PI) / 180.0);
    printf("%.10lf\n",sqrt((double)(A*A+B*B)-(double)(2*A*B*cos(r))));
    return 0;
}

Measured memory_bytes: 3588
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut ans = 0;
    let mut cur = 0;
    let mut cnt = 0;
    for _ in 0..n {
        let h: usize = scan(tokens);
        if h <= cur {
            cnt += 1;
            ans = std::cmp::max(ans, cnt);
        } else {
            cnt = 0;
        }
        cur = h;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**9 + 7
EPS = 10**-10

class UnionFind:
    """ Union-Find木 """

    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n
        self.tree = [True] * n
        self.grpcnt = n

    def find(self, x):
        """ 根の検索(グループ番号の取得) """
        t = []
        while self.par[x] != x:
            t.append(x)
            x = self.par[x]
        for i in t:
            self.par[i] = x
        return self.par[x]

    def union(self, x, y):
        """ 併合 """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        self.grpcnt -= 1
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def is_same(self, x, y):
        """ 同じ集合に属するか判定 """
        return self.find(x) == self.find(y)

    def get_size(self, x=None):
        if x is not None:
            """ あるノードの属する集合のノード数 """
            return self.size[self.find(x)]
        else:
            """ 集合の数 """
            return self.grpcnt
    
    def is_tree(self, x):
        """ 木かどうかの判定 """
        return self.tree[self.find(x)]

N, M = MAP()
uf = UnionFind(N)
for i in range(M):
    a, b = MAP()
    a -= 1; b -= 1
    uf.union(a, b)

ans = uf.get_size() - 1
print(ans)


Measured memory_bytes: 15820
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,k;
    cin >> n >> k;
    ll i=0;
    while(n>0)
    {
        n=n/k;
        i++;
    }
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int Ans = 0;
  
  for (int i = 0; i < N; i++) {
    int r_i , l_i;
    cin >> l_i >> r_i;
    
    Ans += r_i - l_i + 1;
  }
  
  cout << Ans << endl;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
dp = [[0] * (W+1) for i in range(N+1)]

for i in range(N):
  w, v = map(int, input().split())
  for j in range(W+1):
    dp[i+1][j] = max(dp[i][j-w] + v, dp[i][j]) if j >= w else dp[i][j]
print(max(dp[-1]))

Measured memory_bytes: 119916
#include <stdio.h>

int binarySearch(int a[],int k,int head,int tail){
    if(tail<head)return -1;
    
    int mid=(head+tail)/2;
    if(a[mid]==k)return mid;
    else if(a[mid]<k)head=mid+1;
    else if(a[mid]>k)tail=mid-1;
    
    return binarySearch(a,k,head,tail);
}

int main(void){
    int i;
    
    int n;
    scanf("%d\n",&n);
    int a[n];
    for(i=0;i<n;i++)scanf("%d ",&a[i]);
    
    int m;
    scanf("%d\n",&m);
    if(m>n){
        printf("0\n");
        return 0;
    }
    int b[m];
    for(i=0;i<m;i++)scanf("%d ",&b[i]);
    
    int j;
    for(i=0,j=0;i<m;i++){
        j=binarySearch(a,b[i],j,n-1);
        if(j==-1||m-i>n-j){
            printf("0\n");
            return 0;
        }
        j++;
    }
    
    printf("1\n");
    
    return 0;
}



Measured memory_bytes: 3236
#include<stdio.h>
int main()
{
  int h,w,x,y;
  while(1){scanf("%d%d",&h,&w);
    if(h==0&&w==0)break;
      for(x=0;x<h;x++){
      for(y=0;y<w;y++){
	if((x+y)%2==0){printf("#");
	}	  else{printf(".");
	}
      }printf("\n");
      }
      printf("\n");
      }  
      return 0;
  }

Measured memory_bytes: 572
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
int main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

lint segdata[(1<<19)-1];
lint lazy[(1<<19)-1];

lint neutral(){
    return 0; //単位元
}
lint calc(lint a,lint b){
    return (a+b)%MOD; //演算
}
void seginit(){
    rep(i,(1<<19)-1) segdata[i]=neutral();
}
void update(lint i,lint x){ // i番目の値をxに更新 rangeadd()の後に使ったらだめ 単位元が0以外の時だけ使う
    i+=(1<<18)-1;
    segdata[i]=x;
    while(i>0){
        i=(i-1)/2;
        segdata[i]=calc(segdata[i*2+1],segdata[i*2+2]);
    }
}
void eval(lint k,lint l,lint r){
    if(lazy[k]){
        segdata[k]+=lazy[k];
        if(r-l>1) lazy[2*k+1]+=lazy[k]/2,lazy[2*k+2]+=lazy[k]/2;
        lazy[k]=0;
    }
}
void add(lint a,lint b,lint x,lint k,lint l,lint r){
    eval(k,l,r);
    if(r<=a || b<=l) return;
    if(a<=l && r<=b){
        lazy[k]+=(r-l)*x;
        eval(k,l,r);
    }
    else{
        add(a,b,x,2*k+1,l,(l+r)/2);
        add(a,b,x,2*k+2,(l+r)/2,r);
        segdata[k]=calc(segdata[2*k+1],segdata[2*k+2]);
    }
}
lint seg(lint a,lint b,lint k,lint l,lint r){
    eval(k,l,r);
    if(r<=a || b<=l) return neutral();
    if(a<=l && r<=b) return segdata[k];
    else{
        lint left=seg(a,b,k*2+1,l,(l+r)/2);
        lint right=seg(a,b,k*2+2,(l+r)/2,r);
        return calc(left,right);
    }
}
lint query(lint a,lint b){
    return seg(a,b+1,0,0,1<<18); //a~b(閉区間）の範囲での演算
}
void rangeadd(lint a,lint b,lint x){ //a~b(閉区間)にxを加算
    add(a,b+1,x,0,0,1<<18); 
    return;
}

int main(void){
    lint N,K;
    cin >> N >> K;
    lint L[K],R[K];
    rep(i,K) cin >> L[i] >> R[i];
    seginit();
    rangeadd(0,0,1);
    rep(i,N-1){
        rep(j,K){
            int l=i+L[j],r=i+R[j];
            if(l>=N) continue;
            if(r>=N) r=N-1;
            rangeadd(l,r,query(i,i));
        }
    }
    cout << query(N-1,N-1) << endl;
}

Measured memory_bytes: 10864
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

long long int gcd(long long int A,long long int B){
 long long int tmp;
 while(A%B!=0){
  tmp=A%B;
  A=B;
  B=tmp;
 }
 return B;
}

int main(void){
 long long int A,B,C,D;
 int T;
 long long int g;
 cin>>T;
 for(int i=0; i<T; i++){
  cin>>A>>B>>C>>D;
  std::cout<<std::endl;
  g=gcd(B,D);
  //std::cout<<"gcd(B,D)"<<g<<std::endl;
  if(A<B)std::cout<<"No"<<std::endl;
  else if(D<B)std::cout<<"No"<<std::endl;
  else if(C>=B)std::cout<<"Yes"<<std::endl;
  else if((B-g+(A%g))>C)std::cout<<"No"<<std::endl;
  else std::cout<<"Yes"<<std::endl;
 }
 return 0;
}
     
     




Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

ll N;
constexpr ll MOD = 1e9 + 7;
map<tuple<ll, char, char, char>, pair<bool, ll>> memo;

ll solve(ll i, char j, char k, char l) {
    if (i == N) {
        return 1;
    }

    auto curr = make_tuple(i, j, k, l);
    if (memo[curr].first) {
        return memo[curr].second;
    }
    memo[curr].first = true;

    ll ans = 0;
    if ((j == 'A' && l == 'G') || (j == 'A' && k == 'G') || (k == 'G' && l == 'A') || (k == 'A' && l == 'G')) {
        (ans += solve(i + 1, k, l, 'A')) %= MOD;
        (ans += solve(i + 1, k, l, 'T')) %= MOD;
        (ans += solve(i + 1, k, l, 'G')) %= MOD;
    } else if (k == 'A' && l == 'C') {
        (ans += solve(i + 1, k, l, 'A')) %= MOD;
        (ans += solve(i + 1, k, l, 'T')) %= MOD;
        (ans += solve(i + 1, k, l, 'C')) %= MOD;
    } else {
        (ans += solve(i + 1, k, l, 'A')) %= MOD;
        (ans += solve(i + 1, k, l, 'T')) %= MOD;
        (ans += solve(i + 1, k, l, 'C')) %= MOD;
        (ans += solve(i + 1, k, l, 'G')) %= MOD;
    }

    return memo[curr].second = ans;
}

int main() {
    cin >> N;
    cout << solve(0, 'X', 'X', 'X') << endl;
}

Measured memory_bytes: 768
S = input()
s = len(S)
ans = list()
if s == 2:
  print(1)

for i in range(1,(s+2)//2):
  a = s - i*2
  if a == 0:
    ans.append(1)
  test = S[0:a]
  n = 0
  while True:
    if n == a/2:
      ans.append(len(test))
      break
    elif test[n] != test[n + a//2]:
      break
    else:
      n += 1
print(max(ans))

Measured memory_bytes: 3064
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

//#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



int main() {
	int a,n, m;
	cin >> n >> m;
	set<int>s;
	rep(i, m) {
		cin >> a;
		s.insert(a+1);
	}
	vector<int>vec(n + 3,0);
	vec[0] = 0;
	vec[1] = 1;
	for (int i = 2; i < n + 2; i++) {
		if (s.count(i)) {
			continue;
		}
		vec[i] = vec[i - 1] + vec[i - 2];
		vec[i] %= mod;
	}
	cout << vec[n + 1] << endl;
}


Measured memory_bytes: 5376
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import Data.Bits
import Data.Coerce
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

int64Log2 :: Int64 -> Int
int64Log2 x = finiteBitSize x - countLeadingZeros x - 1

naive :: Int64 -> Int64 -> [(Int64, Int64)]
naive l r = [(x,y) | x <- [l..r], y <- [x..r], y `rem` x == y `xor` x]

solve :: Int64 -> Int64 -> N
solve l r | l > r  = 0
          | l == r = 1
          | log2l == log2r = solve2 l r log2l
          | otherwise = solveL l log2l + solveR r log2r + sum [3^i | i <- [log2l+1 .. log2r-1]]
  where
    log2l = int64Log2 l
    log2r = int64Log2 r
    solve2 l r i | int64Log2 l /= i || int64Log2 r /= i = error ("invalid " ++ show (l,r,i))
                 -- Precondition: l < r, int64Log2 l == int64Log2 r
                 | otherwise = loop i
      where loop i | i < 0 = 1
                   | otherwise = case (testBit l i, testBit r i) of
                                   (False, False) -> loop (i-1)
                                   (False, True) -> solveL l (i-1) + solveR r (i-1) + loop (i-1)
                                   (True, True) -> loop (i-1)
                                   (True, False) -> 0

solveL l i | i < 0 = 1
           | otherwise = if testBit l i
                         then solveL l (i-1)
                         else 2 * solveL l (i-1) + 3^i

solveR r i | i < 0 = 1
           | i == int64Log2 r = solveR r (i-1)
           | otherwise = if testBit r i
                         then 2 * solveR r (i-1) + 3^i
                         else solveR r (i-1)

main = do
  [l,r] <- map fromInteger . unfoldr (BS.readInteger . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve l r

--
-- Modular Arithmetic
--

modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined

{-# RULES
"^9/Int" forall x. x ^ (9 :: Int) = let u = x; v = u * u * u in v * v * v
"^9/Integer" forall x. x ^ (9 :: Integer) = let u = x; v = u * u * u in v * v * v
 #-}


Measured memory_bytes: 380
n, m, x = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]

INF = 10**9
ans = INF
for i in range(2**n):
    cost = 0
    y = [0]*m
    for j in range(n):
        flg = i & 1
        if flg:
            cost += a[j][0]
            for cm in range(m):
                y[cm] += a[j][cm+1]
        i >>= 1
    for cm in range(m):
        if y[cm] < x:
            break
        if cm == m-1:
            ans = min(ans, cost)
print(ans) if ans < INF else print(-1)

Measured memory_bytes: 9220
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> V;

int contains(V &v, int i) {
    return find(v.begin(), v.end(), i) != v.end();
}

int main() {
    int x, y;
    cin >> x >> y;
    V v1 = {1, 3, 5, 7, 8, 10, 12};
    V v2 = {4, 6, 9, 11};
    V v3 = {2};
    bool isSame = false;
    if ((contains(v1, x) && contains(v1, y))
        || (contains(v2, x) && contains(v2, y))) {
        isSame = true;
    }
    if (isSame) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int main()
{
    int x,y,z,i,j;
    scanf("%d",&x);
    scanf("%d",&y);
    z=(x+y)/2;
    i=abs(x-z);
    j=abs(y-z);
    if(i==j)
        printf("%d\n",z);
    else
        printf("IMPOSSIBLE\n");

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct RollingHash{
  using ull = unsigned long long;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(const string &S,ull B=1000000007LL){
    int n=S.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l, r)
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};
//END CUT HERE

signed main(){
  string t,p;
  cin>>t>>p;
  RollingHash rt(t),rp(p);
  for(int i=0;i<(int)(t.size()-p.size())+1;i++){
    if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout<<i<<endl;
  }
  return 0;
}
/*
  verified on 2017/10/29
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B&lang=jp
*/



Measured memory_bytes: 19824
#include <iostream>
using namespace std;
int main(){
    int a,b; cin >> a >> b;
    int ans=0;
    for (int i=a; i<=b; i++){
        int p = i / 1000, e = i % 100;
        int pp = p/10, pe=p%10, ep=e/10, ee=e%10;
        if (pp==ee && pe==ep) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
char s[104];
string p[100004];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        cin>>p[i];
        sort(p[i].begin(),p[i].end());
    }
    sort(p+1,p+n+1);
    ll ans=0;
    for(int i=1;i<=n;i++){
        int st=i;
        while(st<=n&&p[st]==p[i]){
            st++;
        }
        ll temp=st-i;
        ans+=1LL*temp*(temp-1)/2;
        i=st-1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7296
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

ll a,b,c;
int main() {
	scanf("%lld%lld%lld",&a,&b,&c);
	if (a%2==0||b%2==0||c%2==0) {
		puts("0");
	} else {
		printf("%lld\n",min(a*min(b,c),b*c));
	}
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<pair<int,int> >ans;
vector<int>G[1<<17];
int N;
int A[2<<17];
int bit[2<<17];
int table[3][20][2<<17];
int query(int L,int R,int w)
{
	int b=bit[R-L];
	int x=table[w][b][L],y=table[w][b][R-(1<<b)];
	return x==-1?y:y==-1?x:A[x]<A[y]?x:y;
}
int dfs(int L,int R)
{
	int mid=query(L,R,L%2?2:1),mmid=query(mid+1,R,mid%2?1:2),id=ans.size();
	ans.push_back(make_pair(-A[mid],-A[mmid]));
	if(L+1<mid)
	{
		G[id].push_back(dfs(L,mid));
	}
	if(mid+2<mmid)
	{
		G[id].push_back(dfs(mid+1,mmid));
	}
	if(mmid+2<R)
	{
		G[id].push_back(dfs(mmid+1,R));
	}
	return id;
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		table[0][0][i]=i;
		table[i%2?2:1][0][i]=i;
		table[i%2?1:2][0][i]=-1;
	}
	for(int i=2;i<=N;i++)bit[i]=bit[i>>1]+1;
	for(int w=0;w<3;w++)
	{
		for(int k=1;k<20;k++)
		{
			for(int i=0;i<=N-(1<<k);i++)
			{
				int x=table[w][k-1][i],y=table[w][k-1][i+(1<<k-1)];
				table[w][k][i]=x==-1?y:y==-1?x:A[x]<A[y]?x:y;
			}
		}
	}
	int root=dfs(0,N);
	priority_queue<pair<pair<int,int>,int> >P;
	P.push(make_pair(ans[root],root));
	while(!P.empty())
	{
		int id=P.top().second;
		pair<int,int>p=P.top().first;
		P.pop();
		cout<<-p.first<<" "<<-p.second<<" ";
		for(int v:G[id])
		{
			P.push(make_pair(ans[v],v));
		}
	}
	cout<<endl;
}

Measured memory_bytes: 73204
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int fie[101][101],ans,gol[101][101],st[101][101],col,muki,bx,by;
int bex[4]={0,1,0,-1},bey[4]={1,0,-1,0},cou,a,b;
    int sx,sy,gx,gy,n;
int func(int y,int x){
    if(fie[sy][sx]==-1)return 0;
    if(y<1||x<1||y>b||x>a)return 0;
    if(fie[y][x]==ans){
        fie[y][x]=0;
        for(int i=0;i<4;i++){
            func(y+bey[i],x+bex[i]);
        }
    }
    return 0;
}
int main(){
    for(;;){
        cin>>a>>b;
        if(a==0&&b==0)break;
        fill(fie[0],fie[0]+101*101,-1);
        cin>>sx>>sy>>gx>>gy;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>col>>muki>>bx>>by;
            if(muki==0){
                for(int i=0;i<=1;i++){
                    for(int j=0;j<=3;j++){
                        fie[by+i][bx+j]=col;
                    }
                }
            }
            if(muki==1){
                for(int i=0;i<=3;i++){
                    for(int j=0;j<=1;j++){
                        fie[by+i][bx+j]=col;
                    }
                }
            }
        }
        ans=fie[sy][sx];
        if(fie[sy][sx]!=0){
            func(sy,sx);
        }
        /*for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                cout<<fie[i][j];
            }
            cout<<endl;
        }*/
        if(!fie[gy][gx])cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
        cou=0;
        /*for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                cout<<fie[i][j];
            }
            cout<<endl;
        }*/
    }
return 0;
}
/*6 5
1 1
5 5
3
2 0 1 1
2 0 2 3
2 0 2 5
*/

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {

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

        int ans = 0;
        for (int i = 0; i < 4; i++) {
            if (s.charAt(i) == '+') {
                ans++;
            } else {
                ans--;
            }
        }
        System.out.println(ans);

        sc.close();
    }

}


Measured memory_bytes: 21844
def ceil(a,b):
    return (a+b-1)//b
X,K,D = map(int,input().split())
n = ceil(D*K-X,2*D)
n = max(0,n)
cand = [0,K,n,n-1]
ans = 10**15
for c in cand:
    if c<0 or c>K:
        continue
    x = abs((2*c-K)*D+X)
    ans = min(ans,x)
print(ans)

Measured memory_bytes: 9188
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=5005;
int n;
int a[4],b[4];
long long f[N*N];
int main()
{
	scanf("%d",&n);
	scanf("%d%d%d",&a[1],&a[2],&a[3]);
	scanf("%d%d%d",&b[1],&b[2],&b[3]);
	for(int i=1;i<=3;i++)
		if(b[i]>a[i])
		{
			for(int j=a[i];j<=n;j++)
				f[j]=max(f[j],f[j-a[i]]+b[i]);
		}
	long long ans=0;
	for(int j=0;j<=n;j++)
		ans=max(ans,f[j]+n-j);
	n=ans;
	memset(f,0,sizeof(f));
	for(int i=1;i<=3;i++)
		if(a[i]>b[i])
		{
			for(int j=b[i];j<=n;j++)
				f[j]=max(f[j],f[j-b[i]]+a[i]);
		}
	ans=0;
	for(int j=0;j<=n;j++)
		ans=max(ans,f[j]+n-j);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 199540
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, n; cin >> h >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        sum += v[i];
    }
    if(sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string> 
using namespace std;
int main()
{
	string str;
	cin>>str;
	int i;
	for(i=1;i<str.length();i++){
		if(str[i]==str[i-1]){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;

signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (d % 2 == 0)cout << a - b << endl;
	else { cout << (a - b)*-1 << endl; }
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll A,B; cin >> N >> A >> B;
    vector<int> p(N);
    for (int i=0;i<N;++i) cin >> p[i];
    vector<vector<ll>> dp(N+1,vector<ll>(N+1,INF));
    dp[0][0]=0;
    for (int i=0;i<N;++i){
        for (int j=0;j<=N;++j){
            if (p[i]>j){
                dp[i+1][p[i]]=min(dp[i+1][p[i]],dp[i][j]);
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]+A);
            } else dp[i+1][j]=min(dp[i+1][j],dp[i][j]+B);
        }
    }
    ll ans=INF;
    for (int j=0;j<=N;++j) ans=min(ans,dp[N][j]);
    cout << ans << '\n';
}

Measured memory_bytes: 195840
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    vll a(N + 1, 0), b(M + 1, 0);
    rep2(i, 1, N + 1) {
        ll x;
        cin >> x;
        a[i] = a[i - 1] + x;
    }
    rep2(i, 1, M + 1) {
        ll y;
        cin >> y;
        b[i] = b[i - 1] + y;
    }
    ll ans = 0;
    rep(i, N + 1){
        auto iter = upper_bound(all(b), K - a[i]);
        ll j = distance(b.begin(), iter) - 1;
        if (j < 0) continue;
        ans = max(ans, i + j);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6320
(defun main ()
  (declare (optimize (speed 3) (safety 0)))
  (let* ((n (read))
         (res 0))
    (declare ((unsigned-byte 62) res)
             ((unsigned-byte 32) n))
    (dotimes (i n)
      (incf res i))
    (princ res)
    (terpri)))

#-swank (main)


Measured memory_bytes: 10208
import java.util.Scanner;

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

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

		if (Math.min(n, m) == 1) {
			if (Math.max(n, m) == 1) {
				System.out.println(1);
			} else {
				System.out.println(Math.max(n, m) - 2);
			}
		} else {
			long ans = (long) (n - 2) * (long) (m - 2);
			System.out.println(ans);
		}
		sc.close();
	}
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

int main()
{
  int64_t N;
  vector<int64_t> A;

  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < A.size(); i++) {
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  int64_t result = 1;
  for (int i = 0; i < A.size(); i++) {
    if (log10(result) + log10(A[i]) > 18.0) {
      cout << -1 << endl;
      return 0;
    }
    result *= A[i];
  }

  if (result > 1000000000000000000) {
    cout << -1 << endl;
  }
  else {
    cout << result << endl;
  }

  return 0;
}


Measured memory_bytes: 4060
// https://atcoder.jp/contests/agc014/tasks/agc014_a

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long a, b, c;
    cin >> a >> b >> c;
    if (a > b)
        swap(a, b);
    if (a > c)
        swap(a, c);
    if (b > c)
        swap(b, c);

    if (a == b & b == c)
    {
        cout << (a & 1 ? 0 : -1) << endl;
        return 0;
    }

    int ans = 0;
    while (a % 2 == 0 & b % 2 == 0 & c % 2 == 0)
    {
        long na, nb, nc;
        na = (b + c) / 2;
        nb = (c + a) / 2;
        nc = (a + b) / 2;
        a = na;
        b = nb;
        c = nc;
        ans++;
    }

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

// 最大値と最小値の差が一回の操作で半分になる
// O(log(D))よりシミュレーションで間に合う
// 最小値==最大値がコーナーケースで
// 奇数なら一度も操作できない
// 偶数なら無限に操作できる


Measured memory_bytes: 3568
import java.util.*;

public class Main {

    /* チェックリスト
     * intの範囲を超えていないか
     * TLEしそうな処理の有無
     */
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String[] ss = sc.nextLine().split(" ");
        double a = Integer.parseInt(ss[0]); //X Z
        double b = Integer.parseInt(ss[1]); //Y
        double x = Integer.parseInt(ss[2]); //体積
        double menseki = x / a; //面積
        double sita = (menseki * 2) / b;
        double test = (a * b / 2) * a;
        if(test >= x) {
            double tanA = b / sita;
            System.out.println(Math.toDegrees(Math.atan(tanA)));
        }else{
            double hidari = (menseki * 2 / a) - b;
            double bx = b - hidari;
            double tanA = bx / a;
            System.out.println(Math.toDegrees(Math.atan(tanA)));

        }
    }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=200010;
vector<int> pos[20];
int a[maxn];
int main(){
	int n;
	scanf("%d",&n);
	ll ans=0;
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		for(int j=19;j>=0;j--)
			if(a[i]&(1<<j))
				pos[j].push_back(i);
		int l=1;
		for(int j=0;j<20;j++)
			if((int)pos[j].size()>1)
				l=max(l,pos[j][(int)pos[j].size()-2]+1);
		ans+=i-l+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9016
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int K = Integer.parseInt(S[1]);
    
    char[] num = new char[K];
    String[] T = sc.nextLine().split(" ");
    for(int i = 0; i < K; i++){
      num[i] = T[i].charAt(0);
    }
    
    con : for(int i = N; i < 100000; i++){
      String str = i + "";
      for(int j = 0; j < str.length(); j++){
        for(int k = 0; k < K; k++){
          if(str.charAt(j) == num[k]){
            continue con;
          }
        }
      }
      System.out.println(i);
      return;
    }
  }
}

Measured memory_bytes: 30036