akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
//#define int long long
using namespace std;
const int N = 1001;
set <pair<int, int> > s;
int a[N][N];


void solve(int F, int T, int A, int B, int n, int m) {
    int i, j;
    for (i = 0; i < T; ++i)
        s.insert({2 * B - n, i});
    for (i = T; i < m; ++i)
        s.insert({0, i});
    for (i = 0; i < n; ++i) {
        vector <pair<int, int> > v;
        if (i >= F) {
            for (j = 0; j < A; ++j) {
                pair <int, int> p= *s.begin();
                s.erase(p);
                a[i][p.se] = 1;
                v.push_back({p.fi + 1, p.se});
            }
        } else {
            for (j = 0; j < m - A; ++j) {
                pair <int, int> p = *s.begin();
                s.erase(p);
                a[i][p.se] = 1;
                v.push_back({p.fi + 1, p.se});
            }
        }
        for (j = 0; j < v.size(); ++j)
            s.insert(v[j]);
        for (j = 0; j < m; ++j)
            cout << a[i][j];
        cout << "\n";
    }
}


signed main() {
    int i, j, k, n, x, q, H, W, A, B;
    //freopen("input.txt", "r", stdin);
    cin >> H >> W >> A >> B;
    int c = A * H - B * W;
    for (int f = 0; f <= H; ++f)
    if (((H == 2 * B) && (c + f * (W - 2 * A) == 0)) || (H != 2 * B && (c + f * (W - 2 * A)) % (H - 2 * B) == 0 && (c + f * (W - 2 * A)) >= 0 && (c + f * (W - 2 * A)) / (H - 2 * B) <= W)) {
        if (H == 2 * B)
            solve(f, 0, A, B, H, W);
        else
            solve(f, (c + f * (W - 2 * A)) / (H - 2 * B), A, B, H, W);
        exit(0);
    }
    cout << -1;
}


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

int main() {
	// your code goes here
	string s;cin>>s;
	int c=0,d=0;
	for(int i=0;i<s.size();i++)
	{
		if(i%2==0)
		{
			if(s[i]=='R' || s[i]=='U' || s[i]=='D')
			{
				c++;
			}
		}
		else if(i%2!=0)
		{
			if(s[i]=='L' || s[i]=='U' || s[i]=='D')
			{
				c++;
			}
		}
	}
//	cout<<c<<endl;
	if(c!=s.size())
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)cin>>a[i];
  ll b[n];
  b[0]=0;
  b[1]=a[1]-a[0];
  if(b[1]<0)b[1]=-b[1];
  for(ll i=2;i<n;i++){
    ll c,d;
    c=a[i]-a[i-1];
    d=a[i]-a[i-2];
    if(c<0)c=-c;
    if(d<0)d=-d;
    if(b[i-1]+c<b[i-2]+d)b[i]=b[i-1]+c;
    else b[i]=b[i-2]+d;
    }
  cout<<b[n-1]<<endl;
  }


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

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,int(n)+1)
#define RREP(i,n) RFOR(i,0,n)
#define RREPS(i,n) RFOR(i,1,int(n)+1)
#define ALL(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void pvp(T a, T b) { for (T i = a; i != b; ++i) cout << "(" << i->first << ", " << i->second << ") "; cout << endl; }
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; }
int in() { int x; scanf("%d", &x); return x; }

using ll = long long;
#define int ll

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

int q;
int a, b;
int ans = 0;

int qu(int a, int b){
    int ab = a*b;
    double sq = sqrt(a*b);
    //debug(sq);
    sq=int(sq);
    //debug(sq);
    
    int sum = sq*2;
    if(ab>sq*(sq+1)) sum++;
    if(a==b) ans = sum-2;
    else if((sum-a)*(sum-b)<ab) ans = sum-2;
    else ans = sum-3;
    
    if(ab==sq*sq && a!=b) ans--;
    
    printf("%lld\n",ans);
    return 0;
}

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> q;
    
    REP(i,q){
        cin >> a >> b;
        qu(a,b);
    }
    
    return 0;
    
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mk make_pair
using namespace std;
int main()
{
	ll a,b;
	cin>>a>>b;
	if(a+b==15){
		cout<<"+";
	}
	else{
		if(a*b==15){
			cout<<"*";
		}
		else{
			cout<<"x";
		}
	}
}

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

parentheses = list(input())

add_open = 0
close_buff = 0

result = ""

for elem in parentheses:
    result += elem

    if elem == "(":
        close_buff += 1

    elif elem == ")":
        if close_buff > 0:
            close_buff -= 1
        else:
            add_open += 1

print("("*add_open + result + ")"*close_buff)


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

int main(){
	int n,i;
	double x[101]={0},y[101]={0},d[101]={0},D,p;
	
	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++){
		 d[i]=fabs(x[i]-y[i]);
	}
	
	for(p=1;p<5;p++){
		D=0;
		if(p==4){
			for(i=0;i<n;i++){
				if(D<d[i]) D=d[i];
			}
		}
		else{
			for(i=0;i<n;i++){
				D+=pow(d[i],p);
			}
			D=pow(D,1/p);
		}
		
		printf("%0.8f\n",D);
	}
	
    return 0;
}


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

