akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	int l=s.length();
	reverse(s.begin(),s.end());
	int f=0,i=0;
	while(i<l){
		string t=s.substr(i,5);
		if(t=="resar"){
			if(s[i+5]=='e'){
				i+=6;
			}else{
				f=1;
				break;
			}
		}else if(t=="esare"){
			i+=5;
		}else if(t=="remae"){
			if(s[i+5]=='r'&&s[i+6]=='d'){
				i+=7;
			}else{
				f=1;
				break;
			}
		}else if(t=="maerd"){
			i+=5;
		}else {
			f=1;
			break;
		}
	}
	if(f==1)cout<<"NO";
	else cout<<"YES";
	cout<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    ll N;
    cin >> N;
    N--;
    map<int, char> ma;
    string s = "";
    deque<char> q;
    rep(i, 26) { ma[i] = i + 'a'; }

    while (N >= 0) {
        char c = ma[N % 26];
        q.push_front(c);
        N /= 26;
        N--;
    }

    rep(i, q.size()) { cout << q[i]; }
    cout << endl;
}

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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N - 1);

    rep(i, N)
    {
        cin >> A.at(i);
        A.at(i)--;
    }
    rep(i, N)
    {
        cin >> B.at(i);
    }
    rep(i, N - 1)
    {
        cin >> C.at(i);
    }

    int sum = 0;
    rep(i, N)
    {
        sum += B.at(A.at(i));
        if (i < N - 1) {
            if (A.at(i) >= 0 && A.at(i) <= N - 2) {
                if (A.at(i + 1) == (A.at(i) + 1)) {
                    sum += C.at(A.at(i));
                }
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
N,Ma,Mb=map(int,input().split())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
c=[0 for i in range(N)]
M=401
dp=[[[10**4 for cb in range(M)]for ca in range(M)]for i in range(N+1)]
for i in range(N):
    a[i],b[i],c[i]=map(int,input().split())
dp[0][0][0]=0
for i in range(N):
    for ca in range(M):
        for cb in range(M):
            if dp[i][ca][cb]==10**4:
                continue
            dp[i+1][ca][cb]=min([dp[i+1][ca][cb],dp[i][ca][cb]])
            dp[i+1][ca+a[i]][cb+b[i]]=min([dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]])
ans=10**4
for i in range(1,M):
    for j in range(1,M):
        if i*Mb==j*Ma:
            if dp[N][i][j]<ans:
                ans=dp[N][i][j]
if ans!=10**4:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 95708
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.valueOf(sc.nextLine());
		Set<String> set = new HashSet<>();
		String[] in = sc.nextLine().split(" ");
		int old = in.length;
		for (String string : in) {
			set.add(string);
		}
		if (old != set.size()) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}

	}
}


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

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

  int sum = 0, ma = 0;
  for (int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    if (a >= n) continue;
    int t = n - a;
    sum += t;
    ma = max(ma, t);
  }

  cout << sum - ma << endl;
}

Measured memory_bytes: 3096
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]

maxi = -10**10

for i in range(1,2**10):
    num = [0]*n
    for j in range(10):
        if ((i >> j) & 1):
            for k in range(n):
                num[k] += l[k][j]
    benefit = 0
    for m in range(n):
        benefit += p[m][num[m]]
    maxi = max(maxi,benefit)
print(maxi)

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

int main(){
    int rating[][2] = {{1, 399}, {400, 799}, {800, 1199}, {1200, 1599}, {1600, 1999}, {2000, 2399}, {2400, 2799}, {2800, 3199}};
    int cnt[10];
    int n;

    for(int i=0; i<10; i++) cnt[i] = 0;
    cin >> n;

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

        if(tmp < 3200){
            for(int j=0;j<8;j++){
                if(rating[j][0]<=tmp && tmp<=rating[j][1])
                    cnt[j]++;
            }
        }else{
            cnt[8]++;
        }
    }
     
    int base = 0;
    for(int i=0; i<8; i++){
        if(cnt[i]>0) base++;
    }
    
    if(base==0){
        cout << 1 << " " << cnt[8] << "\n";
    }else{
        cout << base << " " << base+cnt[8] << "\n";
    }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll a, b;
  cin >> a >> b;
  if(a+b>=24){
    print((a + b)-24);
  }
  else{
    print(a + b);
  }
}

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

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

int main(){
    int k; cin >> k;
    ll ans=0;
    for (int i=1;i<=k;i++){
        for (int j=1;j<=k;j++){
            for (int l=1;l<=k;l++){
                ans+=gcd(i,gcd(j,l));
            }
        }
    }
    cout << ans << "\n";
}



Measured memory_bytes: 3644
#include <stdio.h>
int main(void){
    long int n, a, b, d, m, result;
    scanf("%ld %ld %ld", &n ,&a ,&b);
    d = n / (a+b);
    m = n % (a+b);
    result = d * a;
    if( m < a ){
        result += m;
    } else {
        result += a;
    }
    
    printf("%ld\n", result);
    return 0;
}

