akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

// デバッグを消し忘れるな！！！

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    ll di = llabs(a-b), cv = llabs(v-w);
    if(v >= w){
        if(di <= t*cv) co("YES");
        else co("NO");
    }else if(v < w){
        co("NO");
    }

    return 0;
}


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



int main(){
    int h, w, k;
    cin >> h >> w >> k;
    char arr[h][w];
    int varmi[w] = {0};
    for(int i=0;i<h;i++){
        for(int j=0; j<w; j++){
            cin >> arr[i][j];
            if(arr[i][j] == '#')
            	varmi[j]++;
        }
    }
    int cntr = 1;
    int ans[h][w];
    int bosolmayan;
	for(int i=0; i<w; i++){
		if(varmi[i]){
			bosolmayan = i;
			break;
			
		}
	}
    for(int i=bosolmayan; i<w; i++){
    	bool b=false;
        for(int j=h-1;j>=0;j--){
        	if(varmi[i] == 0 && i!=0){
        		ans[j][i] = ans[j][i-1];
        		continue;
			}
        	if(arr[j][i] == '#'&& b)
            	cntr++;
            if(arr[j][i] == '#')
                b=true;
            
            ans[j][i] = cntr;
        }
        if(varmi[i+1])
			cntr++;
    }
    for(int i=bosolmayan-1; i>=0; i--){
    	for(int j=0; j<h; j++){
    		ans[j][i] = ans[j][i+1];
		}
	}
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 1152
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;


double solvePolygonSpace(vector<double> x,vector<double> y){
    pair<double,double> center;
    long angleSum=x.size();
    double ret=0;
    
    for(int i=0;i<angleSum;i++){
        center.first +=x[i];
        center.second+=y[i];
    }
    
    center.first /=angleSum;
    center.second/=angleSum;
    
    for(int i=0;i<angleSum;i++){
        double a,b,c;
        
        a=sqrt(  pow( (x[i] - center.first),2 )                 + pow( (y[i] - center.second),2 )                 );
        b=sqrt(  pow( (x[i] - x[ (i+1)%angleSum] ),2 )          + pow( (y[i] - y[ (i+1)%angleSum] ),2 )           );
        c=sqrt(  pow( (x[ (i+1)%angleSum ] - center.first),2 )  + pow( (y[ (i+1)%angleSum ] - center.second),2 )  );

        
        double z=(a+b+c)/2.0;
        double triangleSpace=sqrt( z*(z-a)*(z-b)*(z-c) );
        
        ret+= triangleSpace;
        
    }
    return ret;
}



int main(){
    vector<double> x,y;
    double ans;
    
    double a,b;
    char ch;
    while( cin>>a && cin>>ch && cin>>b ){
        x.pb(a);
        y.pb(b);
    }
    cout<<solvePolygonSpace(x,y)<<endl;
}

Measured memory_bytes: 1304
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    nums = [0] * N
    for i in A:
        nums[int(i) - 1] += 1
    
    sum = 0
    for num in nums:
        sum += num * ( num - 1 ) // 2

    for k in range(0, N):
        old = nums[int(A[k]) - 1]
        new = old - 1
        ans = sum - (old * (old - 1) // 2 - new * (new - 1) // 2)
        print(ans)
    

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30196
#include<stdio.h>
int main(void)
{
int A, B;
scanf("%d %d", &A, &B);
  if(A == 1)
    A = A + 13;
  if(B == 1)
    B = B + 13;

  if(A > B){
    printf("Alice\n");
  } else if(A < B){
    printf("Bob\n");
  } else if(A == B){
    printf("Draw\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<cstdio> 
#include<cstring>
char s[100005];bool c=false,f=false;int main(){gets(s);for(int i=0;i<=strlen(s);i++){if(s[i]=='C')c=true;if(s[i]=='F'&&c)f=true;}if(c&&f)puts("Yes");else puts("No");return 0;}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static char[] c;
	static int[] b=new int[12];
	static int m;
	static void Main(){
		Sc sc=new Sc();
		m=sc.I;
		c=new char[m];
		Fu(0,96);
	}
	static void Fu(int n,int g){
		if(n==m){
			Console.WriteLine("{0}",String.Join("",c));
			return;
		}
		if(n==0){
			c[n]='a';
			b[0]++;
			Fu(n+1,97);
		}
		else{
			c[n]='a';
			b[0]++;
			Fu(n+1,97);
			b[0]--;
			for(int i = 1;b[i-1]!=0;i++) {
				b[i]++;
				c[n]=(char)('a'+i);
				Fu(n+1,97+i);
				b[i]--;
			}
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 14504
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

int Roundup(int a,int b){
    return (a+b-1)/b;
}


signed main(void){
    //方針：ドドド貪欲
    //残っているものの中で最も左のものを選んで、爆破
    //このとき巻き添えを食うモンスターが最も多くなるように、H[i]+Dを中心に爆破する
    //倒れたら、最初に戻る　これをすべてのモンスターが倒れるまで続ける
    int N,D,A;
    int x,h;
    vector<pair<int,int>> XH;
    vector<int> X,H;
    cin >> N >> D >> A;
    for(int i=0;i<N;i++){
        cin >> x >> h;
        XH.push_back({x,h});
    }
    //まず、XとHをX順にソートしておく
    sort(XH.begin(),XH.end());
    for(int i=0;i<N;i++){
        X.push_back(XH[i].first);
        H.push_back(XH[i].second);
    }
    
    
    //モンスターに加わるダメージはタイミングに関わらずつねにA
    //つまり、モンスターは必ずroundup(h,A)回目の攻撃で倒れる
    //ので、Hはroundup(H,A)として持っておくとよい
    for(int i=0;i<N;i++){
        H[i]=Roundup(H[i],A);
    }
    
    //Hの差分を取る(累積和の逆の操作)
    //本当はそのまま扱いたいが、「H[i]~H[j]をすべて-xする」という操作は重く、TLEしてしまう
    //Hを差分として持っておくことで、その操作をO(1)で行うことができる
    vector<int> Hs;
    Hs.push_back(H[0]);
    for(int i=0;i<N-1;i++){
        Hs.push_back(H[i+1]-H[i]);
    }
    //HsはHの差分
    int Ans=0;
    int now=0;
    for(int i=0;i<N;i++){
        now+=Hs[i];
        //ここで、now=(操作した後のH[i])である
        if(now<=0)continue;
        //すでに倒れているモンスターは無視
        auto it = std::upper_bound(X.begin(), X.end(), X[i]+2*D);
        //現在地から2D離れたモンスターは巻き添えにできる
        //itは巻き添えをくらわない中で最も左のもの
        if(Hs.size()>it-X.begin()){
            Hs[(int)(it-X.begin())]+=now;
        }
        Hs[i]-=now;
        Ans+=now;
        //now(=操作後H[i])回爆破　相手は死ぬ
        now=0;
        //死んだので体力は0になった
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 11628
import java.util.Scanner;

public class Main {

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

	    int n=gi();
	    int k=gi();

	    
	    //System.out.print(a-b+1);
	    if (k==1) {
	    	System.out.print(0);
	    }else {
	    	System.out.print(n-k);
	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

void insert(int);
void delete(int);
void deleteFirst(void);
void deleteLast(void);
void printNode(void);

NodePointer nil;


int main(void){

  int n,i,x;
  char op[15];

  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;

  scanf("%d",&n);

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

    scanf("%s",op);
    if(strlen(op) < 7) scanf("%d",&x);

    if(strcmp(op,"insert")==0) insert(x);
    else if(strcmp(op,"delete")==0) delete(x);
    else if(strcmp(op,"deleteFirst")==0) deleteFirst();
    else if(strcmp(op,"deleteLast")==0)deleteLast();

  

  }

    printNode();

    return 0;
}


void insert(int key){

  NodePointer x;

  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;

}


void delete(int key){

  int i;
  NodePointer x;

  x = nil->next;

  while(1){

    if(x == nil) break;
    if(x->key == key)break;

    x = x->next;

  }

  if(x == nil){
    return;
  }

  else{
    x->prev->next = x->next;
    x->next->prev = x->prev;

  free(x);
  }

}

void deleteFirst(){

  NodePointer x;
  x = nil->next;
 
  x->prev->next = x->next;
  x->next->prev = x->prev;
  
  
  free(x);

}

void deleteLast(){

  NodePointer x;
  x = nil->prev;
  
  x->prev->next = x->next;
  x->next->prev = x->prev;
  
  
  free(x);

}
 


void printNode(){

  NodePointer x;

  for(x = nil->next ; x != nil ; x = x->next){

    printf("%d",x->key);
    if(x != nil->prev) printf(" ");

  }

  printf("\n");

}

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

using namespace std;
typedef long long ll;
//typedef vector<pair<ll.ll>> pii;
int main()
{
    ll n,k,x;
    cin>>n>>k;
    ll cnt=0;
    if(k>n)
    {
    cout<<0;
    exit(0);
    }
    vector<ll>v;
    for(ll i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end(),greater<ll>());
    for(vector<ll>::iterator it=v.begin()+k;it!=v.end();it++)
    {
        cnt+=(*it);
    }

cout<<cnt;

    return 0;
}


Measured memory_bytes: 2420
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    // しゃくとり法により解を求める
    let (ans, _, _) = (0..N).fold(
        (0, 0, 0),
        |(res, acc, k), j| {
            let mut i = k;
            let mut s = acc;
            while s ^ A[j] != s + A[j] {
                s -= A[i];
                i += 1;
            }
            (res + j - i + 1, s + A[j], i)
        }
    );

    println!("{}", ans);
}


Measured memory_bytes: 10492
#include<iostream>
#define ll int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin>>n;
	if(n>=30)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    char now = s[0];
    int cnt = 1;
    s += "!";
    vector<int> a;
    rep(i, 1, s.size()){
        if(s[i] == now){
            cnt++;
        }else{
            a.push_back(i);
            // a.push_back(cnt);
            cnt = 1;
            now = s[i];
        }
    }
    // for(int ii = 0; ii < a.size(); ii++){
    //     if(ii) cout << ' ';
    //     cout << a[ii];
    // }
    // cout << endl;
    int ans = INF;
    if(a.size() == 1){
        ans = s.size() - 1;
    }else{
        rep(i, 0, a.size()){
            chmin(ans, max(a[i], (int)s.size() - 1 - a[i]));
        }
    }
    cout << ans << endl;
}

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

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A.at(i);
  if (accumulate(A.begin(), A.end(), 0)>=H) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  ll r=0, g=0, b=0;
  rep(i,n) {
    if(s[i]=='R') r++;
    if(s[i]=='G') g++;
    if(s[i]=='B') b++;
  }
  ll ans = r*g*b;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(s[i]=='R'&&s[j]=='G') if(s[2*j-i]=='B') ans--;
      if(s[i]=='G'&&s[j]=='R') if(s[2*j-i]=='B') ans--;
      if(s[i]=='R'&&s[j]=='B') if(s[2*j-i]=='G') ans--;
      if(s[i]=='B'&&s[j]=='R') if(s[2*j-i]=='G') ans--;
      if(s[i]=='B'&&s[j]=='G') if(s[2*j-i]=='R') ans--;
      if(s[i]=='G'&&s[j]=='B') if(s[2*j-i]=='R') ans--;
    }
  }
   cout << ans;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <algorithm>
#include <map>
#include <unordered_map>

using namespace std;

const int MAXN = 1e2 + 5;
const int INF = 1e9;
const int MAXW = 1e5;

struct item
{
    long long v;
    int w;

    item(){};
    item(long long _v, int _w)
    {
        v = _v;
        w = _w;
    }

    bool operator<(item other) const
    {
        return w < other.w;
    }
};

int n, we;
item a[MAXN];
long long T[MAXN][MAXW];

long long rec(int index, int rem)
{
    if(rem < 0) return -INF;
    if(index == n) return 0;
    /*if(T[{index,rem}])
    {
        return T[{index,rem}];
    }*/
    if(T[index][rem])
    {
        return T[index][rem];
    }

    long long ans = rec(index + 1, rem - a[index].w) + a[index].v;
    ans = max(ans, rec(index + 1, rem));

    return T[index][rem] = ans;
}

void read_input()
{
    scanf("%d %d", &n, &we);

    for(int i = 0; i < n; i++)
    {
        scanf("%d %lld", &a[i].w, &a[i].v);
    }
    sort(a, a + n);
}

void solve()
{
    long long ans = rec(0, we);

    printf("%lld\n", ans);
}

int main()
{
    read_input();
    solve();

    return 0;
}


Measured memory_bytes: 77952
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	int n,m;
	cin>>n>>m;
	vector<int> a(m),dist(m-1);
	for(int i=0;i<m;i++) cin>>a[i];
	sort(all(a));
	for(int i=0;i+1<m;i++) dist[i]=a[i+1]-a[i];
	sort(all(dist));
	int ans=0;
	for(int i=0;i<m-n;i++) ans+=dist[i];
	cout<<ans;
	re 0;
}

Measured memory_bytes: 4776
#include<stdio.h>

int main(void){
	
	int n,w[100],i,j,t,count,cp;
	count=0;
	t=0;
	
	scanf("%d",&n);
	
	for(i=0; i<n; i++){
		scanf("%d",&w[i]);
	}
	for(j=0; j<n; j++){
		for(i=n-1; i>=1; i--){
			
			if(w[i] < w[i-1]){
				cp = w[i-1];
				w[i-1] = w[i];
				w[i] = cp;
				
				count++;
		    }
		}
	}
	
	for(i=0; i<n; i++){
		printf("%d",w[i]);
		if(i != n-1){
			printf(" ");
		}
		
		
	}
	printf("\n");
	printf("%d\n",count);
	
	return 0;
}

	


Measured memory_bytes: 2092
def isoverflow(s):
    if len(s)>80: return True
    else: return False

n = input()

for i in range(n):
    a = input()
    b = input()

    if isoverflow(str(a)) or isoverflow(str(b)): print "overflow"
    else:
         tmp = a+b
         if isoverflow(str(tmp)): print "overflow"
         else: print tmp

Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef pair<vector<int>,int>P;

int n;

map<vector<int>,int> BFS(vector<int> A){
  map<vector<int>,int>m;
  m[A]=0;
  queue<P>q;
  q.push(P(A,0));
  while(!q.empty()){
    vector<int> B=q.front().first;
    int cost=q.front().second;q.pop();
    if(cost==4)continue;
    for(int l=0;l<n-1;l++){
      for(int r=l+1;r<n;r++){
        vector<int>C=B;
        reverse(C.begin()+l,C.begin()+r+1);
        if(!m.count(C)){
          m[C]=cost+1;
          q.push(P(C,cost+1));
        }
      }
    }
  }
  return m;
}

int main(){
  cin>>n;
  vector<int>A(n),B(n);
  r(i,n)cin>>B[i],A[i]=i+1;
  map<vector<int>,int>m1=BFS(A);
  map<vector<int>,int>m2=BFS(B);
  int ans=9;
  do{
    if(m1.count(A)&&m2.count(A)){
      ans=min(ans,m1[A]+m2[A]);
    }
  }while(next_permutation(A.begin(),A.end()));
  cout<<ans<<endl;
}


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


void solve() {
  int A,B;
  cin >> A >> B;
  int kansi = 2*B+1;
  if (A%kansi == 0) {
    std::cout << A/kansi << '\n';
  } else {
    std::cout << A/kansi+1 << '\n';
  }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INFTY 1000001
#define MAX 1001
using namespace std;

class Edge{
public:
    int target, cost;
    Edge(int target = 0, int cost = 0) : target(target), cost(cost) {}
};

bool visited[MAX];
int parent[MAX], key[MAX];
int V, minv, min_index;

int minKey() {
    minv = INFTY;
    for (int v = 0; v < V; v++)
        if (!visited[v] && key[v] < minv)
            minv= key[v], min_index = v;
    return min_index;
}

void printMST()
{
    std::sort(key, key+V);
    int mid = V /2;
    printf("%d\n", key[mid]);
}

void prim(vector<Edge> G[]) {
    for (int i = 0; i < V; i++) {
        key[i] = INFTY;
        visited[i] = false;
        parent[i] = -1;
    }
    key[0] = 0;
    parent[0] = -1;

    int current, target, cost;

    for (int i = 0; i < V-1; i++) {
        current = minKey();
        visited[current] = true;

        for (unsigned long v = 0; v < G[current].size(); v++) {
            target = G[current][v].target;
            cost = G[current][v].cost;
            if (!visited[target] && cost < key[target])
                parent[target] = current, key[target] = cost;
        }
    }
    printMST();
}

int main()
{
    int E, source, cost, target;
    for (; ;) {
        std::scanf("%d %d", &V, &E);
        vector<Edge> G[V];
        if (V == 0 && E == 0) break;
        for (int i = 0; i < E; i++) {
            std::scanf("%d %d %d", &source, &target, &cost);
            G[--source].push_back(Edge(--target, cost));
            G[target].push_back(Edge(source, cost));
        }
        prim(G);
    }
    return 0;
}



Measured memory_bytes: 3400
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();
    int c = sc.nextInt();
    int d = sc.nextInt();
    long max = (long)b*d;
    long[] cross = {(long)b*d,(long)a*c,(long)a*d,(long)b*c};


//積が最大になる掛け算を考える
//0<x,0<yのときはx,yは最大値
//x<0,y<0のときはx,yは最小値がベスト
//0<x,y<0のときは、xが最小値,yが最大値
//x<0,0<yのときは、xが最大値,yが最小値

    for(int i=0; i<cross.length; i++){
      if(max<cross[i]){
        max = cross[i];
      }
    }

    System.out.println(max);

	}
}


Measured memory_bytes: 35796
#include<stdio.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>

int main()
{
	int h, w, a[500][500]{}, count{};
	bool is_moved[500][500]{};
	scanf("%d%d", &h, &w);

	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			scanf("%d", a[i] + j);

	for (int i = 0; i < h - 1; ++i)
		for (int j = 0; j < w; ++j)
		{
			if (a[i][j] % 2)
			{
				a[i][j]--;
				a[i + 1][j]++;
				is_moved[i][j] = true;
				count++;
			}
		}
	for (int i = 0; i < w - 1; ++i)
		if (a[h - 1][i] % 2)
		{
			a[h - 1][i]--;
			a[h - 1][i + 1]++;
			is_moved[h - 1][i] = true;
			count++;
		}
	
	printf("%d\n", count);
	for (int i = 0; i < h - 1; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			if (!is_moved[i][j]) continue;
			printf("%d %d %d %d\n", i+1, j+1, i+2, j+1);
		}
	}
	for (int i = 0; i < w - 1; ++i)
	{
		if (!is_moved[h - 1][i]) continue;
		printf("%d %d %d %d\n", h , i+1, h, i+2);
	}

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>

#define N 100

using namespace std;

int main(){
    int n, p[N+1] , m[N+1][N+1];
    cin >> n;
    
    for(int i=1; i<=n; ++i){
        cin >> p[i-1] >> p[i];
    }
    for(int i=1; i<=n; ++i)  m[i][i] = 0;
    for(int l=2; l<=n; ++l){
        for(int i=1; i<=n-l+1; ++i){
            int j = i+l-1;
            m[i][j] = (1 << 21);
            for(int k=i; k<=j-1; ++k){
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]);
            }
        }
    }
    
    cout << m[1][n] << endl;
     
    
    return 0;
}



Measured memory_bytes: 3140
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int l;
main() {
  file("threesum");
  ios;
  cin >> l;
  double s = l / 3.0;
  s = s * 1.0 * s * s;
  cout << fixed << setprecision(12) << s;
  return 0;
}
/**

*/


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

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

int main()
{
	int n,s;cin>>n>>s;
	vector<int> x(n);
	int i;
	rep(i,n) cin>>x[i];
	rep(i,n) x[i]=abs(x[i]-s);
	int ans=x[0];
	rep(i,n-1) ans=gcd(ans,x[i+1]);
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#!/usr/bin/ruby
# encoding: utf-8

# ABC 123 A - Five Antennas

a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i
k = gets.to_i

arr = [a,b,c,d,e]

# これでもOK！
#arr.combination(2).to_a.each {|i,j|
#  if (i-j).abs > k then
#    puts ":("
#    exit
#  end
#}

arr.combination(2) {|i,j|
  if (i-j).abs > k then
    puts ":("
    exit
  end
}

puts "Yay!"


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,n) for(int i=1;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define Rrep(i,n) for(int i=n-1;i>0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define P pair<int,int>
#define Pll pair<ll,ll>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
    ll n,m; cin >> n >> m;
    if(n==1&&m==1){
        cout << 1 << endl;
    }
    else if(n==1||m==1){
        cout << n*m-2 << endl;
    }else{
        cout << (n-2)*(m-2) << endl;
    }
}


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

int main() {
   int n;
   cin >> n;
   vector<int> a(n);
   for (int i = 0; i < n; i++) {
       cin >> a.at(i);
   }
   
   int count = 0;
   int x = 0;
   while (count < n) {
       if (x == 1) {
           break;
       }
       x = a.at(x) - 1;
       count++;
   }

   if (count == n) {
       cout << -1 << endl;
   } else {
       cout << count << endl;
   }
}

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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

using Graph = vector<vector<int>>;

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    template<typename First,typename Second> void inputTwoVec(vector<First> &first,vector<Second>& second){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i] >> second[i];
        }
    }

    void inputGraph(Graph &g,int path_num,bool isdirected){
        for(int i = 0;i < path_num;i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            if(isdirected){
                g[a].push_back(b);
            }
            else{
                g[a].push_back(b);
                g[b].push_back(a);
            }
        }
    }
}

