akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define double long double
#define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

signed main() {
	
	int n;
	string s;
	cin >> n >> s;
	int r = 0, g = 0, b = 0;
	for (int i=0; i<n; i++) {
		if (s[i] == 'R') r++;
		else if (s[i] == 'G') g++;
		else b++;
	}
	
	int to = r * g * b;
	
	for (int i=0; i<n; i++) {
		for (int j=i-1, k=i+1; j>=0 && k<n; j--, k++) {
			if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
				to--;
			}
		}
	}
	
	cout << to << endl;
	
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int K;
    cin >> K;
    if(K % 2 == 0){
        cout << "-1\n";
    } else{
        int rem = 0;
        for(int i = 1 ; i <= 1001000 ; ++i){
            rem = (rem * 10 + 7) % K;
            if(!rem){
                cout << i << '\n';
                break;
            }
        }
        if(rem){
            cout << "-1\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;

//Keitai Message
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[][] k = {
				{},
				{'.',',','!','?',' '},
				{'a','b','c'},
				{'d','e','f'},
				{'g','h','i'},
				{'j','k','l'},
				{'m','n','o'},
				{'p','q','r','s'},
				{'t','u','v'},
				{'w','x','y','z'}
		};
		int t = sc.nextInt();
		while(t--!=0){
			char[] s = sc.next().toCharArray();
			int i = 0;
			StringBuilder sb = new StringBuilder();
			while(i<s.length){
				if(s[i]=='0')i++;
				else{
					char c = s[i++];
					int j = 0;
					while(s[i]==c){i++;j++;}
					sb.append(k[c-'0'][j%k[c-'0'].length]);
					i++;
				}
			}
			System.out.println(sb);
		}
	}
}

Measured memory_bytes: 12000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = input()


def solve(S):
    remove = len(S) - 7
    if remove == 0:
        return S == 'keyence'
    for i in range(len(S) - remove + 1):
        T = S[:i] + S[i+remove:]
        if T == 'keyence':
            return True
    return False
    
if solve(S):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 7972
n = int(input())
h_array = [int(x) for x in input().split()]
cnt = 0


def solver(array):
    cnt = 0
    if array == [0] or not array:
        return 0
    while True:
        aarray = []

        for num in array:
            if num != 0:
                aarray.append(num)
            else:
                cnt += solver(aarray)
                aarray = []
        else:
            if aarray:
                cnt += 1
                cnt += solver([max(0, x-1) for x in aarray])
            break

    return cnt

print(solver(h_array))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
using namespace std;

class RUQ{
public:
  
  typedef pair<int,int> P;
  
  int n, cnt;
  vector<P> A;
  
  const int INF = (1LL<<31)-1;
  
  RUQ(){}

  RUQ(int n_){
    n = 1;
    while( n_ > n ) n *= 2;
    A.resize( n * 2 - 1, P( 0, INF ) );
    cnt = 0;
  }
  
  int find(int x){
    P res = P( 0, INF );
    x += n - 1;
    res = max( res, A[x] );
    while(x){
      x = ( x + 1 ) / 2 - 1;
      res = max( res, A[x] );
    }
    return res.second;
  }
  
  void update(int a, int b, int l, int r, int k, P x){
    if( r <= a || b <= l ) return;
    if( a <= l && r <= b ){
      A[k] = x;
      return;
    }
    update( a, b, l, (l+r)/2, k*2+1, x );
    update( a, b, (l+r)/2, r, k*2+2, x );
  }
  
  void update(int a, int b, int x){
    cnt++;
    update(a,b,0,n,0,P(cnt,x));
  }
  
};

signed main(){
  
  int n, q;
  cin>>n>>q;
  
  RUQ ruq(n);
  
  while(q--){
    
    int com;
    cin>>com;

    if( com == 0 ){
      int s, t, x;
      cin>>s>>t>>x;
      ruq.update(s,t+1,x);
    }
    else{
      int x;
      cin>>x;
      cout<<ruq.find(x)<<endl;
    }
    
  }
  
  return 0;
}



Measured memory_bytes: 7092
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int x = sc.nextInt();
    static int y = sc.nextInt();

    public static void main(String[] args) {
        for(int i = 0; i <= x; i++){
            int j =  x - i;
            if(i * 2 + j * 4 == y){
                System.out.println("Yes");
                return;
            }
        }
            System.out.println("No");

    }
    
}