Measured memory_bytes: 128
package main

import (
    "fmt"
    "os"
    "bufio"
    "strings"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func StrStdin() (stringInput string){
  sc.Scan()
  OneLineString := sc.Text()
  stringInput = strings.TrimSpace(OneLineString)
  return 
}

func IntStdin() (int, error){
  stringInput := StrStdin()
  return strconv.Atoi(stringInput)
}

// ?????????????l??????????Split()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
    stringSplited := strings.Split(stringTargeted, delim)

    for _, str := range stringSplited {
        if str != "" {
            stringReturned = append(stringReturned, str)
        }
    }

    return
}

// ?f???~?^??????????????X???C?X???��
func SplitStrStdin(delim string) (stringReturned []string) {
    // ???????1?s?��
    stringInput := StrStdin()
  
    // ???????
    // stringSplited := strings.Split(stringInput, delim)
    stringReturned = SplitWithoutEmpty(stringInput, delim)

    return
}

// ?f???~?^?????????????l?X???C?X???��
func SplitIntStdin(delim string) (intSlices []int, err error) {
    // ??????X???C?X???��
    stringSplited := SplitStrStdin(delim)
	
    // ?????X???C?X????
    for i := range stringSplited {
        var iparam int
        iparam, err = strconv.Atoi(stringSplited[i])
        if err != nil {
            return
        }
        intSlices = append(intSlices, iparam)
    }
    return
}

func main(){
  in := StrStdin()
  count := 0
  for _, value := range strings.Split(in, "") {
    if value == "1" {
      count += 1
    }
  }
  fmt.Println(count)
}

Measured memory_bytes: 640
a, b, h ,m = gets.chomp.split
hdeg = 360*(((60*h.to_i)+m.to_i).to_f/60/12)
mdeg = 360*(m.to_i.to_f/60)
deg =  ((hdeg-mdeg).abs > 180)? 360 - (hdeg-mdeg).abs : (hdeg-mdeg).abs

puts Math.sqrt((b.to_i**2)+(a.to_i**2)-2*a.to_i*b.to_i*Math.cos(deg*Math::PI/180))

Measured memory_bytes: 14736
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T&ans , T b){ if(ans<b){ ans=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&ans , T b){ if(ans>b){ ans=b; return true; } else{ return false; } } 

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

ll poww(ll x,ll n){
    ll ret = 1;
    while(n>0){
        if(n&1) ret = ret * x % MOD;
        x = x*x % MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    int n,k;
    cin >> n >> k;
    ll d[k+1];
    for(int i=k;i>=1;i--){
        int cnt = k/i;
        d[i] = poww(cnt,n);
        d[i] %= MOD;
    }
    for(int i=k;i>=1;i--){
        for(int j=2*i;j<=k;j+=i){
            d[i] -= d[j];
            d[i] %= MOD;
        }
    }

    ll ans=0;
    for(int i=1;i<=k;i++){
        ans += d[i]*i%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4416
n=int(input())
c=list(map(int, input().split()))

ans = 0

if n == 1:
    print(0)
if n != 1:
    for i in range(1,n):
        if c[i] < c[i-1]:
            ans += abs(c[i-1]-c[i])
            c[i] = c[i-1]
    print(ans)

Measured memory_bytes: 32064
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int r = sc.nextInt();
			final int c = sc.nextInt();
			
			if(r == 0 && c == 0){
				break;
			}
			
			
			System.out.println((r % 2 == 1 && c % 2== 1) ? "no" : "yes");
		}
		
		sc.close();
	}
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
   
       
 
        int flag=0;
        if(a.length()+1 != b.length()) flag=1;
        for(int i=0;i<a.length();i++){
            if(a[i]!=b[i]){
                flag=1;
                break;
            }
        }

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

Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int bitCount(int bits) {
    int cnt = 0;
    for(int mask = 1; mask != 0; mask<<=1) {
        if( (bits & mask) != 0 )
            ++cnt;
    }
    return cnt;
}

//それぞれがただしいことを言っているであろうbit全探索
int main(){

  int N;
  cin >> N;
  vector <vector <pair <int, int> > > syogen(N);
  int res = 0;


  REP(i,N)
  {
    int A;
    cin >> A;
    syogen[i].resize(A);
    REP(j,A)
    {
      cin >> syogen[i][j].first >> syogen[i][j].second;
      --syogen[i][j].first; 
    }
  }

  for(int bit = 0; bit < (1 << N); ++bit)
  {
    bool flg = true;
    for(int i = 0; i < N; ++i)
    {
      //このひとを正直者ということにする
      if(bit & (1 << i))
      {
        for(auto v: syogen[i])
        {
          if(v.second == 1)
          {
            if(!(bit & (1 << v.first)))
            {
              flg = false;
            }
          }
          else
          {
            if(bit & (1 << v.first))
            {
              flg = false;
            }
          }
        }
      }
    }
    if(flg)
    {
      res = max(res, bitCount(bit));
    }
  }

  cout << res << endl;





  return 0;    
}



Measured memory_bytes: 256
n = int(input())
i = 1
ret = ""
while True:
    x = i
    if  x % 3 == 0:
        ret += " " + str(i)
    elif x % 10 == 3:
        ret += " " + str(i)
    else:
        x //= 10
        while x != 0:
            if x % 10 == 3:
                ret += " " + str(i)
                break
            x //= 10
    i+=1
    if i > n:
        break

print(ret)



Measured memory_bytes: 5624
n = int(input())
a = [int(input()) - 1 for i in range(n)]

current_light = 0 #index = 1を光らせるのが目標
push_time = 0
while current_light != 1:
    current_light = a[current_light]
    push_time += 1
    if push_time > n:
        print(-1)
        break
else:
    print(push_time)
    



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


int main()
{
    int n;
    cin>>n;
    int p =n%10;
    if(p==2||p==4||p==5||p==7||p==9){
        cout<<"hon";
    }
    else if(p==0||p==1||p==6||p==8){
        cout<<"pon";
    }
    else{
        cout<<"bon";
    }




    return 0;
}


Measured memory_bytes: 3636
h, w = map(int, input().split())
s = [input() for _ in range(h)]

t = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            bombs = 0
            for k in range(i - 1, i + 2):
                for l in range(j - 1, j + 2):
                    if 0 <= k < h and 0 <= l < w:
                        if s[k][l] == "#":
                            bombs += 1
            else:
                t[i][j] = str(bombs)
        else:
            t[i][j] = "#"
else:
    for i in range(h):
        print("".join(t[i]))

Measured memory_bytes: 9228
def howmany(n)
  ans = 0
  while n%2==0
    n = n/2
    ans+=1
  end
  ans
end

n = gets.to_i
a = gets.split.map{|i|i.to_i}
wareru = []
a.each do |i|
  wareru.push(howmany i)
end

puts wareru.min

Measured memory_bytes: 1788
#include<stdio.h>
  
void spin_w(int x[]){
  int sai1[6],i;
  
  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }
  
  sai1[0]=x[2];
  sai1[2]=x[5];
  sai1[3]=x[0];
  sai1[5]=x[3];
  
  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }
  
}
  
