akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int a, b, x; cin >> a >> b >> x;
    if(x >= a && a+b >= x) cout << "YES" <<endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

table = {}
init_table = {}
move = {}

for i in range(N):
    if A[i] in table:
        move[table[A[i]]], move[i] = i+1, init_table[A[i]]+1
    else:
        if A[i] not in init_table:
            init_table[A[i]] = i
    table[A[i]] = i

T = K
idx = 0
remain = [0]
for i in range(1, K+1):
    while idx in move and idx < move[idx]:
        idx = move[idx]
    remain.append(idx)
    if(idx == N and i != K):
        T = K % i
        break
    if idx in move:
        idx = move[idx]
    else:
        idx += 1

if(T == 0):
    print()
    exit()
idx = remain[T]
ret = []
while idx < len(A):
    while idx in move and idx < move[idx]:
        idx = move[idx]
    if(idx < len(A)):
        ret.append(A[idx])
    idx += 1

print(*ret)



Measured memory_bytes: 122816
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	string s;
	int i, ans = INF, k;

	cin >> s;

	for (i = 0; i < s.size() - 1; i++){
		if (s[i] != s[i + 1]) {
			k = max(i + 1, (int)s.size() - (i + 1));
			if (ans > k) {
				ans = k;
			}
		}
	}

	if (ans == INF) {
		cout << s.size() << endl;
	}
	else {
		cout << ans << endl;
	}
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String s = in.next();
            int x = in.nextInt();
            int y = in.nextInt();

            String[] move = s.split("T");
            List<Integer> yoko = new ArrayList<>();
            List<Integer> tate = new ArrayList<>();
            for (int i = 0; i < move.length; i++) {
                if (i % 2 == 0) {
                    yoko.add(move[i].length());
                } else {
                    tate.add(move[i].length());
                }
            }
            int start = 0;
            if (yoko.size() > 0) {
                start = yoko.remove(0);
            }
            boolean endInX = new DFS(yoko, start, x).solve();
            boolean endInY = new DFS(tate, 0, y).solve();
            String ans = (endInX && endInY)
                    ? "Yes" : "No";
            System.out.println(ans);
        }
    }

    private static class DFS {
        private final List<Integer> arr;
        private final int goal;
        private final int offset;
        private final boolean[][] dp;

        private DFS(List<Integer> arr, int start, int goal) {
            this.arr = arr;
            this.goal = goal;
            int sum = 0;
            for (int a : arr) {
                sum += a;
            }
            this.offset = 10000;
            this.dp = new boolean[arr.size() + 1][(offset * 2 + start)];
            this.dp[0][offset + start] = true;
        }

        private boolean solve() {
            if (dp[0].length <= offset + goal) {
                return false;
            }
            for (int i = 0; i < arr.size(); i++) {
                for (int j = 0; j < dp[0].length; j++) {
                    if (dp[i][j]) {
                        dp[i + 1][j + arr.get(i)] = true;
                        dp[i + 1][j - arr.get(i)] = true;
                    }
                }
            }
            return dp[arr.size()][offset + goal];
        }
    }
}

