akhauriyash/Code-Regression huggingface dataset:
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 2e5 + 10;
int n;
int d0, x0;

int read() {
  if (scanf("%d%d%d", &n, &d0, &x0) < 3) {
    return 0;
  }
  return 1;
}

ld prob[maxn];

void solve() {
  ld res = 0;

  ld d = d0;
  ld x = x0;
  for (int iter = n; iter > 0; --iter) {
    //eprintf("%d  %.3f %.3f\n", iter, (double) d, (double) x);
    res += d + x * (iter - (ld) 0.5);
    d *= (ld) (iter + 1) / iter;
    d += x * 5 / (2 * iter);
    x += x * 2 / iter;
    //eprintf("res = %.3f\n", (double) res);
  }
  printf("%.18f\n", (double) res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main(void) {
    int n;
    std::scanf("%d", &n);
    long long l[100];
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= n; i++) {
        l[i] = l[i-1] + l[i-2];
    }
    std::printf("%lld\n", l[n]);
    return 0;
}

Measured memory_bytes: 256
/*Station and Bus*/

#include <bits/stdc++.h>

using namespace std;

int main(){
    
    string cad;
    
    cin >>cad;
    
    int ans = 0;
    
    for(int i = 0; i < 3; i++){
        if(cad[i]== 'A'){
            ans++;
            break;
        }
    }
    
    for(int i =0; i < 3; i++){
        if(cad[i]=='B'){
            ans++;
            break;
        }
         
    }
    
    if(ans == 2)
      cout << "Yes";
    else 
      cout << "No";
    
    return 0;
}

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

using ll = long long;
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  IN(A); IN(B); IN(C);
  ll K;
  cin >> K;

  if (K%2==0)
    OUT(A-B);
  else
    OUT(B-A);

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int a[100]={0},i,j,k,v,n;
  
  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&a[i]);
  
  for(k=0;k<n-1;k++) printf("%d ",a[k]);printf("%d\n",a[n-1]);

  for(i=1;i<=n-1;i++){
    v = a[i];
    j = i - 1;
    while(j>=0 && a[j]>v){
      a[j+1] = a[j];
      j--;
      a[j+1]=v;
    }
    for(k=0;k<n-1;k++) printf("%d ",a[k]);printf("%d\n",a[n-1]);
  }
}


