akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    string s;
    cin >> s;

    int ans = 0;

    for (int i = 1;i < s.size()/2;i++){
        for (int j = 0;j < i;j++){
            if(s[j] != s[j+i]) break;
            if(j == i-1) ans = i;
        }
    }

    cout << ans*2 << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (int)(s); i < (int)(n); ++i)

int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  rep(i, 2) {
    rep(j, N) {
      cin >> A.at(i).at(j);
    }
  }
  int max_a = 0;
  rep(i, N) {
    int cnt = 0;
    rep(j, i+1) {
      cnt += A.at(0).at(j);
    }
    rep2(j, i, N) {
      cnt += A.at(1).at(j);
    }
    max_a = max(max_a, cnt);
  }
  cout << max_a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
//const long double PI = acos(-1.0);
#define int long long
struct my_pair {
	int f, s;
	bool operator<(const my_pair& other)const {
		return s < other.s;
	}
};
signed main() {
	int n;
	cin >> n;
	vector<int>v(n);
	unordered_map<int, int>ump0;
	unordered_map<int, int>ump1;
	priority_queue<my_pair, vector<my_pair>>p0;
	priority_queue<my_pair, vector<my_pair>>p1;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		if (i % 2 == 0) {
			ump0[v[i]]++;
		}
		else if (i % 2 == 1) {
			ump1[v[i]]++;
		}

	}

	pair<int, int> f0 = { 0,0 };
	pair<int, int> s0 = { 0,0 };
	for (auto e : ump0) {
		int key, value;
		tie(key, value) = e;
		my_pair m;
		m.f = key;
		m.s = value;
		p0.push(m);
	}
	auto e = p0.top();
	f0 = { e.f,e.s };
	p0.pop();
    e = p0.top();
	s0 = { e.f,e.s };
	pair<int, int> f1 = { 0,0 };
	pair<int, int> s1 = { 0,0 };
	for (auto e : ump1) {
		int key, value;
		tie(key, value) = e;
		my_pair m;
		m.f = key;
		m.s = value;
		p1.push(m);
		
	}
	auto e1 = p1.top();
	f1 = { e1.f,e1.s };
	p1.pop();
	e1 = p1.top();
	s1 = { e1.f,e1.s };
	if (ump0.size() == 1 && ump1.size() == 1 && ump0 == ump1) {
		cout << n / 2 << endl;
	}
	else if (f0.first == f1.first) {
		cout << min(n - f0.second - s1.second, n - f1.second - s0.second) << endl;
	}
	else {
		cout << n - f0.second - f1.second << endl;
	}
	return 0;
}


Measured memory_bytes: 7440
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
int main(){
  int n;  cin >> n;
  bool odd = false;
  rep(i,0,n){
    ll x; cin >> x;
    if(x & 1) odd = true;
  }
  if(odd) cout << "first" << endl;
  else cout << "second" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int main(){

    string s;
    cin >> s;

    for(int i=0; i < s.size(); i+=2){
        if(s[i] != 'h' or s[i+1] != 'i'){
            p("No");
            return 0;
        }
    }

    p("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int S,h,m,s; 
	
	scanf("%d",&S); 
	
	h=S/3600;
	m=S/60-60*h;
	s=S%3600%60;
	
	
	
	
	printf("%d:%d:%d\n", h , m , s);
	
	
	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> wa(n+1);
	int ac = 0, pen = 0;
	for (int i = 0; i < m; i++) {
		int p;
		string s;
		cin >> p >> s;
		if (s == "WA") {
			if (wa[p] >= 0) ++wa[p];
		}
		else {
			if (wa[p] >= 0) {
				pen += wa[p];
				wa[p] = -1;
				++ac;
			}
		}
	}
	cout << ac << ' ' << pen << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    ll N, K;
    cin >> N >> K;
    ll i;
    P s[MAX];
    ll clr[MAX]={};
    
    for(i=0; i<N; i++) cin >> s[i].sc >> s[i].ft;
    sort(s, s+N);
    reverse(s, s+N);
    
    priority_queue<P> q;
    ll ans=0;
    ll t=0;
    ll kind=0;
    
    for(i=0; i<K; i++) {
        q.push(P(-s[i].ft, s[i].sc));
        t+=s[i].ft;
        clr[s[i].sc]++;
        if(clr[s[i].sc]==1) kind++;
    }
    chmax(ans, t+kind*kind);

    for(i=K; i<N; i++) {
        P u=q.top();
        
        while(q.size() && clr[u.sc]==1) {
            q.pop();
            
            if(q.empty()) {
                pt(ans);
                return 0;
            }
            
            u=q.top();
        }
        
        q.pop();
        clr[u.sc]--;
        q.push(P(-s[i].ft, s[i].sc));
        t+=u.ft; t+=s[i].ft;
        
        clr[s[i].sc]++;
        if(clr[s[i].sc]==1) kind++;
        
        chmax(ans, t+kind*kind);
    }

    pt(ans);
}




Measured memory_bytes: 4852
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}



fn main() {
    let l1 = read_t_in_line::<i64>();
    let (x, y, _, k) = (l1[0], l1[1], l1[2], l1[3]);
    let alist = read_t_in_line::<i64>();
    let blist = read_t_in_line::<i64>();
    let clist = read_t_in_line::<i64>();
    let mut c1 = vec![];
    let mut c2 = vec![];
    for i in 0..x {
        for j in 0..y {
            let sum = alist[i as usize] + blist[j as usize];
            c1.push(sum);
        }
    }
    sort_rev(& mut c1);
    for i in 0..min(k as usize, c1.len()) {
        for c in &clist {
            c2.push(c + c1[i]);
        }
    }
    sort_rev(& mut c2);
    for i in 0..(k as usize) {
        println!("{}", c2[i]);
    }
}



Measured memory_bytes: 44276
n,k = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]