Measured memory_bytes: 35724
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;
using ll = long long int;

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

  vector<ll> A(N);

  ll sum = 0;
  ll pre = 0;
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
    sum += abs(pre - A[i]);
    pre = A[i];
  }
  sum += abs(0 - A[N - 1]);

  vector<ll> AI = A;

  for (size_t i = 0; i < N; i++)
  {
    ll ans = sum;

    if (i == 0) {
      ans = ans - abs(A[0]) - abs(A[1] - A[0]) + abs(A[1]);
    } else if (i == N - 1) {
      ans = ans - abs(A[N - 1]) - abs(A[N -1] - A[N - 2]) + abs(A[N - 2]);
    } else {
      ans = ans - abs(A[i]- A[i - 1]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]);
    }
    cout << ans << endl;
  }
  

  // for (size_t i = 0; i < N; i++)
  // {
  //   int large = AI[N-1];
  //   int small = AI[0];
  //   if (mx == A[i]) {
  //     large = AI[N - 2];
  //   }
  //   if (mn == A[i]) {
  //     small = AI[1];
  //   }

  //   cout << large << ","<< small << endl;
  //   // if (large >= 0 && small >= 0) {
  //   //   cout << (max(large, small) * 2) << endl;
  //   // } else if (large <= 0 && small <= 0) {
  //   //   cout << (max(abs(large), abs(small)) * 2) << endl;
  //   // } else {
  //   //   cout << (abs(large - small) * 2) << endl;
  //   // }
  // }
  
}

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

int n;
string s;
string t="0123456789";

ll string2ll(string s){
  stringstream ss;
  ss<<s;
  ll res;
  ss>>res;
  return res;
}

int main(){
  cin>>s;
  n=s.size();
  ll target=string2ll(s);

  ll key=1;
  for(int i=0;i<n;i++)key*=10LL;


  ll ans=-1;
  string ans2="";
  
  do{
    string tmp=t.substr(0,n);
    stringstream ss;
    ss<<tmp;
    ll num;
    ss>>num;

    ll mini=min( key - abs(num-target) , abs(num-target) );
    if( mini == ans ){
      ans2=min(ans2,tmp);
    }else if(mini>ans){
      ans=mini;
      ans2=tmp;
    }
    
  }while( next_permutation(t.begin(),t.end()) );
  
  cout<<ans2<<endl;
  return 0;
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define gc getchar_unlocked
#define cases int t;  cin>>t;   while(t--)
ll mod =1e9+7;
//template<typename T> 
inline ll pwr(ll base,ll n){ll ans=1;while(n>0){ if(n%2==1)ans=ans*base;  base=base*base; n/=2;} return ans;}
struct range{int l,h;}; 
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
    int ans=0,ct=0;
    for(int i=1;i<n;i++)
    {
      if(a[i]<=a[i-1])ct++;
      else ct=0;

      ans=max(ans,ct);
    }
    cout<<ans;
    return 0;
}

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

int main() {
	int N;
	string S;
	cin >> N >> S;

	for (int i = 0; i < S.size(); i++) {
		char &A = S[i];
		if (char(A + N) >= 65 && char(A + N) <= 90) {
			cout << char(A + N);
		}
		else {
			int B = char(A + N) - 90;
			cout << char(64 + B);
		}
	}
}

Measured memory_bytes: 256
from collections import deque

def bfs(graph, n, s):
  visited = [0]*n # 移動回数を保持
  visited[s] = 1 # 部屋1の探索は完了としている
  q = deque([s]) # 探索用にdequeを設定し、初期位置としてs(0)を設定する
  while q:
    node = q.popleft() # 先頭から順番に実行
    for i in graph[node]: # 各部屋から行ける別の部屋を確認
      if not visited[i]: # 値が"0"の場合に処理を実行
        visited[i] = node + 1 # 部屋1からの移動回数を保持する
        q.append(i) # 移動先の部屋をqに格納し、探索を継続する
  return visited

n,m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(lambda x: int(x)-1, input().split())
  graph[a].append(b)
  graph[b].append(a)
  
visited = bfs(graph, n, 0)[1:] # 幅優先探索を行い、部屋1以外の結果を取得する
if all(visited):
  print("Yes")
  print(*visited, sep="\n") 
else:
  print("No")

Measured memory_bytes: 38352
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

string S;
int jdg[26];
int ans = 1;
int idx;

int main(){
	
	
	cin>>S;
	
	fill( jdg, jdg+26, 0 );
	
	REP( i, S.size() ){
		idx = S[i]-'a';
		jdg[idx]++;
	}
	
	REP( i, 26 ) if( jdg[i] % 2 ) ans = 0;
	
	if( ans ) puts("Yes");
	else{	puts("No");}
	
	return 0;

}

Measured memory_bytes: 256
from sys import stdin
readline = stdin.readline

N = int(readline())
A = [None] * N
B = [None] * N
for i in range(N):
    a, b = map(int, readline().split())
    A[i] = a
    B[i] = b

A.sort()
B.sort()

