akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()
	sort.Sort(sort.IntSlice(a))

	dp := make([]int, a[n-1]+1)
	for _, ai := range a {
		if dp[ai] < 2 {
			dp[ai]++
			for w := ai * 2; w < len(dp); w += ai {
				dp[w] = 2
				if w >= len(dp) {
					break
				}
			}
		}
	}

	ans := 0
	for _, ai := range a {
		if dp[ai] < 2 {
			ans++
		}
	}

	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 19780
# unihernandez22
# https://atcoder.jp/contests/abc166/tasks/abc166_d
# math
n = int(input())
for a in range(n):
    breaked = True
    for b in range(-1000, 1000):
        if a**5 - b**5 == n:
            print(a, b)
            break;
    else:
        breaked = False
    if breaked:
        break


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


K = int(input())

sum_gcd = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        g = gcd(i, j)
        for k in range(1, K + 1):
            sum_gcd += gcd(g, k)
print(sum_gcd)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
void init_fact(){
	kaijo[0]=1;
	for(int i=1;i<=2000000;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(!kaijo[0])init_fact();
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
	return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
int n,m,now;
string s;
vector<int>ans;
signed main(){
	cin>>n>>m>>s;
	now=n;
	while(now){
		for(int i=max(0ll,now-m);i<now;i++){
			if(s[i]=='0'){
				ans.pb(now-i);
				now=i;
				goto ok;
			}
		}
		puts("-1");
		return 0;
		ok:;
	}
	reverse(all(ans));
	for(int i:ans){
		cout<<i<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1528
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)


Measured memory_bytes: 38384
#include <stdio.h>
#include <stdlib.h>
struct BinaryTree
{
	int data;
	struct BinaryTree *lchild,*rchild;
};
int post[40],i;
void pre_in_order(int *pre,int l1,int r1,int *in,int l2,int r2,struct BinaryTree **root)
{
	int m;
	i=0;
	*root=(struct BinaryTree *)malloc(sizeof(struct BinaryTree));
	(*root)->data=pre[l1];
	m=l2;
	while(pre[l1]!=in[m])
	m++;
	if(m==l2)
	(*root)->lchild=NULL;
	else
	pre_in_order(pre,l1+1,m-l2+l1,in,l2,m-1,&(*root)->lchild);
	if(m==r2)
	(*root)->rchild=NULL;
	else
	pre_in_order(pre,m-l2+l1+1,r1,in,m+1,r2,&(*root)->rchild);
}
void postorder(struct BinaryTree *root)
{
if(root)
{
postorder(root->lchild);
postorder(root->rchild);
post[i]=root->data;
i++;
}
}
int main(int argc, char *argv[])
{
	int pre[40];
	int in[40];
	int n,i;
	struct BinaryTree *root;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&pre[i]);
	for(i=0;i<n;i++)
	scanf("%d",&in[i]);
	pre_in_order(pre,0,n-1,in,0,n-1,&root);
	postorder(root);
	for(i=0;i<n;i++)
	{
		printf("%d",post[i]);
		if(i+1==n)
		printf("\n");
		else
		printf(" ");
	}
	return 0;
}

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

int main(){
    string s,me,tmp,p;
    int q,a,b;
    cin >> s >> q;
    for(int i=0; i<q; i++){
        cin >> me >> a >> b;
        tmp = s.substr(a,b-a+1);
        if(me == "print"){
            cout << tmp << endl;
        }else if(me == "reverse"){
            for(int j=0; j<tmp.size()/2; j++){
                swap(tmp.at(j),tmp.at(tmp.size()-1-j));
            }
            s.replace(a,b-a+1,tmp);
        }else if(me == "replace"){
            cin >> p;
            s.replace(a,b-a+1,p);
        }
    }
    return 0;
}


Measured memory_bytes: 3204
#include "bits/stdc++.h"

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple < int, int, int >
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >
#define pis pair < int, string >

#define vi vector < int >
#define vd vector < double >
#define vld vector < ld >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define vpi vector < pii >
#define vpll vector < pll >
#define vpis vector < pis >

#define pb push_back
#define mt make_tuple
#define gt0 get < 0 >
#define gt1 get < 1 >
#define gt2 get < 2 >

#define pi acos(-1)

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 1e6 + 5;
const int mod = 1e9 + 9;

int a[maxn];

void solve()
{
    fill(a, a + maxn, 2);
    a[1] = 1;

    for(int i = 2; i < maxn; i++){
        for(int j = i + i; j < maxn; j += i) a[j]++;
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    fast;

    solve();

    int n;

    scanf("%d", &n);

    ll ans = 0;

    for(int i = 1; i < n; i++){
        int tmp = n - i;
        ans += a[tmp];
    }

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

    return 0;
}


Measured memory_bytes: 7736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main () {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  vector<int> a;
  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    a.push_back(p[i - 1]);
    a.push_back(p[i]);
    a.push_back(p[i + 1]);
    sort(a.begin(), a.end());
    if (a[1] == p[i]) {
      ans++;
    }
    a.clear();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
int main(){
    int N, D, M, T;
    cin >> N;
    multiset <int> S;
    while(N-- && cin >> D){
        S.insert(D);
    }
    cin >> M;
    while(cin >> T){
        if(!S.count(T)){
            cout << "NO" << endl;
            return 0;
        }
        S.erase(S.find(T));
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 12920
N = int(input())
nums = [0] + list(map(int, input().split())) + [0, 0]

L = [0] * (N+1)
R = [0] * (N+1)

for i in range(1, N+1):
  L[i] = L[i-1] + abs(nums[i-1] - nums[i-2])
  R[N-i] = R[N-i+1] + abs(nums[N-i+2] - nums[N-i+1])
for i in range(1, N+1):
  print(L[i]+R[i]+abs(nums[i+1]-nums[i-1]))

Measured memory_bytes: 16268
def main():
    h, n = list(map(int, input().split()))
    A, B = [], []
    for _ in range(n):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)
    mx = max(A)
    INF = float('inf')
    dp = [INF] * (h + mx + 1)
    dp[0] = 0
    for i in range(1, h + mx + 1):
        for a, b in zip(A, B):
            if i - a < 0:
                dp[i] = min(dp[i], b)
            else:
                dp[i] = min(dp[i], dp[i - a] + b)
    print(min(dp[h:h + mx + 1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42860
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] colors = sc.nextLine().split(" ");
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.nextLine();
        String throwAway = sc.nextLine().trim();

        if (throwAway.equals(colors[0].trim())) {
            a--;
        } else {
            b--;
        }

        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 23636
#include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
     
    using namespace std;
    int main()
    {
    	char a,b;
    	scanf("%s %s",&a, &b);
    	
    		if(a > b)
    			printf(">\n");
    		else if(a < b)
    			printf("<\n");
    		else
    			printf("=\n");
    		
    }

Measured memory_bytes: 256
def sprint(str, a, b):
 print(str[a:b+1])

def reverse(str, a, b):
 str1 = str[:a]
 str2 = str[a: b+1]
 str3 = str[b+1:]
 str = str1 + str2[::-1] + str3
 return str

def replace(str, a, b, p):
 str1 = str[:a]
 str3 = str[b+1:]
 str = str1 + p + str3
 return str

str = input()
q = int(input())
for i in range(q):
 L = input().split()
 if L[0] == "replace":
  str = replace(str, int(L[1]), int(L[2]), L[3])
 if L[0] == "reverse":
  str = reverse(str, int(L[1]), int(L[2]))
 if L[0] == "print":
  sprint(str, int(L[1]), int(L[2]))

Measured memory_bytes: 7744
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        h: u32,
        w: u32,
        n: usize,
        p: [(u32, u32, u32, u32); n],
    }
    let map = |a: u32, b: u32| -> Option<u32> {
        if a == 0 {
            Some(b)
        } else if b == w {
            Some(w + a)
        } else if a == h {
            Some(w + h + (w - b))
        } else if b == 0 {
            Some(w + h + w + (h - a))
        } else {
            None
        }
    };
    let mut x = vec![];
    for (i, (a, b, c, d)) in p.into_iter().enumerate() {
        match (map(a, b), map(c, d)) {
            (Some(p), Some(q)) => {
                x.push((p, i));
                x.push((q, i));
            },
            _ => (),
        }
    }
    x.sort();
    let mut stack = vec![];
    while let Some((_, k)) = x.pop() {
        if stack.last().map_or(false, |p| *p == k) {
            stack.pop();
        } else {
            stack.push(k);
        }
    }
    let ans = if stack.is_empty() {"YES"} else {"NO"};
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 15472
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int a = stdin.nextInt();
		int b = stdin.nextInt();
		int m = a * b;

		String result = "Even";
		if (m % 2 > 0) {
			result = "Odd";
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 23508
from __future__ import annotations

from dataclasses import dataclass, field
from typing import List, Optional, Generator


@dataclass
class Sweet:
    id: int


@dataclass
class User:
    id: int
    sweets: List[Sweet] = field(default_factory=list)

    def has_no_sweets(self) -> bool:
        return len(self.sweets) == 0

    def register_sweet(self, sweet: Sweet) -> None:
        self.sweets.append(sweet)


@dataclass(frozen=True)
class Users:
    values: List[User] = field(default_factory=list)

    @classmethod
    def create(cls, num_people: int) -> Users:
        users = [User(id=i) for i in range(1, num_people + 1)]

        return Users(users)

    def find_by_id(self, user_id: int) -> Optional[User]:
        return self.values[user_id - 1]

    def count_users_have_no_sweets(self) -> int:
        return sum([user.has_no_sweets() for user in self.values])


@dataclass
class DistributePlan:
    """どのお菓子をどのユーザに配布するか情報"""
    sweet_id: int
    user_ids: List[int] = field(default_factory=list)


@dataclass
class DistributePlans:
    num_people: int
    values: List[DistributePlan] = field(default_factory=list)

    @classmethod
    def create(cls, num_people, sweet_ids, distribution_plans) -> DistributePlans:
        plans = []

        for sweet_id, distribution_plan in zip(sweet_ids, distribution_plans):
            distribution_plan = DistributePlan(sweet_id, distribution_plan)
            plans.append(distribution_plan)

        return DistributePlans(num_people, plans)

    def gen(self) -> Generator:
        for plan in self.values:
            for user_id in plan.user_ids:
                yield plan.sweet_id, user_id

    def distribute(self) -> Users:
        users = Users.create(self.num_people)

        for sweet_id, user_id in self.gen():
            user = users.find_by_id(user_id)
            user.register_sweet(Sweet(id=sweet_id))

        return users


def actual(n, k, sweet_ids, distribution_user_ids):
    plans = DistributePlans.create(n, sweet_ids, distribution_user_ids)

    users = plans.distribute()

    return users.count_users_have_no_sweets()


n, k = map(int, input().split())

sweet_ids = []
distribution_user_ids = []

for k_i in range(1, k + 1):
    d_i = int(input())
    a_i = list(map(int, input().split()))

    sweet_ids.append(d_i)
    distribution_user_ids.append(a_i)

print(actual(n, k, sweet_ids, distribution_user_ids))


Measured memory_bytes: 12528
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N,A,B,C,D;
  cin>>N>>A>>B>>C>>D;
  int64_t x=B-A;
  string ans="NO";
  for(int64_t i=0;i<N;i++){
  if(C*i-D*(N-1-i)<=x && x<=D*i-C*(N-1-i)){ans="YES"; break;}
  }cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3616
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,m]=i2()
a=i2()
a.sort()
t=[]
z=0
import bisect
for _ in range(m):
 [b,c]=i2()
 x=bisect.bisect_left(a,c)
 j=x-1
 if j<0:
    continue
 t.append([j,c,b])

l=len(t)

d=sum(a)
dd=n
if l>0:
 t.sort()
 l0=t[l-1][0]
 l1=t[l-1][1]
 l2=t[l-1][2]
 d=0
 for i in range(n):
  if i>l0:
    continue
  dd=i
  d+=l1
  l2-=1
  if l2==0:
    l-=1
    l0=t[l-1][0]
    l1=t[l-1][1]
    l2=t[l-1][2]
    if l-1<0:
       break

print(d+sum(a[dd+1:]))

Measured memory_bytes: 27212
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m;
	char flg[51][51];
	int i,j,k;
	int wcnt[51];
	int rcnt[51];
	int bcnt[51];
	int cnt=0;
	cin>>n>>m;
	for(i=0;i<n;i++){
		wcnt[i]=0;
		rcnt[i]=0;
		bcnt[i]=0;
		for(j=0;j<m;j++){
			cin>>flg[i][j];
			if(flg[i][j]=='W'){
				wcnt[i]++;
			}
			if(flg[i][j]=='B'){
				bcnt[i]++;
			}
			if(flg[i][j]=='R'){
				rcnt[i]++;
			}
		}
	}
	
	int cnt1=0,cnt2,cnt3;	
	int MIN=INT_MAX;
	for(i=0;i<n-2;i++){
		cnt1+=rcnt[i]+bcnt[i];
		//cout<<"I="<<i<<endl;
		cnt2=0;
		for(j=i+1;j<n-1;j++){
			cnt2+=wcnt[j]+rcnt[j];
			//cout<<"J="<<j<<endl;
			cnt3=0;
			for(k=j+1;k<n;k++){
				cnt3+=wcnt[k]+bcnt[k];
				//cout<<"K="<<k<<endl;
			}
			cnt+=cnt1+cnt2+cnt3;
			//cout<<cnt<<endl;
			//cout<<cnt<<endl;
			MIN=min(MIN,cnt);
			cnt=0;
		}
	}
	cout<<MIN<<endl;
	return 0;
}
			


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

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

    int a, b;
    string s, t, u;
    cin >> s >> t >> a >> b >> u;
    if (u == s) {
        a--;
    } else {
        b--;
    }
    cout << a << " " << b;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, c, k;
    int sum1, sum2, sum3;
    int a1, b1, c1;

    scanf("%d %d %d %d", &a, &b, &c, &k);

    a1 = a;
    b1 = b;
    c1 = c;

    for (int i = 0; i < k; i++)
    {
        a1 = a1*2;
    }
    sum1 = a1 + b + c;

    for (int i = 0; i < k; i++)
    {
        b1 = b1*2;
    }
    sum2 = a + b1 + c;

    for (int i = 0; i < k; i++)
    {
        c1 = c1*2;
    }
    sum3 = a + b + c1;


    if(sum1 >= sum2 && sum1 >= sum3)
    {
        printf("%d\n", sum1);
    }
    else if (sum2 >= sum1 && sum2 >= sum3)
    {
        printf("%d\n", sum2);
    }
    else if (sum3 >= sum1 && sum3 >= sum2)
    {
        printf("%d\n", sum3);
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long ll;


int main(){
    ios::sync_with_stdio(false);

    int n, a, b;
    cin>>n>>a>>b;
    if(b>a*n) cout<<a*n;
    else cout<<b;
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s = []
for _ in range(H):
    s.append(input())
dx = (0, 1, 0, -1)
dy = (1, 0, -1, 0)

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            for d in range(4):
                ni = i + dy[d]
                nj = j + dx[d]
                if ni < 0 or ni >= H:
                    continue
                if nj < 0 or nj >= W:
                    continue
                if s[ni][nj] == "#":
                    break
            else:
                break
            continue
    else:
        continue
    print("No")
    break
else:
    print("Yes")



Measured memory_bytes: 67812
function main(){
	var n = scan();
	var w = scan();
	var h = scan();

	var x = [];
	rep(w + 1, function(i){
		x[i] = 0;
	});
	var y = [];
	rep(h + 1, function(i){
		y[i] = 0;
	});
	
	rep(n, function(){
		var a = scan();
		var b = scan();
		var c = scan();
		++x[Math.max(a - c, 0)];
		--x[Math.min(a + c, w)];
		++y[Math.max(b - c, 0)];
		--y[Math.min(b + c, h)];
	});

	rep(w, function(i){
		x[i + 1] += x[i];
	});
	rep(h, function(i){
		y[i + 1] += y[i];
	});

	var s = true;
	rep(w, function(i){
		s = x[i] > 0 && s;
	});
	var t = true;
	rep(h, function(i){
		t = y[i] > 0 && t;
	});

	print(s || t ? 'Yes' : 'No');
}
 
function rep(a, b, c){
	if(c == null){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input = '';
var input_index = 0;
 
function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}
 
function print(val){
	console.log(val);
}
 
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});

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

int main(){
    int x_1, x_2, y_1, y_2;
    cin >> x_1 >> y_1 >> x_2 >> y_2;

    int dx, dy;
    dx = x_2 - x_1;
    dy = y_2 - y_1;

    cout << x_2 - dy << " " << y_2 + dx << " " << x_1 - dy << " " << y_1 + dx << endl;
}

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

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

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;

int main(){
    string a,b;cin>>a>>b;
    int comp=0;
    string s[3]={"EQUAL","GREATER","LESS"};

    if(a.length()>b.length()) comp = 1;
    else if(a.length()<b.length()) comp = 2;
    else {
        for(int i=0;i<a.length();i++){
            if(a[i]>b[i]) {
                comp = 1;
                break;
            }
            else if(a[i]<b[i]) {
                comp = 2;
                break;
            }
        }
    }
    cout<<s[comp]<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <cstring>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};

const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/
ll N, L, Q;
vector<ll> X(100010);
ll Next[100010][20];
int main(){
  cin >> N;
  X.resize(N);

  rep(i, N) cin >> X[i];
  X.pb(INFL);
  cin >> L;
  rep(i, N){
    Next[i][0] = upper_bound(X.begin(), X.end(), X[i] + L) - X.begin() - 1;
  }

  for(ll j = 1; j < 20; j++){
    rep(i, N){
      Next[i][j] = Next[Next[i][j-1]][j-1];
    }
  }

  cin >> Q;
  rep(i, Q){
    ll a, b;
    cin >> a >> b;
    a--, b--;
    if(a > b) swap(a, b);
    ll now = a;
    ll cnt = 0;
    while(now != b){
      if(Next[now][0] >= b){
        cnt++;
        break;
      }
      rep(j, 20){
        if(Next[now][j] >= b){
          now = Next[now][j-1];
          cnt += pow_long(2, j-1);
          break;
        }
      }
    }
    cout << cnt << endl;
  }
}


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

using namespace std;

long long n, a[1000005], res = 0, t;

int main(){
    cin >>  n;
    for(long long i = 1; i <= n; i++) cin >> a[i];
    for(long long i = 1; i <= n - 1; i++){
        if(a[i] == i && a[i + 1] == i + 1){
            res++;
            swap(a[i], a[i + 1]);
        }
    }
    if(n % 2 == 0) t = n - 1;
    else t = n - 2;
    for(long long i = 1; i <= t; i = i + 2){
        if(a[i] == i || a[i + 1] == i + 1) res++;
    }
    if(n % 2 == 1 && a[n] == n) res++;
    cout << res;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define int long long
#define P pair<int,int>

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

    if(c - a - b < 0) {
        cout << "No" << endl;
        return 0;
    }

    int left = 4 * a * b;
    int right = (c - a - b) * (c - a - b);
    if(left < right) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ( a == b && c == d ||
       a == c && b == d ||
       a == d && b == c ) cout << "yes" << endl;
  else cout << "no" << endl;

  return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++) 
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long

int main(int argc, char** argv) {
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll x,y;
  cin >> x >> y;
  if(x%y==0) cout << -1 << endl;
  else {
    cout << x << endl;
  }
}

Measured memory_bytes: 256
import heapq
n,m = map(int,input().split())
x_input = sorted(list(map(int,input().split())))

cost_li = []
for i in range(m-1):
    heapq.heappush(cost_li,-(x_input[i+1]-x_input[i]))

for i in range(n-1):
    if len(cost_li)==0:
        print(0);exit()
    heapq.heappop(cost_li)

print(-sum(cost_li))

Measured memory_bytes: 13960
//##Moh_K_Imar .......
//27/08/2020  ...  8.01
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
   ll a;
   cin>>a;
   if(a%1000==0)cout<<0<<endl;
   else
    cout<<1000-(a%1000)<<endl;


    return 0;
}




Measured memory_bytes: 3624
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;


public class Main {

    public static void main(String[] args) {
    
    	FastScanner scan = new FastScanner();
    	
    	int n = scan.nextInt();
    	int [][] arr = new int [n][2];
    	
    	for(int i=0; i<n; i++) {
    		for(int j=0; j<2; j++) {
    			arr[i][j] = scan.nextInt();
    		}
    	}
    	
    	boolean works = false;
    	int count = 0;
    	
    	for(int i=0; i<n; i++) {
    			if(arr[i][0] == arr[i][1]) count++;
    			else count = 0;
    			if(count == 3) works = true;
    	}
    	
    	System.out.println((works) ? "Yes" : "No");
    	
    	
    }

    static class FastScanner{
    	
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}
    	
    	int nextInt() {
    		return Integer.parseInt(next());
    	}
    	
    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}
    	
    	long nextLong() {
    		return Long.parseLong(next());
    	}
    	
    	
    }
    
   
}



Measured memory_bytes: 32844
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	map<string, int> votes;
	int most = 0;
	string s;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		++votes[s];
		most = max(most, votes[s]);
	}

	for (auto it = votes.begin(); it != votes.end(); ++it) {
		if (it->second == most) {
			cout << it->first << "\n";
		}
	}

	return 0;

}

Measured memory_bytes: 23808
from collections import deque

def penetrate(x, y, count):
    global max_idx
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]

        if 0 <= nx < h and 0 <= ny < w and A[nx][ny] == "." and d[nx][ny] == -1:
            d[nx][ny] = count + 1
            q.append((nx, ny, d[nx][ny]))
            max_idx = max(max_idx, d[nx][ny])