void spin_side(int x[]){
int sai1[6],i;
  
for(i=0;i<6;i++){
  sai1[i]=x[i];
 }
  
sai1[1]=x[2];
sai1[2]=x[4];
sai1[3]=x[1];
sai1[4]=x[3];
  
for(i=0;i<6;i++){
  x[i]=sai1[i];
 }
}
  
  
void spin_s(int x[]){
    int sai1[6],i;
      
  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }
  sai1[0]=x[4];
  sai1[1]=x[0];
  sai1[4]=x[5];
    sai1[5]=x[1];
      
  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }
}
  
int conf(int x[],int y[]){
      
    int i,count=0,count2=0,a=0,sai1[6],sai2[6];
      
    for(i=0;i<6;i++){
        sai1[i]=x[i];
        sai2[i]=y[i];
    }
      
    for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
    }
    }
      
  if(count!=6){
        for(i=0;i<=3;i++){
            spin_w(sai1);
            count2++;
        if(sai1[0]==sai2[0])break;
        }
        if(count2==4){
            for(i=0;i<=3;i++){
            spin_s(sai1);
        if(sai1[0]==sai2[0])break;
            }
        }
              
    for(i=0;i<=3;i++){
      spin_side(sai1);
      if(sai1[1]==sai2[1] && sai1[2]==sai2[2] && sai1[3]==sai2[3] && sai1[4]==sai2[4])break;
        }
  }
  
  count=0;
  
  
  for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
        }
    }
    if(count==6){
        return 1;
    }else{
        return 0;
    }
}
  