Measured memory_bytes: 2096
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r = sc.nextInt();
    int d = sc.nextInt();
    int ans = 0;
    for (int i = n; i <= r; i++){
      if (i%d==0) ans++;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35048
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int ans = 7;
		if(S.equals("MON"))
			ans = 6;
		else if(S.equals("TUE"))
			ans = 5;
		else if(S.equals("WED"))
			ans = 4;
		else if(S.equals("THU"))
			ans = 3;
		else if(S.equals("FRI"))
			ans = 2;
		else if(S.equals("SAT"))
			ans = 1;
		System.out.println(ans);

	}

}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <initializer_list>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n; cin >>n;
	vector<int> a(n);
	cinf(n,a);
	map<int,int> mp;
	for(int i=0;i<n;i++){
		mp[a[i]]++;
		mp[a[i]-1]++;
		mp[a[i]+1]++;
	}
	int ans=0;
	for(auto p:mp){
		ans=max(ans,p.second);
	}
	cout << ans << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    double a, b, ans1, ans2;
    cin >> a >> b;
    double ans = -1;
    for(double i = 0; i <= 1000; i++){
        int x = floor(i * 0.08), y = floor(i * 0.1);
        if(x == a && y == b){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
' Imports System.Collections.Generic
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim A, B As Integer
        Dim arr() As String
        arr = Split(Console.ReadLine())
        A = arr(0) : B = arr(1)
        Console.WriteLine(A * B)
    End Sub
End Class


Measured memory_bytes: 28348
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	std::ios::sync_with_stdio(false);
	cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0) cout<<"Possible";
	else cout<<"Impossible";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
N,M,Q = map(int,input().split())
# 10個の数列で、A_i <= A_i+1となる組み合わせ（最大10）は
# [1,1,1,1,1,1,1,1,1,1]のどこに10個のUPを入れるかの組み合わせであり
# 20C10 = 184756
# この組み合わせに対して最大50のクエリを試すと、9237800通り
# 全探索する

query = [None] * Q
for i in range(Q):
  query[i] = list(map(int,input().split()))
  
stack = []
for i in range(1,M + 1):
  stack.append([i])

def calc(arr,query):
  res = 0
  for q in query:
    a,b,c,d = q
    if arr[b-1] - arr[a-1] == c:
      res += d
  return res
  
ans = 0
while stack:
  arr = stack.pop()
  if len(arr) == N:
    val = calc(arr,query)
    if val > ans:
      ans = val
    continue
  for i in range(arr[-1],M+1):
    stack.append(arr + [i])

print(ans)

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

int main() {
  int N;
  scanf("%d", &N);

  vector<pair<int,int>> BC(N);
  for (int i = 0; i < N; ++i) {
    cin >> BC[i].second;
    cin >> BC[i].first;
  }

  sort(BC.begin(),BC.end());

  //cout << BC[0].first << endl;

  int sum = 0;
  bool flug = true;


  for (int i = 0; i < N; ++i){
    sum += BC[i].second;
    if(sum>BC[i].first) flug = false;
  }

  if(flug==true) cout << "Yes" << endl;
  else cout << "No" << endl;



}



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

int main(){
    int n;
    cin >> n;
    map<string,int> key;
    string tmp,front;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        if(key.find(tmp) == key.end() && (i == 0 |(i > 0 && front[front.size()-1] == tmp[0]))){
            key[tmp] = 1;
            front = tmp;
        }
        else{
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

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

struct UnionFind{
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

typedef pair<int,int> P;
typedef pair<int,P> PP;
bool used[314514];
signed main(){
  int n;
  cin>>n;
  vector<P> v(n),u(n);
  for(int i=0;i<n;i++) cin>>v[i].first>>v[i].second;
  for(int i=0;i<n;i++) u[i]=P(v[i].second,v[i].first);
  sort(v.begin(),v.end());
  sort(u.begin(),u.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  u.erase(unique(u.begin(),u.end()),u.end());
  //for(P p:v) cout<<p.first<<" "<<p.second<<endl;
  n=v.size();
  map<P,int> m;
  for(int i=0;i<n;i++) m[v[i]]=i;
  map<int,int> mx,my;
  int cx=0,cy=0;
  priority_queue<PP,vector<PP>,greater<PP> > q;
  for(int i=0;i<n;i++){
    if(!mx.count(v[i].first)) mx[v[i].first]=cx++;
    if(!my.count(u[i].first)) my[u[i].first]=cy++;
  }
  for(int i=0;i<n;i++){
    //cout<<mx[v[i].first]<<" "<<my[v[i].second]<<endl;
    q.push(PP(0,P(i,n+mx[v[i].first])));
    q.push(PP(0,P(i,n+cx+my[v[i].second])));
  }
  for(int i=0;i<n-1;i++){
    if(v[i].first==v[i+1].first) continue;
    q.push(PP(abs(v[i].first-v[i+1].first),
	      P(n+mx[v[i].first],n+mx[v[i+1].first])));
  }
  for(int i=0;i<n-1;i++){
    if(u[i].first==u[i+1].first) continue;
    q.push(PP(abs(u[i].first-u[i+1].first),
	      P(n+cx+my[u[i].first],n+cx+my[u[i+1].first])));
  }
  //cout<<n<<" "<<cx<<" "<<cy<<endl;
  int ans=0;
  UnionFind uf(n+cx+cy);
  while(!q.empty()){
    PP pp=q.top();q.pop();
    P p=pp.second;
    int d=pp.first,s=p.first,t=p.second;
    //cout<<d<<" "<<s<<" "<<t<<endl;
    if(uf.same(s,t)) continue;
    //cout<<d<<" "<<s<<" "<<t<<endl;
    ans+=d;
    uf.unite(s,t);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 38248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  bool ans=true;
  cin>>n;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin>>vec.at(i);
  }
  vec.at(0)=vec.at(0)-1;
  for(int i=1; i<n; i++){
    if(vec.at(i)-vec.at(i-1)>0){
      vec.at(i)=vec.at(i)-1;
    }
    if(vec.at(i)-vec.at(i-1)<0){
      ans=false;
      break;
    }
  }
  string str="Yes";
  if(ans){
    cout<<str;
  }
  else{
    str="No";
    cout<<str;
  }
}

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

int minSwaps(int A[], int n)
{

    pair<int, int> arrPos[n];
    for (int i = 0; i < n; i++)
    {
        arrPos[i].first = A[i];
        arrPos[i].second = i;
    }

    sort(arrPos, arrPos + n);

    vector<bool> vis(n, false);

    int ans = 0;

    for (int i = 0; i < n; i++)
    {
        if (vis[i] || arrPos[i].second == i)
            continue;

        int cycle_size = 0;
        int j = i;
        while (!vis[j])
        {
            vis[j] = 1;

            j = arrPos[j].second;
            cycle_size++;
        }
        if (cycle_size > 0)
        {
            ans += (cycle_size - 1);
        }
    }

    return ans;
}

int main()
{
    int n;
    cin>>n;
    int a[n+1];
    int counter=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]!=i)
            counter++;
    }
    if(counter<=2)
        cout<<"YES";
    else
        cout<<"NO";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;

public class Program
{
    private static void Main()
    {
        string[] WHxyr = Console.ReadLine().Split(' ');
        int W = int.Parse(WHxyr[0]);
        int H = int.Parse(WHxyr[1]);
        int x = int.Parse(WHxyr[2]);
        int y = int.Parse(WHxyr[3]);
        int r = int.Parse(WHxyr[4]);

        if (x >= W || y >= H || x - r < 0 || y - r < 0 || x + r > W || y + r > H)
            Console.WriteLine("No");
        else
            Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 8920
#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define n 300000
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
struct edge{
	int to, weight;
};
void solve();
int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}
vector<edge> V[n + 50];
int a, b, c, d, e, f;
int arr[n + 50], arr1[n + 50], arr2[n + 50];
string str, str1, str2;

void solve()
{
	cin >> a;
	cin >> str;
	if(a % 2)
	{
		cout << "No";
		return;
	}
	int mid = a / 2;
	for(int i=0, j=mid; i<mid; i++, j++)
	{
		if(str[i] != str[j])
		{
			cout << "No";
			return;
		}
	}
	cout << "Yes";
}


Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,k,ans=0,fl=0;
	string s;
	cin>>n;
	if(n==0)
		cout<<"1\n";
	else
		cout<<"0\n";
	return 0;
}

Measured memory_bytes: 3636
import java.io.*
import java.util.*

fun solve(N: Int, a: IntArray, b: IntArray){
    val tree = AdjacentListGraph<Int, Int>(Array(N){ Vertex<Int, Int>() }.toMutableList())
    for(i in 0 until N - 1){
        tree.addEdge(a[i] - 1, b[i] - 1, 1)
        tree.addEdge(b[i] - 1, a[i] - 1, 1)
    }
    val distances1 = tree.getDistances(0)
    val distances2 = tree.getDistances(N - 1)
    val fennec = (0 until N).count{ distances1[it] <= distances2[it] }
    if(fennec > N - fennec){ println("Fennec") }
    else println("Snuke")
    return
}

fun AdjacentListGraph<Int, Int>.getDistances(from: Int): IntArray{
    // Bread First Search
    val distances = IntArray(vertices.size){ -1 }
    distances[from] = 0
    val queue = ArrayDeque<Int>()
    queue.add(from)
    while(queue.size > 0){
        val node = queue.removeFirst()
        val curDist = distances[node]
        vertices[node].edges.filter{ distances[it.to] == -1 }.forEach{
            val delta = it.weight?: 1
            distances[it.to] = curDist + delta
            queue.add(it.to)
        }
    }
    return distances
}
data class Vertex<T : Comparable<T>, E : Comparable<E>>(val data: T? = null) {
    data class Edge<T : Comparable<T>>(val to: Int, val weight: T? = null)

    val edges = mutableListOf<Edge<E>>()

    fun addEdge(to: Int, weight: E?) = when (edges.find { it.to == to }) {
        null -> {
            edges.add(Edge(to, weight))
            true
        }
        else -> false
    }

    fun removeEdge(to: Int): Boolean{
        for ((i, edge) in edges.withIndex()){
            if (edge.to == to){
                edges.removeAt(i)
                return true
            }
        }
        return false
    }
}

class AdjacentListGraph<T : Comparable<T>, E : Comparable<E>>(
    val vertices: MutableList<Vertex<T, E>>
) {
    // T = data of Vertex, E = weight of Edge
    fun getWeight(from: Int, to: Int): E? = vertices[from].edges.find { it.to == to }?.weight
    fun addEdge(from: Int, to: Int, weight: E? = null) = vertices[from].addEdge(to, weight)
    fun removeEdge(from: Int, to: Int) = vertices[from].removeEdge(to)
    fun isAdjacent(from: Int, to: Int) = vertices[from].edges.find { it.to == to } != null
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val a = IntArray((N-1).toInt())
    val b = IntArray((N-1).toInt())
    for (i in 0 until (N-1).toInt()) {
        a[i] = sc.next().toInt()
        b[i] = sc.next().toInt()
    }
    solve(N, a, b)
}



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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<double> a(n), s(n + 1);
  REP(i, n) cin >> a[i];
  REP(i, n) {
    ll sum = a[i] * (a[i] + 1) / 2;
    a[i] = sum / a[i];
  }

  s[0] = 0;
  REP(i, n) s[i + 1] = a[i] + s[i];

  double mx = 0;
  REP(i, n - k + 1) {
    double tmp = s[i + k] - s[i];
    mx = max(mx, tmp);
  }
  printf("%.10f\n", mx);
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
    int k;
    cin >> k;
    int x = 7%k;
    set<int> s;
    int i = 1;
    while(s.count(x) == 0){   //s.count(x)はsに含まれるxの個数
        if(x == 0){
            cout << i << endl;
            return 0;        //return 0はここでプログラムを終えるという意味
        }
        s.insert(x);         //setだから0か1
        x = (x*10+7)%k;
        i++;
    }
    cout << -1 << endl;
    return 0;
}

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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int N, K;
    cin >> N >> K;

    int ret = K;
    for (int i = 1; i < N; i++) {
        ret *= (K-1);
    }
    cout << ret << endl;
    
}


Measured memory_bytes: 256
a=int(input())
b=list(map(int,input().split()))
count=0
for i in range (a):
 if b[i]%2==0 and b[i]%3!=0 and b[i]%5!=0:
  count=0
  break
 else:count=1
if count==1:
 print("APPROVED")
else: print("DENIED")

Measured memory_bytes: 3060
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.PriorityQueue

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val n, m, s, t = in.next().toInt

  val graphA = Array.fill[List[(Int, Int)]](n+1)(Nil)
  val graphB = Array.fill[List[(Int, Int)]](n+1)(Nil)

  for(_ <- 1 to m) {
    val u, v, a, b = in.next().toInt
    graphA(u) = (v, a) :: graphA(u)
    graphA(v) = (u, a) :: graphA(v)
    graphB(u) = (v, b) :: graphB(u)
    graphB(v) = (u, b) :: graphB(v)
  }


  // fro から to への最短距離(v は頂点数)
  def dijkstra(from: Int, to: Int, v: Int, edge: Array[List[(Int, Int)]]): Array[Long] = {
    val MAX = Long.MaxValue

    val dist = Array.fill(v+1)(MAX)   // fro からの距離を格納する
    val check = new Array[Boolean](v+1)  // すでにその頂点からを調べたかのフラグ

    dist(from) = 0

    val pq = new PriorityQueue[(Long, Int)]  // (-cost, node) queue
    pq.enqueue((-0, from))

    // 頂点は v 個あるので、v 周する
    for(_ <- 0 until v) {
      // 調べ済みでない頂点のうち、最も近い頂点を now に入れる
      var nowNode = -1       // このターンにフォーカスするノード

      breakable {
        while(true) {
          nowNode = pq.dequeue._2  // 最小コストから貪欲に取っていく
          if(!check(nowNode)){  // まだチェックされていないノードだったら決定
            check(nowNode) = true
            break
          }
        }
      }

      // その頂点からたどり着ける頂点の情報を更新する
      for((nextNode, cost) <- edge(nowNode)) {
        val nextDist = dist(nowNode) + cost
        if(nextDist < dist(nextNode)){  // 既存の通路より近いなら更新
          dist(nextNode) = nextDist
          pq.enqueue((-nextDist, nextNode))
        }
      }
    }

    dist
  }

  val init = 1e15.toLong

  val dpA = dijkstra(s, t, n, graphA)
  val dpB = dijkstra(t, s, n, graphB)

  val ans = new Array[Long](n+1)
  ans(n) = 0L

  for(i <- (0 until n).reverse) {
    val now = init - (dpA(i+1) + dpB(i+1))
    ans(i) = now max ans(i+1)
  }

  for(i <- 0 until n) {
    pw.println(ans(i))
  }
  pw.flush()
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 142656
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode().rstrip()

print(S[:3])


Measured memory_bytes: 26984
N, M = map(int, input().split())
h = list(map(int, input().split()))

l = []

all = sum(h)
border = all / (4 * M)

for i in h:
    if i >= border:
        l.append(i)
    else:
        pass

if len(l) < M:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3316
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int m1 = sc.nextInt();
    int d1 = sc.nextInt();
    int m2 = sc.nextInt();
    int d2 = sc.nextInt();
    if( d1 > d2 && m1 < m2) {
      System.out.println(1);
    } else {
      System.out.println(0);
    }
}
}


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