if N % 2 == 0:
    b = (B[N // 2] + B[(N - 1) // 2]) / 2
    a = (A[N // 2] + A[(N - 1) // 2]) / 2
    print(int((b - a) * 2 + 1))
else:
    print(B[N // 2] - A[N // 2] + 1)


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

using namespace std;
#define ff first
#define ss second
#define pb push_back
#define quicker ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
 
int main()
{
    quicker
    int n = 3, b, s;
    int A[n][n];
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        cin >> A[i][j];
      }
    }
    cin >> s;
    for (int k = 0; k < s; k++){
      cin >> b;
      for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
          if (A[i][j] == b) A[i][j] = 0;
        }
      }
    }
    int r = 0, d = 0, e = 0;
    for (int i = 0; i < n; i++){
      r = 0;
      for (int j = 0; j < n; j++){
        if (A[i][j] == 0) {
          ++r;
          if (i + j == n - 1) ++d;
          if (i == j) ++e;
        }
        else {
          r = 0;
          if (i + j == n - 1) d = 0; 
          if (i == j) e = 0;
        }
        if (r >= 3 || d >= 3 || e >= 3) {
          cout << "Yes";
          return 0;
        }
      }
    }
    for (int i = 0; i < n; i++){
      r = 0;
      for (int j = 0; j < n; j++){
        if (A[j][i] == 0) ++r;
        else r = 0;
        if (r >= 3) {
          cout << "Yes";
          return 0;
        }
      }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
      	char[] c1 = sc.next().toCharArray();
      	char[] c2 = sc.next().toCharArray();
      	
      	if(c1[0] == c2[2] && c1[1] == c2[1]
           && c1[2] == c2[0]) {
        	System.out.println("YES");  
        } else {
        	System.out.println("NO");  
        } 
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define INF 200001 
using namespace std;
int n;
int A[1000][1000];
int D[1000][1000];
 
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  } 
}
 
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
  
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
   
      }    
  }
  for(int i=0;i<n;i++)D[i][i] = 0;

  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);

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

Measured memory_bytes: 0
n=int(input())
A=[int(input()) for _ in range(n)]

if A[0]!=0:print(-1);exit()

cnt=0
for i in range(1,n):
    if A[i-1]+1==A[i]:
        cnt +=1
    elif A[i-1]==A[i] or A[i-1]>A[i]:
        cnt +=A[i]
    else:print(-1);exit()

print(cnt)

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

int low[300000];
int high[300000];
long long h[300000];

int part(long long a[],int l,int r){
  int i,j,x;
  long long t;

  i = l - 1;
  j = r;

  x = a[r];

  while(1){
    while(a[++i] < x);
    while(i < --j && x < a[j]);

    if(i >= j) break;

    t = a[i]; a[i] = a[j]; a[j] = t;
  }

  t = a[i]; a[i] = a[r]; a[r] = t;
  return i;
}

void quicksort(long long a[],int n){
  int l,r,v;
  int sp;

  low[0] = 0;
  high[0] = n - 1;
  sp = 1;

  while(sp > 0){
    sp--;
    l = low[sp];
    r = high[sp];

    if(l >= r);

    else {
      v = part(a,l,r);

      if(v - l < r - v){
        low[sp] = v + 1;
        high[sp++] = r;
        low[sp] = l;
        high[sp++] = v - 1;
      }

      else{
        low[sp] = l;
        high[sp++] = v - 1;
        low[sp] = v + 1;
        high[sp++] = r;
      }
    }
  }
}

int main(){
  int n;
  int k;
  long long cnt = 0;
  int i;
  int m;

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

  for(i = 0;i < n;i++){
    scanf("%lld", &h[i]);
    cnt += h[i];
  }

  quicksort(h,n);

  m = n - 1;

  while(k > 0){
    k--;
    cnt -= h[m];
    m--;
  }

  printf("%lld\n", cnt);
  return 0;
}


Measured memory_bytes: 3072
#include<stdio.h>
main()
{
	int n,sum=0,temp,j,i,k,t[100000],m,p[100],x[100];
	scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    	scanf("%d",&t[i]);
	}
	scanf("%d",&m);
	for(i=0;i<m;i++)
    {
    	scanf("%d %d",&p[i],&x[i]);
	}
	for(j=0;j<m;j++)
	{
		for(i=0;i<n;i++)
    	{
    		k = p[j];
    		temp = t[k-1];
			t[k-1] = x[j];
			break ;
		}
		for(i=0;i<n;i++)
        {
        	sum = sum+t[i];
	    }
	    printf("%d\n",sum);
	    sum = 0;
	    t[k-1] = temp;  
	}
	return 0;
}


Measured memory_bytes: 128
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**9]*n

dp[0]=0
for i in range(1,n):
    for j in range(1,min(k+1,i+1)):
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
    
print(dp[n-1])

