akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* Atcoder Grand Contest 007F
Pre-calculate the position that t[i] is updated from s[i].
And for two consecutive pairs (i,j) and (a,b),
they'll merge into (a-1,j) in one process of merging.
(Suppose we move greedily in one process.)
Only using brute-force to simulate won't be enough,
after p times of merging,we'll get (fi-p,i-p) as our answer.
And we can determine whether it's ok using binary search then
*/
char s[1000005],t[1000005];
int n,cnt=0;
struct node
{int a,b;
}q[1000005];
int tag[1000005];
int main (){
int i,cur;
scanf ("%d",&n);
scanf ("%s",s+1);
scanf ("%s",t+1);
cur=n;cnt=0;
for (i=1;i<=n;i++)
{if (s[i]!=t[i]) {break;}
if (i==n) {printf ("0");return 0;}
}
tag[1]=1;q[1].b=1;
for (i=2;i<=n;i++)
{if (t[i]==t[i-1]) {tag[i]=tag[i-1];}
else {tag[i]=tag[i-1]+1;}
q[tag[i]].b=i;
}
for (i=n;i>=1;i--)
{cur=min(cur,i);
int pos=cur;
while (cur&&t[i]!=s[cur]) {cur--;}
if (cur<=0) {printf ("-1\n");return 0;}
q[tag[i]].a=cur;
}
int l=0,r=tag[n],mid;
while (l<=r)
{mid=(l+r)>>1;
int tagw=0;
for (i=mid+1;i<=tag[n];i++)
{int t1=q[i].a-mid,t2=q[i-mid].b;
if (t1<t2) {tagw=1;break;}
}
if (tagw==1) {l=mid+1;}
else {r=mid-1;}
}
printf ("%d\n",l);
return 0;
}


Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
 