int A, B, C;
void solve()
{
	int five = 0, seven = 0;
	if(A == 5)
		five++;
	else if(A == 7)
		seven++;
	if(B == 5)
		five++;
	else if(B == 7)
		seven++;
	if(C == 5)
		five++;
	else if(C == 7)
		seven++;
	if(five == 2 && seven == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl; 
}
int main()
{
	
	cin >> A >> B >> C;
	solve();
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define ll long long
#define inf 100005
#define mod 1000000007
using namespace  std;

vector<vector<ll>>g(inf);
vector<ll>indgree(inf);
vector<ll>dist(inf);
bool visted[inf];



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

	vector<double>p(n+1);

	for(ll i=1;i<=n;i++){
		cin>>p[i];
	}

	vector<vector<double>>dp(n+1,vector<double>(n+1));
	dp[0][0]=1;
	for(ll i=1;i<=n;i++){
		for(ll j=0;j<=n;j++){
			if(j==0){
				dp[i][j] = (1-p[i])*dp[i-1][j];
			}else{
				dp[i][j] = (p[i])*dp[i-1][j-1]+(1-p[i])*dp[i-1][j];
			}
		}
	}

	double res = 0;

	for(ll i=n/2+1;i<=n;i++){
		res+=dp[n][i];
	}

	
	printf("%.10lf\n",res);
	return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[100005][3];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(3);
  rep(i,3) cin>>a[i];
  string s; cin>>s;
  vll ctoi(256);
  ctoi['r']=2;
  ctoi['c']=0;
  ctoi['p']=1;
  ll ans=0;
  rep(i,k){
    vll x;
    for(ll j=i; j<n; j+=k){
      x.push_back(ctoi[s[j]]);
    }
    vll dp(2); // dp[0] 今回は負ける
    ll pre=-1;
    for(auto nx: x){
      vll p(2);
      swap(dp,p);
      dp[0]=max(p[0],p[1]);
      if(pre==nx){
        dp[1]=p[0]+a[nx];
      }else{
        dp[1]=max(p[0],p[1])+a[nx];
      }
      pre=nx;
    }
    ans+=max(dp[0],dp[1]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1528
s = input()
q = int(input())

up = 0

head = []
tail = []

for _ in range(q):
    query = list(input().split())

    if query[0] == "1":
        if up:
            up = 0
        else:
            up = 1

    elif query[0] == "2":
        if query[1] == "1":
            if up:
                tail.append(query[2])
            else:
                head.append(query[2])
        elif query[1] == "2":
            if up:
                head.append(query[2])
            else:
                tail.append(query[2])

head=''.join(map(str,head))
tail=''.join(map(str,tail))

ans = head[::-1] + s + tail

if up:
    ans = ans[::-1]
print(ans)

Measured memory_bytes: 6268
from collections import deque

N, M = map(int, input().split())

AB = [map(lambda x: int(x) - 1, input().split()) for _ in range(M)]
to_list = [[] for _ in range(N)]

for a, b in AB:
    to_list[a].append(b)
    to_list[b].append(a)

result = [-1] * N
q = deque([0])
while q:
    i = q.popleft()
    for j in to_list[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i + 1) for i in result[1:]))

Measured memory_bytes: 134996
(defun chanc (s k)
  (let* ((pos (- k 1))
         (c (char s pos))
         (new-c (char-downcase c)))
    (setf (char s pos) new-c) 
    s))

#|
(print 
  (chanc "ABC" 1))

(print 
  (chanc "CABA" 3))
|#

(let ((n (read))
      (k (read))
      (s (read-line)))
  (format t (chanc s k)))


Measured memory_bytes: 11240
/*
17D8101013F 森田　匡博
ID:key4 使用言語:C++
*/

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>

int main() 
{
  std::vector<std::string> str;
  std::string str2[200];
  std::vector<int> num;
  int ans[200];

  int n = 0;
  std::cin >> str2[0];
  n++;
  while(getchar() != '\n') {
    std::cin >> str2[n];
    n++;
  }

  for(int i = 0; i < n; i++) {
    str.push_back(str2[i]);
  }

  /*
  str.erase(str.begin());
  for(int i = 0; i < n; i++) {
    std::cout << str[i] << " ";
  }
  */

  
  /*
  for(int i = 0; i < n; i++) {
    if(str[i] != "+" || str[i] != "-" || str[i] != "*") {
      num[i] = std::stoi(str[i]);
    }
  }
  */

  int i = 2;
  //std::cout<< str.size();
  while(str.size() > 1) {
    //std::cout << str[i] << " ";
    if(str[i] == "+") {
      str[i-2] = std::to_string(std::stoi(str[i-2]) + std::stoi(str[i-1]));
      str.erase(str.begin() + i - 1, str.begin() + i + 1);
      i = 1;
    }
    if(str[i] == "-") {
      str[i-2] = std::to_string(std::stoi(str[i-2]) - std::stoi(str[i-1]));
      str.erase(str.begin() + i - 1, str.begin() + i + 1);
      i = 1;
    }
    if(str[i] == "*") {
      str[i-2] = std::to_string(std::stoi(str[i-2]) * std::stoi(str[i-1]));
      str.erase(str.begin() + i - 1, str.begin() + i + 1);
      i = 1;
    }
    i++;
  }

  /*
  for(int i = 0; i < n; i++) {
    std::cout << str[i] << " ";
  }
  */
  

  std::cout << str[0] <<"\n";

  return 0;
}



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

A = [[0 for i in range(m)]for j in range(n)]
B = [[0 for i in range(l)]for j in range(m)]
C = [[0 for i in range(l)]for j in range(n)]

for i in range(n):
    lst = list(map(int,input().split()))
    for j in range(m):
        A[i][j] = lst[j]

for i in range(m):
    lst = list(map(int,input().split()))
    for j in range(l):
        B[i][j] = lst[j]
        
for i in range(n):
    for j in range(l):
        total = 0
        for k in range(m):
            total += A[i][k] * B[k][j]
        C[i][j] = total
    s = map(str, C[i])
    print(" ".join(s))


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

using namespace std;

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

    int res = 0;
    int now;
    int prev;
    for (int i = 0; i < N - 1; i++) {
        cin >> now;
        if (i == 0) {
            res += now;
        } else {
            res += min(prev, now);
        }
        prev = now;
    }
    res += now;

    cout << res;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
using P = pair<ld,ld>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=998244353;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll D;
    cin >> D;
    if(D==25)prt("Christmas")
    if(D==24)prt("Christmas Eve")
    if(D==23)prt("Christmas Eve Eve")
    if(D==22)prt("Christmas Eve Eve Eve")

    return 0;
}


Measured memory_bytes: 256
function main (input) {
	const args = input.split(' ');
	const a = parseInt(args[0], 10);
	const b = parseInt(args[1], 10);
 
	if ((a * b) % 2 === 0) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
s = gets.chomp
q = gets.to_i

cnt = 0
sl = []
sr = []
q.times do
  t, f, c = gets.chomp.split
  if t == "1"
    cnt += 1
  elsif t == "2"
    if f.to_i % 2 + cnt % 2 == 1
      sl.unshift(c)
    else
      sr.push(c)
    end
  end
end

if cnt % 2 != 0
  puts sr.reverse.join("") + s.reverse + sl.reverse.join("")
else
  puts sl.join("") + s + sr.join("")
end

Measured memory_bytes: 29244
using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputLine = Console.In.ReadLine();
            var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });
            if (inputs.Length != 3)
            {
                return;
            }

            var a = int.Parse(inputs[0]);
            var b = int.Parse(inputs[1]);
            var c = int.Parse(inputs[2]);
            Func<int, bool> check = (int i) =>
            {
                if (i < 0) return false;
                if (i > 100) return false;
                return true;
            };
            if (false
                || check(a) == false
                || check(b) == false
                || check(c) == false
                )
            {
                return;
            }

            var result = "No";
            if (a < b && b < c)
            {
                result = "Yes";
            }

            Console.WriteLine(result);
        }
    }
}


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