for i in range(len(a)):
    a[i] = '{:040b}'.format(a[i])
p = len(bin(k))-2
k = '{:040b}'.format(k)
t = True
ans = 0
for i in range(0,40):
    num_1 = 0
    num_0 = 0
    if t:
        if k[i] == '1':
            for j in range(n):
                if a[j][i] == '1':
                    num_1 += 1
                elif a[j][i] == '0':
                    num_0 += 1
            if num_0 > num_1:
                num = num_0
                ans += (2**(39-i))*num
            else:
                t = False
                num = num_1
                ans += (2**(39-i))*num
        elif k[i] == '0':
            for j in range(n):
                if a[j][i] == '1':
                    num_1 += 1
                elif a[j][i] == '0':
                    num_0 += 1
            num = num_1
            ans += (2**(39-i))*num
    else:
        for j in range(n):
            if a[j][i] == '1':
                num_1 += 1
            elif a[j][i] == '0':
                num_0 += 1
        if num_0 > num_1:
            num = num_0
            ans += (2**(39-i))*num
        else:
            num = num_1
            ans += (2**(39-i))*num
print(ans)

Measured memory_bytes: 91992
#include<iostream>
using namespace std;
int main(){
while(true){
int n,x;
cin >> n >> x;
if(n == 0 && x == 0)break;
int count = 0;
for( int i = 1;i <= n-2;i++){
for( int j = i + 1;j <= n-1;j++){
for( int k = j + 1;k <= n; k++){
if(i+j+k == x)count++;
}
}
}
cout << count << endl;
}
return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	int h, w;
	cin >> h >> w;
	int c[10][10], a[205][205] = {};
	rep(i, 10)rep(j, 10)cin >> c[i][j];
	rep(i, h)rep(j, w)cin >> a[i][j];
	rep(k, 10)rep(i, 10)rep(j, 10)
		if (c[i][j] > c[i][k] + c[k][j])c[i][j] = c[i][k] + c[k][j];
	int ans = 0;
	rep(i, h)rep(j, w)
	{
		int v = a[i][j];
		if (v != -1)
		{
			ans += c[v][1];
		}
	}
	co(ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     int n;cin >> n;
     if(n==3||n==5||n==7) cout <<"YES";
     else cout <<"NO";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

int main() {
    string S;
    cin >> S;
    
    int ans;
    if ( S == "RRR" ) ans = 3;
    else if ( S == "RRS" or S == "SRR" ) ans = 2;
    else if ( S == "SSS" ) ans = 0;
    else ans = 1;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
s = input()

ans = 0
front = -1
back = -1

for i in range(len(s) - 1):
    j = i + 1
    if s[i] == s[j]:
        ans = 1
        front = i + 1
        back = j + 1

for i in range(len(s) - 2):
    j = i + 2
    if s[i] == s[j]:
        ans = 1
        front = i + 1
        back = j + 1

if ans == 0:
    print("-1 -1")
else:
    print(front, back)

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

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	long long n, x, t;
	cin >> n >> x >> t;
	cout << (n / x + (n % x ? 1 : 0)) * t << endl;

	return 0;
}


Measured memory_bytes: 3608
n=int(input())
hoge=input()
ans=[]
for i in  range(n-1):
  ho1=hoge[:i+1]
  ho2=hoge[i+1:]

  kari=0
  
  if(ho1.count("a") and ho2.count("a")):
    kari+=1
  if(ho1.count("b") and ho2.count("b")):
    kari+=1
  if(ho1.count("c") and ho2.count("c")):
    kari+=1
  if(ho1.count("d") and ho2.count("d")):
    kari+=1
  if(ho1.count("e") and ho2.count("e")):
    kari+=1
  if(ho1.count("f") and ho2.count("f")):
    kari+=1
  if(ho1.count("g") and ho2.count("g")):
    kari+=1
  if(ho1.count("h") and ho2.count("h")):
    kari+=1
  if(ho1.count("i") and ho2.count("i")):
    kari+=1
  if(ho1.count("j") and ho2.count("j")):
    kari+=1
  if(ho1.count("k") and ho2.count("k")):
    kari+=1
  if(ho1.count("l") and ho2.count("l")):
    kari+=1
  if(ho1.count("m") and ho2.count("m")):
    kari+=1
  if(ho1.count("n") and ho2.count("n")):
    kari+=1
  if(ho1.count("o") and ho2.count("o")):
    kari+=1
  if(ho1.count("p") and ho2.count("p")):
    kari+=1
  if(ho1.count("q") and ho2.count("q")):
    kari+=1
  if(ho1.count("r") and ho2.count("r")):
    kari+=1
  if(ho1.count("s") and ho2.count("s")):
    kari+=1
  if(ho1.count("t") and ho2.count("t")):
    kari+=1
  if(ho1.count("u") and ho2.count("u")):
    kari+=1
  if(ho1.count("v") and ho2.count("v")):
    kari+=1
  if(ho1.count("w") and ho2.count("w")):
    kari+=1
  if(ho1.count("x") and ho2.count("x")):
    kari+=1
  if(ho1.count("y") and ho2.count("y")):
    kari+=1
  if(ho1.count("z") and ho2.count("z")):
    kari+=1
    
  ans.append(kari)
  
print(max(ans))

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

int main(){
  int N,y,r=0;
  int p=100000000;
  cin>>N;
  r=N;
  for(int i=1;i<10;i++){
    y=y+r/p;
    r=r%p;
    p/=10;
  }
  if(N%y==0){
  cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	set<int>s;
	for (int i = 0; i < N; i++) {
		cin >> K;
		s.insert(K);
	}

	cout << s.size() << endl;
	return 0;
}

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

int main(void){
    long long N,T,A;cin>>N>>T>>A;
    vector<long long>H(N);
    double near=9999999.99;
    long long ans=0;
    for(long long i=0;i<N;i++){
        cin>>H[i];
        double t=T-H[i]*0.006;
        if(abs(near-A)>=abs(t-A)){
            near=t;
            ans=i+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

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

    long long int X = N, fX = 0;
    for( ; X != 0; ){
        fX += X % 10;
        X /= 10;
    }

    if( N%fX == 0 ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque

fun main(args: Array<String>){
    val (n, q) = readLine()!!.split(' ').map{ it.toInt() }
    val queue = ArrayDeque<Pair<String, Int>>()
    repeat(n){
        val (a, b)  = readLine()!!.split(' ')
        queue.addLast(Pair(a, b.toInt()))
    }
    var time = 0
    while(queue.size >0){
        val task = queue.removeFirst()
        if (task.second <= q){
            time += task.second
            println("${task.first} ${time}")
        }else{
            time += q
            queue.addLast(Pair(task.first, task.second - q))
        }
    }
}



Measured memory_bytes: 75700
package main

import (
	"fmt"
)

var n int
var s string
var i int
var seats []string

func main() {
	fmt.Scan(&n)
	seats = make([]string, n)

	l := 0
	r := n - 1
	m := (r + l) / 2
	if ask(l) {
		return
	}
	if ask(r) {
		return
	}

	for {
		m = (r + l) / 2
		if ask(m) {
			return
		}
		before := false
		if (m-l)%2 == 0 {
			before = (seats[m] != seats[l])
		} else {
			before = (seats[m] == seats[l])
		}
		if before {
			r = m
		} else {
			l = m
		}
	}

}

func ask(i int) bool {
	fmt.Println(i)
	fmt.Scan(&s)
	seats[i] = s
	return s == "Vacant"
}


Measured memory_bytes: 1108
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(b%a==0){
      System.out.println(a+b);
    }else{
      System.out.println(b-a);
    }
  }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int W, a, b;
    cin >> W >> a >> b;
    
    if(b > a + W) cout << b - (a + W) << endl;
    else if(a > b + W) cout << a - (b + W) << endl;
    else cout << 0 << endl;
}

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

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 400010;
const int INF = 2147483600;

int N,M;
int Node[MAXN<<1],Next[MAXN<<1],Root[MAXN+1],cnt;
int deg[MAXN+1]; queue<int> que;
char str[MAXN+1];

inline void insert(int u,int v){
	Node[++cnt]=v; Next[cnt]=Root[u]; Root[u]=cnt; deg[v]++;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(),M=read();
	scanf("%s",str+1);
	for(int i=1;i<=M;i++){
		int u=read(),v=read(); 
		int x=(str[u]!=str[v]);
		insert(u+(x^1)*N,v+x*N);
		insert(v+(x^1)*N,u+x*N);
	}  queue<int> que; int all=0;
	for(int i=1;i<=2*N;i++) if(!deg[i]) que.push(i);
	while(!que.empty()){
		int k=que.front(); ++all; que.pop();
		for(int x=Root[k];x;x=Next[x]){
			int v=Node[x]; --deg[v];
			if(!deg[v]) que.push(v);
		}
	} if(all==N*2) puts("No");
	else puts("Yes");
	return 0;
}




Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
const int N=101000;
const int K=20;
double EPS=1e-7;
typedef long long ll;

int aresta[N],mx=0;
vector<pair<int,int>> lista[N];
void dfs(int u,int c,int p)
{
	int k=1;
	for(auto v:lista[u])
	{
		if(v.first==p)
			continue;
		if(k==c)
			k++;
		mx=max(k,mx);
		aresta[v.second]=k;
		dfs(v.first,k,u);
		k++;
	}
}

int32_t main()	
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
	int n,a,b;
	cin>>n;
	for (int i = 0; i < n-1; ++i)
 	{
 		cin>>a>>b;
 		lista[a].push_back({b,i});
 		lista[b].push_back({a,i});
 	} 	
 	dfs(1,0,1);
 	cout<<mx<<"\n";
 	for (int i = 0; i < n-1; ++i)
 	{
 		cout<<aresta[i]<<"\n";
 	}
    return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF = (1LL<<31)-1;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
    int n,m; cin >> n >> m;
    UnionFind tree(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        tree.unite(a,b);
    }

    map<int,int> sz;
    rep(i,n){
        sz[tree.find(i)] = tree.size(i);
    }

    int ma = -1;
    for(auto it : sz){
        ma = max(ma, it.second);
    }

    cout << ma << endl;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  char a;
  cin >> a;
  if (a >= 'A' && a <= 'Z') {
    cout << 'A' << '\n';
  } else {
    cout << 'a' << '\n';
  }
  return 0;
}

Measured memory_bytes: 3604
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Control.Monad.ST
import           Data.Array.IArray
import           Data.Array.MArray
import           Data.Array.ST
import           Data.Array.Unboxed
import           Data.Sequence         (Seq, ViewL (..), (><))
import qualified Data.Sequence         as S

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

bfs :: Int -> Array Int [Int] -> UArray Int Int
bfs n grp = runSTUArray $ do
    d <- newArray (1, n) (-1) :: ST s (STUArray s Int Int)
    writeArray d 1 0
    go (S.singleton 1) d
    return d
  where
    go q d
      | EmptyL  <- S.viewl q = return ()
      | x :< xs <- S.viewl q = do
            xd <- readArray d x
            vs <- filterM (fmap (== -1) . readArray d) (grp ! x)
            forM_ vs $ \v -> writeArray d v (xd + 1)
            go (xs >< S.fromList vs) d

main :: IO ()
main = do
    n <- readLn
    xss <- fmap (fmap readi . B.words) . B.lines <$> B.getContents
    let f [i, 0]   = (i, [])
        f (i:_:is) = (i, is)
    let grp = array (1, n) (fmap f xss) :: Array Int [Int]
    let dst = bfs n grp
    forM_ [1 .. n] $ \i -> do
        putStrLn . unwords $ fmap show [i, dst ! i]



Measured memory_bytes: 4168
#include <iostream>

int main(){
  long n;
  long x[5];
  std::cin >> n;
  for(int i = 0; i < 5; i++) std::cin >> x[i];

  long min = x[0];
  for(int i = 1; i < 5; i++)
    if(x[i] < min) min = x[i];

  long ret = 0;
  if(n%min == 0) ret = n/min + 4;
  else ret = n/min + 5;
  std::cout << ret << std::endl;
  
  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const ll INF = ll(1e18);
ll hoge(ll cost, ll x, vector<ll> &v)
{
    auto it = lower_bound(v.begin(), v.end(), x);
    int idx = it - v.begin();
    ll cost3, cost4;
    cost3 = INF, cost4 = INF;
    if (idx < v.size())
    {
        cost4 = cost + abs(x - v[idx]);
    }
    if (idx > 0)
    {
        cost3 = cost + abs(x - v[idx - 1]);
    }
    return min(cost3, cost4);
}
int main()
{
    cin.sync_with_stdio(false);
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A);
    vector<ll> t(B);
    rep(i, A) cin >> s[i];
    rep(i, B) cin >> t[i];
    vector<ll> ans;
    rep(i, Q)
    {
        ll x;
        cin >> x;
        auto it = lower_bound(s.begin(), s.end(), x);
        int idx = it - s.begin();
        ll cost1 = INF, cost2 = INF;
        ll x1 = INF, x2 = INF;
        if (idx < s.size())
        {
            cost2 = abs(x - s[idx]);
            x2 = s[idx];
        }
        if (idx > 0)
        {
            cost1 = abs(x - s[idx - 1]);
            x1 = s[idx - 1];
        }
        ll cost = min(hoge(cost1, x1, t), hoge(cost2, x2, t));

        it = lower_bound(t.begin(), t.end(), x);
        idx = it - t.begin();
        cost1 = INF,
        cost2 = INF;
        x1 = INF, x2 = INF;
        if (idx < t.size())
        {
            cost2 = abs(x - t[idx]);
            x2 = t[idx];
        }
        if (idx > 0)
        {
            cost1 = abs(x - t[idx - 1]);
            x1 = t[idx - 1];
        }

        ans.push_back(min({cost, hoge(cost1, x1, s), hoge(cost2, x2, s)}));
    }
    rep(i, Q) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 3828
import numpy as np
import sys
input = sys.stdin.buffer.readline

N, M, K = map(int, input().split())
cumA = np.zeros(N+1, dtype=np.int64)
cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum()
cumB = np.zeros(M+1, dtype=np.int64)
cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum()
# print(cumA)
# print(cumB)

cumA = cumA[cumA <= K]
cumB = cumB[cumB <= K]
ans = np.searchsorted(cumA, K - cumB, side='right') - 1
ans += np.arange(len(cumB))
print(ans.max())

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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}
const int MX = 1e7 + 10;
const int MAXN = 12000;

int n, m;
set<int> ss;
int pr[MX];
vector<int> eds[MAXN];
int p[MAXN];
int was[MAXN];

int dfs1(int v) {
    was[v] = 1;
    for (int u: eds[v]) {
        if (p[u] == -1) {
            p[u] = v;
            p[v] = u;
            return 1;
        }
    }
    for (int u: eds[v]) {
        if (!was[p[u]] && dfs1(p[u])) {
            p[u] = v;
            p[v] = u;
            return 1;
        }
    }
    return 0;
}

vector<int> v0;
vector<int> v1;

int main() {
    pr[0] = pr[1] = 1;
    for (int i = 2; i * i < MX; ++i) {
        if (pr[i])
            continue;
        for (int j = i * i; j < MX; j += i)
            pr[j] = 1;
    }
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (ss.count(x))
            ss.erase(x);
        else
            ss.insert(x);
        ss.insert(x + 1);
    }
    for (int i: ss) {
        if (i % 2 == 0)
            v0.push_back(i);
        else
            v1.push_back(i);
    }
    n = v0.size();
    m = v1.size();
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
            if (!pr[abs(v0[i] - v1[j])])
                eds[i].push_back(j + n);
        }
    fill(p, p + n + m, -1);
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        memset(was, 0, sizeof(was));
        if (dfs1(i))
            ++cnt;
    }
    int ans = cnt;
    n -= cnt;
    m -= cnt;
    ans += 2 * (n / 2 + m / 2);
    if (n % 2 == 1)
        ans += 3;
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 39680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	sort(a.begin(),a.end());
	int ans=2000000000;
	rep(i,n-k+1) ans=min(ans,a[i+k-1]-a[i]);
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

class ModInt {
  ll val; static const int MOD = 1e9 + 7; static_assert(MOD > 0ll, "Modulus not set!");
  int modInverse(int a) { // simplified extended GCD, only solving for x
    int b = MOD, x = 0, x_ = 1, q; while (a != 0) { q = b / a; swap(b, a); a %= b;
    swap(x, x_); x_ -= q * x; } assert(b == 1); return (x %= MOD) < 0 ? (x + MOD) : x; }
  public: ModInt() : val(0) { } ModInt(int v) : val(v) { if ((val %= MOD) < 0) val += MOD; }
    ModInt& operator += (const ModInt& b) { if ((val += b.val) >= MOD) val -= MOD; return *this; }
    ModInt& operator -= (const ModInt& b) { if ((val -= b.val) < 0) val += MOD; return *this; }
    ModInt& operator *= (const ModInt& b) { val = (val*b.val) % MOD; return *this; }
    ModInt& operator /= (const ModInt& b) { if (((val *= modInverse(b.val)) %= MOD) < 0) val += MOD; return *this; }
#define _op(op) ModInt& operator op (int b) { ModInt w(b); return *this op w; }
    _op(+=); _op(-=); _op(*=); _op(/=);
#undef _op
#define _op(op, btype, op2) ModInt operator op (btype b) const { ModInt ans = *this; return ans op2 b; }
    _op(+, const ModInt&, +=); _op(-, const ModInt&, -=); _op(*, const ModInt&, *=); _op(/, const ModInt&, /=);
    _op(+, int, +=); _op(-, int, -=); _op(*, int, *=); _op(/, int, /=);
#undef _op
    operator int() const { assert(0 <= val && val < MOD); return val; }
};

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n, k;
  cin >> n >> k;
  VI nums(n);
  forx(i,n) cin >> nums[i];
  
  vector<ModInt> ways(k+1);
  //make into prefix sum
  forx(i, k+1) {
    if (i <= nums[0])
      ways[i] = i + 1;
    else
      ways[i] = nums[0] + 1;
  }


  forx(c, n-1) {
    //push c'th child to c+1
    vector<ModInt> nx(k+1);
    //consider having i candies for the next child
    forx(i, k+1) {
      int lb = max(0, i - nums[c+1]);
      int ub = i;
      nx[i] = ways[ub];
      if (lb) nx[i] -= ways[lb - 1];
    }
    //make into prefix sum
    forx(i, k) {
      nx[i+1] += nx[i];
    }
    ways.swap(nx);
  }


  ModInt ans = ways[k];
  if (k) ans -= ways[k-1];
  cout << ans << nl;
  
  cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl;
  return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>

#define MaxN 300000
int a[MaxN], b[MaxN];

int main(void) {
  int n;
  scanf("%i", &n);
  
  for (int i = 0; i < n; i++) {
    scanf("%i", &a[i]);
  }
  
  int l = 0, r = n-1, f = 0;
  for (int i = n-1; i >= 0; i--) {
    if (f) {
      b[r--] = a[i]; 
    } else {
      b[l++] = a[i];
    }
    f ^= 1;
  }
  
  for (int i = 0; i < n; i++) {
    printf("%i ", b[i]);
  }
  puts("");
  
  return 0;
}

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

main(){
	int N,Y;
	int x=0,y=0,z=0;
	int a,b,c;
	
	scanf("%d",&N);
	scanf("%d",&Y);
	
	for(x=0;x<=N;x++){
		a = x*10000;
;
		for(y=0;y<=N;y++){
			b = y*5000;
			if(N-(x+y)<0){
				break;
			}
			else{
				z =N-x-y;
				c = z*1000;
				
			}
			if(Y  == a+b+c && N==x+y+z){
				printf("%d\t%d\t%d",x,y,z);
				return 0;
			}
			
	}
		 
	}
	printf("-1 -1 -1");
	
}

Measured memory_bytes: 128
#include<stdio.h>

int c1,c5,c10,c50,c100,c500;

int SUM();

int main(){
	int sum;
	
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	
	c5  *=  5;
	c10 *= 10;
	c50 *= 50;
	c100*=100;
	c500*=500;
	
	sum=SUM();
	
	if(sum>=1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}

int SUM(){
	int sum=0;
	
	sum+=c1+c5+c10+c50+c100+c500;
	
	return sum;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void EducationalDP_I()
{
	int N;
	cin >> N;
	vector<double> p(N);
	for (auto& x : p)
		cin >> x;
	vector<vector<double> > dp(N, vector<double>(N+1));
	dp[0][0] = 1.0 - p[0];
	dp[0][1] = p[0];

	for (int i = 1; i < N; ++i)
	{
		for (int j = 0; j <= i + 1; ++j)
		{
			dp[i][j] = (j == 0 ? 0.0 : dp[i - 1][j - 1] * p[i]) + dp[i - 1][j] * (1.0 - p[i]);
		}
	}

	double pr = 0.0;
	for (int i = N / 2 + 1; i <= N; ++i)
	{
		pr += dp[N - 1][i];
	}
	cout << std::fixed << std::setprecision(30) << pr << endl;

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

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    string s;
    cin >> s;
    int n = s.size();
    int cntA = 0;
    int ans = 0;
    int i = 0;
    while (i < n) {
        if (s.substr(i, 2) == "BC") {
            int cntBC = 0;
            int j = i;
            while (j < n && s.substr(j, 2) == "BC") {
                cntBC++;
                j += 2;
            }
            ans += cntA * cntBC;
            i = j;
        } else if (s[i] == 'A') {
            cntA++;
            i++;
        } else {
            cntA = 0;
            i++;
        }
    }
    cout << ans << endl;

    return 0;
}

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




























int main() {
    long long N;
    cin >> N;
    long long a = 1;
    long long b = 1;
    long long c = 1;
    for (long long i = 0; i < N; i++) {
        a = (a * 10) % (1000000007);
        b = (b * 9) % (1000000007);
        c = (c * 8) % (1000000007);
    }
    long long ans = (a -2 * b + c) % (1000000007);

    while (ans < 0) ans += 1000000007;

    cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  string s[n][2];
  string d;
  for(int i=0;i<n;i++){
    cin >> s[i][0];
    cin >> s[i][1];
  }
  cin >> d;
  int a;
  for(int i=0;i<n;i++){
    if(d == s[i][0]){a=i;}
  }
  int ans=0;
  for(int i=a+1;i<n;i++){
    ans += stoi(s[i][1]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int x;
    cin >> x;
    int res = 0;
    for (int i = 1; i < 1000; i++)
    {
        for (int j = 2; j < 1000; j++)
        {
            ll tmp = pow(i,j);
            if(tmp>x){
                continue;
            }
            if(res < tmp){
                res = tmp;
            }
        }
        
    }
    cout << res << endl;
    
}


Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    string u="";
    rep(i,n){
        u=u+s[i]+t[i];
    }
    cout << u;

}

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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const ll INF = 1e9;
const ll INFF = 1e18;
const ll MAXN = 510;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

ll mul(ll x,ll y)
{
    return ((x % MOD) * (y % MOD)) % MOD;
}

ll add(ll x,ll y)
{
    return ((x % MOD) + (y % MOD)) % MOD;
}

ll sub(ll x,ll y)
{
    ll ret = ((x % MOD) - (y % MOD)) % MOD;
    if (ret < 0)
        ret += MOD;
    return ret;
}

ll modpow(ll x,ll y)
{
    if (!y) return 1;
    ll z = modpow(x,y / 2);
    z = mul(z,z);
    if (y & 1) z = mul(z,x);
    return z;
}

ll inv(ll x)
{
    return modpow(x,MOD - 2);
}

ll bagi(ll x,ll y)
{
    return mul(x,inv(y));
}

ll pref[65][300010];
ll tab[300010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    for (ll i = 1 ; i <= n ; i++)
    {
        for (ll j = 0 ; j < 60 ; j++)
            pref[j][i] = pref[j][i - 1];
        ll ta;
        cin >> ta;
        for (ll j = 0 ; j < 60 ; j++) if (ta & (1ll << j))
        {
            pref[j][i]++;
        }
        tab[i] = ta;
    }
    ll ans = 0;
    for (ll i = 1 ; i <= n ; i++)
    {
        ll pengali = 1;
        ll rem = n - i;
        for (ll j = 0 ; j < 60 ; j++)
        {
            ll satu = pref[j][n] - pref[j][i];
            ll nol = rem - satu;
            // cout << j << ": " << satu << " " << nol << endl;
            if (tab[i] & (1ll << j))
                ans = add(ans,mul(nol,pengali));
            else
            {
                // cout << "yo\n";
                ans = add(ans,mul(satu,pengali));
            }
            pengali = mul(pengali,2ll);
        }
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 146556
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;


lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli a[100010] = {};
bool broken[1000110] = {};

int main(void) {

	lli N, M;
	cin >> N >> M;

	FOR(M) {
		lli a;
		cin >> a;
		broken[a] = true;
	}

	cout.precision(18);

	a[0] = 1;
	FOR(N) {
		if (broken[i] == true)
			continue;
		a[i] %= mod197;
		a[i + 1] += a[i];
		a[i + 2] += a[i];
	}

	COUT(a[N] % mod197);

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='b') 
            a[i]='d';
        else if(a[i]=='d') 
            a[i]='b';
        else if(a[i]=='p') 
            a[i]='q';
        else if(a[i]=='q') 
            a[i]='p';
    }
    if(a==b) 
        cout<<"Yes";
    else 
        cout<<"No";
    return 0;
}

Measured memory_bytes: 512
def main():

    # inputの取得
    N = int(input())
    X = []
    for i in range(N):
        tmp = []
        a = int(input())
        for _ in range(a):
            tmp.append(list(map(int,input().split())))
        X.append(tmp)


    cnt = 0
    
    # bit探索で候補をあげる
    for i in range(2**N):
        flag = 0
        c = ("0" * N + bin(i)[2:])[-N:]

        for j in range(N):
            if c[j] == "0":
                continue
            for k, l in X[j]:
                # 正直者な場合矛盾してないかチェック
                if not (l == int(c[k-1]) ):
                    # 矛盾してるのでフラグあげてbreak
                    flag = 1
                    break

        if flag == 1:
            continue
        cnt = max(cnt, c.count("1"))

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.lang.Integer.max
import kotlin.math.min

//

fun main() {
    abc177d()
}

fun abc177d() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val group = IntArray(n + 1) { it }
    val counts = IntArray(n + 1) { 1 }
    val pair = mutableSetOf<Pair<Int, Int>>()
    var maxSize = 1
    for (i in 0 until m) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        val p = min(a, b) to max(a, b)
        if (p in pair) continue
        pair.add(p)
        var ta = p.first
        var tb = p.second
        while (group[ta] != ta) {
            ta = group[ta]
        }
        group[p.first] = ta
        while (group[tb] != tb) {
            tb = group[tb]
        }
        group[p.second] = tb
        if (ta != group[tb]) {
            group[tb] = ta
            counts[ta] += counts[tb]
            maxSize = max(maxSize, counts[ta])
        }
    }
    println(maxSize)
}


Measured memory_bytes: 86860
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> v_x, v_y;
  rep(i, N) {
    int x;
    cin >> x;
    v_x.push_back(x);
  }
  rep(i, M) {
    int y;
    cin >> y;
    v_y.push_back(y);
  }

  bool war = false;

  if (!(X < Y)) {
    war = true;
  }

  sort(v_x.begin(), v_x.end());
  sort(v_y.begin(), v_y.end());

  if (!(v_x[N - 1] < v_y[0] && X < v_y[0] && v_x[N - 1] < Y)) {
    war = true;
  }

  if (war) {
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N,K;
        String S;
        N = sc.nextInt();
        K = sc.nextInt();
        S = sc.next();
        String[] array = S.split("",0);
        for (int i = 0; i < N; i++) {
            if (i==K-1) array[i] = array[i].toLowerCase();            
            System.out.print(array[i]);
        }
    }
}

Measured memory_bytes: 22356
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int M = Integer.parseInt(sc.get());
		BitSet A = new BitSet(N + 1);
		for (int i = 0; i < M; i++) {
			A.set(Integer.parseInt(sc.get()));
		}


		int[] table = new int[N + 1];
		table[0] = A.get(0) ? 0:1;
		table[1] = A.get(1) ? 0:1;
		for (int i = 2; i <= N; i++) {
			if (A.get(i)) continue;
			table[i] = (table[i - 1]  + table[i - 2]) % 1000000007;
		}
		System.out.println(table[N]);
	}
}