Measured memory_bytes: 52448
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  int ans = 0;
  for(int i = 1;i<=a;i++){
    int count = 0;
    for(int j = 1;j<=i;j++){
      if(i%j == 0)
        count++;
    }
    if(count == 8 && i%2 == 1)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
    int n,m,l;
 
   cin >> n >> m >> l;
  
   if(n==m&&m==l&&n==l){
     cout << "No" << endl;
     
   }else{
     
     if(n==m||m==l||n==l){
       
       cout << "Yes" << endl;
     }else{
       cout << "No" << endl;
     }
     
   }
   
   
   
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class  Main
{
	static int Binary(long bp[],int m,long k)
	{
	 int ans=-1;
	 int start=0;
	 int end=m-1;
	 
	 while(start<=end)
	 {
	   int mid=start+(end-start)/2;
	   if(bp[mid]>k)
	   {
		
		end=mid-1;
	   }
	   else
	   {	
		ans=mid;
		start=mid+1;
	   }
 	 }
	 return (ans+1);
	  
	}
	 public static void main(String[] args)
	 {
	   Scanner s=new Scanner(System.in);
	   int n=s.nextInt();
	   int m=s.nextInt();
	   long k=s.nextLong();
	   long a[]=new long[n];
	   long b[]=new long[m];
	   long bp[]=new long[m];
	   long ap[]=new long[n];
	   long ans=0;
	   long fans=0;
	  //int l[]=new int[n];
	   for(int i=0;i<n;i++)
	   {
		a[i]=s.nextLong();
	   }
	   for(int i=0;i<m;i++)
	   {
		b[i]=s.nextLong();
	   }
	      ap[0]=a[0];
	      bp[0]=b[0];
	      for(int i=1;i<m;i++)
	      {bp[i]=bp[i-1]+b[i];}
	      for(int i=1;i<n;i++)
	      {ap[i]=ap[i-1]+a[i];}	
	 
	  for(int i=0;i<n;i++)
	   {
		long temp=k;
		ans=0;
		if(temp>=ap[i])
		{
		  temp-=ap[i];
		  ans+=i+1;
		  //System.out.println((i+1)+" "+Binary(bp,m,temp));
		  ans+=Binary(bp,m,temp);
		 fans=Math.max(ans,fans);
		}
	   }
	  for(int i=0;i<m;i++)
	   {
		long temp=k;
		ans=0;
		if(temp>=bp[i])
		{
		  temp-=bp[i];
		  ans+=i+1;
		  //System.out.println((i+1)+" "+Binary(bp,m,temp));
		  ans+=Binary(ap,n,temp);
		 fans=Math.max(ans,fans);
		}
	   }
	   System.out.println(fans);
	   
	 }	
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int n;
  cin >> n;

  vector<int> v(n), va(n);
  rep(i, n) {
    cin >> v[i];
    va[i] = v[i];
  }

  sort(all(v));

  int sum = 0;
  rep(i, n) {
    sum += v[i];
  }
  int a = 0;

  rep(i, n) {
    if (v[i] % 10 != 0) {
      a = v[i];
      break;
    }
  }
  int b = ((sum - a) % 10 == 0 ? 0 : sum - a);

  int bb = (sum % 10 == 0 ? 0 : sum);

  cout << max(b, bb) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
 using namespace std;
 int main (){
   int a;
   cin >> a;
   char op;
   cin >> op;
   int b;
   cin >> b;
    while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
  return 0;
}



Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  int i = K;
  int c = N;
  double ans = 0.0;
  double coin = 1.0;
  // N 3 K 3
  while (i >= 1) {
    if (c >= i) {
      // cout << "c:" << c << " i:" << i << endl;
      ans += (c-i+1) * coin;
      c = i-1;
    }
    if (i!= 1 && i%2==1) {
      i = i/2+1;
    } else {
      i /= 2;
    }
    coin *= 0.5;
  }
  ans /= (double)N;
  printf("%.9lf\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  int n,k,h[100000],cnt=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>h[i];
    if(h[i]>=k)
        cnt++;
  }
  cout<<cnt<<endl;
  return 0;
  }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



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

  int x,y;
  x=min(a,b);
  y=min(c,d);
  int ans=x+y;

  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,m,a[20][20],b[20],c,i,j,s=0,ans=0;
    scanf("%d%d%d",&n,&m,&c);
    for(i=0;i<m;i++)
        scanf("%d",&b[i]);
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            scanf("%d",&a[i][j]);
    for(i=0;i<n;i++){
        s=0;
        for(j=0;j<m;j++)
            s+=a[i][j]*b[j];
        if(s+c>0) ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
	//作るときはParentの値を全て-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
	//AとBをくっつける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついているからくっつけない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっつけたい
		//大小が逆だったらひっくり返しちゃう
		if (size(A) < size(B)) swap(A, B);
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
	//AとBが同じグループにいるか
	bool same(int A, int B) { return root(A) == root(B); }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<P> p(m);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		p[i] = P(a, b);
	}
	UnionFind Uni(n);
	vector<ll> ans(m);
	ll sum = 0;
	for (int i = m - 1; i >= 0; --i) {
		int a = p[i].first, b = p[i].second;
		if (!Uni.same(a, b)) {
			ll tmp = Uni.size(a);
			tmp *= Uni.size(b);
			ans[i] = sum;
			sum += tmp;
			Uni.connect(a, b);
		}
		else ans[i] = sum;
	}
	rep(i, m) printf("%lld\n", sum - ans[i]);
	return 0;
}


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