void calculate(){
    long long x;
    Input::input(x);
    long long have = 100;
    for(int i = 0;;++i){
        if(have >= x){
            cout << i << '\n';
            return;
        }
        have *= 1.01;
    }
}

int main(int,char**){
    calculate();    
}





Measured memory_bytes: 3636
n = int(input())
INF = 10**5
answer = INF

for i in range(n+1):
    cost = i
    ans = 0
    for p in range(8):
        ans += (cost // 6**p) % 6

    cost = n-i
    for q in range(7):
        ans += (cost // 9**q) % 9
    if answer > ans:
        answer = ans
print(answer)


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

using namespace std;
using LLONG = long long;

const int SumOfDigits(const int value)
{
    int v = value;
    int c = 0;
    for (int i = 0; i < 5; ++i)
    {
        c += v % 10;
        v /= 10;
    }
    return c;
}

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int sum = 0;
    for (int i = 1; i <= N; ++i)
    {
        int v = SumOfDigits(i);
        if (A <= v && v <= B) sum += i;
    }
    cout << sum << endl;
    return 0;
}

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

arr = list(map(int, input().split(" ")))

ans = 1
case = 0

for i in range(1, n):
  judge = arr[i] - arr[i-1]
  if case == 0:
    if judge > 0:
      case = 1
    elif judge < 0:
      case = -1
  elif case == 1 and judge < 0 or case == -1 and judge > 0:
    case = 0
    ans += 1
print(ans)

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

int main() {
	// your code goes here
	int n,d;
	cin>>n>>d;
	int c=0;
	while(n--)
	{
		int x,y; 
		cin>>x>>y;
		double dist=sqrt((long long int)x*x+(long long int)y*y);
		//cout<<dist<<"$";
		if(dist<=double(d))
		c++;
	}
	cout<<c<<"\n";
	return 0;
}

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

int main(){
	int N,A,B;

	cin >> N >> A >> B;
	int res = 0;
	for(int n = 0; n <= N; n++){
		int m = n;
		int sum = 0;
		for(int i = 0; i < 5; i++){
			sum += m % 10;
			m /= 10;
		}

		if(A <= sum && sum <= B)
			res += n;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <bitset>
#include <iostream>
#include <vector>
using namespace std;

// Self settings
// clang-format off
#define MAX_N 10
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int N, M;

int k[MAX_N + 1];
int p[MAX_N + 1];
int s[MAX_N + 1];

void itob(int n)
{
  char str[12];
  if (n == 0) {
    str[0] = '0';
    str[1] = '\0';
    cout << str;
  }
  int cur = 0;
  while (n > 0) {
    if (n & 1) {
      str[cur] = '1';
    }
    else {
      str[cur] = '0';
    }
    n >>= 1;
    cur++;
  }
  for (int i = 0; i < (cur / 2); i++) {
    swap(str[i], str[cur - 1 - i]);
  }
  str[cur] = '\0';
  cout << str;
}

int main(void)
{
  cin >> N >> M;
  REP(i, M)
  {
    int k;
    cin >> k;
    REP(j, k)
    {
      int ss;
      cin >> ss;
      s[i] += (int)pow(2, ss - 1);
    }
  }
  REP(i, M) cin >> p[i];

  int ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    int onLight = 0;
    for (int j = 0; j < M; j++) {
      int no1 = s[j] & i;
      int cnt = 0;
      // count # 1
      while (no1 > 0) {
        if (no1 & 1) cnt++;
        no1 >>= 1;
      }
      if (cnt % 2 == p[j]) onLight++;
    }
    if (onLight == M) ans++;
  }

  cout << ans << endl;

  return 0;
}


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


void solve(std::string S, std::string T){
  long long mymin = LLONG_MAX;
  for(long long i = 0; i < (S.size() - T.size()); i++) {
    long long count = 0;
    for(long long j = 0; j < T.size(); j++) {
      if(S[i+j] != T[j]) count++;
    }

    mymin = min(mymin, count);
  }

  if(S.size() == T.size()) {
    long long count = 0;
    for(long long i = 0; i < S.size(); i++) {
      if(S[i] != T[i]) count++;
    }
    cout << count << endl;
  }
  else {
    cout << mymin << endl;
  }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3628
import java.util.*
 
fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()
    val K = scn.nextInt()
 
    var p = 0
    var list = mutableListOf<Int>()
    list.add(0)
    var maxP = 0
    for(i in 1..N){
        p = scn.nextInt()
        list.add(p + list[i-1])
 
        if(i>=K){
            var tmp = list[i] - list[i-K]
            if(maxP < tmp) maxP = tmp
        }
    }
 
    println((maxP+K).toFloat()/2f)
}

Measured memory_bytes: 74440
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;


int a[200010];
int b[200010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n;
    map<int, int> mp;
    cin >> n;
    REP(i, n){
        int a; cin >> a;
        mp[a]++;
    }
    int m; cin >> m;
    REP(i, m){
        int a; cin >> a;
        mp[a]++;
    }
    
    for(auto it=mp.begin(); it!=mp.end(); ++it){
        if(it->second==2) cout << it->first << endl;
    }
	return 0;
}


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

int frog(vector<int> v){
  vector<int> a(v.size(), 0);
  a[1]=abs(v[0]-v[1]);
  for(int i=2; i<v.size(); i++){
  	a[i] = min(abs(v[i]-v[i-2])+a[i-2], abs(v[i]-v[i-1])+a[i-1]);
  }
  return a[v.size()-1];
}

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0; i<n; i++) cin>>v[i];
  cout<<frog(v);
  return 0;
}

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