Measured memory_bytes: 128956
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,k;cin >> n >> k;
    int ans = 0;
    rep(i,n){
        int x;cin >> x;
        ans += 2*min(abs(x), abs(k - x));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int N,K;
string S;

int main(){
    cin >> N >> K >> S;
    S[K-1] = S[K-1] + 32;
    cout << S << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int LIM = 105;
int n, w;
int q[LIM];
long long ans = 0, sum[100005], v[LIM];


int main() {
    cin >> n >> w;

    for(int i = 1; i <= n; ++i) {
        cin >> q[i] >> v[i];
    }

    vector <int> s;

    for (int j = 1; j <= n; ++j) {
        vector<pair<int,long long>> modificari;

        ans = max(ans, v[j]);

        int lg = s.size();

        if(sum[q[j]] == 0)  //daca nu exista o multime cu a j greutate, o punem in sirul de multimi
            s.push_back(q[j]);

        for (int k = 0; k < lg; ++k) {


            //cout << s[k] <<" " << sum[s[k]] << "\n";
            if (s[k] + q[j] <= w){ //daca greutatea se incadreaza in W

                 //cout << s[k] << "+" << q[j] << " " << sum[s[k]] << " " << v[j] << " " << sum[s[k]] + v[j] << "\n";

                if (sum[s[k] + q[j]] == 0) // daca nu am greutatea multime + element nou in sir
                    s.push_back(s[k] + q[j]);

                modificari.push_back(make_pair(s[k] + q[j], sum[s[k]] + v[j]));

                ans = max(ans, sum[s[k]] + v[j]);
            }
        }
        //cout <<"\n";
        sum[q[j]] = max(sum[q[j]], v[j]);

        for(size_t i = 0; i < modificari.size(); ++i) {
            sum[modificari[i].first] = max(sum[modificari[i].first], modificari[i].second);
        }
    }


    cout << ans;

    return 0;
}


Measured memory_bytes: 7928
#include<bits/stdc++.h>
#include<ext/numeric>

using namespace std;
using namespace __gnu_cxx;

const int MAX = 1e5 + 5, MOD = 1e9 + 7;

int n, a[MAX];
map<int, int> mp, rect, sq;

int main() {

	cin >> n;
	for (int i = 0; i < n; ++i) {
		int s;
		scanf("%d", &s);
		a[i] = s;
		mp[s]++;
	}
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		if (mp[a[i]] >= 4)
			sq[a[i]] = 1;
		if (mp[a[i]] >= 2)
			rect[a[i]] = 1;
	}
	if (!sq.empty()) {
		auto it = sq.end();
		--it;
		ans = it->first * 1ll * it->first;
	}
	if (rect.size() > 1) {
		auto it = rect.end();
		--it;
		auto it2 = it;
		--it2;
		ans = max(ans, it->first * 1ll * it2->first);
	}
	cout << ans;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n, r;
    cin >> n >> r;
    if(n<10) r += 100*(10-n);
    cout << r << endl;
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
//#define MOD 1000000007
#define INF LONG_LONG_MAX

const int MAX = 1000000;
const int MOD = 1000000007;

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

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

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

int x,y,d,ans=1;

signed main() {
    COMinit();
    cin >> x >> y;
    d = abs(x-y);
    if ((min(x,y)-d)%3 == 0) {
        int a = (x+y)/3,b = (min(x,y)-d)/3+d;
        cout << COM(a,b) << endl;
    } else cout << 0 << endl;
}




Measured memory_bytes: 23680
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll n;
    ll a,b;
    cin>>n>>a>>b;
    vector<ll> flag(10000);
    for(ll i=1;i<=n;++i){
        flag[i-1] = i/10000%10 + i/1000%10 + i/100%10 + i/10%10 + i%10;
    }
    ll ans=0;
    for(ll i=0;i<n;++i){
        if(a <= flag[i] and flag[i] <= b){
            ans += i+1;
        }
    }
    cout<<ans<<endl;
}

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

int main(){
		set<int> snukes;
        int n, k;
        scanf("%d%d", &n, &k);
        for (int i=0; i<k; ++i){
			int d;
			scanf("%d",&d);
			for (int j=0; j<d; ++j){
				int snuke;
				scanf("%d",&snuke);
				snukes.insert(snuke);
			}
		}
		int result;
		result = n - (int) snukes.size();
		printf("%d", result);
        return 0;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P; // (x, y)

int H, W;
int A[1010][1010];

P dir[4] = {P(-1, 0), P(0, 1), P(1, 0), P(0, -1)};

static bool is_in_range(int i, int j) {
    return (0 <= i and i < H) and (0 <= j and j < W);
}

void bfs() {
    queue<P> q;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if(A[i][j] == 0)
          q.push(P(i, j));
      }
    }

    while (q.size()) {
      P current = q.front(); q.pop();
      int cx = current.first;
      int cy = current.second;

      // 4方向を調べる
      for(const auto& nextDir : dir) {
        int nx = cx + nextDir.first;
        int ny = cy + nextDir.second;

        // 到達可能かつ未踏
        if ( is_in_range(nx, ny) and A[nx][ny] == -1) {
          q.push(P(nx, ny));
          A[nx][ny] = A[cx][cy] + 1;
        }
      }
    }
    return;
}

int main() {
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      char a;
      cin >> a;
      if(a == '.')
        A[i][j] = -1;
      else // a == '#'
        A[i][j] = 0;
    }
  }
  bfs();

  int res = -1;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      res = max(res, A[i][j]);
    }
  }
  cout << res << endl;
}

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

char winner;
vector<string> deck(3);

void game(int turn, vector<int> np) {
  if (deck[turn][np[turn]] == '\0') {
    winner = turn + 'A';
  } else {
    np[turn] += 1;
    game(deck[turn][np[turn] - 1] - 'a', np);
  }
}