const int maxn = 1e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int,int>>v[n];
    f(n) {
        int t;
        cin >> t;
        while(t--) {
            int x ,y;
            cin >> x >> y;
            v[i].pb({x-1,y});
        }
    }
    int ans = 0;
    for (int i = 0 ; i < (1<<n) ; i ++) {
        int c[n];
        int f = 0;
        for (int j = 0 ; j < n ; j++) {
            if (i & (1<<j)) {
                c[j] = 1;
            }
            else {
                c[j] = 0;
            }
        }
        for (int j = 0 ; j < n ; j++) {
            if (i & (1<<j)) {
                for (auto k : v[j]) {
                    if (c[k.F] != k.S) {
                        f = 1;
                        break;
                    }
                }
            }
            if (f) {
                break;
            }
        }
        if (!f) {
            //cout << i << endl;
            ans = max(ans, __builtin_popcount(i));
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
/*
 © 2020-01-31 19:54:48 crystaalroo all Rights Reserved
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for(int i = (a); i <(b); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define sz(x) (int) (x).size()
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long lli;
typedef pair<lli,lli > ii;
#define ENDL '\n'
#define deb(x) cout << #x": " << (x) << endl;
const int INF=1e9;
const lli mod = 1e9+7;
const int N = 1E6;


int main(){
  lli n,W;
 cin>>n>>W;
 vector<ii>th(n);
 fore(i,0,n)cin>>th[i].f>>th[i].s;
 lli dp[n+1][W+1];
 fore(i,0,n+1)fore(j,0,W+1)dp[i][j]=0;
 fore(i,0,n+1)dp[i][0]=0;
 fore(i,0,W+1)dp[0][i]=0;
 fore(i,1,n+1)
   fore(j,0,W+1){
     if(th[i-1].f<=j)dp[i][j]=max(th[i-1].s+dp[i-1][j-th[i-1].f],dp[i-1][j]);
     else dp[i][j]=dp[i-1][j];
   }
  cout<<dp[n][W]<<ENDL;


}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int count;
    count = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == 'R')
        {
            count++;
        }
    }
    if (s[1] == 'S' && count == 2)
    {
        count = 1;
    }
    cout << count << endl;
    return (0);
}


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

const int N = 1e6 + 5 , MOD = 1e9 + 7;
long long fact[N] , fact_inv[N];

long long mul(long long a , long long b) {
    return a * b % MOD;
}

long long power(long long a , long long b) {
    if (!b) return 1;
    long long r = power(a , b / 2);
    r = mul(r , r);
    if (b&1) return mul(r , a);
    return r;
}

long long mod_inv(long long x) {
    return power(x , MOD - 2);
}

long long nCr(long long n , long long r){
    if (!n) return !r;
    if(r>n) return  0;
    return mul(fact[n] , mul(fact_inv[n - r] , fact_inv[r]));
}

void pre() {
    fact[0] = fact_inv[0] = 1;
    for(int i = 1 ; i < N ;i++) {
        fact[i] = mul(fact[i - 1] , i);
        fact_inv[i] = mod_inv(fact[i]);
    }
}

int main() {
    pre();
    int x, y; cin >> x >> y;
    long long ans = 0;
    for(int i = 0; i <= x; i++) {
        int cura = i;
        int curb = 2 * i;
        int a = x - cura;
        int b = y - curb;
        if(a != 2 * b) continue;
        ans += nCr(i+b, i);
        ans %= MOD;
    }

    cout << ans;
}

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

using namespace std;

int main() {
    string S;
    cin >> S;
    if (S[0] == S[1] || S[0] == S[2] || S[1] == S[2]) cout << "No";
    else cout << "Yes";

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int n,x;
    cin>>n>>x;
    vector<int> a(n);
    int ans=n;
    int sum=0;
    rep(i,n){
        cin>>a[i];
        sum += a[i];
    }
    x -= sum;
    all(a);
    ans += x/a[0];
    cout<<ans<<endl;
}

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

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

	return 0;
}

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

typedef long long ll;
#define INF 1000000

int main(){
  ll n, m;
  cin>>n>>m;
  vector<ll> c;
  for(ll i=0; i<m; i++){
    ll tmp;
    cin>>tmp;
    c.push_back(tmp);
  }
  ll dp[n+1]; //dp[i]:=i????????????????????????????????????????°??????°
  for(ll i=0; i<=n; i++)
    dp[i]=INF;
  dp[0]=0;
  for(ll i=0; i<c.size(); i++){
    for(ll j=0; j<=n; j++){
      if(c[i]<=j)dp[j]=min(dp[j], dp[j-c[i]]+1);
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}

Measured memory_bytes: 1596
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
using namespace std;

int main(void){

    long long int n,m;
    cin>>n>>m;

    pair<long long int,long long int> p;
    vector<pair<long long int, long long int>> v;

    long long int r=0;

    for(int i=0;i<n;i++){

        long long int x, y;

        cin>>x>>y;

        v.push_back(make_pair(x, y));

    }

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

   /* for(int i=0;i<v.size();i++){
        cout<<v[i].first<<", "<<v[i].second<<endl;
    }*/

    for(int i=0;m>0;i++){
        r += ((m > v[i].second) ? v[i].first * v[i].second : v[i].first * m);
        m -= v[i].second;
    }

    cout<<r<<endl;

    return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>

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

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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

int a, p;
int main() {
  cin.tie(0); cin.exceptions(cin.failbit);

  scanf("%d%d", &a, &p);

  int pieces = 3*a + p;
  printf("%d\n", pieces/2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  vector<char> a(9);
  fo(i,9)
    cin>>a[i];
  cout<<a[0]<<a[4]<<a[8]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,N,0);
  rep(i,0,N)cin >> P[i];
  Vec(Q,lli,N,0);
  rep(i,0,N)Q[P[i]-1]++;
  Vec(Ans1,lli,N,0);
  Vec(Ans2,lli,N,0);
  rep(i,0,N){
    Ans1[i]=(Q[i]-1)*(Q[i]-2)/2;
    Ans2[i]=Q[i]*(Q[i]-1)/2;
  }
  rep(i,0,N)sum+=Ans2[i];
  rep(i,0,N){
    Out(sum-Ans2[P[i]-1]+Ans1[P[i]-1]);
  }
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int n = 3;
    map<int, pair<int, int>> m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int temp;
            cin>>temp;
            m[temp] = make_pair(i, j);
        }
    }
    int r[3]={0,0,0}, c[3]={0,0,0};
    int diag1 = 0, diag2 = 0;
    int s;
    cin>>s;
    int flag = 1;
    for(int i = 0; i < s; i++){
        int temp;
        cin>>temp;
        if(m.find(temp)!=m.end()){
            int row, col;
            row = m[temp].first;
            col = m[temp].second;
            r[row]++;
            if(r[row]==3){
                flag = 0;
            }
            c[col]++;
            if(c[col]==3){
                flag = 0;
            }
            if(row == col){
                diag1++;
                if(diag1 == 3){
                    flag = 0;
                }
            }
            if((row == 1 && col == 1) || (row == 0 && col == 2) || (row == 2 && col == 0)){
                diag2++;
                if(diag2 == 3){
                    flag = 0;
                }
            }
        }

    }
    if(flag)
    cout<<"No";
    else
    {
        cout<<"Yes";
    }
    
    return 0;
}