h, w = map(int, input().split())
d = [[-1] * w for _ in range(h)]

A = [[] for i in range(h)]
q = deque()

for i in range(h):
    A[i] = list(input())
    for j in range(w):
        if A[i][j] == "#":
            d[i][j] = 0
            q.append((i, j, d[i][j]))

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
max_idx = 0

while len(q) > 0:
    idx = q.popleft()
    penetrate(idx[0], idx[1], idx[2])

print(max_idx)


Measured memory_bytes: 166004
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   X : Integer;
   Y : Integer;
   Z : Integer;
begin
   Get (X);
   Get (Y);
   Get (Z);
   Put (Integer'Image (Z));
   Put (Integer'Image (X));
   Put (Integer'Image (Y));
end Solve;

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   long long n;
   cin >> n;
   long long a;
   a = n;
   long long count = 0;
   while(a>0) {
       count+=a%10;
       a=a/10;
   }
   if(n%count==0) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int w, v[30];
    int n, i;
    int a, b;
    int t;

    scanf("%d", &w);
    scanf("%d", &n);

    for (i = 0; i < w; i++) {
        v[i] = i + 1;
    }

    for (i = 0; i < n; i++) {
        scanf("%d,%d", &a, &b);
        t = v[a - 1];
        v[a - 1] = v[b - 1];
        v[b - 1] = t;
    }

    for (i = 0; i < w; i++) {
        printf("%d\n", v[i]);
    }

    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

/*
    AOJ 2224 Save your cats
*/

/*
3 3
0 0
3 0
0 4
1 2
2 3
3 1

3.000


4 3
0 0
-100 0
100 0
0 100
1 2
1 3
1 4

0.000


6 7
2 0
6 0
8 2
6 3
0 5
1 7
1 2
2 3
3 4
4 1
5 1
5 4
5 6

7.236



6 6
0 0
0 1
1 0
30 0
0 40
30 40
1 2
2 3
3 1
4 5
5 6
6 4


31.000
*/

struct edge {
    int from;
    int to;
    double cost;

    edge(int from = 0, int to = 0, double cost = 0): from(from), to(to), cost(cost) {}

    bool operator < (const edge &b) const {
        return cost < b.cost;
    }
};

const int MAX_N = 1e4 + 10;

int N = 0;
int M = 0;
int X[MAX_N];
int Y[MAX_N];

// 实现并查集
int par[MAX_N + 1];
int rnk[MAX_N + 1];

void init(int n) {
    for (int i = 0; i <= n; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    }

    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) {
        return;
    }

    if (rnk[x] < rnk[y]) {
        par[x] = y;
    }
    else {
        par[y] = x;
        if (rnk[x] == rnk[y]) {
            rnk[x]++;
        }
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

vector<edge> es;

double kruskal() {
    sort(es.begin(), es.end());
    double res = 0;
    for (int i = 0; i < es.size(); i++) {
        edge e = es[i];
        if (!same(e.from, e.to)) {
            res += e.cost;
            unite(e.from, e.to);
        }
    }

    return res;
}

void solve() {
    // 本质是最大生成树问题
    init(N);
    double res = kruskal();

    for (int i = 0; i < es.size(); i++) {
        res -= es[i].cost;
    }

    printf("%.3f\n", res);
}

int main() {
    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; i++) {
        scanf("%d %d", &X[i], &Y[i]);
    }
    int from = 0;
    int to = 0;
    for (int i = 0; i < M; i++) {
        scanf("%d %d", &from, &to);
        int x = X[from] - X[to];
        int y = Y[from] - Y[to];
        double cost = sqrt(x * x + y * y);

        es.push_back(edge(from, to, -cost));
    }

    solve();

    return 0;
}



Measured memory_bytes: 3684
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  int n;
  cin >> n >> s;
  for(int i=0; i<s.size(); i++){
    if(s[i]+n>90) s[i]+=n-26;
    else s[i]+=n;
    cout << s[i];
  }
  return 0;
}

Measured memory_bytes: 256
main = do
    [a,b,k] <- (fmap read . words) <$> getLine :: IO [Int]
    print $ (reverse $ factors (gcd a b))!!(k-1)

divides :: Int -> Int -> Bool
n `divides` m = m `mod` n == 0

factors :: Int -> [Int]
factors n = [ y | y <- [1..n], y `divides` n ]

Measured memory_bytes: 508
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    uf.union(a, b)

ans = 0
for x in uf.roots():
    ans = max(ans, uf.size(x))

print(ans)


Measured memory_bytes: 87780
n=int(input())
z=list(map(int,input().split()))
flag=1
a=0
cnt=0
while flag:
    flag=0

    for i in reversed(range(a,n)):
        if i ==0:
            break
        if z[i]<z[i-1]:
            tmp=z[i]
            z[i]=z[i-1]
            z[i-1]=tmp
            flag=1
            cnt+=1
        
    a+=1
print(' '.join(list(map(str,z))))
print(cnt)

Measured memory_bytes: 7732
import java.io.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;
		
		while((line = in.readLine()) != null){
			int size = Integer.parseInt(line);
			if(size==0) break;
			int[] data = new int[size];
			for(int i=0; i<size; i++){
				line = in.readLine();
				data[i] = Integer.parseInt(line);
			}
			
			int count = 0;
			for(int i=1; i<size; i++){
				for(int j=size-1; j>=i; j--){
					if(data[j] < data[j-1]){
						int t = data[j];
						data[j] = data[j-1];
						data[j-1] = t;
						count++;
					}
				}
			}
			
			System.out.println(count);
		}
	}
}

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

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