int main() {
    std::string s;
    std::cin >> s;
    int n = s.size();
    bool flg = (s[n - 1] == '0' && s[0] == '1');
    for (int i = 0; i < n - 1; i++) {
        flg = flg && (s[i] == s[n - 2 - i]);
    }
    if (!flg) {
        std::cout << -1 << std::endl;
        return 0;
    }

    int prev = 1;
    std::deque<std::pair<int, int>> q;
    for (int i = 2; i <= n / 2; i++) {
        if (s[i - 1] == '0') continue;
        q.emplace_back(prev, i);
        for (int j = prev + 1; j < i; j++) {
            q.emplace_back(j, i);
        }
        prev = i;
    }
    // q.pop_front();
    q.emplace_back(prev, prev + 1);
    auto remain = n - 1 - q.size();
    for (int i = 0; i < remain; i++) q.emplace_back(prev + 1, prev + 2 + i);
    for (auto& el : q) std::cout << el.first << " " << el.second << std::endl;

    return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>
void f(long long k){
	int n=54;
	while(((1LL<<(n-1))-(n-1)-1)*81>=k)n--;
	k-=((1LL<<(n-1))-(n-1)-1)*81;
	//n桁の数でk番目
	int a=1+(k-1)/(((1LL<<(n-1))-1)*9);
	k=(k-1)%(((1LL<<(n-1))-1)*9)+1;
	int b;
	putchar(a+48);
	n--;
	for(;;){
		long long lower=(long long)a<<(n-1);
		long long upper=(((1LL<<n)-1)*9)-((9LL-a)<<(n-1));
		if(k<=lower){
			b=(k-1)/(1LL<<(n-1));
			k=(k-1)%(1LL<<(n-1))+1;
			n--;
			break;
		}
		if(k>upper){
			k-=upper;
			b=(k-1)/(1LL<<(n-1))+a+1;
			k=(k-1)%(1LL<<(n-1))+1;
			n--;
			break;
		}
		putchar(a+48);
		k-=lower;
		n--;
	}
	putchar(b+48);
	k--;
	if(a<b){int t=a;a=b;b=t;}
	for(int i=n-1;i>=0;i--)putchar((k>>i)&1?a+48:b+48);
	puts("");
}

int main(){
	long long k;
	while(scanf("%lld",&k),k)f(k);
}


Measured memory_bytes: 2048
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
ll longinf=(1ll<<60);

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

ll mod=1e9+7;
signed main(){
    int n;
    cin>>n;
    double p[n];
    rep1(i,n){
        cin>>p[i];
    }
    double dp[n+1][n+1];
    rep0(i,n+1)rep0(j,n+1) dp[i][j]=0;
    dp[1][1]=p[1];
    dp[1][0]=1-p[1];
    for(int i=2;i<=n;i++){
        for(int j=i;j>=0;j--){
            if(j==i) dp[i][j]=dp[i-1][j-1]*p[i];
            else if(j==0) dp[i][j]=dp[i-1][j]*(1-p[i]);
            else{
                dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
            }
        }
    }
    double ans=0;
    for(int i=n;2*i>=n;i--){
        ans+=dp[n][i];
    }
    cout<<shosu<<ans<<endl;
    return 0;
}


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

using namespace std;
using Long = long long;

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

	Long n;
	int k;

	cin >> n >> k;

	vector<Long> vals(k);

	for (int i = 0; i < k; ++i)
		cin >> vals[i];

	Long ans = vals.back() - vals[0];

	for (int i = 0; i < k; ++i)
	{
		Long currAns = vals[i] + n - vals.back() + (vals.back() - vals[i]);

		ans = min(ans, currAns);

		if (i > 0)
		{
			currAns = n - vals[i] + vals[i - 1];

			ans = min(ans, currAns);
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
const int MAXN=100005;
int n,m;
int fa[MAXN];
bool vis[MAXN];
int ans=0;

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

int main()

{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<MAXN;i++){
		fa[i]=i;
	}

	for (int i=1;i<=m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		fa[find(x)]=find(y);
	}

	for (int i=1;i<=n;i++){
		if (!vis[find(i)]){
			vis[find(i)]=true;
			ans++;
		}
	}

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


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    int n;
    cin >>n ;
    map<string ,int > mp;
    int max = 0;
    string str[n];
    for(int i =0; i<n;i++){
        string s;
        cin >> s;
        str[i] = s;
        mp[s]++;
        if(max < mp[s]) max = mp[s];
    }
    set<string> s;
    for(int i =0; i<n ; i++){
        if(mp.count(str[i]) && mp[str[i]] == max){
            s.insert(str[i]);
            mp.erase(str[i]);
        }   
    }
    for(auto &it: s) cout << it << endl;
    
}

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

int main(void){

	char ab[256];
	char ai[256]={0},bi[256]={0};
	int i,j,x,y;
	
	gets(ab);
	
	for(i = 0;ab[i] != 0x20;i++){
		ai[i] = ab[i];
	}
	
	for(j = 0;ab[i] != '\0';i++){
		bi[j] = ab[i];
		++j;
	}	
	
	x = atoi(ai);
	y = atoi(bi);
	
	printf("%d %d\n",x * y,(x + y) * 2);
	
	return 0;
}

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

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

    while (n) {
        if (n % 10 == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3604
n, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
for i in range(n):
    if sum(A[:i + 1]) > x:
        print(i)
        exit()
    if sum(A[:i + 1]) == x:
        print(i + 1)
        exit()
print(i)

Measured memory_bytes: 9056
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := nextInt()
		b := nextInt()
		c := nextInt()
		if a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		continue
	}
}


Measured memory_bytes: 1084
var s,t,u:string;
i,j,k,l,m,n:longint;
begin
        readln(s);
        t:=copy(s,1,pos(' ',s)-1);
        val(t,i,n);
        delete(s,1,pos(' ',s));
        if(s[1]='+') then j := 10 else j := -10;
        delete(s,1,2);
        val(s,l,n);
        if j = 10 then writeln(i+l) else writeln(i-l);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) cin >> d[i];
	sort(all(d));
	int mid = n / 2;
	cout << d[mid] - d[mid - 1] << endl;
}