int main() {
  cin >> deck[0] >> deck[1] >> deck[2];
  game(0, {0, 0, 0});
  cout << winner;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    long long ans = 0;
    for(int i = 0; i< N; i++){
        ans += A[i] / 2;
        if(i < N - 1) {
            if(A[i + 1] > 0){
                ans += A[i] % 2;
                A[i + 1] -= A[i] % 2;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
#include<iostream>                                        
#include<cstring>                                         
using namespace std;                                      
                                                          
int main(){                                               
  char str_s1[101],str_s2[101],str_p[101];                
  cin >> str_s1;                                          
  cin >> str_p;                                           
                                                          
  strcpy(str_s2,str_s1);                                  
  strcat(str_s1,str_s2);                                  
                                                          
  if(strstr(str_s1,str_p) != NULL)                        
    cout << "Yes";                                        
  else                                                    
    cout << "No";                                         
                                                          
  cout << endl;                                           
                                                          
  return 0;                                               
}                                                         
  

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 200001
#define ll long long
#define pi pair<int , int>
#define pip pair<pi ,int>
#define mp make_pair 
#define f first
#define s second
#define int ll 
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
// this is triplet class , which will help us .
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
// this is for finding inversing multiplicative module of a number.
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
      lps[i] = j+1;
   i++;
   j++;
  }
  else{
        if(j != 0){
         j = lps[j-1];
        }
        else{
         lps[i] = 0;
         i++;
        }
  }
 }
 return lps[len-1];
}


int32_t main(){
   ios_base::sync_with_stdio(false);
      cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    long double d;
    cin>>d;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
         int x , y;
         cin>>x>>y;
         x = abs(x)*abs(x);
         y = abs(y)*abs(y);
         long double val = (x+y)*1.0;
         if(sqrtl(val) <= d)ans++;

}
cout<<ans<<endl;    

    
}