int main(){
	int n;
	cin>>n;
	int h[n];
	for(int i=0; i<n; i++) cin>>h[i];
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i=2; i<n; i++){
		dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

int main (){
    int N;
    cin >> N;
    double  X[N];
    double Y[N];
    for (int i=0;i<N;i++){
        cin >> X[i] >> Y[i];
    }
    double sum=0;
    double c=1;
    for (int i=2;i<=N;i++){
        c *= i;
    }
    double k = N*(N-1)/2;
    //cout << c<<endl;
    for (int i=0;i<N;i++){
        for (int j=i;j<N;j++){
            double l = sqrt( (X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]) );
            // cout << l;
            sum +=  (((N-1)*c) / k) * l;
        }    
    }
    printf("%.10f", sum / c);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a,b,c;
  cin>>a>>b>>c;
  if (a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0)) {
    cout << "YES";
  }
  else cout << "NO";
}

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

int calc(int N)
{
  return to_string(N).size();
}

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

  int ans=0;
  for(int i=1;i<=N;i++){
    if(calc(i)%2==1) ans++;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
while True:
    scores = input().split()
    m = int(scores[0])
    f = int(scores[1])
    r = int(scores[2])
    if m==r==f==-1:
        break
    elif m==-1 or f==-1:
        print("F")
    elif m+f>=80:
        print("A")
    elif 65<=m+f<80:
        print("B")
    elif 50<=m+f<65:
        print("C")
    elif 30<=m+f<50:
        if r>=50:
            print("C")
        else:
            print("D")
    elif m+f<30:
        print("F")
        



Measured memory_bytes: 5592
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

const long long int inf=199999;
long long int mod;

const long long int INF = 9999999999999999;

long long int free_XOR[50]={},two[55]={1},n,a[100400];
long long int atwo[100040][45]={},cou[50]={},res=0,k;


int main() {
	cout << fixed << setprecision(10);
	cin>>n>>k;
	for(int i=1;i<=50;i++){
		two[i]=2*two[i-1];
	}
	for(int i=1;i<=n;i++){
		cin>>a[i];
		for(int j=44;j>=0;j--){
			atwo[i][j]=a[i]/two[j]%2;
		}
		
	}
	
	for(int i=0;i<=44;i++){
		long long int count_zero=0;
		for(int j=1;j<=n;j++){
			if(atwo[j][i]==0){
				count_zero++;
			}
		}
		cou[i]=count_zero;
		if(2*count_zero<n&&i==0){
			free_XOR[i]=n-count_zero;
		}else if(2*count_zero<n){
			free_XOR[i]=free_XOR[i-1]+two[i]*(n-count_zero);
		}else if(i==0){
			free_XOR[i]=count_zero;
		}else{
			free_XOR[i]=free_XOR[i-1]+two[i]*count_zero;
		}
	}
	
	long long int memo=0;
	for(int i=44;i>=0;i--){
		if(k<two[i]){
			memo+=two[i]*(n-cou[i]);
		}else if(i!=0){
			res=max(memo+two[i]*(n-cou[i])+free_XOR[i-1],res);
			memo+=two[i]*cou[i];
			k-=two[i];
		}else {
			memo+=two[i]*cou[i];
			k-=two[i];
		}
		if(i==0){res=max(res,memo);}
		//cout<<memo<<endl;
	}
	cout<<res<<endl;
} 


Measured memory_bytes: 36224
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int ans = 0;
			
			int V = sc.nextInt();
			int d = sc.nextInt();
			int[] F = new int[V+1];
			F[0] = 1;
			F[1] = 2;
			for(int i=2;i<=V;i++) {
				F[i] = (F[i-1] + F[i-2]) % 1001;
			}
			UnionFind u = new UnionFind(V);
			for(int i=1;i<=V-1;i++) {
				for(int j=i+1;j<=V;j++) {
					if (Math.abs(F[i]-F[j])<d) {
						u.union(i-1, j-1);
					}
				}
			}
			System.out.println(u.groupNum());
		}
	}
}
class UnionFind {
	private int[] data;
	public UnionFind(int size) {
		data = new int[size];
		Arrays.fill(data, -1);
	}
	public void union(int x,int y) {
		x = root(x);
		y = root(y);
		if (x!=y) {
			if (data[y] < data[x]) {
				int tmp = y;
				y = x;
				x = tmp;
			}
			data[x] += data[y];
			data[y] = x;
		}
	}
	public boolean isConnected(int x,int y) {
		return root(x)==root(y);
	}
	private int root(int x) {
		return data[x] < 0 ? x : (data[x] = root(data[x]));
	}
	public int size(int x) {
		return -data[root(x)];
	}
	public int groupNum() {
		int num = 0;
		for(int x:data) {
			if (x<0) {
				num++;
			}
		}
		return num;
	}
	public String toString() {
		return Arrays.toString(data);
	}
}