long long lcm(long long c, long long d) {
  return abs(c*d) / gcd(c, d);
}

int main() {
  long long A, B, C, D; cin >> A >> B >> C >> D;
  long long ans = (B-A+1) - B/C - B/D + B/lcm(C, D) + (A-1)/C + (A-1)/D - (A-1)/ lcm(C, D);
  cout << ans << endl;

  return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll a, b, k; cin >> a >> b >> k;
    ll mn = min(a,k);
    a -= mn;
    k -= mn;
    b -= min(b,k);
    cout << a << ' ' << b << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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;}

const long long mod = 1e9 + 7;
vector<long long> dp(1e5+10);

int main(){
    int n,m; cin >> n >> m;
    vector<bool> a(n+1,true); 
    for(int i = 0; i < m; i++){ int tmp; cin >> tmp; a[tmp] = false; }
    dp[0] = 1;
    for(int now = 0; now < n; now++){
        for(int next = now+1; next <= min(n,now+2) ; next++){
            if(a[next]){
                dp[next] += dp[now];
                dp[next] %= mod;
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a, ans = 1, cnt = 0;
    bool renzoku = false;
    rep (i, n) {
        int a;
        cin >> a;
        if (a) {
            if (renzoku) cnt++;
            else cnt = 2, renzoku = true;
        }
        else {
            if (renzoku) ans = max(ans, cnt), renzoku = false, cnt = 0;
        }
        if (i == n - 1) ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3120
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
count=0
for i in range(N):
    for j in range(i+1,N):
        distance=0
        for d in range(D):distance+=pow(abs(X[i][d]-X[j][d]),2)
        if distance==int(distance**.5)**2:count+=1
print(count)

Measured memory_bytes: 3064
import java.util.*;

public class Main 
{
	    public static void main(String[] args) 
        {
        	Scanner scanner = new Scanner(System.in);
        	String S = scanner.next();
        	Long countA = 0L;
        	Long countB = 0L;
        	for (int i = 0; i < S.length(); i++) 
            {
            	if(S.charAt(i) == '0')
                  	countA++;
            	if(S.charAt(i) == '1') 
                  	countB++;
        	}
        	countA = Math.min(countA, countB) * 2;
        	System.out.println(countA);
    	}
}


Measured memory_bytes: 28272
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);

	final int INF = 1 << 29;
	int w;
	int h;
	int map[][];
	boolean broken[][];
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { 1, 0, -1, 0 };

	int sx;
	int sy;

	void run() {
		while (true) {
			w = sc.nextInt();
			h = sc.nextInt();

			if ((w | h) == 0)
				break;
			map = new int[h][w];
			broken = new boolean[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					map[i][j] = sc.nextInt();
					if (map[i][j] == 2) {
						sx = j;
						sy = i;
					}
				}
			}
			int ans = dfs(sx, sy, 0);
			System.out.println(ans == INF ? -1 : ans);
		}
	}

	int dfs(int x, int y, int c) {
//		System.out.println(x + " " + y + " " + c);
		int res = INF;
		if (map[y][x] == 3) {
			return c;
		}
		if (c >= 10) {
			return INF;
		}
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (check(nx, ny) || (map[ny][nx] == 1 && !broken[ny][nx]))
				continue;
			boolean next = false;
			for (;;) {
				if (map[ny][nx] == 3) {
					break;
				}
				nx += dx[i];
				ny += dy[i];
				if (check(nx, ny)) {
					next = true;
//					System.out.println("wawasi " + nx + " " + ny);
					break;
				}
				if (map[ny][nx] == 1 && !broken[ny][nx]) {
					broken[ny][nx] = true;
					nx -= dx[i];
					ny -= dy[i];
					break;
				}
			}
			if (next)
				continue;
			res = Math.min(res, dfs(nx, ny, c + 1));
			if (map[ny][nx] != 3)
				broken[ny + dy[i]][nx + dx[i]] = false;
		}
		return res;
	}

	boolean check(int nx, int ny) {
		return nx < 0 || ny < 0 || nx >= w || ny >= h;
	}

	public static void main(String[] args) {
		new Main().run();

	}
}

Measured memory_bytes: 38876
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int Q;
	int c, a, n;

	scanf("%d", &Q);

	for (int i = 0; i < Q; i++){
		int cnt = 0;
		scanf("%d%d%d", &c, &a, &n);
		while (c && a && n){
			c--;
			a--;
			n--;
			cnt++;
		}
		while (c >= 2 && a){
			c -= 2;
			a--;
			cnt++;
		}
		while (c >= 3){
			c -= 3;
			cnt++;
		}
		printf("%d\n", cnt);
	}

	return (0);
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    /* 入力受け取り */
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    /* しゃくとり法 */
    long long res = 0;
    int right = 0;
    int sum = 0; // AND 和
    for (int left = 0; left < n; ++left) {
        while (right < n && (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            ++right;
        }
        res += right - left;
        if (left == right) ++right;
        else {
            sum -= a[left]; // a[left] を削除 (sum ^= a[left] でも OK)
        }
    }

    cout << res << endl;
}

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

int main() {
    ll n, x;
    cin >> n >> x;
    ll a[n];
    rep(i, n) cin >> a[i];

    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ll sum = a[i - 1] + a[i];
        if (sum > x) {
            if (a[i - 1] > x) {
                ans += sum - x;
                a[i] = 0;
            } else {
                a[i] -= sum - x;
                ans += sum - x;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4380
#include<stdio.h>
#include<string.h>

int main(void)
{
	int a,b,o,ab,i;
	char s[5];
	a=b=o=ab=0;
	while(scanf("%d,%s",&i,&s)!=EOF){

		if(strcmp(s,"A")==0)
			a++;
		else if(strcmp(s,"B")==0)
			b++;
		else if(strcmp(s,"O")==0)
			o++;
		else if(strcmp(s,"AB")==0)
			ab++;
	}
	printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
#include <climits>
using namespace std;

const long long INF = LLONG_MAX / 4;

int main(){
	int n, m, w, t;
	cin >> n >> m >> w >> t;

	map<string, int> name;

	vector<int> v(m), sell(m); // ツ重ツつウツ、ツ氾個板可ソツ格
	for(int i=0; i<m; ++i){
		string s;
		cin >> s >> v[i] >> sell[i];
		name[s] = i;
	}

	vector<int> x(n), y(n);
	vector<vector<long long> > buy(n, vector<long long>(m, INF)); // ツ仕ツ禿シツづェツ値
	for(int i=0; i<n; ++i){
		int l;
		cin >> l >> x[i] >> y[i];
		for(int j=0; j<l; ++j){
			string s;
			int a;
			cin >> s >> a;
			buy[i][name[s]] = a;
		}
	}

	vector<int> order(n);
	for(int i=0; i<n; ++i)
		order[i] = i;

	vector<long long> minTime(1<<n, INF);
	vector<vector<long long> > minBuy(1<<n, vector<long long>(m, INF));
	do{
		bitset<7> bs;
		long long len = 0;
		int y0 = 0;
		int x0 = 0;
		for(int j=0; j<n; ++j){
			int curr = order[j];
			bs[curr] = true;
			for(int k=0; k<m; ++k)
				minBuy[bs.to_ulong()][k] = min(minBuy[bs.to_ulong()][k], buy[curr][k]);
			len += abs(y0 - y[curr]) + abs(x0 - x[curr]);
			minTime[bs.to_ulong()] = min(minTime[bs.to_ulong()], len + abs(y[curr]) + abs(x[curr]));
			y0 = y[curr];
			x0 = x[curr];
		}
	}while(next_permutation(order.begin(), order.end()));

	vector<long long> maxMoney(1<<n, 0); // ツ嘉アツづゥツ店ツづ可妥篠つオツづづ個催妥・ツ猟伉益
	for(int i=0; i<(1<<n); ++i){
		vector<long long> maxMoneyTmp(w+1, 0); // ツ重ツづ敖づ可妥篠つオツづづ個催妥・ツ猟伉益
		for(int j=1; j<=w; ++j){
			maxMoneyTmp[j] = maxMoneyTmp[j-1];
			for(int k=0; k<m; ++k){
				if(j - v[k] >= 0)
					maxMoneyTmp[j] = max(maxMoneyTmp[j], maxMoneyTmp[j-v[k]] + sell[k] - minBuy[i][k]);
			}
		}
		maxMoney[i] = maxMoneyTmp[w];
	}

	vector<long long> ret(t+1, 0); // ツ篠楪甘板づ可妥篠つオツづづ個催妥・ツ猟伉益
	for(int i=1; i<=t; ++i){
		ret[i] = ret[i-1];
		for(int j=0; j<(1<<n); ++j){
			if(i - minTime[j] >= 0)
				ret[i] = max(ret[i], ret[i-minTime[j]] + maxMoney[j]);
		}
	}

	cout << ret[t] << endl;

    return 0;
}

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

using namespace std;
int main()
{
    string s;
    long long k;
    while(cin >> s >> k)
    {
        int flag=1;
        for (int i = 0; i < k; i++)
        {
            if (s[i] != '1')
            {
                cout << s[i] << endl;
                flag=0;
                break;
            }
        }
        if(flag)
            cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100000;
int l,f[MAXN+5],ans,sum;
char c[MAXN+5];
int main(){
	scanf("%s",c+1);
	l=strlen(c+1);
	for(int i=1;i<=l;i++){
		if(c[i]=='g'&&(sum+1)*2<=i)
			ans++,sum++;
		if(c[i]=='p'){
			if((sum+1)*2>i)
				ans--;
			else sum++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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


Measured memory_bytes: 256