Measured memory_bytes: 3788
#include<iostream>
#include<bits/stdc++.h>
#define pq priority_queue
#define Pi acos(-1.0)
using namespace std;
#define MOD 1000000007
long long num[100005],ans=0;
int main()
{
    int n;
    long long a,b;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
        scanf("%d",num+i);
    for(int i=1;i<n;i++)
    {
        ans+=min(a*(num[i+1]-num[i]),b);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cassert>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

const int N_MAX = int(2e5);
int N;
long A,B;
long h[N_MAX];

// T回で、全て倒すことが可能かどうか
bool enough(long T)
{
  long s = 0;
  REP(i,0,N) {
    long r = h[i] - B * T;
    // もし r <= 0 ならば、これだけで倒せる
    if (r > 0) {
      double t = double(r) / (A-B);
      // t を切り上げる
      s += long(ceil(t));
    }
  }
  // s が T 以下ならば可能
  return (s <= T);
}

// enough(T) を満たす最小の T を探索する
// そのとき、
// enough(T) かつ !enough(T-1) が成り立つ
long bsearch(long a, long b)
{
  assert(a <= b);

  long c = (a + b) / 2;
  if (enough(c)) {
    // c が最小と分かる
    if (!enough(c-1)) return c;
    // 十分過ぎるケース
    // もっと左を探す
    return bsearch(a,c);
  }
  // 右を探す
  return bsearch(c+1,b);
}

int main()
{
  cin >> N >> A >> B;
  REP(i,0,N) cin >> h[i];

  // h[i] の最大値
  long hmax = -1;
  REP(i,0,N) {
    if (h[i] > hmax) hmax = h[i];
  }

  // B だけで hmax を倒すのに十分な回数
  // を b とすれば、答えはこれ以下になるはず。
  long b = long(ceil(double(hmax)/B));

  long T = bsearch(1, b);
  cout << T << endl;

  return 0;
}


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

int main()
{
    int n;
    vector<pair<int,int>>v;
    cin>>n;
    for(int x,y,i=0;i<n;i++){ 
        cin>>x>>y;
        v.push_back({y,x});
    } 
    sort(v.begin(),v.end());
    int cur=0;
    for(int i=0;i<n;i++){ 
        cur+=v[i].second;
        if(cur>v[i].first){ 
            cout<<"No";
            return 0;
        } } 
        cout<<"Yes";
        
        
        
        

    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin >> n >> x;
    ll ans = x,a = n-x,b = n;
    while(b%a != 0){
        ans += ((b/a)*2-1)*a+b%a;
        ll na,nb;
        na = b%a;
        nb = a;
        a = na;
        b = nb;
    }
    PRINT(ans+2*(b-a));
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    ll a[n], b[n];
    ll sumA = 0, sumB = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sumA += a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
        sumB += b[i];
    }
    ll diff = sumB - sumA;
    // a_i < b_i
    ll cnt1 = 0;
    for(int i=0;i<n;i++){
        if(a[i] < b[i]){
            cnt1 += ((b[i] - a[i]) %2 == 0) ? ((b[i] - a[i]) / 2) : ((b[i] - a[i]) / 2 + 1);
        }
    }
    if(cnt1 > diff){
        cout << "No" << endl;
        return 0;
    }
    // a_i > b_i
    ll cnt2 = 0;
    for(int i=0;i<n;i++){
        if(a[i] > b[i]){
            cnt2 += (a[i] - b[i]);
        }
    }
    if(cnt2 > diff){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

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

using namespace std;
// const double MIN_ERR = 0.0000001;
int sqs[4003];
void emuSqs(){
    for(int i=0; i<=4000; i++){
        sqs[i] = i*i;
    }
    return;
}

int main(void){
    int d,n;
    cin>>n>>d;
    int x[n][d];
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin>>x[i][j];
        }
    }

    int ans=0;
    emuSqs();
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int sqsum=0.0;
            for(int k=0; k<d; k++){
                sqsum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            for(int i=0; i<=4000; i++){
                if(sqs[i]==sqsum){
                    ans++;
                    break;
                }
            }
            // double dist=sqrt(sqsum);
            // if(abs(ceil(dist)-dist)<MIN_ERR){
            //     ans++;
            // }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

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

Measured memory_bytes: 256
Q,H,S,D = map(int,input().split())

N = int(input())

if Q*2<H: H=2*Q
if H*2<S: S=2*H
if S*2<D: D=2*S
    
ans = (N//2)*D
if N%2==1: ans += S
    
print(ans)

Measured memory_bytes: 3060
/**
 *    author:  tourist
 *    created: 21.09.2019 15:49:47       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int x = (j < a) ^ (i < b);
      cout << x;
    }
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int64_t n,h;
    cin >> n>>h;
    vector<int64_t> a(n),b(n);
    rep(i,n){
        cin >> a[i]>>b[i];
    }
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int k=0;
    rep(i,n){
        if(a[0]>=b[i]){
            break;
        }
        k=i;
    }
    //最高の場合k=n-1
    //cout <<"k="<<k<<endl;
    int64_t ans=0;
    //k回刀を投げて、そっからはa[0]で切り続ける
    for(int i=0;i<=k;i++){
        h -= b[i];
        ans++;
        if(h<=0){
            cout<<ans<<endl;
            return 0;
        }
    }
    if(h%a[0]==0){
        cout << ans+h/a[0]<<endl;
    }
    else{
        cout << ans+h/a[0]+1<<endl;
    }
}

Measured memory_bytes: 1920
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
//use proconio::fastout;
use proconio::{input, marker::*};
//use std::collections::*;
use std::cmp::*;

fn main() {
  input! {
    s:Chars
  }
  let e = s[s.len() - 1];

  for c in s {
    print!("{}", c);
  }
  if e == 's' {
    println!("es");
  } else {
    println!("s");
  }
}


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

int main(){
  int a[5];
  for (int i=0;i<5;i++)cin >> a[i];
  for (int i=0;i<5;i++){
    int d;//コピー変数
    for (int j = i+1;j<5;j++){
      if (a[i] < a[j]){
        d = a[i];
        a[i] = a[j];
        a[j] = d;
      }
    }
  }
  
  int b = a[0] - a[4];
  int k;
  cin >> k;
  
  if(b > k)cout << ":(" << endl;
  else  cout << "Yay!" << endl;
  return 0;
  
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N, W int
	fmt.Scan(&N)

	var Ws []int
	for i := 0; i < N; i++ {
		fmt.Scan(&W)
		Ws = append(Ws, W)
	}

	min := 10000

	for i := 0; i < N; i++ {
		left := sum(Ws[:i])
		right := sum(Ws[i:])
		
		if min > absDif(left, right) {
			min = absDif(left, right)
		}
	}

	fmt.Println(min)
}

func sum(ints []int) int {
	s := 0

	for _, int := range ints {
		s += int
	}

	return s
}

func absDif(left int, right int) int {
	if left > right {
		return left - right
	} else {
		return right - left
	}
}

Measured memory_bytes: 512
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	int inf = (int)1e9;

	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		scanner.nextLine();
		int[] arr = strToIntArray(scanner.nextLine());

		double aver = getAver(arr);
		int meet_pos = (int)aver;

		int res = 0;
		for (int i=0; i<arr.length; i++) {
			int t = Math.abs(meet_pos - arr[i]);
			res += t * t;
		}
		System.out.println(res);
		
		return;
	}

	private double getAver(int[] arr) {
		double sum = 0.0;
		for (int u: arr) sum += u;

		return Math.round(sum / arr.length);
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,x,y,z,k,h,w,sum,mi,ma,ans,s,t,l[10],r,res,tmp,itr,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<int, int> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<int,int> > VP;

// 16桁のbitDP. 各桁が00,01,10,11で使わない、竹a,b,cに使うに対応
ll ta,tb,tc;

int main(){
    ll t[3];
    cin>>n>>t[0]>>t[1]>>t[2];
    rep(i,n)cin>>l[i];
    bool x,y;
    mi=inf;
    VL v;
    ll gsum=0;
    rep(i,1<<2*n){
        ta=0;tb=0;tc=0;gsum=0;
        rep(j,n){
            x=0;y=0;
            if(i>>2*j & 1)x=1;
            if(i>>2*j+1 & 1)y=1;
            //d(i)d(j)d(x);d(y);
            if(x&&y){if(tc!=0)gsum+=10;tc+=l[j];}
            if(x&&!y){if(tb!=0)gsum+=10;tb+=l[j];}
            if(!x&&!y){if(ta!=0)gsum+=10;ta+=l[j];}
        }
        if(ta==0||tb==0||tc==0)continue;
        //d(ta);d(tb);d(tc);
        v.pb(ta);v.pb(tb);v.pb(tc);
        sort(all(v));
        do {
            sum=0;
            ll itr=0;
            for(auto x : v){sum+=abs(x-t[itr]);itr++;}
            mi=min(sum+gsum,mi);
        } while (next_permutation(all(v)));
        v.clear();
    }
    p(mi);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,x,t;
    cin >> n >> x >> t;
    cout << ((n + x - 1) / x) * t << endl;
}

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

Measured memory_bytes: 3632
n = int(input())
a = []
max_num = 0
max_ind = 0
max_count = 0
for i in range(n):
    inp = int(input())
    a.append(inp)
    if inp > max_num:
        max_num = inp
        max_ind = i
        max_count = 1
    elif inp == max_num:
        max_count += 1
for i in range(n):
    if max_count > 1:
        print(max_num)
    else:
        if i == max_ind:
            a.remove(max_num)
            print(max(a))
        else:
            print(max_num)

Measured memory_bytes: 12520
main = do
  s <- getContents
  let t =  map aux $ takeWhile (/=[0,0]) $ map (map (read::String->Int) .  words) . lines $ s
  mapM_ putStrLn t

aux :: [Int] ->String  
aux [h,w] = concat $ map ((++"\n").take w) $ take h $ v
    where
      s = (concat (repeat "#."))
      t = (concat (repeat ".#"))
      u = [s, t]
      v = (concat . repeat) u

Measured memory_bytes: 4768
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main(void) {
	int n, m, d, sum = 0, ans = 0;  cin >> n >> m >> d;
	char a;
	int test[101][101] = { 0 };
	for (int h = 0; h < n; h++) {
		for (int i = 0; i < m; i++) {
			cin >> a;
			if (a == '#') {
				test[h][i] = 1;
			}
			if (a == '.') {
				test[h][i] = 0;
			}
		}
	}
	for (int h = 0; h < n; h++) {
		for (int i = 0; i < m - d + 1; i++) {
			for (int k = 0; k < d; k++) {
				sum += test[h][i + k];
			}
			if (sum == 0) {
				ans++;
			}
			sum = 0;
		}
	}
	for (int h = 0; h < m; h++) {
		for (int i = 0; i < n - d + 1; i++) {
			for (int k = 0; k < d; k++) {
				sum += test[i + k][h];
			}
			if (sum == 0) {
				ans++;
			}
			sum = 0;
		}
	}
	cout << ans << endl;
}


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

int main()
{
    int N, K;

    bool end = true;

    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    rep(i, K)
    {
        end = true;
        vector<int> B(N, 0);
        rep(j, N)
        {
            int l = max(j - A[j], 0);
            int r = min(j + A[j], N - 1);
            B[l]++;
            if (r + 1 < N)
                B[r + 1]--;
        }
        rep(j, N) if (j > 0) B[j] += B[j - 1];
        rep(j, N)
        {
            A[j] = B[j];
            if (A[j] < N)
                end = false;
        }
        if (end)
        {
            rep(j, N)
            {
                cout << N << endl;
            }
            return 0;
        }
    }
    rep(j, N) cout << A[j] << endl;
}

Measured memory_bytes: 4904
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	
	int n;
	cin >> n;
	
	set<int> s;
	rep(i, 10){
		rep(j, 10){
			s.insert(i * j);
		}
	}
	if(s.count(n)) puts("Yes");
	else puts("No");
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int A = in.nextInt();
            N %= 500;
            System.out.println(N <= A ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 26856
#include <stdio.h>
#include <string.h>
using namespace std;
int a[100001];
double s(long long n){
 long long i=n,j=0;
 while(i){
 	j+=i%10;
 	i/=10;
 }
 return (double)(n)/(double)j;
}
int main(){
	long long i=1,j=1,l,m,n;
	int k;
	scanf("%d",&k);
	while(k--){
	printf("%lld\n",i);
	while(s(i+j)>s(i+2*j))j*=10;
	i+=j;
	}
		
		

	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long N;
    string S;

    cin >> N;
    cin >> S;

    vector<vector<long long>> ids(3, vector<long long>{});
    for (long long i = 0; i < N; i++)
    {
        if (S[i] == 'R')
            ids[0].push_back(i);
        else if (S[i] == 'G')
            ids[1].push_back(i);
        else
            ids[2].push_back(i);
    }

    long long count = 0;
    for (long long i = 0; i < N - 2; i++)
    {
        for (long long j = i; j < N - 1; j++)
        {
            if (S[i] != S[j])
            {
                if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R'))
                {
                    long long d = lower_bound(ids[2].begin(), ids[2].end(), j) - ids[2].begin();
                    count += ids[2].size() - d;
                    if (j - i + j < N && S[j - i + j] == 'B')
                        count--;
                }
                else if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R'))
                {
                    long long d = lower_bound(ids[1].begin(), ids[1].end(), j) - ids[1].begin();
                    count += ids[1].size() - d;
                    if (j - i + j < N && S[j - i + j] == 'G')
                        count--;
                }
                else if ((S[i] == 'G' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'G'))
                {
                    long long d = lower_bound(ids[0].begin(), ids[0].end(), j) - ids[0].begin();
                    count += ids[0].size() - d;
                    if (j - i + j < N && S[j - i + j] == 'R')
                        count--;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,x,now=0;
	cin>>n>>x;
	ll ans=1;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;
		now+=a;
		if(now<=x){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
N,P = map(int,input().split())
def combi(N,K):
    a = 1
    for i in range(K):
        a *= N-i
    for j in range(K):
        a /= j+1
    return a

ans = 0
lis = list(map(int,input().split()))
ls = []
for a in lis:
    ls.append(a%2)
one = ls.count(1)
zero = ls.count(0)
pattern_a = 0
pattern_b = 0
for j in range(zero+1):
    pattern_b += combi(zero,j)
time = 0
while time<=one:
    if time%2 ==P:
        pattern_a += combi(one,time)
    time += 1
print(int(pattern_a*pattern_b))

Measured memory_bytes: 63364
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    A, B, Q = map(int, input().split())
    a = [int(input()) for _ in range(A)]
    b = [int(input()) for _ in range(B)]
    q = [int(input()) for _ in range(Q)]
    INF = 2*10**10
    a = [-INF] + a + [INF]
    b = [-INF] + b + [INF]

    for x in q:
        ai = bisect_left(a, x)
        ap = a[ai]-x
        am = x-a[ai-1]
        bi = bisect_left(b, x)
        bp = b[bi]-x
        bm = x-b[bi-1]

        ret = INF
        if max(ap,bp)<INF:
            ret = min(ret, max(ap, bp))
        if max(am,bm)<INF:
            ret = min(ret, max(am, bm))
        ret = min(ret, ap+2*bm, am+2*bp, bp+2*am, bm+2*ap)
        print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 16740
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<string> S(2*N);
  range(i, N) {
    std::cin >> S[i];
    S[i] = S[i] + S[i];
  }
  //range(i, N) std::cout << S[i] << '\n';
  ranges(i, N, 2*N) S[i] = S[i-N];
  std::vector<int> st(2*N-1);
  range(i, N-1){
    st[i] = N-1-i;
  }
  st[N-1] = 0;
  ranges(i, N, 2*N-1){
    st[i] = i - N + 1;
  }
  int x = 0,y = 0, ans = 0, point;
  for(int i=0;i<2*N-1;i++){
    if(i<N-1) x=0,y=st[i], point=i+1;
    else if(i==N-1) x = y = 0, point=N;
    else x=st[i], y=0, point = N - (i - N) - 1;
    //std::cout << point << '\n';
    //std::cout << x << y << '\n';
    bool flag = true;
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
        if(S[x+k][y+j]!= S[x+j][y+k]) flag = false;
      }
    }
    if(flag) ans+=point;
  }
  std::cout << ans << '\n';
  return 0;
}


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

#define int long long
#define ff first
#define ss second
#define endl '\n'
#define ii pair<double, double>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

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

double solve(vector<ii> p, vector<char> d, double x) {
  double mnx = INF, mxx = -INF, mny = INF, mxy = -INF;
  int i = -1;
  for (ii cur : p) {
    i++;
    if (d[i] == 'L')
      cur.ff -= x;
    else if (d[i] == 'R')
      cur.ff += x;
    else if (d[i] == 'U')
      cur.ss += x;
    else
      cur.ss -= x;
    mnx = min(mnx, cur.ff);
    mxx = max(mxx, cur.ff);
    mny = min(mny, cur.ss);
    mxy = max(mxy, cur.ss);
  }
  return (mxx - mnx) * (mxy - mny);
}

//#define MULTIPLE_TEST_CASE
void solution() {
  int n;
  vector<ii> p;
  cin >> n;
  vector<char> d(n);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    p.pb(ii(x, y));
    cin >> d[i];
  }
  double l = 0, r = 2e8;
  for (int it = 0; it < 100; it++) {
    double m1 = l + (r - l) / 3.;
    double m2 = r - (r - l) / 3.;

    double fa = solve(p, d, m1);
    double fb = solve(p, d, m2);

    if (fa < fb) {
      r = m2;
    } else if (fa > fb) {
      l = m1;
    } else {
      l = m1;
      r = m2;
    }
  }
  cout << fixed << setprecision(10) << solve(p, d, l) << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


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

int main() {
  string S;
  cin >> S;
  
  int sum = 700;
  
  for(int i = 0; i < 3; i++) {
  	if(S.at(i) == 'o') sum += 100;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
	public static void main (String[] args){
		Scanner sc =  new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		double[] p = new double[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextDouble();
		}
		double sum = 0;
		for(int i =0; i < K; i++) {
			sum+=p[i];
		}
		double max = (sum+K)/2;
		for(int i = K; i < N; i++) {
			sum+= p[i]-p[i-K];
			if((sum+K)/2 > max) {
				max = (sum+K)/2;
			}
		}	
		System.out.println(max);
	}	
}

Measured memory_bytes: 160444
rooms = Array.new(4).map{Array.new(3).map{Array.new(10,0)}}

gets.to_i.times do
    b, f, r, v = gets.split(' ').map(&:to_i)
    rooms[b-1][f-1][r-1] += v
end

4.times do |house|
    3.times do |floor|
        puts ' ' + rooms[house][floor].join(' ')
    end
    puts '#'*20 if house < 3
end


Measured memory_bytes: 6896
import Data.List

main = do
  n <- readLn
  let ans = solve n
  print$ length ans
  putStr$ unlines$ map (\(a,b)->unwords.map show$[a,b]) ans

solve n
  | odd n = fromNs ++ (concat.go) (n-1)
  | otherwise = (concat.go) n
  where
  fromNs = zip [1..n-1] $ repeat n
  go n = map f [1..n]
    where
    f i = zip (repeat i) $ delete i.delete (n+1-i) $ [i+1..n]

Measured memory_bytes: 1404
#include<cstdio>
#include<iostream>
#define SENTINEL 1000000000
using namespace std;
struct   card
{
    char c;
    int k;
}a[100010],A[100010],temp;
int partition(int p,int r)
{
    int x=a[r].k,i=p-1;
    int j;
    for (j=p;j<r;j++)
        if(a[j].k<=x)
        {
            i++;
            temp = a[j];
            a[j] = a[i];
            a[i]=temp;
        }
        temp = a[i+1];
        a[i+1] = a[r];
        a[r] =temp;
        return i+1;
}
void quicksort(int p,int r)
{
    if(p < r)
    {
        int q = partition(p,r);
        quicksort(p,q-1);
        quicksort(q+1,r);
    }
}
void Merge (int left,int mid,int right)
{
    int n1,n2,i,j,m;
    n1=mid-left;
    n2=right-mid;
    struct card L[n1+10],R[n2+10];
    for(i=0;i<n1;i++)
        L[i]=A[left+i];
      for(i=0;i<n2;i++)
        R[i]=A[mid+i];
    i=j=0;
      L[n1].k=R[n2].k=SENTINEL;
    for(m=left;m<right;m++) {
            if(L[i].k<=R[j].k)
                A[m]=L[i++];
            else
                A[m]=R[j++];
        }
}
void Merge_Sort(int left,int right)
{
    if(left+1<right)
    {
         int mid=(left+right)/2;
         Merge_Sort(left,mid);
         Merge_Sort(mid,right);
         Merge(left,mid,right);
    }
}
int main()
{
    int n,i,flag=0;
    cin >> n;
    for(i=0;i<n;i++)
    {
          cin >> a[i].c >>a[i].k ;
           A[i].c=a[i].c;
           A[i].k=a[i].k;
    }
    quicksort(0,n-1);
    Merge_Sort(0,n);
    for(i=0;i<n;i++)
        if(a[i].c!=A[i].c)
    {
        flag = 1;
        break;
    }
    if(flag == 0)
        printf("Stable\n");
    else
        printf("Not stable\n");
    for (i=0;i<n;i++)
        printf("%c %d\n",a[i].c,a[i].k);
    return 0;
}

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

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

    int a2, b2;
    a2 = a;
    b2 = b;
    if (a2 == 1)
    {
        a2 = 14;
    }
    if (b2 == 1)
    {
        b2 = 14;
    }
    if (a2 > b2)
    {
        cout << "Alice" << endl;
    }
    else if (a2 < b2)
    {
        cout << "Bob" << endl;
    }
    else
    {
        cout << "Draw" << endl;
    }
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ok_pattern = 0
for i in range(a+1):
    for j in range(b+1):
        for l in range(c+1):
            cost = 500 * i + 100 * j + 50 * l
            if cost == x:
                ok_pattern += 1
print(ok_pattern)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
 
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll s, w; cin >> s >> w;
    ll ans = 0;
    
    (s <= w) ? (cout << "unsafe" << endl) : (cout << "safe" << endl);
} 

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

int main() {
	long long a, b, k;
	
	cin >> a >> b >> k;
	
	if (a < k) {
		k -= a;
		a = 0;
		
		if (b < k) {
			b = 0;
		}
		else {
			b -= k;
		}
	}
	else {
		a -= k;
	}
	
	cout << a << " " << b << endl;
}


Measured memory_bytes: 256
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;cin>>n;
  map<int,int>mp;
  rep(i,n){
    int x;cin>>x;
    mp[x]=i+1;
  }
  for(int i=1;i<n+1;i++){
    cout<<mp[i]<<endl;
  }
  
}



Measured memory_bytes: 5504
N, M = gets.split.map(&:to_i)

require 'prime'

puts M == 1 ? 1 : ([[1]] + M.prime_division.map{|a, b| (0 .. b).map{|c| a**c}}).inject(&:product).map{|a| a.flatten.inject(:*)}.sort.reverse.find{|m| M/m >= N}

Measured memory_bytes: 2428
// https://atcoder.jp/contests/abc110/tasks/abc110_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<double, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> vx(n), vy(m);
    REP(i, n) cin >> vx[i];
    REP(i, m) cin >> vy[i];
    sort(ALLR(vx));
    sort(ALL(vy));
    int z = vx[0] + 1;
    if (z <= vy[0] && x < z && z <= y) {
        cout << "No War\n";
    } else {
        cout << "War\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  
  cin >>N;
  vector<string> A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  
  cin>>M;
  vector<string> B(M);
  for(int i=0;i<M;i++)
    cin>>B.at(i);
  
  int max=0;
  for(int i=0;i<N;i++){
    int point=0;
    for(int j=0;j<N;j++){
      if(A.at(i)==A.at(j))
        point++;
    }
    for(int j=0;j<M;j++){
      if(A.at(i)==B.at(j))
        point--;
    }
    if(point>max)
      max=point;
  }
  
  cout<<max<<endl;
}
    


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

char judgeGrade(int m, int f, int r){
        if ((m==-1) || (f==-1)) return 'F';
        int total;
        total = m + f;
        if (total<30) return 'F';
        if (total>=80) return 'A';
        if (total>=65) return 'B';
        if (total>=50) return 'C';
        if (r>=50) return 'C';
        return 'D';
}

int main(){
    while(true){
        int m, f, r;
        cin >> m >> f >> r;
        if ((m==-1) && (f==-1) && (r==-1)) break; 
        cout << judgeGrade(m, f, r) << endl;
    }
}\


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

vector<int> v[100100];
int n;
int dp[100100];

void solve(int t){
	vector<int> v1;
	for(int i=0;i<v[t].size();i++){
		solve(v[t][i]);
		v1.push_back(dp[v[t][i]]);
	}
	sort(v1.begin(),v1.end());
	int td=0;
	REP(i,v1.size()){
		v1[i]+=(v1.size()-i);
		td=max(td,v1[i]);
	}
	dp[t]=td;
	return ;
}
	
int main(){
	cin>>n;
	FOR(i,2,n+1){
		int a;
		cin>>a;
		v[a].push_back(i);
	}
	solve(1);
	cout<<dp[1]<<endl;
	return 0;
}

Measured memory_bytes: 13952