Measured memory_bytes: 20744
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools


def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29


def mk1d(n, val=INF):
    return [val for i in range(n)]

def mk2d(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]

DIV = 998244353


def convolve(a, b):
    p, g = 1107296257, 5
    n0, n1 = len(a), len(b)
    n = 1 << (max(n0, n1) - 1).bit_length() + 1
    a = a + [0] * (n-n0)
    b = b + [0] * (n-n1)
    w = pow(g, (p - 1) // n, p)
    invw = pow(w, p-2, p)

    def fft(f):
        d = n // 2
        v = w
        while d >= 1:
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * v % p
            v = v * v % p
            d //= 2

    def ifft(f):
        d = 1
        while d < n:
            v = pow(invw, n // (2 * d), p)
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j+d] *= u
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * v % p
            d *= 2

    fft(a), fft(b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(a)
    invn = pow(n, p - 2, p)
    return [a[i] * invn % p for i in range(n0 + n1 - 1)]


def main():
    N,M = isRaw()
    ans = "Yes" if 500*N >=M else "No"
    return ans

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38256
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return v.copy()
    return [nlist(n[1:], v) for _ in range(n[0])]

# Union-Find木
class UFT:
    def __init__(self, n):
        self.height = [1] * n
        self.group = [-1] * n
    def root(self, v):
        if self.group[v] < 0:
            return v
        self.group[v] = self.root(self.group[v])
        return self.group[v]
    def size(self, v):
        return - self.group[self.root(v)]
    def equal(self, v1, v2):
        v1, v2 = self.root(v1), self.root(v2)
        return v1 == v2
    def merge(self, v1, v2):
        v1, v2 = self.root(v1), self.root(v2)
        if self.equal(v1, v2):
            return False
        if self.height[v1] < self.height[v2]:
            self.group[v2] += self.group[v1]
            self.group[v1] = v2
            self.height[v2] = max(self.height[v1] + 1, self.height[v2])
        else:
            self.group[v1] += self.group[v2]
            self.group[v2] = v1
            self.height[v1] = max(self.height[v1], self.height[v2] + 1)
        return True

# エントリーポイント
def main():
    N, M = input(int, int)
    XYZ = input([[int, 3], M])

    uft = UFT(N + 1)
    for x, y, _ in XYZ:
        uft.merge(x, y)

    cnt = 0
    for t in uft.group[1:]:
        if t < 0:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


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

using namespace std;

int main()
{
    int N, Y;
    cin >> N >> Y;
    for (int i = N; i >= 0; i--)
    {
        for (int j = N - i; j >= 0; j--)
        {
            int k = N - i - j;
            int sum = 10000 * i + 5000 * j + 1000 * k;
            if (sum == Y)
            {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
            else if (sum < Y)
            {
                break;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
money = 1000
kabu = 0

input()
A = [int(x) for x in input().strip().split(" ")]
As = [[]]

for i, a in enumerate(A):
    if len(As[-1]) == 0:
        As[-1].append(a)
    elif As[-1][-1] <= a:
        As[-1].append(a)
    else:
        As.append([a])
As = [As_ for As_ in As if len(As_) > 1]
for As_ in As:
    kabu, money = divmod(money, As_[0])
    money += kabu * As_[-1]
print(money)

Measured memory_bytes: 9204
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	
	vector<pair<int, int>> edge;
	edge.reserve(N*(N-1)/2);

	if (N & 1) {

		int node = N, except = 0;
		while (except < N) {
			for (int j = 1; j < node; j++) {
				if (j != except) edge.emplace_back(j, node);
			}
			node--;
			except++;
		}

	}
	else {

		for (int i = 1; i < N / 2; i++) edge.emplace_back(i, i + 1);
		edge.emplace_back(N / 2, N);
		for (int i = N; i > N / 2 + 1; i--) edge.emplace_back(i, i - 1);
		edge.emplace_back(N / 2 + 1, 1);

		if(N!=4) for (int i = 0; i < N; i++) edge.emplace_back(edge[i].first, N + 1 - edge[i].second);

	}

	cout << edge.size() << "\n";
	for (const auto &e : edge) cout << e.first << " " << e.second << "\n";

	//// dbg
	//vector<int> dbg(N);
	//for (const auto &e : edge) {
	//	dbg[e.first-1] += e.second;
	//	dbg[e.second-1] += e.first;
	//}
	//DMP(dbg);
	//assert(all_of(dbg.begin(), dbg.end(), [&](int d) {return d == dbg[0]; }));

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 1005
#define MAXK 20005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len;
pair<int,pii> items[MAXN];
ll dp[MAXK],res;

inline bool cmp(pair<int,pii> a, pair<int,pii> b){
	return a.first+a.second.first<b.first+b.second.first;
}

int main(){
	scanf("%d",&len);
	for(int i=1; i<=len; i++)
		scanf(" %d %d %d",&items[i].first,&items[i].second.first,&items[i].second.second);
	sort(items+1,items+len+1,cmp);
	memset(dp,-0x3f,sizeof dp);
	dp[0] = 0;
	for(int i=1; i<=len; i++){
		int W = items[i].first, S = items[i].second.first, V = items[i].second.second;
		for(int k=S; k>=0; k--)
			dp[k+W] = max(dp[k+W],dp[k]+V);
	}
	for(int t=0; t<=20000; t++)
		res = max(res,dp[t]);
	printf("%lld\n",res);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int d = sc1.nextInt();
		int n = sc1.nextInt();

		if ( d == 0 ) {
			if (n < 100) {
				System.out.println(n);
			}
			else {
				System.out.println(n + 1);
			}
		}
		else if ( d == 1 ){
			if (n < 100) {
				System.out.println( n * 100);
			}
			else {
				System.out.println( n * 100 + 100);
			}
		}
		else {
			if (n < 100) {
				System.out.println( n * 10000);
			}
			else {
				System.out.println( n * 10000 + 10000);
			}
		}

		sc1.close();

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000;
const char END = '\n';



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

	ll N, Ans = 0;
	cin >> N;
	ll n;
	rep(i, N) {
		cin >> n;
		Ans += n - 1;
	}
	cout << Ans << END;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        String s = stdIn.nextLine();
        String t = stdIn.nextLine();
        int c = 0;
        int x = t.length();
        for(int i = 0 ; i < (s.length() - t.length()) + 1 ; i++){
            for(int j = 0 ; j < t.length() ; j++){
                if(t.charAt(j) != s.charAt(i + j)){
                    c += 1;
                }
            }
            if(x > c){
                x = c;
            }
            c = 0;
        }
        System.out.println(x);
    }
}


Measured memory_bytes: 35684
import java.util.*;

public class Main{

	static void Missing(int[] S,int[] H,int[] C,int[] D){
		
		for(int i = 0; i < 13 ; i++){
			if(S[i] == 0){
				System.out.println("S "+(i+1));
			}
		}
		for(int i = 0; i < 13 ; i++){
			if(H[i] == 0){
				System.out.println("H "+(i+1));
			}
		}
		for(int i = 0; i < 13 ; i++){
			if(C[i] == 0){
				System.out.println("C "+(i+1));
			}
		}
		for(int i = 0; i < 13 ; i++){
			if(D[i] == 0){
				System.out.println("D "+(i+1));
			}
		}
		
	}
	
	static void Input(){
		Scanner scanner = new Scanner(System.in);
		int N	= scanner.nextInt();
		int[] S = new int[13];
		int[] H = new int[13];
		int[] C = new int[13];
		int[] D = new int[13];
		for(int i = 0; i < N ; i++){
			String 	gara = scanner.next();
			int 	kazu = scanner.nextInt();
			switch(gara){
			case "S":S[kazu-1]=1; break;
			case "H":H[kazu-1]=1; break;
			case "C":C[kazu-1]=1; break;
			case "D":D[kazu-1]=1; break;
			}
		}
		Missing(S, H, C, D);
		scanner.close();
	}
	
	public static void main(String[] args) {
		Input();
		
	}

}

Measured memory_bytes: 26276
#include <iostream>

using namespace std;

int main()
{
    int n;
    int res=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(i%2!=0&&x%2!=0)
            res++;
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  int X[100][100];
  for(int i=0; i<100; ++i){
    for(int j=0; j<100; ++j){
      X[i][j]=0;
    }
  }
  string A[N],B[M];
  for(int i=0; i<N; ++i) cin>>A[i];
  for(int i=0; i<M; ++i) cin>>B[i];
  bool CAN=false;
  
  if(N<M) CAN=false;
  else{
    for(int i=0; i<=N-M; ++i){
      for(int j=0; j<=N-M; ++j){
        bool CAN2=true;
        for(int k=0; k<M; ++k){
          for(int l=0; l<M; ++l){
            if(A[i+k].at(j+l)!=B[k].at(l)) CAN2=false; 
          }
        }
        if(CAN2) X[i][j]=1;
      }
    }
  }
  
  for(int i=0; i<100; ++i){
    for(int j=0; j<100; ++j){
      if(X[i][j]==1) CAN=true;
    }
  }
  
  if(CAN) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256