class Main {
	public static void main(String... args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
	}
}

Measured memory_bytes: 33108
#include<stdio.h>

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


Measured memory_bytes: 2148
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,(n))
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    cout << (n - 2) * 180 << endl;
    return 0;
}

Measured memory_bytes: 384
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = longList().map {
        var count = 0
        var r = it
        while (r % 2 == 0L) {
            r /= 2
            count++
        }
        count
    }.min()!!.toInt()
    println(a.toString())
}


Measured memory_bytes: 37892
#include<iostream>
    using namespace std;
    int main()
    {
        //Input
        int n;
        cin >> n;
        int v[n], c[n];
        for(int i = 0; i < n; ++i) cin >>v[i];
        for(int i = 0; i < n; ++i) cin >>c[i];

        int bestVal = 0;

        for(int p = 0; p<n; ++p){
            if (v[p] > c[p]){
                bestVal += (v[p] - c[p]);
            }
        }

        // 出力
        cout << bestVal<<endl;
        return 0;
    }

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

         }


    }
    if(c==0)
        cout<<"YES"<<endl;
    else if(c<3)
    {
        swap(a[b[0]], a[b[1]+1]);
        for(i=0; i<n-1; i++)
    {
        if(a[i]>a[i+1])
            k++;
    }
    if(k==0)
        cout<<"YES"<<endl;
         else cout<<"NO"<<endl;

    }
    else cout<<"NO"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n,i,s,z;
	
	scanf("%d",&n);
	int x[n+1],y[n+1],t[n+1];
	
	for(i=0;i<=n-1;i++){
		scanf("%d %d %d",&t[i],&x[i],&y[i]);
	}
	if(x[0]+y[0]>=0){
		z=x[0]+y[0];
	}else{
		z=-x[0]-y[0];
	}
	s=t[0];
	if((z>s)||(z%2!=s%2)){
		printf("No");
		return 0;
	}
	for(i=1;i<=n-2;i++){
		if(x[i]+y[i]<=x[i+1]+y[i+1]){
			z=x[i+1]+y[i+1]-x[i]-y[i];
		}else{
			z=x[i]+y[i]-x[i+1]-y[i+1];
		}
		s=t[i+1]-t[i];
		if((z>s)||(z%2!=s%2)){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 1280
import java.lang.Math

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

fun main(args: Array<String>)
{
    val a = read().toInt()
    val b = read().toInt()

    if (a*b == 6) println(1)
    else if (a*b == 3) println(2)
    else if (a*b == 2) println(3)
}

fun read(): String = readLine()!!


Measured memory_bytes: 31744
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int a,b;
    int s;

    s=0;

    scanf("%d %d\n",&a,&b);

    if(a>b){
        s=a-1;
    }
    else{
        s=a;
    }

    printf("%d\n",s);

    return 0;
}

Measured memory_bytes: 128