@SuppressWarnings("unchecked")
public class Main {
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int ans=0;
			if(n==0)break;
			for (int i = 1; i < n;i++){
				int sum = 0;
				for (int j = i; j < n; j++) {
					sum+=j;
					if(sum==n){
						ans++;
					}
					if(sum>n)break;
				}
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 18048
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define all(x) ((x).begin(), (x).end())
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(), (x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7
    
using namespace std;
    
int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};

int32_t main(){
    string s;
    cin >> s;

    int n=s.length()-1;
    int ans=0;
    REP(i, (1 << n)){
        int c=0;
        REP(j, n){
            if(i & (1 << j)){
                string st=s.substr(c, j-c+1);
                c=j+1;
                int num=stol(st);
                ans+=num;
            }
        }
        string st=s.substr(c, n-c+1);
        int num=stol(st);
        ans+=num;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/*
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 1000009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
int n,b[maxn];
struct ee
{
    int v,mi1,mi2;
    int l,r;
}tr[maxn*4];
void build(int a,int l,int r)
{
    tr[a].l=l;
    tr[a].r=r;
    tr[a].v=0;
    tr[a].mi1=2e9;
    if(l==r)
    {
        tr[a].mi1=b[l];
        return;
    }
    int mid=(l+r)/2;
    build(a*2,l,mid);
    build(a*2+1,mid+1,r);
}

int query(int a,int l,int r)
{
    if(tr[a].v)
    {
        tr[a*2].v^=1;
        tr[a*2+1].v^=1;
    }
    return tr[a].mi1;
}

void add(int a,int l,int r,int v)
{
    if(tr[a].l==l&&tr[a].r==r)
    {
        tr[a].mi1-=v;
        return;
    }
    int mid=(l+r)/2;
    if(l<=mid)
        add(a*2,l,mid,v);
    else
        add(a*2+1,mid+1,r,v);

}

int main()
{
    //freopen("d:\\in.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    build(1,1,n);
    vector<pair<int,int>> ans;
    for(int i=1;i<=n/2;i++)
    {
        int a1=query(1,1,n);
        int a2=query(1,a1,n);
        ans.push_back(make_pair(a1,a2));
    }
    printf("%d\n",ans.size());
    for(int i=0;i<ans.size();i++)
        printf("%d %d ",ans[i].first,ans[i].second);
    return 0;
}
*/


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 109
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
int h,w,n,a[1000009];
int ans[maxn][maxn];

int main()
{
    //freopen("d:\\in.txt","r",stdin);
    scanf("%d%d%d",&h,&w,&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int tmp=1;
    for(int i=1;i<=h;i+=2)
    {
        for(int j=1;j<=w;j++)
        {
            if(a[tmp]==0)
                tmp++;
            ans[i][j]=tmp;
            a[tmp]--;
        }
        if(i==h)
            break;
        for(int j=w;j>=1;j--)
        {
            if(a[tmp]==0)
                tmp++;
            ans[i+1][j]=tmp;
            a[tmp]--;
        }
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
            printf("%d ",ans[i][j]);
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 384
n=int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
a=sorted(a,key=lambda x:(x[1]))
#print(a)

time=0
for i in a:
    time+=i[0]
    if time>i[1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 42716
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=c if c>r//2 else r-c
  if a<b:a=b
 print(a)


Measured memory_bytes: 6912
n, x = map(int, input().split())
a = list(map(int, input().split()))

mins = a[:]
result = float("inf")

for k in range(n):
    for i in range(len(mins)):
        mins[i] = min(a[i - k], mins[i])
    result = min(x * k + sum(mins), result)

print(result)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>h(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  reverse(h.begin(),h.end());
  int val=0;
  int ans=0;
  for(int i=1;i<n;i++){
    if(h.at(i-1)<=h.at(i)){
      val++;
    }
    else {
      val=0;
    }
      ans=max(ans,val);
  }
    cout<<ans<<endl;
}
  


Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

int n,k;

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

    cin>>n>>k;
    vector<pii> answer;

    int now=(n-1)*(n-2)/2;
    if(k>now){
        cout<<-1;
        return 0;
    }
    for(int i=1; i<n; i++) answer.push_back({0,i});

    for(int i=1; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(k==now) break;
            answer.push_back({i,j});
            now-=1;
        }
    }

    cout<<answer.size()<<"\n";
    for(pii& p : answer){
        cout<<p.first+1<<" "<<p.second+1<<"\n";
    }
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
using namespace std;

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

    int Q;

    Q = N/(2*D+1);

    if(N%(2*D+1) != 0){
        Q++;
    }

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


Measured memory_bytes: 128
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())

    if B > A:
        print('No')
    elif B > D:
        print('No')
    elif C >= B:
        print('Yes')
    else:
        g = gcd(B, D)
        if B - g + (A % g) > C:
            print('No')
        else:
            print('Yes')


Measured memory_bytes: 3060
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    var str = scanner.next
    val q = scanner.nextInt
    for(_ <- 1 to q) {
      scanner.next match {
        case "print" => println(str.substring(scanner.nextInt, scanner.nextInt + 1))
        case "reverse" => str = reverse(str, scanner.nextInt, scanner.nextInt)
        case _ => str = replace(str, scanner.nextInt, scanner.nextInt, scanner.next)
      }
    }
  }

  def reverse(str: String, a: Int, b: Int): String =
    str.substring(0, a) + str.substring(a, b + 1).reverse + str.substring(b + 1, str.length)

  def replace(str: String, a: Int, b: Int, p: String): String =
    str.substring(0, a) + p + str.substring(b + 1, str.length)
}



Measured memory_bytes: 47828
# C
import itertools
tmp = input()
siz = len(tmp)
N = int(tmp)

table = ['3','5','7']
cnt = 0 
for i in range(3, siz):
    #print("i", i)
    for combi in itertools.product(table, repeat=i):
        #print(combi)
        cnt += 1 if len(set(combi)) == 3 else 0

for combi in itertools.product(table, repeat=siz):
    # combiを数字に変換
    cur = 0
    for i,v in enumerate(combi[::-1]):
        cur += 10**i * int(v)
    #print(cur, combi)
    # Nと比較
    if N >= cur:
        cnt += 1 if len(set(combi)) == 3 else 0
        

print(cnt)
    

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

int d[100000];

int main()

{
	
	int s=0, n;
	cin >> n;
	for (int i=0;i<n;i++)
	{
		cin >> d[i];
	}
	for (int i=0;i<n;i++)
	{
		for (int j=i+1;j<n;j++)
		s=d[j]*d[i]+s;
		
		
	}
	cout << s;
}


Measured memory_bytes: 256
n, a, b, c, d = gets.chomp.split.map(&:to_i)
s = gets.chomp
b.upto(d-2) do |i|
  if s[i, 2] == "##"
    puts "No"
    exit
  end
end
a.upto(c-2) do |i|
  if s[i, 2] == "##"
    puts "No"
    exit
  end
end
if c < d
  puts "Yes"
else
  (b-2).upto(d-2) do |i|
    if s[i, 3] == "..."
      puts "Yes"
      exit
    end
  end
  puts "No"
end


Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n,m) for(int i=(n);i<(m);i++)
int count(int N,ll a,int b){
  int c=0;
  if(a<=N){
    if(b==7)c++;
    c+=count(N,a*10+3,b|1);
    c+=count(N,a*10+5,b|2);
    c+=count(N,a*10+7,b|4);
  }
  return c;
}

int main(){
  int N;
  cin>>N;
  cout<<count(N,0,0)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] check = new int[4][4];
        for (int i = 0; i < 4; i++) {
            check[i] = IntStream.rangeClosed(i * 4 + 1, i * 4 + 4).toArray();
        }
        while (sc.hasNext()) {
            int offsetX = 0;
            int offsetY = 0;
            int sum = 0;
            for (int i = 0; i < 8; i++) {
                String text = sc.next();
                for (int j = 0; j < 8; j++) {
                    if (text.charAt(j) == '1') {
                        if (sum == 0) {
                            offsetX = j;
                            offsetY = i;
                            sum++;
                        } else {
                            int dx = j - offsetX;
                            int dy = i - offsetY;
                            if (dx >= 0) {
                                sum += check[dy][dx];
                            }
                        }
                    }
                }
            }
            char answer = 0;
            switch (sum) {
            case 14:
                answer = 'A';
                break;
            case 28:
                answer = 'B';
                break;
            case 10:
                answer = 'C';
                break;
            case 6:
                answer = 'D';
                break;
            case 16:
                answer = 'E';
                break;
            case 22:
                answer = 'F';
                break;
            case 8:
                answer = 'G';
                break;
            }
            System.out.println(answer);
        }
    }
}


Measured memory_bytes: 31868