Measured memory_bytes: 3656
import java.util.*;
import java.io.*;

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      int N = sc.nextInt();
      if (N == 1) {
        System.out.println("Hello World");
      } else {
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println(A+B);
      }
    }
  }
}


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

using ll = long long;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)


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

  int X;
  cin>>X;

  if(X==3||X==5||X==7)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    vector<ll> b(n-1);
    rep(i,n-1)cin>>b[i];
    vector<ll> c(n);
    c[0]=b[0];
    c[n-1]=b[n-2];
    ll sum=c[0]+c[n-1];
    for(int i=1;i<n-1;++i){
        c[i]=min(b[i],b[i-1]);
        sum+=c[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cEdges=vector<vector<pair<int,int>>>;

int main() {
	int a,b;
	cin>>a>>b;
	if(a<0){
		if(b<0){
			if((b-a+1)%2==0)cout<<"Positive"<<endl;
			else cout<<"Negative"<<endl;
		}
		else{
			cout<<"Zero"<<endl;
		}
	}
	else if(a==0){
		cout<<"Zero"<<endl;
	}
	else{
		cout<<"Positive"<<endl;
	}

	//system("pause");
	return 0;
}

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

using namespace std;

int main(void)
{

    string A;
    string B;
    cin >> A;
    cin >> B;

    int sum = 0;
    for(int i=0; i<3; i++){
        if(A.at(i)==B.at(i)){
            sum++;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int N,D;
	int i,ans;
	char str[100000];
 
	fgets(str, sizeof(str), stdin);
	N=atoi(strtok(str," "));
	D=atoi(strtok(NULL," "));

	ans=0;
	for(i=0;i<N;i++){
		int x,y;
		fgets(str, sizeof(str), stdin);
		x=atoi(strtok(str," "));
		y=atoi(strtok(NULL," "));
		if( ((long long)x*x+(long long)y*y) <= ((long long)D*D) ) ans++;
	}

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

	return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

bool Ci(int i,vector<int> &p){
    int p1 = p[i-1];
    int p2 = p[i];
    int p3 = p[i+1];
    bool ans = false;
    if(p1 < p2) if(p2 < p3) ans = true;
    if(p3 < p2) if(p2 < p1) ans = true;
    return ans;
}
int main(){
    int n;cin >> n;
    vector<int> p(n);
    rep(i,n)cin >> p[i];
    int ct = 0;
    bool ok = false;
    for(int k = 1;k < n-1;k++){
        ok = Ci(k,p);
        if(ok) ct++;
    }
    cout << ct << endl;
}


Measured memory_bytes: 256
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::*;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
  input! {
  n: usize,
  m: usize,
  k: u64,
  mut a: [u64; n],
  mut b: [u64; m],
  }

  let mut a_sum = vec![];
  let mut b_sum = vec![];

  a_sum.push(0);
  b_sum.push(0);

  for i in 0..n {
    a_sum.push(a_sum[i] + a[i]);
  }

  for i in 0..m {
    b_sum.push(b_sum[i] + b[i]);
  }

  let mut cnt = 0;
  let mut j = m;
  for i in 0..=n {
    if a_sum[i] > k {
      break;
    }

    while b_sum[j] > k - a_sum[i] {
      j -= 1;
    }

    cnt = max(cnt, i + j);
  }
  println!("{}", cnt);
}


Measured memory_bytes: 12560
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

typedef unsigned short us;

int n;
int c;
int dp[31][1<<16];
us a[31];
us b[31];

int count_bits(us bits) {
	int cnt = 0;
	while(bits > 0){
		cnt += bits&1;
		bits >>= 1;
	}
	return cnt;
}

int main() {
	for(;;) {
		scanf("%d %d", &n, &c);

		if((n|c) == 0) break;

		for( int i = 0; i < n; ++i ) {
			us bits = 0;
			for( int j = 0; j < 16; ++j ) {
				int b;
				scanf("%d", &b);

				bits |= b << j;
			}
			a[i] = bits;
		}
		a[n] = 0;
		for( int i = 0; i < c; ++i ) {
			us bits = 0;
			for( int j = 0; j < 16; ++j ) {
				int b;
				scanf("%d", &b);

				bits |= b << j;
			}
			b[i] = bits;
		}
		b[c] = 0;

		memset(dp, -1, sizeof(dp));
		dp[0][a[0]] = 0;
		for( int i = 0; i < n; ++i ) {
			for( int j = 0; j < 1<<16; ++j ) {
				if(dp[i][j] == -1) continue;
				for( int k = 0; k < c; ++k ) {
					int res = count_bits(j&b[k]) + dp[i][j];
					int nbs = ((j^b[k])&j) | a[i+1];

					dp[i+1][nbs] = max(dp[i+1][nbs], res);
				}
			}
		}

		int ans = 0;
		for( int i = 0; i < 1<<16; ++i ) {
			ans = max(ans, dp[n][i]);
		}

		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 8972
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long int llint;

int main(){
    llint N;
    cin >> N;
    long double A[N]; 
    long double ans = 0.000000000;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        ans += 1/A[i];
    }
    cout << fixed << setprecision(10) <<1/ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-09-28
#

# Usage
#
"""
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import absolute_import

def input_process():
    """Receive Inputs."""
    return input()


def insert_space(target_str: str) -> str:
    """
    >>> insert_space("codefestival")
    code festival
    """
    return target_str[0:4] + " " + target_str[4:]

if __name__ == "__main__":
    target = input()

    print(insert_space(target))


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    long long int x,y;
    char c;
    scanf("%lld %c %lld",&x,&c,&y);
    if(c =='+')
        printf("%lld\n",x+y);
    else if(c == '-')
        printf("%lld\n",x-y);
    return 0 ;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, P, S):
    if P == 2 or P == 5:
        n = 0
        ans = 0
        for c in reversed(S):
            if int(c) % P == 0:
                n += 1
            ans += n
        return ans

    p = Counter()
    t = 1
    ans = 0
    c = 0
    for i in range(N):
        a = ((int(S[N-i-1]) * t) + c)% P
        c = a
        if a == 0:
            ans += 1
        ans += p[a]
        p[a] += 1
        t = (t * 10) % P

    return ans

def main():
    N, P = read_int_n()
    S = read_str()
    print(slv(N, P, S))



if __name__ == '__main__':
    main()


Measured memory_bytes: 63816
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <cmath>
# include <functional>
# include <utility>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	ll sum = 0, ans = 0, pass = 0, counter = 0;
	ll  a = 0, b = 0, c = 0, k = 0, n = 0, m = 0;
	bool flag=false;
	//newdefine
	cin >> a;
	rep(i, 9) {
		if (a % (i + 1) == 0 && a / (i + 1) <= 9) {
			flag = true;
			break;
		}
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;

void main() {
    int n = getStdin!(int[])()[0];
    
    int flg = 1;
    int i = 1;
    int x;
    while(flg > 0) {
        // CHECK_NUM
        if (flg == 1) {
            x = i;
            if (x % 3 == 0) {
                " %d".writef(i);
                flg = 3;
                continue;
            }
            flg = 2;
            continue;
    	}

        // INCLUDE3
        if (flg == 2) {
            if (x % 10 == 3) {
                " %d".writef(i);
                flg = 3;
                continue;
            }
            x /= 10;
            if (x != 0) {
                flg = 2;
                continue;
            }

            flg = 3;
            continue;
        }

        // END_CHECK_NUM
        if (flg == 3) {
            if (++i <= n) {
                flg = 1;
                continue;
            }

            "".writeln;
            break;
        }
    }
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

Measured memory_bytes: 2464
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   ll h,w;
           cin>>h>>w;
           if(h==1||w==1){
             cout<<1<<endl;
             return 0;
           }
             
           ll ans;
           if(h%2==0||w%2==0)ans=h*w/2;
           else{
             ans=h*(w-1)/2;
             ans+=(h+1)/2;
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 3608
#import <Foundation/Foundation.h>

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

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSData *stdinData = [[NSFileHandle fileHandleWithStandardInput] availableData];
        NSString *s = [[NSString alloc] initWithData:stdinData encoding:NSUTF8StringEncoding];
        int n = [s intValue];
        long long v = (long long)n*2/gcd(n,2);
        NSString *answer = [NSString stringWithFormat:@"%lld", v];
        
        NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
        [fileHandle writeData:[answer dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle closeFile];
    }
    
    return 0;
}


Measured memory_bytes: 2404
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
char g[10][10];
int main() {
  IOS;
  int h, w, k;
  cin >> h >> w >> k;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> g[i][j];
    }
  }
  int ans = 0;
  for (int x = 0; x < (1 << (h + w)); x++) {
    bitset<12> b(x);
    int cnt = 0;
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        if (!b[i - 1] && !b[h + j - 1])
          (cnt += g[i][j] == '#');
      }
    }
    ans += (cnt == k);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int res = 0;
    for (int i = 1; i <= n; i++) {
      int d = 0;
      int v = i;
      while (v > 0) {
        v /= 10; d++;
      }
      if (d % 2 == 1) res++;
    }
    os.println(res);
  }
}

Measured memory_bytes: 21844
package main

import (
	"fmt"
)

func main() {
	var (
		n int
	)
	fmt.Scan(&n)

	m := make([]string, n)
	goodM := make([][]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&m[i])
		goodM[i] = make([]int, n)
	}

	// fmt.Println(m)

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			v := 0
			for k := 1; k < n; k++ {
				if m[(i+k)%n][j] != m[i][(j+k)%n] {
					break
				}
				v++
			}
			goodM[i][j] = v
		}
	}

	// fmt.Println(goodM)

	ans := 0

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			good := true
			for k := 0; k < n; k++ {
				if goodM[(i+k)%n][(j+k)%n] < n-1-k {
					good = false
					break
				}
			}
			if good {
				ans++
			}
		}
	}

	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,K;
string s;
deque<P> q;
void push_back(int v){
	if(q.empty())q.push_back(P(v,1));
	else if(q.back().fi==v)q.back().sec++;
	else q.push_back(P(v,1));
}
void pop_front(){
	assert(!q.empty());
	if(q.front().sec==1)q.pop_front();
	else q.front().sec--;
}
void clear(){
	while(!q.empty())q.pop_back();
}
bool check(int k){
	clear();
	for(int i=0;i<N;i++){
		if(i>=k)pop_front();
		push_back(s[i]-'0');
		if(i>=k-1){
			int sz = q.size();
			if(q.front().fi==1)sz--;
			if(sz!=0&&q.back().fi==1)sz--;
			if((sz+1)/2<=K)return true;
		}
	}
	return false;
}
int main(){
	cin >> N >> K;
	cin >> s;
	int l = 1, r= N+1;
	while(r-l>1){
		int mid = (l+r)/2;
		if(check(mid))l=mid;
		else r = mid;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 988
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
using namespace std;

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

    int N;
    cin >> N;

    vector<int> X(N, 0);

    int x;
    int i = 0;
    while (cin >> x){ 
        X[i] = x;
        ++i;
        if (i >= N){
            break;
        }
    }

    int minHP = numeric_limits<int>::max();
    for (int p = 0; p < 100; ++p){
        int hp = 0;
        for (int i = 0; i < N; ++i){
            hp += pow((X[i] - p), 2);
        }
        if (minHP > hp){
            minHP = hp;
        }
    }

    cout << minHP << "\n";

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int C[700][700];
vector<int> E[707];
int vis[707];
int cnt[2];
int ok[707][707];

void dfs(int cur,int c) {
	if(vis[cur]!=-1) {
		if(vis[cur]==c) return;
		cout<<"-1"<<endl;
		exit(0);
		return;
	}
	cnt[c]++;
	vis[cur]=c;
	FORR(e,E[cur]) dfs(e,c^1);
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		C[x-1][y-1]=C[y-1][x-1]=1;
	}
	FOR(x,N) {
		C[x][x]=1;
		FOR(y,N) if(C[x][y]==0) E[x].push_back(y);
	}
	
	
	ok[0][0]=1;
	int sum=0;
	MINUS(vis);
	FOR(i,N) if(vis[i]==-1) {
		cnt[0]=cnt[1]=0;
		dfs(i,0);
		
		FOR(x,sum+1) if(ok[x][sum-x]) {
			ok[x+cnt[0]][sum-x+cnt[1]]=1;
			ok[x+cnt[1]][sum-x+cnt[0]]=1;
		}
		
		sum+=cnt[0]+cnt[1];
	}
	
	int mi=1<<30;
	FOR(x,N+1) if(ok[x][N-x]) mi=min(mi,x*(x-1)/2+(N-x)*(N-x-1)/2);
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main(){
	int a,b;
	char op;
	while(cin >> a >> op >> b,op != '?'){
		switch(op){
			case '+':
				cout << a+b <<endl;
				break;
			case '-':
				cout << a-b <<endl;
				break;
			case '*':
				cout <<a*b <<endl;
				break;
			case '/':
				cout <<a/b<<endl;
				break;
			default:
				break;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#include<map>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
int main(){
    int A, B;
    cin >> A >> B;
    if(A>=13){
        cout << B << endl;
    }else if(A >= 6){
        cout << B / 2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


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

int gcd(int a,int b){
    int r;
    if(a>b) swap(a,b);
    while(a!=0){
        r=a;
        a=b%a;
        b=r;
    }
    return b;
} 

signed main(){
    int N,K;
    int A[114514];
    int G;
    int M=0;
    cin >> N >> K;
    REP(i,N){
        cin >> A[i];
        M=max(M,A[i]);
    }
    REP(i,N){
        if(i==0){
            G=A[i];
        }else{
            G=gcd(G,A[i]);
        }
    }
   // cout<<G << endl;
    if(K<=M && K%G==0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    
	return 0;
}


Measured memory_bytes: 1024
a = int(input()) #500
b = int(input()) #100
c = int(input()) #50
x = int(input())

i=0


result=0

while i<=a:
  j=0
  while j<=b:
    k=0
    while k<=c:
     # print(i*500+j*100+k*50)
      if i*500+j*100+k*50==x:
        result=result+1
      k=k+1
    j=j+1
  i=i+1

print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int N,C; cin >>N >>C;
  vector<vector<int>> time(C, vector<int>(100001, 0));
  rep(i, N){
    int s,t,c; cin >>s >>t >>c; s--; t--; c--;
    time[c][s]++;
    time[c][t]--;
  }
  rep(c, C){
    rep(i, 100000){
      time[c][i+1] += time[c][i];
    }
  }
  rep(c, C){
    rep(i, 100000){
      if (time[c][i] == 0 && time[c][i+1] == 1) time[c][i]++;
    }
  }
  rep(i, 100001){
    rep(c, C-1){
      time[c+1][i] += time[c][i];
    }
  }
  int res = 0;
  rep(i, 100001) chmax(res, time[C-1][i]);
  cout <<res <<endl;
}

Measured memory_bytes: 12416
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> c;
  for (int i = 0; i < h; i++) {
    string tmp;
    cin >> tmp;
    c.push_back(tmp);
  }

  const int H = 6;
  const int W = 6;
  int ans = 0;
  for (int tmp1 = 0; tmp1 < (1 << h); tmp1++) {
    bitset<H> bs1(tmp1);
    for (int tmp2 = 0; tmp2 < (1 << w); tmp2++) {
      bitset<W> bs2(tmp2);
      int cnt = 0;
      auto c2 = c;

      for (int i = 0; i < h; i++) {
        if (bs1.test(i)) {
          for (auto &cij : c2.at(i)) cij = '-';
        }
      }
      for (int j = 0; j < w; j++) {
        if (bs2.test(j)) {
          for (auto &ci : c2) ci.at(j) = '-';
        }
      }

      // for (auto &ci : c2) cout << ci << endl;
      // cout << endl;

      for (auto &ci : c2) {
        for (auto &cij : ci) {
          if (cij == '#') cnt++;
        }
      }
      if (cnt == k) ans++;
    }
  }

  cout << ans << endl;
}

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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

using namespace std;

int solve(int N) {
	int A, B, C, X; cin >> A >> B >> C >> X;
	int res = 0;
	vector<int> val(N);
	rep(i, N) cin >> val[i];
	rep(i, N) {
		while (X != val[i]) {
			res++; X = (A * X + B) % C;
			if (res > 10000) break;
		}
		if (i != N-1) {
			res++; X = (A * X + B) % C;
		}
	}
	if (res > 10000) return -1;
	return res;
}

signed main() {
	int N;
	while (cin >> N, N) cout << solve(N) << endl;
}




Measured memory_bytes: 3096
import itertools
n, m, R = map(int, input().split())
r = list(map(int, input().split()))
dis = [[float("inf") for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    dis[a - 1][b - 1] = c
    dis[b - 1][a - 1] = c

def war(dis):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dis[i][j] > dis[i][k] + dis[k][j]:
                    dis[i][j] = dis[i][k] + dis[k][j]
    return dis
dis = war(dis)
_min = float("inf")
it = itertools.permutations(r)
for iterR in it:
    _dis = 0
    start = iterR[0] - 1
    for end in iterR[1:]:
        _dis += dis[start][end - 1]
        start = end - 1
    _min = min(_min, _dis)
print(_min)


Measured memory_bytes: 5536
#-*-coding:utf-8-*-

def main():
    n, m = map(int, input().split())

    if 2 * n <= m:
        ans = n + (m - 2 * n) // 4
    else:
        ans = m // 2
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include<stdio.h>
long long n,k,L,R,M;
long long t[100000];
 
int check(long long x){
  long long i,id=0,cnt=0;
  for(i=0;i<n;i++){
    if(cnt+t[i]>x){
      cnt=t[i];
      id++;
    }else{
      cnt+=t[i];
    }
    if(id==k)return 0;
  }
  return 1;
}
 
int main(){
  int i;
  scanf("%d %d",&n,&k);
  L=1;
  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
    L=(L<t[i]?t[i]:L);
  }
 
  R=1000000000LL;
  while(L<R){
    M=(L+R)/2;
    if(check(M)==1){
      R=M;
    }else{
      L=M+1;
    }
  }
  printf("%d\n",L);
  return 0;
}

Measured memory_bytes: 1376
from collections import deque
sl = list(input())
q = int(input())
dl = deque(sl)
r = 0
for _ in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        r += 1
    else:
        if r % 2 == 0:
            if query[1] == "1":
                dl.appendleft(query[2])
            else:
                dl.append(query[2])
        else:
            if query[1] == "1":
                dl.append(query[2])
            else:
                dl.appendleft(query[2])
if r % 2 == 1:
    dl.reverse()
print("".join(dl))


Measured memory_bytes: 9460
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <cstring>
#include <cctype>
#include <functional>
#include <climits>
#include <complex>
 
using namespace std;
#define pr(...) do { _ost << #__VA_ARGS__ << " = "; ~(_ost,__VA_ARGS__); } while(0);
ostream & _ost = cout;
template <class T>
ostream &operator,(ostream& ost, const T& value) { return ost << value << ","; }
ostream &operator~(ostream& ost) { return ost << endl; }
template <class T>
string tos(const T& var){ ostringstream ss; ss << var; return ss.str(); }
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RALL(c) (c).rbegin(), (c).rend()
 
typedef vector<int> vi;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;
 
const int mod = 1000000007;
const int INF = 1000000;
const double EPS = 1e-10;

int main(){
    int n;cin>>n;
    FOR(i,0,n){
        bool ppp = true;
        int a,b;cin>>a>>b;
        complex<int> p(a,b);
        int np=norm(p);
        FOR(m,0,np+1){ // circle <- square
            FOR(n,0,np+1){
                complex<int> i(m,n);
                int ni=norm(i);
                if(ni!=1&&ni!=0&&ni!=np&&np%ni==0){
                    ppp=0;break;
                }
            }
            if(!ppp)break;
        }
        cout<<(ppp?"P":"C")<<endl;
    }
}

Measured memory_bytes: 1148
fun main(args: Array<String>) {
    readLine()!!
    val list: List<Int> = readLine()!!.split(" ").map { it.toInt() }.distinct()
    readLine()!!
    val list2: List<Int> = readLine()!!.split(" ").map { it.toInt() }.distinct()
    var match:Int = 0
    for (i in (0..list2.count()-1))
    {
        if (binarySearch(list,list2[i]) != -1)
        {
            match++
        }
    }
    println(match)
}
private fun binarySearch(A:List<Int>,key:Int):Int
{
    var left:Int = 0
    var right:Int= A.count()
    while (left<right)
    {
        var mid:Int = (left + right) / 2
        if (A[mid] == key)
        {
            return mid
        }
        else if (key < A[mid])
        {
            right = mid
        }
        else
        {
            left = mid+ 1
        }
    }
    return -1
}



Measured memory_bytes: 69112
import scala.util.control.Breaks

object Main {

    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val break = new Breaks
        break.breakable{
        	while(sc.hasNext){
	            val n = sc.nextInt
	            if(n == 0) break.break
	            var list = List.empty[Int]
	            for(_ <- 1 to n){
	            	val a = sc.nextInt
		            if(list.isEmpty) list = a :: list
		            else list = Math.max(list.take(1)(0) + a, a) :: list
	        	}
	            println(list.max)
	        }
        }
    }
}

Measured memory_bytes: 52904
/*
ID: jerrywcy
LINK:
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define init(array,x) memset(array,x,sizeof(array))

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

int n;
int h[100010];
int ans;

int read(){
    int f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}

int main()
{
    n=read();
    for (int i=1;i<=n;i++)h[i]=read();
    for (int i=1;i<=n;i++){
        int cnt=0;
        while (i<n && h[i]>=h[i+1])i++,cnt++;
        ans=max(ans,cnt);
    }
    printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 640
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

  static int mod = 1000000007;

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();

    long[] num = new long[n];
    int count = 0;
    long sum = 0;
    for (int i=0;i<n;i++) {
      long item = cin.nextLong();
      if (item<0)
        count++;
      num[i] = Math.abs(item);
      sum += Math.abs(item);
    }
    if (count%2==0) {
      System.out.println(sum);
    }
    else {
      Arrays.sort(num);
      sum -= 2*num[0];
      System.out.println(sum);
    }

  }


}


Measured memory_bytes: 50556
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int a,b;
    cin>>a>>b;
    cout<<max(a*b,max(a-b,a+b));
    
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define quick ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
char s[100000];
int l[100000],r[100000],a[100000];
int main()
{
	quick;
	int n,q,ans=0;
  	cin>>n>>q;
  	cin>>s;
  	for(int i=0;i<q;++i)
    	cin>>l[i]>>r[i];
  	for(int i=0;i<n;++i)
  	{
    	a[i]=ans;
    	if(s[i]=='A' && s[i+1]=='C')
     		++ans;
  	}
  	for(int i=0;i<q;++i)
    	cout<<a[r[i]-1]-a[l[i]-1]<<endl;
  	return 0;
}


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

bool check(int v,int c,vector<vector<int>> &edge,vector<int> &used){
    used[v]=c;
    bool res=true;
    for(int i=0;i<edge[v].size();i++){
        int to=edge[v][i];
        if(used[to]==c){
            return false;
        }
        if(used[to]!=-1) continue;
        res&=check(to,!c,edge,used);
    }
    return res;
}

long long int cnt(int v,vector<vector<int>> &edge,vector<int> &used){
    long long int res=1;
    used[v]=100;
    for(int i=0;i<edge[v].size();i++){
        int to=edge[v][i];
        if(used[to]==100) continue;
        res+=cnt(to,edge,used);
    }
    return res;
}

pair<long long int,long long int> cnt2(int v,vector<vector<int>> &edge,vector<int> &used){
    long long int r1=0;
    long long int r2=0;
    if(used[v]) r1=1;
    else r2=1;
    used[v]=100;
    for(int i=0;i<edge[v].size();i++){
        int to=edge[v][i];
        if(used[to]==100) continue;
        auto ret=cnt2(to,edge,used);
        r1+=ret.first;
        r2+=ret.second;
    }
    return {r1,r2};
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> edge(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    long long int res=0;
    vector<int> used(n,-1);
    for(int i=0;i<n;i++){
        if(used[i]==-1){
            bool ret=check(i,1,edge,used);
            if(!ret){
                auto ret2=cnt(i,edge,used);
                res+=ret2*(ret2-1)/2;
            }
            else{
                auto ret2=cnt2(i,edge,used);
                res+=ret2.first*ret2.second;
            }
        }        
    }
    res-=m;
    cout<<res<<endl;

    
    return 0;
}

Measured memory_bytes: 6912