int main(){
  int i,j,k,l,sai1[6],sai2[6],sai_c[105][6],n,a=0;
      
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<6;j++){
            scanf("%d",&sai_c[i][j]);
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<6;j++){
            sai1[j]=sai_c[i][j];
        }
        for(k=i+1;k<n;k++){
            for(l=0;l<6;l++){
                sai2[l]=sai_c[k][l];
            }
                if(conf(sai1,sai2)==1){
            a++;
            }
        }
    }
  if(a==0){
      printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
const int inf=100000;

vll par(inf),myrank(inf);
//par[i]=iならiは根（はじめは全て根）
void init(ll n){
  REP(i,n){
    par[i]=i;myrank[i]=0;
  }
  return;
}
//xの根
ll root(ll x){
  return (par[x]==x)?x:par[x]=root(par[x]);
}
//xが根の木とyが根の木を繋げる
void unite(ll x,ll y){
  x=root(x);y=root(y);
  if(x==y){return;}
  if(myrank[x]<myrank[y]){par[x]=y;}
  else{par[y]=x;}
  if(myrank[x]==myrank[y]){myrank[x]++;}
}
//根が同じかどうか
bool same(ll x,ll y){
  return root(x)==root(y);
}


int main(){
  ll n,q,ans=0;
  cin>>n>>q;
  vvll e(q,vll(2));
  init(n);
  REP(i,q){
    cin>>e[i][0]>>e[i][1];
    e[i][0]--;e[i][1]--;
  }
  REP(i,q){
    init(n);
    REP(j,q){
      if(i!=j&&!same(e[j][0],e[j][1])){
        unite(e[j][0],e[j][1]);
      }
    }
    ll cnt=0;
    REP(j,n){
      if(par[j]==j)cnt++;
    }
    if(cnt>1)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>  
#include<cmath>
#include<string>
#include<stack>
#include<queue> 
#include<algorithm>
#include<stdlib.h> 
#include<ctime>
#include<iomanip>
using namespace std;
int main(){ 
	long double n;
	cin>>n;
	cout<<fixed<<setprecision(8)<<(n/3)*(n/3)*(n/3);
}



Measured memory_bytes: 256
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  n,i = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  print(n-(i-1))

if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
import java.util.*;

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

        int N = sc.nextInt();
        int[] points = new int[N];

        for(int i = 0; i<N ;i++){
            points[i] = sc.nextInt();
        }

        Arrays.sort(points);
        System.out.println(points[N-1] - points[0]);
    }
}


Measured memory_bytes: 21204
import java.util.Scanner;

public class Main {

	
	public static void main (String args[]) {
		
	//input array length/initialize array S of length n
	Scanner scan = new Scanner(System.in);
	int arrayLenS = scan.nextInt();
	int[] arrayS = new int[arrayLenS];
	
	//int[] myArray = {1, 2, 3, 4, 5, 6};
	
	//create first array S
	for(int i = 0; i < arrayLenS; i++) {
		int arrayNumsS = scan.nextInt();
		arrayS[i] = arrayNumsS;
	}
	
	//initialize length of array T -- enter array length q
	int arrayLenT = scan.nextInt();
	int[] arrayT = new int[arrayLenT];
	
	//create second array T
	for(int i = 0; i < arrayLenT; i++) {
		int arrayNumsT = scan.nextInt();
		arrayT[i] = arrayNumsT;
	}	
	
	//count number of matches between the arrays
   	int matchCount = 0;
	for(int i = 0; i < arrayT.length; i++) {
		for(int j = 0; j < arrayS.length; j++) {
			if(arrayS[j]==arrayT[i]) {
				matchCount += 1;
				break;	
			}
		}
	}
	System.out.println(matchCount);
	
	}
}


Measured memory_bytes: 40276
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
const int MAXLEN = 5*1e3 + 5;

int n;
string s;
int dp[MAXLEN][MAXLEN];

int solve(int i, int j, int lim) {
    if(i >= n || j >= n) return 0;
    if(i >= lim) return 0;

    if(dp[i][j] >= 0) return dp[i][j];

    if(s[i] != s[j]) return 0;

    dp[i][j] = 1 + solve(i + 1, j + 1, lim);
    return dp[i][j];
}
    
int main() {
    cin >> n >> s;
    
    memset(dp, -1, sizeof(dp));
    
    int len = 0;

    for(int i=0; i < n; i++) {
        for(int j=i+1; j < n; j++) {
            len = max(len, solve(i, j, j));
        }
    }

    cout << len;
}

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


#define ll long long
#define pll pair <ll,ll>
#define fi first
#define se second
#define endl "\n"
#define sqr(b) (b)*(b)


using namespace std;

string a, b;
ll dp[3333][3333];
pll p[3333][3333];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    cin >> a >> b;

    ll n = a.size(), m = b.size();

//    if (n == 1 && m == 1) {
//        if (a == b) {
//            cout << b << endl;
//        } else {
//            cout << endl;
//        }
//        return 0;
//    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i] == b[j]) {
                if (i != 0 && j != 0) dp[i][j] = dp[i - 1][j - 1];
                dp[i][j]++;
                p[i][j] = {i - 1, j - 1};
            } else {
                if (i != 0) {
                    dp[i][j] = dp[i - 1][j];
                    p[i][j] = {i - 1, j};
                }
                if (j != 0) {
                    if (dp[i][j] < dp[i][j - 1]) {
                        dp[i][j] = dp[i][j - 1];
                        p[i][j] = {i, j - 1};
                    }
                }
                if (i == 0 && j == 0) p[i][j] = {-1, -2};
            }
        }
    }