int main(){
   int N, K;
   cin >> N >> K;
   vector<int> d(K);
   vector<int> A(N);
   for (int i=0; i<K; i++){
      cin >> d.at(i);
      for (int j=0; j<d.at(i); j++){
         int temp;
         cin >> temp;
         A.at(temp-1)++;
      }
   }
   int cnt = 0;
   for (int i=0; i<N; i++){
      if (A.at(i) == 0){
         cnt++;
      }
   }
   cout << cnt << endl;

}



Measured memory_bytes: 3628
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

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

  cout << min(a + b, min(a + c, b + c)) << endl;
}


Measured memory_bytes: 256
from math import gcd

mod = 10**9 +7
N = int(input())
dic = {}

zero = 0
for _ in range(N):
    a,b = map(int, input().split())
    if  a ==0 and b == 0:
        zero += 1
        continue
    elif a == 0:
        key = (0,1)
    elif b == 0:
        key = (1,0)
    else:
        if a<0:
            a=-a 
            b=-b
        g = gcd(a,abs(b))
        key = (a//g,b//g)
    
    if key not in dic:
        dic[key]=0

    dic[key] +=1

ans = 1
for k1, v1 in dic.items():
    if v1 ==0:
        continue

    if k1[1] >0:
        k2 = (k1[1],-k1[0])
    else:
        k2 = (-k1[1],k1[0])

    if k2 not in dic:
        ans *= 2**v1
        ans %= mod
    else:
        ans *= ((2**v1-1) %mod) + ((2**dic[k2]-1) %mod) +1
        ans %= mod
        dic[k2]=0

ans = (ans + zero -1 )%mod
print(ans)

Measured memory_bytes: 46144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(int i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(){
  ios::sync_with_stdio(false);
  ll N,M;
  cin>>N>>M;
  ll A[M];
  rep(i,M) cin>>A[i];
  
  ll ans = 0; 

  rep(i,M) ans+=A[i];
  
  if(ans>N){
  	cout<<-1;
  }else{
  	cout<<N-ans;
  }
    
    
  
}

Measured memory_bytes: 3688
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int cnt=0,max=0,ans=1;
    for(int i=1;i<=n;i++){
      cnt=0;
      int num=i;
      while(num%2==0){
        cnt++;
        num/=2;
      }
      if(max<cnt){
        ans=i;
        max=cnt;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
/*input
4 4

*/
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 

using namespace std;
long long mod=1e9+7;
typedef long long int lld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define Error(x) cerr << #x << " = " << (x) <<endl;
#define Error2(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c) cerr<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d) cerr<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define popcount __builtin_popcountll
typedef pair<lld,lld> PA;
#define lim 1000010
#define lim2 3003
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

lld B[lim],A[lim],C[lim];
// PA P[lim],Q[lim];
lld n,m,p,q;
// string S[lim],R[lim];
// vector<lld> V[lim];
// unordered_map<lld,lld> Ind;


lld powP(lld a,lld b){
    if(b==0) return 1%mod;
    lld k;
    k=powP(a,b/2);
    k=k*k%mod;
    if(b%2==0) return k;
    else return a*k%mod;
}
bool bitSet(lld n,lld i){
    if((n&(1LL<<i))!=0) return true;
    else return false;
}


int main(){
    lld T,i,j,h,l,r,b,k,c,a,d,w,x,y,v,z,t,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc2(n,k);
    if(n==1){
        printf("Yes\n1\n");
        return 0;
    }
    if(n==2){
        if(k==2) printf("Yes\n1\n2\n3\n");
        else printf("No\n");
        return 0;
    }
    if(k==1 || k==2*n-1){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    A[k]=A[k-1]=A[k+1]=1;
    B[n]=k;
    B[n-1]=k-1;
    B[n+1]=k+1;
    if(k-2>=1){
        A[k-2]=1;
        B[n+2]=k-2;
    }
    else{
        A[k+2]=1;
        B[n-2]=k+2;
    }
    i=1;
    j=1;
    while(i<=2*n-1){
        if(A[i]!=0) i++;
        else if(B[j]!=0) j++;
        else{
            B[j]=i;
            i++;
            j++;
        }
    }
    rep(i,1,2*n-1) prL(B[i]);
    return 0;
}


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

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template <typename T> using orderSet =
//tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long llu;
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout)
#define inf 1000000000000000018
#define mod 998244353
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
ll power(ll b,ll p){ll res=1,x=b;while(p > 0){if(p&1ll)res=res*x;x=x*x;p >>= 1;}return res;}

ll bigmod (ll b, ll p, ll m) {
    ll res = 1, x = b % m;
    while (p > 0) {
        if (p & 1) res = (res * x) % m;
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}

#define MX 1000006
ll g[MX], cnt[MX];
bool is_composite[MX];
vector <ll> primes;

void linear_multi_func()
{
	memset(is_composite, false, sizeof is_composite);

	g[1] = 1;
	for(int i = 2; i < MX; i++) {
        if(!is_composite[i]) {
			cnt[i] = 1;
			g[i] = 1-i;
			primes.pb(i);
        }

        for(int j = 0; j < primes.size() && i*primes[j] < MX; j++) {
            is_composite[i*primes[j]] = true;

            if(i%primes[j]==0) {
				cnt[i*primes[j]] = cnt[i]+1;
				ll x = power(primes[j], cnt[i]);
				g[i*primes[j]] = (g[primes[j]] * g[i/x]) % mod;
				break;
            }
			else {
				cnt[i*primes[j]] = 1;
				g[i*primes[j]] = (g[i] * g[primes[j]]) % mod;
			}
        }
	}
}

ll arr[200005], freq[MX], F[MX];

void f(ll n)
{
    for(ll d = 1; d <= n; d++) {
		for(ll i = d; i <= n; i+=d) {
			F[d] = (F[d] + (i*freq[i])%mod)%mod;
		}
    }
}

int main()
{
    linear_multi_func();

    ll n, mx = 0, ans = 0;

    scanf("%lld", &n);
    for(int i = 0; i < n; i++) {
		scanf("%lld", &arr[i]);
		ans -= arr[i];
		freq[arr[i]]++;
		mx = max(mx, arr[i]);
    }

    f(mx);
    for(ll l = 1; l <= mx; l++) {
        ans = (ans + (g[l] * ((((F[l]*bigmod(l, mod-2, mod)) % mod) * F[l])%mod))%mod)%mod;
    }
    ans = (ans + mod) % mod;
    ans = (ans * bigmod(2, mod-2, mod)) % mod;

    cout<<ans<<endl;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll n, ans = 0;;
  cin >> n;
  vector<ll> a(n), b(n), c(n-1);
  rep(i, n) { cin >> a[i]; a[i]--; }
  rep(i, n) { cin >> b[i]; ans += b[i]; }
  rep(i, n-1) cin >> c[i];

  rep(i, n-1) {
    if (a[i] + 1 == a[i+1]) {
      ans += c[a[i]];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		a: isize,
		b: isize,
		c: isize,
	}

	let mut v = vec![a, b, c];
	v.sort();
	let d1 = (v[1]-v[2]).abs();
	let mut d2 = ((v[0]+d1)-v[2]).abs() / 2;
	if ((v[0]+d1)-v[2]).abs() % 2 == 1 {
		d2 += 2;
	}
//	println!("d1={}, d2={}", d1, d2);
	println!("{}", d1 + d2);
}



Measured memory_bytes: 2136
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

int a, b;
string s;

int main(){
	cin >> a >> b;
	cin >> s;
	bool b = 1;
	if(s[a] == '-'){
		for(int i = 0; i < s.size(); i++){
			if(i != a && s[i] == '-')
				b = 0;
		}
	}
	else b = 0;
	if(b) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
  int a,b;
   scanf("%d %d",&a,&b); 
  if (a < b)
  {
    printf("a < b\n");
  }
  else if (a > b)
  {
    printf("a > b\n");
  }
  else
  {
    printf("a == b\n");
  }

  return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    int N,W;
    cin >> N >> W;
    ll w[N];
    ll v[N];
    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }
    ll minWeight[N + 1][N * 1000 + 1];
    ll MAX = 1ll << 60;
    for(int ni = 0; ni < N + 1; ni++){
        for(int vi = 0; vi < N * 1000 + 1; vi++){
            minWeight[ni][vi] = MAX;
        }
    }
    minWeight[0][0] = 0;
    for(int ni = 1; ni <= N; ni++){
        for(int vi = 0; vi < N * 1000 + 1; vi++){
            ll tmp = 0;
            tmp = minWeight[ni - 1][max(0ll,vi - v[ni - 1])] + w[ni - 1];

            minWeight[ni][vi] = min(tmp,minWeight[ni - 1][vi]);

        }
    }
    ll result = 0;
    for(ll i = N * 1000; i >= 0; i--){
        if(minWeight[N][i] <= W){
            result = i;
            break;
        }
    }
    cout << result << endl;
}



Measured memory_bytes: 79232
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    long long num=0;
    if(k==0)num=n*n;
    else
    {
        for(int b=k+1;b<=n;b++)
            /* (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).*/
        {
            num+=(n/b)*(b-k);
            if(n%b>=k)num+=n%b-k+1;/*a%b取余只有当b>k时，才能余数>=k,*/
        }
    }
    printf("%lld\n",num);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<utility>
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;

int main2(), main();


int main(){
    int n, k, x, i, j;
    string s;
    cin >> s;
    int len = s.length();
    rep(i,len){
        if(i%2 ==0 && s[i] == 'L'){cout << "No" << endl; return 0;}
        if(i%2 ==1 && s[i] == 'R'){cout << "No" << endl; return 0;}
        
    }
    cout << "Yes" << endl;    

}

Measured memory_bytes: 256
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	int n;
	cin >> n;
	long long int a[300000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long int ans = 0;
	for (int i = 0; i < 60; i++) {
		long long int tmp = ((long long int)1 << i);
		// long long int cntsum = 0;
		long long int cnt[2] = {};
		for (int j = 0; j < n; j++) {
			if ((a[j] & tmp) > 0) {
				cnt[1]++;
			} else {
				cnt[0]++;
			}
		}
		// cout << i << " " << tmp << " " << cntsum << endl;
		ans += ((tmp % MOD) * ((cnt[0] * cnt[1]) % MOD)) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

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

#define pi 2*acos(0)
#define INF 1e16
#define MIN 1e-9
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define m_p make_pair
#define p_b push_back
#define n_p(a) next_permutation(all(a))
#define all(v) v.begin(),v.end()
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define rev(s) reverse(all(s))
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define mem(a,k) memset(a,k,sizeof a)
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define u_b(X,V) upper_bound(X.begin(),X.end(),V)
#define l_b(X,V) lower_bound(X.begin(),X.end(),V)
#define cnt(s,c) count(all(s),c)

//bitwise helpers
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)

#define modulo(S, N) ((S) & (N - 1))
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S - 1))
#define turnOnLastZero(S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))

using namespace std;

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

    int h, w;

    cin >> h >> w;

    char grid[h][w];

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> grid[i][j];
        }
    }
    int dp[h][w];
    dp[0][0] = 1;
    for(int i = 1; i < h; i++) {
        if(grid[i][0] == '#')
            dp[i][0] = 0;
        else
            dp[i][0] = dp[i - 1][0];
    }

     for(int i = 1; i < w; i++) {
        if(grid[0][i] == '#')
            dp[0][i] = 0;
        else
            dp[0][i] = dp[0][i - 1];
    }

    for(int i = 1; i < h; i++) {
        for(int j = 1; j < w; j++) {
            if(grid[i][j] == '#')
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
        }
    }

    cout << dp[h - 1][w - 1] << endl;

    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a >> b >> c >> d;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(a > b) a = b;
  if(c > d) c = d;
//  else anss = "No";

  cout << a+c << endl;

}

Measured memory_bytes: 256
n = int(input())
a= [[0]*9 for _ in range(9)]
ans = 0
for i in range(1,n+1):
    if (i%10==0):
        continue
    p = str(i)
    front = int(p[0])
    back = int(p[-1])
    a[front-1][back-1] += 1
for i in range(1,10):
    for j in range(1,10):
        ans += a[i-1][j-1]*a[j-1][i-1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>


using namespace std;
int main(){

    int x;
    while(cin>>x){
        int count=0;
        for(int i=1; i<=x; i++){
            if(i==1){
                count=2;
            }else{
                count+=i;
            }
        }
        cout<<count<<endl;
    }

}

Measured memory_bytes: 1160
# 参考 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3277276#1
from math import acos, hypot, isclose, sqrt

def intersection(circle, polygon):
    # 円と多角形の共通部分の面積
    # 多角形の点が反時計回りで与えられれば正の値、時計回りなら負の値を返す
    x, y, r = circle
    polygon = [(xp-x, yp-y) for xp, yp in polygon]
    area = 0.0
    for p1, p2 in zip(polygon, polygon[1:] + [polygon[0]]):
        ps = seg_intersection((0, 0, r), (p1, p2))
        for pp1, pp2 in zip([p1] + ps, ps + [p2]):
            c = cross(pp1, pp2)  # pp1 と pp2 の位置関係によって正負が変わる
            if c == 0:  # pp1, pp2, 原点が同一直線上にある場合
                continue
            d1 = hypot(*pp1)
            d2 = hypot(*pp2)
            if le(d1, r) and le(d2, r):
                area += c / 2  # pp1, pp2, 原点を結んだ三角形の面積
            else:
                t = acos(dot(pp1, pp2) / (d1 * d2))  # pp1-原点とpp2-原点の成す角
                sign = 1.0 if c >= 0 else -1.0
                area += sign * r * r * t / 2  # 扇形の面積
    return area

def cross(v1, v2):  # 外積
    x1, y1 = v1
    x2, y2 = v2
    return x1 * y2 - x2 * y1

def dot(v1, v2):  # 内積
    x1, y1 = v1
    x2, y2 = v2
    return x1 * x2 + y1 * y2

def seg_intersection(circle, seg):
    # 円と線分の交点（円の中心が原点でない場合は未検証）
    x0, y0, r = circle
    p1, p2 = seg
    x1, y1 = p1
    x2, y2 = p2

    p1p2 = (x2 - x1) ** 2 + (y2 - y1) ** 2
    op1 = (x1 - x0) ** 2 + (y1 - y0) ** 2
    rr = r * r
    dp = dot((x1 - x0, y1 - y0), (x2 - x1, y2 - y1))

    d = dp * dp - p1p2 * (op1 - rr)
    ps = []

    if isclose(d, 0.0, abs_tol=1e-9):
        t = -dp / p1p2
        if ge(t, 0.0) and le(t, 1.0):
            ps.append((x1 + t * (x2 - x1), y1 + t * (y2 - y1)))
    elif d > 0.0:
        t1 = (-dp - sqrt(d)) / p1p2
        if ge(t1, 0.0) and le(t1, 1.0):
            ps.append((x1 + t1 * (x2 - x1), y1 + t1 * (y2 - y1)))
        t2 = (-dp + sqrt(d)) / p1p2
        if ge(t2, 0.0) and le(t2, 1.0):
            ps.append((x1 + t2 * (x2 - x1), y1 + t2 * (y2 - y1)))

    # assert all(isclose(r, hypot(x, y)) for x, y in ps)
    return ps

def le(f1, f2):  # less equal
    return f1 < f2 or isclose(f1, f2, abs_tol=1e-9)

def ge(f1, f2):  # greater equal
    return f1 > f2 or isclose(f1, f2, abs_tol=1e-9)

N, cx, cy, r = map(int, input().split())
ans = 0
from math import pi
circle_area = pi * r * r
for _ in range(N):
    p, score = map(int, input().split())
    ps = []
    for _ in range(p):
        x, y = map(int, input().split())
        ps.append((x, y))
    area = intersection((cx, cy, r), ps)
    ans += abs(area) * score / circle_area

print(f"{ans:.10f}")



Measured memory_bytes: 5764
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define y1 y_golabi
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 2e5 + 10;
int n , np , p[MAXN] , ptr , ptr2 , l , r;
bool bo[MAXN];
bool check(int x)
{
	for(int i = 0 ; i < np ; i ++)
		bo[i] = (p[i] >= x) , ptr = ptr2 = 0;
	while(bo[n - ptr - 2] != bo[n - ptr - 1] and ptr <= n - 2)
		ptr ++;
	while(bo[ptr2 + n] != bo[ptr2 + n - 1] and ptr2 <= n - 2)
		ptr2 ++;
	if(ptr == n - 1 and ptr2 == n - 1)
		return (!(n % 2) ^ bo[n - 1]);
	if(ptr <= ptr2)
		return bo[n - ptr - 2];
	return bo[ptr2 + n];
}
int32_t main()
{
	cin >> n , np = 2 * n - 1;
	for(int i = 0 ; i < np ; i ++)
		cin >> p[i];
	l = 0 , r = np;
	while(r - l > 1)
	{
		int mid = (l + r) / 2;
		if(check(mid))
			l = mid;
		else
			r = mid;
	}
	/*for(int i = 0 ; i < np ; i ++)
		cout << bo[i] << " ";
	cout << endl;*/
	return cout << l << endl , 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mem[100000];

int main(){
    int N,W;
    cin >>N >>W;
    fill(mem,mem+100000,0);
    vector<ll> w(N),v(N);
    for (int i=0;i<N;i++){
        cin >>w[i] >>v[i];
    }
    for(int i=0;i<N;i++){
        for(int j=W;j>=0;j--){
         if(j >=w[i])   mem[j]=max(mem[j],mem[j-w[i]]+v[i]);
        }
    }
//for(ll j=0;j<=W;j++)cout <<j <<" " <<mem[j]<<endl;

cout <<mem[W]<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
 
#define N_MAX 10000
 
int main(){
 
  string n;
  cin >> n;
 
  if(n[0]==n[2]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
typedef long long ll;
#define INF 1001001001

using namespace std;
vector<int> to[2505];
vector<int> rto[2505];
bool reachfrom1[2505];
bool reachtoN[2505];
bool ok[2505];

void dfs(int v){
	if(reachfrom1[v]) return;
	reachfrom1[v] = true;
 	for(int t : to[v]){
    	dfs(t);
    }
}
void rdfs(int v){
	if(reachtoN[v]) return;
	reachtoN[v] = true;
 	for(int t : rto[v]){
    	rdfs(t);
    }
}
int main(){
	int N, M, P;
  	cin >> N >> M >> P;
  	vector<tuple<int, int, int>> edges;
  	for(int i = 0; i < M; i++){
    	int a, b, c;
      	cin >> a >> b >> c;
      	a--;
      	b--;
      	c-=P;
      	c = -c;
      	edges.emplace_back(a, b, c);
      	to[a].push_back(b);
      	rto[b].push_back(a);
    }
  	dfs(0);
  	rdfs(N-1);
  	for(int i = 0; i < N; i++){
    	ok[i] = reachfrom1[i] & reachtoN[i];
    }
    {
  	  vector<int> d(N, INF);
	  d[0] = 0;
  	  int step = 0;
      bool updt = true;
      while(updt){
          updt=false;
          for(int i = 0; i < M; i++){
              int a,b,c;
              tie(a,b,c) = edges[i];
              if(!ok[a]) continue;
              if(!ok[b]) continue;
              if(d[b] > d[a]+c){
                  d[b] = d[a]+c;
                  updt = true;
              }
          }
          step++;
          if(step > N){
              cout << -1 << endl;
              return 0;
          }
      }
      int ans = -d[N-1];
      ans = max(0, ans);
  	  cout << ans << endl;
    }
  	return 0;
}

Measured memory_bytes: 640
#define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
typedef          char      s8;
typedef unsigned char      u8;
typedef          short    s16;
typedef unsigned short    u16;
typedef          int      s32;
typedef unsigned int      u32;
typedef          long int s64;
typedef unsigned long int u64;
typedef float             f32;
typedef double            f64;
#define rep(_i, _n) for (int _i = 0; _i < (int)(_n); _i++)
#if DEBUG
#define PHERE()			{ cerr << "L" << setw(3) << __LINE__ << ": PHERE" << clock() << endl; }
#define PVAL( _var )	{ cerr << "L" << setw(3) << __LINE__ << ":" << #_var "=" << (_var) << endl; }
#else
#define PHERE()
#define PVAL( _var )
#endif


int main()
{
	//////// 入力 ////////
	s64 N;
	cin >> N;
	--N;
	/////////////////////
	
	if( N <= 0 ) {
		cout << "a";
		return 0;
	}
	string AZ = "abcdefghijklmnopqrstuvwxyz";
	string out;
	s64 val = N;
	while( val >= 0 ) {
		s64 mod = (val) % 26;
		out = AZ[mod] + out;
		
		val /= 26;
		--val;
	}
	
	//////// 出力 ////////
	cout << out;
	/////////////////////
	
	return 0;
}


//1000 0000 0000 0001
//1000000000000001
//0x3 8D7E A4C6 8001


Measured memory_bytes: 3628
function Main(input) {
  let args = input
    .trim()
    .split("\n")
    .map((x) => parseInt(x, 10));

  let n = args.length;
  for (let i = 0; i < n; i++) {
    if (args[i] === 0) {
      break;
    }
    console.log("Case " + String(i + 1) + ": " + String(args[i]));
  }
}

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


Measured memory_bytes: 22324
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,x;
    cin >> N >> x;
    deque<ll> que;
    if(x == 1 || x == 2*N-1){
        cout << "No" << endl;        
        return 0;
    }
    if(N == 2 && x != 2){
        cout << "No" << endl;
        return 0;
    }else if(N == 2 && x == 2){
        cout << "Yes" << endl;
        rep(i,3){
            cout << i+1 << endl;
        }
        return 0;
    }
    cout << "Yes" << endl;
    ll w,y,z;
    if(x == 2){
        w = x+1;
        y = x-1;
        z = x+2;
    }else{
        w = x-1;
        y = x+1;
        z = x-2;
    }
    ll cur = 1;
    rep(i,(N-2)){
        while(cur == w || cur == x || cur == y || cur == z){
            cur++;
        }
        cout << cur << endl;
        cur++;
    }
    cout << w << endl;
    cout << x << endl;
    cout << y << endl;
    cout << z << endl;
    rep(i,N-3){
        while(cur == w || cur == x || cur == y || cur == z){
            cur++;
        }
        cout << cur << endl;
        cur++;
    }

    /*
    que.push_back(x);
    REP(i,1,N-1){
        que.push_back(x+i);
        que.push_front(x-i);
    }
    if(que.front() < 1 || que.back() > 2*N - 1){
        cout << "No" << endl;
        return 0;
    }else if(que.front() == 1 && que.back() == 2*N - 1){
        cout << "No" << endl;
        return 0;
    }else if(que.front() == 1){
        cout << "Yes" << endl;
        que.push_back(2*N-2);
        que.push_front(2*N-1);
    }else if(que.back() == 2*N -1){
        cout << "Yes" << endl;
        que.push_back(1);
        que.push_front(2);
    }else{
        cout << "Yes" << endl;
        que.push_front(1);
        que.push_back(2*N-1);
    }
    rep(i,2*N-1){
        cout << que[i] << endl;
    } */
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
vector<set<pair<pp,int> > >adj[300006];
vector<int>visited(300006,0);
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


       int n,m;
       cin>>m>>n;
       int s1,s2,d1,d2;
       cin>>s1>>s2>>d1>>d2;
       s1--;s2--;d1--;d2--;
       vector<string>v(m);
       for(int i=0;i<m;i++)cin>>v[i];

       set<pair<int,pp> >q;  // working as priority queue to get least weight node
       q.insert({0,{s1,s2}});
       int dis[m+1][n+1];
       for(int i=0;i<m;i++)for(int j=0;j<n;j++)dis[i][j]=INT_MAX;
       // dsitance vector
       dis[s1][s2]=0;// dis[source]=0

       while(!q.empty())
       {
           auto it=q.begin();
           pair<int,pp> d=*it;
           q.erase(it);
           int i1=d.second.first;
           int j1=d.second.second;


           for(int i=-2;i<=2;i++)
           {
               for(int j=-2;j<=2;j++)
               {
                   if(i==0&&j==0)continue;
                 int i2=i1+i;
                 int j2=j1+j;
                 if(i2>=0&&i2<m&&j2>=0&&j2<n&&v[i2][j2]=='.')
                 {
                     if((i==0&&j==1)||(i==0&&j==-1)||(i==1&&j==0)||(i==-1&&j==0))
                     {
                         int wt=0;
                         if(dis[i2][j2]>dis[i1][j1]+wt)
                       {
                          q.erase({dis[i2][j2],{i2,j2}});
                          dis[i2][j2]=dis[i1][j1]+wt;
                          q.insert({dis[i2][j2],{i2,j2}});
                       }
                     }
                     else
                     {
                         int wt=1;
                         if(dis[i2][j2]>dis[i1][j1]+wt)
                       {
                          q.erase({dis[i2][j2],{i2,j2}});
                          dis[i2][j2]=dis[i1][j1]+wt;
                          q.insert({dis[i2][j2],{i2,j2}});
                       }
                     }
                 }

               }
           }
       }
       if(dis[d1][d2]==INT_MAX)cout<<-1<<endl;
       else cout<<dis[d1][d2]<<endl;

}


Measured memory_bytes: 21604
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x, y, ans;
	scanf("%d%d", &x, &y);
	ans = 2e9;
	if (-x <= -y) ans = min(ans, 2 + -y - (-x));
	if (-x <= y) ans = min(ans, 1 + y - (-x));
	if (x <= -y) ans = min(ans, 1 + (-y) - x);
	if (x <= y) ans = min(ans, y - x);
	printf("%d\n", ans);
}



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

namespace ABC_C
{
    class C085
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int Y = int.Parse(s[1]) / 1000;

            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= N - i; j++)
                {
                    int k = N - i - j;
                    int sum = 10 * i + 5 * j + k;
                    if (sum == Y)
                    {
                        Console.WriteLine(i + " " + j + " " + k);
                        goto END;
                    }
                }
            }

            Console.WriteLine("-1 -1 -1");

        END:
            ;

        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>  // ver2.3.0
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int scomb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (小さい場合)
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
int comb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (%MOD)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}
int stpow(int n){  //  階乗(%MOD)
if(n==0)return 1;int a=1;rep(i,1,n+1)a=a*i%MOD;return a;}
Vi stpowV(){Vi a(100001);  //  階乗配列(%MOD)
a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);
  int n;
  cin >> n;
  VPii ans(0);
  
  if(n%2==0){
    int s = n+1;
    int p;
    repeq(i,1,n){
      p = s-i;
      repeq(j,i+1,n){
        if(i==j || j==p) continue;
        ans.pb(mp(i,j));
      }
    }
  }
  
  else {
    int s = n;
    int p;
    repeq(i,1,n){
      p = s-i;
      repeq(j,i+1,n){
        if(i==j || j==p) continue;
        ans.pb(mp(i,j));
      }
    }
  }
  
  cout << ans.size() << endl;
  VPout(ans);
  return 0;
}

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

int n, q;
int rank[10000], par[10000];

void init(){
	rep(i,n) par[i] = i;
	rep(i,n) rank[i] = 0;
}

int find(int x){
	if(x == par[x]) return x;
	return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(par[x]);
	y = find(par[y]);
	if(x == y) return;
	
	if(rank[x] < rank[y]){
		par[x] = y;
	} else{
		par[y] = x;
		if(rank[x] == rank[y]) rank[x]++;
	}
}

int same(int x, int y){
	return find(x) == find(y);
}

int main(){
	scanf("%d%d",&n,&q);
	init();
	rep(i,q){
		int com, x, y;
		scanf("%d%d%d",&com,&x,&y);
		if(com == 0){
			unite(x,y);
		} else {
			printf("%d\n",same(x,y));
		}
	}
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
# define mod 1000000007


int main()
{
    IOS;
    ll i,j,k,t,n,sum=0,prod=1,flag=0;
    ll cnt;
    cin >> n >> k;
    ll a[n];
    ll l=1,h=1000000000,mid;
    for(i=0;i<n;i++)
            cin >> a[i];
    ll ans=-1;
    while(l<h)
    {
        mid=(h+l)/2;
        cnt=0;
        for(i=0;i<n;i++)
             {
                 cnt+=(a[i]+mid-1)/mid;
                 cnt--;
             }
        if(cnt<=k)
            h=mid;
        else
           l=mid+1;
    }
    cout << l;
}


Measured memory_bytes: 5224
#include <cstdio>
const int N = 105;
int n, ans;
int vis[N][N];
int main() {
	scanf("%d", &n);
	ans = n * (n - 1) / 2;
	if (n % 2 == 0) {
		for (int i = 1; i <= n; i++)
		if (!vis[i][n - i + 1])
			vis[i][n - i + 1] = vis[n - i + 1][i] = true, ans--;
	} else {
		for (int i = 1; i < n; i++)
		if (!vis[i][n - i]) vis[i][n - i] = vis[n - i][i] = true, ans--;
	}
	printf("%d\n", ans);
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
		if (!vis[i][j]) printf("%d %d\n", i, j);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

		while(true){
			int pc_num = sc.nextInt();
			int student_num = sc.nextInt();
			if(pc_num==0) break;
			int record_num = sc.nextInt();

			Student[] person = new Student[student_num];
			for(int i=0; i<student_num; i++){
				person[i] = new Student(new int[record_num], new int[record_num/2]);
			}

			int t, n, m, s;
			for(int i=0; i<record_num; i++){
				t = sc.nextInt();	n = sc.nextInt();
				m = sc.nextInt();	s = sc.nextInt();
				m--;
				if(s==1){
					if(person[m].using++ == 0){
						person[m].time[person[m].index++] = t;
					}
				}else{
					if(--person[m].using == 0){
						person[m].time[person[m].index] = t;
						person[m].length[person[m].index/2] = person[m].time[person[m].index]
						- person[m].time[person[m].index-1];
						person[m].index++;
					}
				}
			}

			int q_num = sc.nextInt();

			int ts, te;
			int is, ie;
			for(int i=0; i<q_num; i++){
				ts = sc.nextInt();
				te = sc.nextInt();
				m = sc.nextInt();
				m--;

				is = Arrays.binarySearch(person[m].time, 0, person[m].index, ts);
				if(is<0) is = -is-1;
				ie = Arrays.binarySearch(person[m].time, 0, person[m].index, te);
				if(ie<0) ie = -ie-1;

				int sum = 0;
				if(is%2==0){
					if(is!=person[m].index){
						for(int j=is/2; j<ie/2; j++){
							sum += person[m].length[j];
						}
						if(ie%2==1){
							sum += (te - person[m].time[ie-1]);
						}
					}
				}else{
					sum += (person[m].time[is-1] - ts);
					for(int j=is/2; j<ie/2; j++){
						sum += person[m].length[j];
					}
					if(ie%2==1){
						sum += (te - person[m].time[ie-1]);
					}
				}

				System.out.println(sum);
			}
		}
	}

	public static class Student{
		int using = 0;
		int[] time = null;
		int[] length = null; 
		int index = 0;
		Student(int[] temp1, int[] temp2){
			time = temp1;
			length = temp2;
		}
	}
}

Measured memory_bytes: 191348
#include<bits/stdc++.h>
using namespace std;
int n;
int w[105],v[105];
long long int dp[105][100005];
long long int cost(int i,int W)
{
	if(i == n || W == 0)return 0;
	if(dp[i][W] != -1)return dp[i][W];
	if(w[i] > W)dp[i][W] = cost(i+1,W);
	else
	{
		dp[i+1][W-w[i]] = cost(i+1,W-w[i]);
		dp[i+1][W] = cost(i+1,W);
		dp[i][W] = max(v[i] + dp[i+1][W-w[i]], dp[i+1][W]);
	}
	return dp[i][W];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int W;
	cin>>n>>W;
	for(int i=0;i<n;i++)cin>>w[i]>>v[i];
	for(int i=0;i<105;i++)for(int j=0;j<100005;j++)dp[i][j]=-1;
	cout<<cost(0,W)<<endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll a,b;

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

  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<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    vector<unsigned long> uf(2 * N), sz(2 * N);
    iota(uf.begin(), uf.end(), 0UL);
    fill(sz.begin(), sz.begin() + N, 1);
    const auto& find = [&uf](unsigned long i) -> unsigned long {
        while(i != uf[i])i = uf[i] = uf[uf[i]];
        return i;
    };
    const auto& unite = [&uf, &sz, &find](unsigned long i, unsigned long j) -> unsigned long {
        i = find(i);
        j = find(j);
        if(i == j)return 0;
        if(sz[i] < sz[j])swap(i, j);
        sz[i] += sz[j];
        uf[j] = i;
        return 1;
    };
    const auto& add_edge = [&N, &unite](unsigned long i, unsigned long j) -> void { unite(i, j + N); unite(i + N, j); };
    for(unsigned long i{0}, u, v; i < M; ++i){
        cin >> u >> v;
        add_edge(u - 1, v - 1);
    }
    if(find(0) == find(N))cout << N * (N - 1) / 2 - M << endl;
    else cout << sz[find(0)] * sz[find(N)] - M << endl;
    return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && b==c){
    cout << 1 << endl;
  }else if(a==b || b==c || c==a){
    cout << 2 << endl;
  }else{
    cout << 3 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 1000000007;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a[5];
  for (int i = 0; i < 5; ++i)
  {
    cin >> a[i];
  }
  for (int i = 0; i < 5; ++i)
  {
    if (a[i] == 0)
    {
      cout << i + 1 ;
      exit(0);
    }
  }

}

Measured memory_bytes: 3580
package main

import(
	"os"
	"io"
	"bufio"
	"bytes"
	"fmt"

	"strings"
	"strconv"
	"sort"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

func max(lhs, rhs int) int {
	if lhs < rhs {
		return rhs
	} else {
		return lhs
	}
}

func solve(activities *[]Activity) int {
	// sort by start
	sort.Slice((*activities), func(lhs, rhs int) bool {
		return (*activities)[lhs].end < (*activities)[rhs].end
		// if (*activities)[lhs].begin == (*activities)[rhs].begin {
		// }
		// return (*activities)[lhs].begin < (*activities)[rhs].begin
	})
	// fmt.Println(*activities)
	count := 0
	current := 0
	for _, v := range *activities {
		if v.begin <= current {
			continue
		} else {
			count++
			current = v.end
		}
	}
	return count
}

type Activity struct {
	begin int
	end int
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	inputs, err := ReadLongLines(n)
	if err != nil {
		fmt.Println(err)
		return
	}

	activities := make([]Activity, n)
	for i := range activities {
		s := strings.Split(inputs[i], " ")
		b, _ := strconv.Atoi(s[0])
		e, _ := strconv.Atoi(s[1])
		activities[i] = Activity{b, e}
	}
	result := solve(&activities)
	fmt.Printf("%d\n", result)
}


Measured memory_bytes: 10320