Measured memory_bytes: 640
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!long;

    if (N%2 == 1 || N <= 10) {
        writeln(0);
    } else {
        long r;
        N /= 10;
        while (N) {
            r += N;
            N /= 5;
        }
        writeln(r);
    }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    # input
    N, T = map(int, input().split())
    a, b = [], []
    a0_b = []
    for i in range(N):
        a_in, b_in = map(int, input().split())
        if a_in == 0:
            a0_b.append(b_in)
        else:
            a.append(a_in)
            b.append(b_in)
    L = len(a)

    # sort
    ab_ratio = [a[i] / (b[i] + 1) for i in range(L)]
    key = sorted(range(L), key=lambda x: -ab_ratio[x])
    a = [a[i] for i in key]
    b = [b[i] for i in key]
    a0_b.sort()

    # --- case a >= 1 --- #
    # dp[for i shops][passed j shops] := min time
    # j:29 for T < 10^9
    J_MAX = min(L + 1, 29)
    dp = [[float('inf') for _ in range(J_MAX)] for _ in range(L + 1)]
    dp[0][0] = 0
    for i in range(L):
        for j in range(J_MAX):
            if j > 0:
                dt = 1 + a[i] * (dp[i][j - 1] + 1) + b[i]
                if dp[i][j - 1] + dt <= T:
                    dp[i + 1][j] = min(dp[i][j], dp[i][j - 1] + dt)
                else:
                    dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = dp[i][j]

    # --- case a = 0 --- #
    ans = 0
    for i in range(J_MAX):
        if dp[L][i] == float('inf'):
            break
        else:
            time_cnt = dp[L][i]
            shop_cnt = i
            for t_b in a0_b:
                if time_cnt + 1 + t_b <= T:
                    time_cnt += 1 + t_b
                    shop_cnt += 1
            if ans < shop_cnt:
                ans = shop_cnt

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 226956
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

pa = [0]
for i in a:
    pa.append(i + pa[-1])

ans = 0
for i, v in enumerate(a):
    ans += (v * (pa[-1] - pa[i + 1])) % mod
    ans %= mod
print(ans)


Measured memory_bytes: 102304
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
  cin>>n;
  int arr[n];
  int vec[n];
  for(int j=0;j<n;j++)
  {
     cin>>vec[j];
  }

  arr[0] = vec[0];
  arr[1] = abs(vec[1]-vec[0]);
  arr[2] = abs(vec[2]-vec[0]);

  for(int i=3;i<n;i++)
  {
    arr[i] = min(arr[i-1]+abs(vec[i]-vec[i-1]),arr[i-2]+abs(vec[i]-vec[i-2]));
  }
  cout<<arr[n-1];

}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
	int res = 1;

	while (b)
	{
		if (b & 1) res = (res * a);

		a = (a * a); 
		b >>= 1;
	}
	return res;
}

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

#define N 200010
#define MOD 1000000007


int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	double l;
	cin >> l;

	double k = l / 3;
	double ans = k * k * k;

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

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

int main() {
  int n;
  cin >> n;
  vector<int> cnt(n + 1);
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= 100; j++) {
      for (int k = 1; k <= 100; k++) {
        int t = i*i + j*j + k*k + i*j + j*k + k*i;
        if (t > n) continue;
        cnt[t]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
  }
  return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int A, B, C, D;
	cin >>A >>B >>C >>D;
	cout <<min(A, B)+min(C, D) <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    vector<int> x, y;
    string res = "War"; 
    for (int i = 0; i < N; i++)
    {
        int xi; cin >> xi;
        x.push_back(xi);
    }
    sort(x.begin(), x.end());
    int xmax = x.at(N-1);
    for (int i = 0; i < M; i++)
    {
        int yi; cin >> yi;
        y.push_back(yi);
    }
    sort(y.begin(), y.end());
    int ymin = y.at(0);
    if (xmax < ymin && X < ymin && ymin <= Y)
    {
        res = "No War";
    }
    cout << res << endl;
	return 0;
}

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

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

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    la = rli()
    su = sum(la)
    ans = 0
    mod = 10**9+7
    for a in la:
        su -= a
        ans += su*a
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31528
import fractions
def gcd(a,b):
   f=fractions.gcd(a,b)
   f2=a*b//f
   return f2

a,b,c,d=map(int, input().split())
bc=b//c
bd=b//d
bcd=b//gcd(c,d)

a=a-1
ac=a//c
ad=a//d
acd=a//gcd(c,d)

print((b-(bc+bd-bcd))-(a-(ac+ad-acd)))

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}
template<class T>
void print_array(T a[],size_t n){
  cerr<<"array:";
  REP(n-1)cerr<<a[i]<<",";
  cerr<<a[n-1]<<endl;
}