//    for (int i = 0; i < n; i++) {
//        for (int j = 0; j < m; j++) {
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }

    int i = n - 1, j = m - 1;
    string ans;
    while (i != -1 && j != -1) {
        if (p[i][j].fi == i - 1 && p[i][j].se == j - 1) {
            ans += a[i];
        }
        pll pos = p[i][j];

        i = pos.fi;
        j = pos.se;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 234316
import java.util.Scanner;

// 提出時にclass Main に書き換え
public class Main {
	public static void main(String[] args)  {
		// 標準入力を受け取る
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(); // int Aを受け取る
		int B = sc.nextInt(); // int Bを受け取る
		int C = sc.nextInt(); // int Cを受け取る
		int X = sc.nextInt(); // int Xを受け取る
		sc.close(); // 標準入力を終了

		int x = 0; // 合計金額をX円にする方法の数

		for(int a = 0; a <= A; a++) {
			for(int b = 0; b <= B; b++) {
				for(int c = 0; c <= C; c++) {
					if(500*a + 100*b + 50*c == X) {
						// 合計金額がX円にする方法
						x += 1;
					}
				}
			}
		}

		// xを出力
		System.out.println(x);
	}

}

Measured memory_bytes: 35852
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long;

const int INF = 1e9;
const long long  LLINF = 1e15;

using namespace std;

string s;
bool flag[26];
vector<string> v;

void dfs(int pos, string str){
  if(pos == s.size()){
    v.push_back(str);
    return;
  }

  if(flag[s[pos]-'a'] || s[pos] == 'a'){
    bool tmp = flag[s[pos]-'a'];
    flag[s[pos]-'a'] = true;
    dfs(pos+1, str + s[pos]);
    flag[s[pos]-'a'] = tmp;
  }
  if(!flag[s[pos]+1-'a'] && s[pos]!='z'){
    flag[s[pos]+1-'a'] = true;
    dfs(pos+1, str + (char)(s[pos]+1));
    flag[s[pos]+1-'a'] = false;
  }
  return;
}

int main() {
  while (1) {
      cin>>s;
      if(s == "#") break;
      REP(i,0,26) flag[i] = false;
      v.clear();
      dfs(0,"");
      cout<<v.size()<<endl;
      if(v.size() <= 10){
        REP(i,0,v.size()) cout<<v[i]<<endl;
      }else{
        REP(i,0,5) cout<<v[i]<<endl;
        REP(i,v.size()-5,v.size()) cout<<v[i]<<endl;
      }
  }
  return 0;
}

Measured memory_bytes: 4188
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i] == L[j] or L[j] == L[k]:
                continue
            if L[i] + L[j] > L[k]:
                cnt += 1

print(cnt)


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

int main() {
  int N;
  cin >> N;
  int count = 1;
  
  vector<string>S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i); 
  }
  sort(S.begin(), S.end());
  
  for (int i = 0; i < N-1; i++) {
    if (S.at(i) != S.at(i+1)){
      count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 9576
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

int n, k;
const int maxn = 1e5 + 5;

int dp[maxn];
int h[maxn];

int main(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        scanf("%d", &h[i]);
        dp[i] = 1e9 + 7;
    }
    dp[1] = 0;
    for(int i = 2;i <= n;i++){
        for(int j = 1;j <= k and i - j >= 1;j++){
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define For(i, j, k) for(int i = j; i <= k; ++i)
using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for(; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for(; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= p;
}

inline void File() {
#ifndef ONLINE_JUDGE
	freopen("APC001D.in", "r", stdin);
	freopen("APC001D.out", "w", stdout);
#endif
}

const int N = 1e5 + 10;
int n, m, a[N], u, v, fa[N], vis[N];
priority_queue<int, vector<int>, greater<int> > Q[N], Q1;
long long ans;

inline int find(int x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); }

int main() {
	n = read(), m = read();
	For(i, 1, n) a[i] = read(), fa[i] = i;
	For(i, 1, m) {
		u = read() + 1, v = read() + 1;
		fa[find(v)] = find(u);
	}


	int tot = 0;
	For(i, 1, n) {
		fa[i] = find(i), Q[fa[i]].push(a[i]);
		if (!vis[fa[i]]) ++ tot; vis[fa[i]] = 1;
	}
	
	if (tot == 1) return printf("0\n"), 0;

	memset(vis, 0, sizeof vis);
	For(i, 1, n) {
		int now = fa[i];
		if (vis[now]) continue;
		if (Q[now].empty()) continue;
		ans += Q[now].top(), Q[now].pop(), vis[now] = 1;
		while(!Q[now].empty()) Q1.push(Q[now].top()), Q[now].pop();
	}	

	int flag = 1, cnt = tot - 2;
	while(cnt --) {
		if(Q1.empty()) { flag = 0; break; }
		ans += Q1.top(), Q1.pop();
	}

	if (!flag) printf("Impossible\n");
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7680
use std::io::*;
use std::str::*;


fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

pub fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let n: Vec<i32> = (0..3)
        .map(|_| (read(&mut stdin).unwrap()))
        .collect();

    if n[0] <= n[2] && (n[0] + n[1] - n[2]) >= 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

    double n,k;
    cin>>n>>k;
    vector<double> v(n);
    rep(i,n){
        double p;
        cin>>p;
        v[i]=(1+p)/2;
        //cout<<v[i]<<endl;
    }

    double ans=0;
    double s=0;
    rep(i,n){
        s+=v[i];
        if(i+1-k>=0){
            ans=max(ans,s);
            s-=v[i-k+1];
        }
    }

    cout<<ans<<endl;
            

}

Measured memory_bytes: 1792
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 2019;
int n, m, q, A[N][N], L[N][N], U[N][N];
char S[N][N];
int main()
{
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= n; i ++)
        scanf("%s", &S[i][1]);
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
        {
            A[i][j] = A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1];
            L[i][j] = L[i - 1][j] + L[i][j - 1] - L[i - 1][j - 1];
            U[i][j] = U[i - 1][j] + U[i][j - 1] - U[i - 1][j - 1];
            if (S[i][j] == '0')
                continue;
            A[i][j] ++;
            if (S[i - 1][j] == '1')
                U[i][j] ++;
            if (S[i][j - 1] == '1')
                L[i][j] ++;
        }
    for (; q; q --)
    {
        int a, b, c, d, tot = 0;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        a --; b --;
        tot = A[c][d] - A[a][d] - A[c][b] + A[a][b];
        if (a < c)
            tot -= U[c][d] - U[a + 1][d] - U[c][b] + U[a + 1][b];
        if (b < d)
            tot -= L[c][d] - L[a][d] - L[c][b + 1] + L[a][b + 1];
        printf("%d\n", tot);
    }
    return 0;
}

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

int main() {
  // int型の2次元配列(3×4要素の)の宣言
  vector<vector<int>> data(3, vector<int>(3));
 
  // 入力 (2重ループを用いる)
  for (int i = 0; i < 3; i++) {
      cin >> data.at(i).at(0) >> data.at(i).at(1) >> data.at(i).at(2);
  }

  int n,tmp;
  cin >> n;
  for(int q = 0 ; q < n; q++ ){
    cin >> tmp;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if(tmp == data.at(i).at(j)){
          data.at(i).at(j) = 0;
        }
      }
    }
  }

  //たて
  if(data.at(0).at(0) == 0 && data.at(1).at(0) == 0 && data.at(2).at(0) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(data.at(0).at(1) == 0 && data.at(1).at(1) == 0 && data.at(2).at(1) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(data.at(0).at(2) == 0 && data.at(1).at(2) == 0 && data.at(2).at(2) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  
  //よこ
  if(data.at(0).at(0) == 0 && data.at(0).at(1) == 0 && data.at(0).at(2) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(data.at(1).at(0) == 0 && data.at(1).at(1) == 0 && data.at(1).at(2) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(data.at(2).at(0) == 0 && data.at(2).at(1) == 0 && data.at(2).at(2) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  
  //ななめ
  if(data.at(0).at(0) == 0 && data.at(1).at(1) == 0 && data.at(2).at(2) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(data.at(2).at(0) == 0 && data.at(1).at(1) == 0 && data.at(0).at(2) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N, M;
  cin >> N >> M;
  if(N==1&&M==1){
    cout << 1 << endl;
    return 0;
  }
  if(N==2 || M==2){
    cout << 0 << endl;
    return 0;
  }
  if(N>=3 && M == 1){
    cout << N-2 << endl;
    return 0;
  }
  if(M>=3 && N == 1){
    cout << M-2 << endl;
    return 0;
  }
  if(M>=3 && N >= 3){
    cout << (N-2)*(M-2) << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
ll a[100005];
ll b[100005];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n+1; i++) {
		cin >> a[i];
	}
	for (int j = 0; j < n; j++) {
		cin >> b[j];
	}
	ll ans = 0;
	for (int j = 0; j < n; j++) {
		if (a[j] >= b[j]) {
			ans += b[j];
		}
		else {
			ans += a[j];
			b[j] -= a[j];
			if (a[j+1]-b[j] <= 0) {
				ans += a[j+1];
				a[j + 1] = 0;
			}
			else {
				ans += b[j];
				a[j + 1] -= b[j];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
(n,t) = (int(i) for i in input().split())
T = [int(j) for j in input().split()]
if n == 1:
    print(t)
else:
    S = [a-b for a,b in zip(T[1:],T[:-1])]
    U = [u if u <= t else t for u in S]
    print(sum(U)+t)

Measured memory_bytes: 25196
from collections import Counter
n = input()
V = list(map(int, input().split(" ")))

v1 = V[0::2]
v2 = V[1::2]

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 == v2:
        ans = min(len(v1), len(v2))
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        ans1 = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        ans2 = (len(v1) - f1[1][1]) + (len(v2) - f2[0][1])
        ans = min(ans1, ans2)

print(ans)


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;

const string YES = "Yes";
const string NO = "No";

void solve()
{
  ll N;
  scanf("%lld",&N);
  ll A;
  scanf("%lld",&A);
  if (N%500<=A) cout << YES << endl;
  else cout << NO << endl;
}

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


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int X, Y, Z, K; cin >> X >>Y >> Z >> K;
    vector<ll>A(X), B(Y), C(Z);
    vector<ll>AB;


    rep(i,X){
        cin >> A[i];
    }
    rep(i,Y){
        cin >> B[i];
    }
    rep(i,Z){
        cin >> C[i];
    }
    for(auto a:A){
        for(auto b: B){
            AB.push_back(a+b);
        }
    }
    sort(AB.begin(), AB.end(), greater<>());

    vector<ll>ans;
    for(int i=0; i<min(3000, (int)AB.size()); i++){
        for(auto c:C){
            ans.push_back(AB[i]+c);
        }
    }

    sort(ans.begin(), ans.end(), greater<>());

    for(int i=0;  i<K; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 43240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >>D;
  int Ans=0;
  Ans+=abs(C-A)+abs(D-B);
  Ans-=__gcd(abs(C-A),abs(D-B));
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    string s;
    cin >> s;

    vector<vector<ll>> dp(s.size() + 1, vector<ll>(4));
    dp[0][0] = 1;
    REP(i, s.size()) {
        REP(j, 4) {
            if (s[i] == '?')
                dp[i + 1][j] += dp[i][j] * 3;
            else
                dp[i + 1][j] += dp[i][j];
            MOD(dp[i + 1][j]);
        }
        if (s[i] == 'A' || s[i] == '?') {
            dp[i + 1][1] += dp[i][0];
            MOD(dp[i + 1][1]);
        }
        if (s[i] == 'B' || s[i] == '?') {
            dp[i + 1][2] += dp[i][1];
            MOD(dp[i + 1][2]);
        }
        if (s[i] == 'C' || s[i] == '?') {
            dp[i + 1][3] += dp[i][2];
            MOD(dp[i + 1][3]);
        }
    }
    print(dp[s.size()][3]);

    return 0;
}

Measured memory_bytes: 7376
N = input()
a = [input() for i in range(N)]

def smax(N,a):
  smin = a[0]
  smax = -10**9
  for j in range(1,N):
   smax = max(smax,a[j]-smin)
   smin = min(smin,a[j])
  return smax

print smax(N,a)

Measured memory_bytes: 18932
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll a,b,c,tmp=0;
	cin >> a >> b >> c;
	for (ll i = max(a, max(b, c));; i++) {
		if ((3 * i) % 2 == (a + b + c) % 2) { tmp = i; break; }
	}
	cout << (3*tmp - (a+b+c))/2 << endl;
}




Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (i = 1; i <= n; i++)

using namespace std;

const int N = 1e5 + 10;

int a[N], b[N];
int A, B, M;

int main() {
	cin >> A >> B >> M;
	int i;
	rep(i, A) cin >> a[i];
	rep(i, B) cin >> b[i];
	
    int minA = a[1];
    rep(i, A) minA = min(minA, a[i]);
    
    int minB = b[1];
    rep(i, B) minB = min(minB, b[i]);
	
	int res = minA + minB;
	rep(i, M) {
		int x, y, c;
		cin >> x >> y >> c;
		int hoge = a[x] + b[y] - c;
		if (hoge < 0) hoge = 0;
		res = min(res, hoge);
	}
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 1024
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

diffVW = V - W  # m/s
diffAB = abs(A - B)  # m

if diffVW <= 0:
    print("NO")
    exit(0)
else:
    diffVW = abs(diffVW)

if (diffAB / diffVW) <= T:
    print("YES")
else:
    print("NO")


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n * 3);
    for (int i = 0; i < n * 3; i++)
    {
        cin >> a.at(i);
    }
    
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += (long long)a.at(i * 2 + 1);
    }
    cout << ans << endl;
}


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

// traduções

// even -> par
// odd -> impar

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-12
const double PI = acos(-1.0);

#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define FILL(a,v) memset(a, v, sizeof a)

// bitmask operations
#define SETBIT(S, j) S |= (1 << j)
#define CLEARBIT(S, j) S &= ~(1 << j)
#define ISSET(S, j) S & (1 << j)
#define FLIPBIT(S, j) S ^= (1 << j)
#define LSBIT(S) (S & (-S))

// debug
#define DEBUGSTR(S) cout << "(" << S << ")\n";

int main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int N, X;

    scanf(" %d %d", &N, &X);

    vi m(N);

    int menor = INF;

    REP(i, 0, N) {
        scanf(" %d", &m[i]);
        X -= m[i];
        menor = min(menor, m[i]);
    }

    int total = N + (X / menor);   

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

    return 0;
}


Measured memory_bytes: 3732
#include <math.h>

int main(){
	int n;
	double m;
	double alpha = 0;
	int p[1000];
	
	while(1){
		scanf("%d",&n);
		if(n == 0)break;
		
		int i;
		m = 0;
		alpha = 0;
		
		for(i = 0;i < n;i++){
			scanf("%d",&p[i]);
			m += p[i];
		}
		m /= n;
		
		for(i = 0;i < n;i++){
			alpha += pow(fabs(p[i]-m),2);
		}
		
		alpha = sqrt(alpha/n);
		
		printf("%lf\n",alpha);
	}
	return 0;
}

Measured memory_bytes: 636
import static java.lang.Math.*;
import static java.util.Arrays.*;

import java.util.*;
import java.io.*;

public class Main {
	
	boolean[][] map;
	int W, H;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			W = sc.nextInt(); H = sc.nextInt();
			if( (W|H) == 0 ) break;
			map = new boolean[H+2][W+2];
			int sx=-1, sy=-1;
			
			for(int i=1;i<=H;i++) {
				String l = sc.next();
				for(int j=1;j<=W;j++) {
					 if(l.charAt(j-1) == '@' ) { sx = j; sy = i; }
					 map[i][j] = l.charAt(j-1) == '.';
				}
			}
			System.out.println(dfs(sx, sy));
		}
	}
	int[] dx = {1,0,-1,0};
	int[] dy = {0,-1,0,1};
	int dfs(int x, int y) {
		map[y][x] = false;
		int cnt = 1;
		for(int i=0;i<4;i++) if(map[y+dy[i]][x+dx[i]]) {
			cnt += dfs(x+dx[i], y+dy[i]);
		}
		return cnt;
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 27132
#include<iostream>
#include<vector>

int main(){
    int N;
    std::cin >> N;
    std::vector< int > A(N);
    for(int i=0;i<N;i++){
        std::cin >> A[i];
    }
    
    std::vector< int > ans(N);
    
    int pm = true;
    long long tmp = 0;
    for(int i=0;i<N;i++){
        tmp = pm ? tmp + A[i] : tmp -  A[i];
        pm = pm ^ true;
    }
    ans[0] = tmp;
    
    for(int i=1;i<N;i++){
        ans[i] = -1 * ans[i-1] + 2 * A[i-1];
        pm = pm ^ true;
    }
    
    for(int i=0;i<N;i++){
        if(i != 0){
            std::cout << " ";
        }
        std::cout << ans[i];
    }
    std::cout << std::endl;
    return 0;
}



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

ll S(ll n) {
  ll res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

double f(ll n) {
  return (double)n / S(n);
}


int main2() {
  int N = nextInt();
  ll ans = 0;
  cout << ans << endl;
  return 0;
}

int main() {

  vector<ll> c;
  REP(i, 10000) {
    ll n = i;
    while (n <= (ll)1e18) {
      c.push_back(n);
      n = n*10 + 9;
      if (n < 0) break;
    }
  }
  sort(ALL(c));
  c.erase(unique(ALL(c)), c.end());
  // REP(i, c.size()) cout << c[i] << endl;
  // return 0;
  vector< pair<ll,double> > v;
  REP(ci, c.size()) {
    ll i = c[ci];
    pair<ll,double> p = {i, f(i)};
    while (v.size() > 0 && v.back().second > 1e-9 + p.second) v.pop_back();
    v.push_back(p);
    i++;
  }
  // REP(i, v.size()) { cout << v[i] << " " << S(v[i].first) << endl; }
  int K = nextInt();
  REP(i, K) cout << v[i+1].first << endl;
  // for (;!cin.eof();cin>>ws)
    // main2();
  return 0;
}


Measured memory_bytes: 2420
from operator import itemgetter

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

an = [0]*n

sc = 0
er = 0

for i in range(m):
    t, s = map(str, input().split())
    p = int(t)-1
    if (an[p] != m+1 and s == "AC"):
        sc += 1
        er += an[p]
        an[p] = m+1
    elif (an[p] != m+1 and s == "WA"):
        an[p] += 1


print("{} {}".format(sc, er))


Measured memory_bytes: 7028
#include <iostream>
#include <vector>
using namespace std;
const int INF = 100100100;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    
    long long int sum = 0;
    int max = -INF;
    int min = INF;
    for(int i = 0; i < n; i++){
        sum += a[i];
        if(max < a[i]) max = a[i];
        if(min > a[i]) min = a[i];
    }
    
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec)
    is >> x;  // for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

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

  ll compsum = 0;
  for (ll i = 0; i < n; i++) {
    compsum += l + i;
  }

  ll absmax = LLINF;
  ll minnum = 0;
  for (ll i = 0; i < n; i++) {
    if (abs(l + i) < absmax ){
      absmax = abs(l+i);
      minnum = l + i;
    }
  }


  cout << (compsum - minnum );
}


Measured memory_bytes: 256
#include <stdio.h>

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

	for(c=1;c<=n;c++){
		
		if((int)c%3==0||
		   /*(int)c%10==3||(int)c/10==3||
		   (int)c%100==3||(int)c/100==3||(int)c%100/10==3||(int)c%100%10==3||*/
		   (int)c%1000==3||(int)c/1000==3||(int)c%1000%100%10==3||(int)c%1000%100/10==3||(int)c%1000/100%10==3||(int)c%1000/100/10==3){
		printf(" %d",c);
		}
	}
printf("\n");
return 0;
}

Measured memory_bytes: 596