int N,K;

int main(){
  cin>>N>>K;
  if(K%2){
    ll num=N/K;
    cout<<num*num*num<<endl;
  }
  else{
    ll num1=N/K;
    ll num2=num1+(((N%K)>=(K/2))?1:0);
    cout<<num1*num1*num1+num2*num2*num2<<endl;
  }
  return 0;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author dilip
 */

/*
*   author : dilip
*   time : 23-06-2019 22:11
*/

#include <iostream>
#include <fstream>

#include <iostream>
#include<stdio.h>
#include<bits/stdc++.h>

using namespace std;

class BOrdinaryNumber {
public:
	void solve(std::istream& in, std::ostream& out) {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        int n;
        in >> n;
        int p[n];
        for(int i=1;i<=n;i++)in >> p[i];
		int c = 0;
        for(int i=2;i<n;i++){
        	if((p[i] < p[i-1] && p[i] > p[i+1]) || (p[i] > p[i-1] && p[i] < p[i+1])){
        		c++;
        	}
        }

        out << c << endl;

	}
};


int main() {
	BOrdinaryNumber solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

MOD = 10 ** 9 + 7

cnt = 0
for i in range(M - 1):
    l = Y[i + 1] - Y[i]
    var = (i + 1) * (M - (i + 1))
    cnt += l * var
    cnt %= MOD

ans = 0
for i in range(N - 1):
    l = X[i + 1] - X[i]
    var = (i + 1) * (N - (i + 1))
    ans += l * var * cnt
    ans %= MOD

print(ans)


Measured memory_bytes: 18624
#abc145d
import sys

def com(n,r,m):
 f=[1,1]
 for i in range(2,n+1):
  f.append(f[i-1]*i%m)
 return f[n]*pow(f[r]*f[n-r]%m,m-2,m)%m

mod=10**9+7
x,y=map(int,raw_input().split())
z=(x+y)/3
if (x+y)%3 or abs(x-y)>z:
 print 0
 sys.exit()
print com(z,x-z,mod)


Measured memory_bytes: 45060
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: baisganon
 *
 * Created on 2017/06/04, 17:44
 */

#include<iostream>
using namespace std;

int partition(int A[],int p,int r){
	int x = A[r];
	int i = p-1;
	for(int j=p;j<r;j++){
		if(A[j]<=x){
			i++;
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	int tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;
	return i+1;
}

int main(){
	int size;
	cin >> size;
	int S[size];
	for(int i=0;i<size;i++){
		cin >> S[i];
	}

	int q = partition(S,0,size-1);

	for(int i=0;i<size;i++){
		if(i==q){
			cout<<"["<<S[i]<<"]";
		}else{
			cout<<S[i];
		}
                if(i!=size-1)cout<<" ";
	}
	cout <<endl;
	return 0; 
}

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

int main(){
    int count = 0;
    string s;
    cin >> s;
    if(s[0] == 'o') count++;
    if(s[1] == 'o') count++;
    if(s[2] == 'o') count++;
    cout << 700 + count*100 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()


def is_ok(arg, S):
    # 条件を満たすかどうか？問題ごとに定義
    dic = {}
    ans = False
    for i in range(len(S)-arg+1):
        c = S[i:i+arg]
        if c in dic:
            if i-dic[c] >= arg:
                ans = True
                break
        else:
            dic[c] = i
    return ans


def meguru_bisect(ng, ok, S):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, S):
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N = int(input())
    S = input()
    print(meguru_bisect((N//2)+1, -1, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 15280
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int n, a;
	cin >> n >> a;
	if(a >= n % 500){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define ri register int
#define pii pair<int, int>
#define pll pair<LL, LL>
using namespace std;
inline int read()
{
	int ret = 0; char ch = getchar();
	while(ch < '0' || ch > '9')
		ch = getchar();
	do {
		ret = ret * 10 + ch - '0';
		ch = getchar();
	} while('0' <= ch && ch <= '9');
	return ret;
}
inline void write(int x) // x > 0 (x != 0) ***
{
	if(!x)
		return ;
	write(x / 10);
	putchar(x % 10 + '0');
}
#define maxn 1010
#define hshs 310
int n, m;
int a[maxn][maxn];
int s1[maxn][maxn], s2[maxn][maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	string s;
	for(int i = 1; i <= n; i ++)
	{
		cin >> s;
		for(int j = 1; j <= m; j ++)
		{
			a[hshs + i][hshs + j] = s[j - 1] == '#';
		}
	}
	for(int i = 1; i <= n + 2 * hshs; i ++)
	{
		for(int j = 1; j <= m + 2 * hshs; j ++)
			s1[i][j] = s1[i - 1][j - 1] + a[i][j];
		for(int j = m + 2 * hshs; j; j --)
			s2[i][j] = s2[i - 1][j + 1] + a[i][j];
	}
	int Ans = 0;
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++)
			for(int k = 1; k <= min(n, m); k ++)
			{
//				cout << i << ' ' << j << ' ' << k << ' ' << Ans << endl;
				if(i - k > 0 && j - k > 0 && a[hshs + i][hshs + j - k] && a[hshs + i - k][hshs + j])
					Ans += s2[hshs + i + k - 1][hshs + j + 1] - s2[hshs + i - 1][hshs + j + k + 1];
				if(i - k > 0 && j + k <= m && a[hshs + i][hshs + j + k] && a[hshs + i - k][hshs + j])
					Ans += s1[hshs + i + k][hshs + j] - s1[hshs + i][hshs + j - k];
				if(i + k <= n && j + k <= m && a[hshs + i][hshs + j + k] && a[hshs + i + k][hshs + j])
					Ans += s2[hshs + i][hshs + j - k] - s2[hshs + i - k][hshs + j];
				if(i + k <= n && j - k > 0 && a[hshs + i][hshs + j - k] && a[hshs + i + k][hshs + j])
					Ans += s1[hshs + i - 1][hshs + j + k - 1] - s1[hshs + i - k - 1][hshs + j - 1];
			}
	cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 10880
#include <iostream>
int main()
{
  int n, ichi;
  std::cin >> n;
  switch (n % 10)
  {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    std::cout << "hon" << std::endl;
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    std::cout << "pon" << std::endl;
    break;
  case 3:
    std::cout << "bon" << std::endl;
    break;
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}



int main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i,n) cin >> s[i];

    sort(s);
    rep(i,n) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{
int n;
cin>>n;
int a,b,c,A,B,C,p,q,r;
cin>>a>>b>>c; 
for(int i=1; i<n; i++){ 
    cin>>A>>B>>C; 
    p=a;q=b;r=c;
    a=A+max(q,r);
    b=B+max(p,r);
    c=C+max(p,q);
}
cout<<max(a,max(b,c));
return 0; 
} 


Measured memory_bytes: 256
import numpy as np
 
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
 
cycles, check = [], [False]*n
for pi in p:
    if not check[pi-1]:
        curr, cycle = pi, []
        check[pi-1] = True
        while pi != p[curr-1]:
            check[curr-1] = True
            cycle.append(c[curr-1])
            curr = p[curr-1]
        check[curr-1] = True
        cycles.append(cycle + [c[curr-1]])
 
scores = []
for cycle in (np.array(cycle) for cycle in cycles):
    for i in range(cycle.size):
        cum = np.roll(cycle, i).cumsum()
        if cum[-1] > 0 and k > cycle.size:
            scores.append(cum[-1]*(k//cycle.size-1) + np.concatenate([cum, cum[:k % cycle.size]+cum[-1]]).max())
        else:
            scores.append(cum[:min(k, cum.size)].max())
print(max(scores))

Measured memory_bytes: 28248
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

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

queue<int> que;

int BFS(int n, vector<string> & mp, vector<int> & d) {
	int i, j;
	rep(i, mp.size()) {
		if (mp[n][i] == '1') {
			if (d[i] == INF) {
				d[i] = d[n] + 1;
				que.push(i);
			}
			else if (abs(d[i] - d[n]) != 1)
				return -1;
		}
	}
	if (que.empty())
		return d[n];
	n = que.front();
	que.pop();
	return BFS(n, mp, d);
}

int BFS(int n, vector<string> & mp) {
	vector<int> d(mp.size(), INF);
	d[n] = 1;
	return BFS(n, mp, d);
}

int main(void) {
	int num, i, j, ans = -1;
	cin >> num;
	vector<string> mp(num);
	rep(i, num)
		cin >> mp[i];
	rep(i, num)
		chmax(ans, BFS(i, mp));
	cout << ans << "\n";
	return 0;
}

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

int main() {
    ll x,ans;
    cin>>x;
    ans=(x/11)*2;
    if (x%11>0) {
        if (x%11>6) ans+=2;
        else ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int p, q, r;

	cin >> p >> q >> r;

	if (p > q)
	{
		if (p > r) cout << q + r << endl;
		else cout << q + p << endl;
	}
	else
	{
		if (q > r) cout << p + r << endl;
		else cout << q + p << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
void multiply(vector<int>&fact,int &n,vector<int>&ans,int i)
{
    int carry=0;
    int sum=0;
    for(int j=0;j<n;j++)
    {
        fact[j]=fact[j]*i+carry;
        carry=fact[j]/10;
        fact[j]=fact[j]%10;
        sum+=fact[j];
    }
    while(carry)
    {
        fact.push_back(carry%10);
        sum+=carry%10;
        carry=carry/10;
        n++;
    }
    ans[i]=sum;
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    int x;
    cin>>x;
    if(n*500<x)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;

}

Measured memory_bytes: 3584
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let n : i64 = read();
    let x : Vec<i64> = read_vec();
    let mut sumarray = Vec::<i64>::new();

    for a in 0..100 {
        let mut sum : i64 = 0;
        let aa = (a + 1)as i64;
        for b in 0..x.len(){
            sum += (x[b] - aa) * (x[b] - aa);
        }
        sumarray.push(sum);
        // println!("a {} sum {}", a, sum);
    }

    let res = sumarray.iter().min_by(|x, y| x.cmp(y)).unwrap();

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


Measured memory_bytes: 4352