akhauriyash/Code-Regression huggingface dataset:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
ans=0
for x in a:
  ans+=lcm//x
print(ans%mod)

Measured memory_bytes: 6116
#include <algorithm>
#include <cstdio>

using namespace std ;

const int N=400 ;

int a[N][N] , w[N] , del[N] ;
int n , m ;
inline int check ( int x )
{
	// printf("Check %d\n",x);
	int i ;
	for ( i=1 ; i<=m ; i++ ) w[i]=0,del[i]=0;
	for ( i=1 ; i<=n ; i++ ) a[i][0]=1,w[a[i][1]]++;
	while ( 1 )
	{
		int mx=0 , pos=0 ;
		for ( i=1 ; i<=m ; i++ ) 
			if ( w[i]>mx ) mx=w[i],pos=i;
		if ( mx<=x ) return 1 ;
		del[pos]=1;
		for ( i=1 ; i<=n ; i++ ) 
			if ( a[i][a[i][0]]==pos ) 
			{
				while ( a[i][0]<=m && del[a[i][a[i][0]]] ) a[i][0]++;
				if ( a[i][0]>m ) return 0 ;
			}
		for ( i=1 ; i<=m ; i++ ) w[i]=0;
		for ( i=1 ; i<=n ; i++ ) w[a[i][a[i][0]]]++;
	}
	return 0 ;
}

int main ()
{
	int i , j ;
	scanf("%d%d",&n,&m);
	for ( i=1 ; i<=n ; i++ ) 
		for ( j=1 ; j<=m ; j++ ) scanf("%d",a[i]+j);
	int l=1 , r=n , mid ;
	for ( mid=(l+r)>>1 ; l<r ; mid=(l+r)>>1 )
		if ( check(mid) ) r=mid;
		else l=mid+1;
	printf("%d\n",l);
	return 0 ;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int n,i,j;
    scanf("%d",&n);
    int a[n],b[n];
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[a[i]]=i;
    }
    for(i=1;i<=n;i++){
        printf("%d ",b[i]);
    }
}


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

#define ing long long

int field[10][10];

void dfs(int x, int y) {
  field[x][y] = 0;

  for (int ty = max(1, y - 3); ty <= min(8, y + 3); ++ty) {
    if (field[x][ty]) dfs(x, ty);
  }

  for (int tx = max(1, x - 3); tx <= min(8, x + 3); ++tx) {
    if (field[tx][y]) dfs(tx, y);
  }
}

void data() {
  fill(field[0], field[10], 0);
  for (int y = 1; y <= 8; ++y) {
    string tmp;
    cin >> tmp;
    for (int x = 1; x <= 8; ++x) {
      field[x][y] = tmp[x - 1] - '0';
    }
  }

  int px, py;
  cin >> px >> py;
  dfs(px, py);

  for (int y = 1; y <= 8; ++y) {
    for (int x = 1; x <= 8; ++x) {
      cout << field[x][y];
    }
    cout << endl;
  }
}

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

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cout << "Data " << i + 1 << ":" << endl;
    data();
  }
}

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

const int N = 2e5 + 10;
char s[N];

int main() {
	while (scanf("%s", s + 1) != EOF) {
		int res = 1;
		int len = strlen(s + 1); 
		int pre = 1;
		for (int i = 2; i <= len; ) { 
			if (i - pre == 2) {
				pre = i;
				++i;
			} else {
				if (s[i] == s[pre]) {
					pre = i;
					i += 2;
				} else {
				    pre = i;	
					++i; 
				}
			}
			if (i <= len + 1) ++res;
		}
		printf("%d\n", res);
	}
	return 0;
}


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

using namespace std;
#define ll long long int
#define mod 1000000007
long long power(long long x,
                int y, int p)
{
   long long res = 1;
   x = x % p; 

   while (y > 0)
   {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1; // y = y/2
      x = (x * x) % p;
   }
   return res;
}

long long modInverse(long long n, int p)
{
   return power(n, p - 2, p);
}



int main()
{
   ll t;
   t = 1;
   // cin t;
   while (t--)
   {
      ll k;
      cin >> k;
      string s;
      cin >> s;
      int l = s.length();
      ll ans = 1;
      ll p25[k + 1];
      ll p26[ k + 1];
      p25[0] = 1;
      p26[0] = 1;
      ll ncr[k + 1];
      ncr[0] = 1;
      for(int i = 1 ; i<=k ; i ++)
      {
         ncr[i] = (ncr[i - 1] * (l - 1 + i) % mod * modInverse(i, mod) % mod) % mod;
      }
      for(int i = 0 ; i <= k ; i ++)
      {
         ans = (ans +  (power(25 , k - i ,mod) % mod * power(26 , i ,mod)  % mod * ncr[k - i] % mod) % mod ) % mod;
      }
      cout << ans - 1<< endl;
   }
}


Measured memory_bytes: 12044
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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 all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    vin a(n);
    rep(i,n)cin>>a[i];
    rep(i,n)a[i]-=i+1;
    sort(all(a));
    ll sum=0;
    rep(i,n)sum+=(ll)abs(a[i]-a[n/2]);
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) // <a> must be sorted in advance

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

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


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

    int N, A;
    cin >> N >> A;
    cout << N*N - A << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

template<class T> T pow(T a, T b) {
	if (b == 0)return 1;
	if (b % 2) {
		T ret = pow(a, (b - 1) / 2);
		return ret * ret * a;
	}
	else {
		T ret = pow(a, b / 2);
		return ret * ret;
	}
}

int main() {
	init();
	
	int N, K; cin >> N >> K;
	int ans = K * pow(K - 1, N - 1);
	cout << ans << "\n";
	

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int N = scanner.nextInt();
		    int counter = 0;
		    for(int i = 0; i < N; i++) 
		    {
		    	int a = scanner.nextInt();
		    	counter = counter + a - 1;
		    }
		    System.out.println(counter);
		    scanner.close();}
		  }

Measured memory_bytes: 25324
import math
import sys
N,Y= map(int, input().split()) 
for a in range(N+1):
    for b in range(N+1-a):
        if (10000*a+5000*b+1000*(N-a-b)==Y):
            print(a, b, N-a-b)
            sys.exit()
print(-1, -1, -1)

Measured memory_bytes: 9040
#include <cstdio>

int H,W;
int res = 0;
char field[105][105];
int sh_x[4] = {0, 0, -1, 1};
int sh_y[4] = {1, -1, 0, 0};

void solve(char target, int x, int y) {
  field[y][x] = '!';
  for (int i=0;i<4;i++) {
    int new_x = x + sh_x[i];
    int new_y = y + sh_y[i];
    if (new_x >= 0 && new_x < W && new_y >=0 && new_y < H && field[new_y][new_x] == target)
      solve(target, new_x, new_y);
  }
}

int main() {
  while (1)
  {
    scanf("%d %d", &H, &W);
    getchar();
    if (!W && !H) {
      break;
    }

    int i,j;
    for (i=0;i < H; i++) {
      fgets(field[i], 105, stdin);
      field[i][W] = '!';
    }

    for (i=0;i<W;i++) {
      field[H][i] = '!';
    }

    for (i=0;i<H;i++) {
      for (j=0;j<W;j++) {
        if (field[i][j] != '!') {
          solve(field[i][j], j, i);
          res++;
        }
      }
    }
    printf("%d\n", res);
    res = 0;
  }

  return 0;
}




Measured memory_bytes: 3208
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;
// int m[1001][1001] = {0};
//----------------------------------------------------------------
signed main(){

	ll n;
	string s;
	cin >> n >> s;

	ll ans = 0;

	for(int l = 0;l < n-1;l++){
		vll A(n-l);
		int c = 0;
		for (int i = 1; i+l < s.size(); i++){
		if (i+A[i-c] < c+A[c]) {
			A[i] = A[i-c];
		} else {
			int j = max(0LL, c+A[c]-i);
			while (i+j+l < s.size() && s[j+l] == s[i+j+l]) ++j;
			A[i] = j;
			c = i;
		}
		}
		rep(m,n-l)ans = max(ans,min(m,A[m]));
	}

	cout << ans << endl;

	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://agc038.contest.atcoder.jp/tasks/agc038_a

Measured memory_bytes: 256
// https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int c, int d) { return c / gcd(c, d) * d; }

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
    } else {
        cout << max(n - k, 0LL) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()

mod = 10**9+7


print((pow(10,n,mod)-pow(9,n,mod)*2+pow(8,n,mod)+mod*2)%mod)


Measured memory_bytes: 61968
# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    result = 0
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            result += bisect.bisect_left(l, l[i] + l[j]) - (j + 1)

    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        long A = in.longNext();
        char[] num = in.next().toCharArray();
        StringBuilder number = new StringBuilder();
        for (char ch: num) if (ch != '.') number.append(ch);
        out.println(Long.parseLong(number.toString()) * A / 100);

        out.close();
    }


    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}




Measured memory_bytes: 32652
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;

  if(a>b) swap(a,b);
  if(a>c) swap(a,c);
  if(b>c) swap(b,c);

  cout<<10*c+b+a<<endl;
}

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

int main() {
  int N, K, k, count=0;
  cin >> N >> K;
  vector<int> kind(K+1);
  vector<int> sun(10002);
  kind.at(0)=0;
 
  for (int i=0; i<K; i++) {
    cin >> k;
    kind.at(i+1)=k;
    count+=k;
    //cout << count << endl;
    for (int j=count-k; j<count; j++) {
      cin >> sun.at(j);
    }
  }
  
  //for (int i=0; i<count; i++) cout << sun.at(i) << " ";
  
  sort(sun.begin(), sun.end());
  count=0;
  
  for (int i=0; i<sun.size()-1; i++) {
    if (sun.at(i)!=sun.at(i+1)) count++;
  }
  
  cout << N-count << endl;
}

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

int main(void){
   char a[11],b[11],c[11];
   int al,bl,cl;

   scanf("%s%s%s",a,b,c);
   al=strlen(a);
   bl=strlen(b);
                                                                                
   if ((a[al-1]==b[0]) && (b[bl-1]==c[0])){
      printf("YES\n");
   } else {
      printf("NO\n");
   }
   return 0;
}

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

a = [int(input())-1 for _ in range(n)]

flag = False
index = 0
count = 0

for i in range(n):
  index = a[index]
  count += 1
  if index == 1 :
    flag = True
    break

if flag:
  print(count)
else:
  print(-1)


Measured memory_bytes: 76224
/*
* @author:  codancer
* @createTime:  time
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int main(){
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

typedef long long lli;

const lli INF = 1LL << 59;
const int N = 1000;

int n;
vector<lli> v;

void solve(){
  lli dp[N][N];
  fill(dp[0],dp[N],INF);
  
  for(int i=0;i<=n;i++) dp[i][i] = 0;
  for(int i=2;i<=n;i++){
    for(int j=0;j+i-1<n;j++){
      int next = j + i - 1;
      for(int k=j;k<next;k++){
        dp[j][next] = min(dp[j][next], dp[j][k] + dp[k+1][next] + v[j] * v[k+1] * v[next+1]);
      }
    }
  }

  cout << dp[0][n-1] << endl;
}

int main(){
  while(cin >> n){
    v.clear();
    for(int i=0;i<n;i++) {
      int a,b;
      cin >> a >> b;
      if(i == 0) v.push_back(a);
      v.push_back(b);
    }
    solve();
  }
}

Measured memory_bytes: 9020
package main

import "fmt"

func isKaibun(s string) bool {
	n := len(s)
	for i := 0; i < n/2; i++ {
		if s[i] != s[n-i-1] {
			return false
		}
	}
	return true
}

func main() {
	var s string
	fmt.Scan(&s)

	n := len(s) - 1

	a := s[:n/2]
	b := s[(n+2)/2:]

	if isKaibun(s) && isKaibun(a) && isKaibun(b) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int n,m;
pair<int,int> a[100001];
bool cmp(pii x,pii y){
	return x.first<y.first;
}
ll ans;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>> n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i].first>>a[i].second;
	}
	sort(a,a+n);
	int nw=0;
	while(m>0){
		ans+=1ll*min(m,a[nw++].second)*a[nw-1].first;
		m-=a[nw-1].second;
	}
	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 1024
#include <stdio.h>
int trump[101]={};
int n;

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

    for(i=0;i<n;i++)
    {
        scanf("%d",&trump[i]);
    }

    int flag=1;
    int count=0;
    while(flag)
    {
        flag=0;
        for(j=n-1;j>=1;j--)
        {
            if(trump[j]<trump[j-1])
            {
                int c;
                c=trump[j-1];
                trump[j-1]=trump[j];
                trump[j]=c;
                flag=1;
                count++;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%d",trump[i]);
        if(i<n-1)printf(" ");
    }
    printf("\n%d\n",count);


    return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pcase printf("Case %d:\n",ca)
int ca=1;
using namespace std;
int main()
{
    ll n;
    ll ans = 1000;
    cin>>n;
    if(n%1000==0){
        cout<<0<<nl;
    }else{

        while(n>ans){
            ans = ans+1000;
        }
        cout<<ans-n<<nl;
}
}


Measured memory_bytes: 3636
from sys import stdin
from itertools import groupby

n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()

lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

lin.sort()

if len(lin) <= k:
    print(0)
else:
    print(sum(lin[:len(lin)-k]))

Measured memory_bytes: 25248
#include <stdio.h>
int main ()
{
    int n,i,j,a[55],sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            sum += a[i] * a[j];
        }
    }
    printf("%d\n",sum);

}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

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

		int D = scanner.nextInt();
		int N = scanner.nextInt();

		N = (N==100)?101:N;
		System.out.println((int)Math.pow(100, D)*N);

	}

}


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

int main()
{
  char n;

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

    if (n == '1')
    {
      cout << '9';
    }
    else
    {
      cout << '1';
    }
  }
}


Measured memory_bytes: 3560
main :: IO ()
main = do
    [n, m] <- map read . words <$> getLine :: IO [Int]
    print $ solve n m

solve n m
    | n == 1 && m == 1 = 1
    | n == 1 = m - 2
    | m == 1 = n - 2
    | otherwise = max 0 $ n * m + 4 - 2 * (n + m)


Measured memory_bytes: 508
#include <stdio.h>
#include <ctype.h>
int main(void) {
    int cnt = 0;
    char c, prev;
    while ((c = getchar()) != '\n');
    while (c = getchar()) {
        if (!isdigit(c)) cnt += prev & 1;
        prev = c;
        if (c == EOF) break;
    }
    printf("%s\n", cnt & 1 ? "NO" : "YES");
    return 0;
}

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

int n, k, a[10], tmp,ans = 0;
bool chk(int x){
	while(x){
		if (a[x % 10])return 0;
		x /= 10;
	}
	return 1;
}

int main(){
	cin >> n >> k;
	rep(i, k)cin >> tmp, a[tmp] = 1;
	

	for(int i=n;i<n*10;i++){
		if (!chk(i))continue;
		cout << i << endl;
		return 0;
	}
		


}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    ll N; cin>>N;
    ll mid =floor(sqrt(N));
    for(ll i=mid;1<=i;i--){
        if(N%i==0){
            ll a=N/i;
            cout<<i-1+a-1<<endl;
            return 0;
        }
    }
    cout<<N-1<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
const int MAXN = 1e5 + 7;
using namespace std;
int n, maxn, sum, d1, d2;


int main() {
	cin >> n;
	while (n--) {
		cin >> d1 >> d2;
		if (d1 == d2) {
			sum++;
			if (sum > maxn) maxn = sum;
		}
		else sum = 0;
	}
	if (sum > maxn) maxn = sum;
	if (maxn >= 3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

typedef pair<int, int> pii;

int main()
{
    int N, M;
    while (cin >> N, N) {
        map<char, char> mp;
        for (int i = 0; i < N; i++) {
            char a, b;
            cin >> a >> b;
            mp[a] = b;
        }

        cin >> M;
        for (int i = 0; i < M; i++) {
            char c;
            cin >> c;
            if (mp.count(c) > 0) {
                cout << mp[c];
            } else {
                cout << c;
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3068
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


int main() {
	float n, m;
	float sum = 0;
	cin >> n >> m;
	vector<float> a(n);
	repz(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	float check_sum = sum / (4 * m);
	//sort(a.rbegin(), a.rend());
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= check_sum) {
			count++;
		}
	}
	if(count >= m)cout << "Yes" << endl;
	else cout << "No" << endl;
	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

vi adj[N];
bool visited[N];
int arr[N];
int cnt = 0;

// void bfs(int node){

// }

void solve(){    

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

    rep(i,1,n+1) cin>>arr[i];

    while(m--){
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    for(int i = 1;i<=n;i++){
        if(adj[i].size()==0) cnt++;
        else{
            int currHeight = arr[i];
            bool flag = true;
            for(int x : adj[i]){
                if(arr[x]>=currHeight){
                    flag = false;
                    break;
                }
            }
            if(flag){
                //cout<<"mil gaya "<<i<<"\n";
                cnt++;
            }
        }
    }
    cout<<cnt;
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 10220
using System;
using System.Collections.Generic;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ');
			var N = int.Parse(arr[0]);
			int Y = int.Parse(arr[1]);
			for(int x = 0; x <= N; x++)
				for(int y = 0; y <= N-x; y++)
				{
					var z = N - x - y;
					var sum = (10000 * x) + (5000 * y) + (1000 * z);
					if (sum == Y)
					{
						Console.WriteLine($"{x} {y} {z}");
						return;
					}
				}
			Console.WriteLine("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
  int n, m;
  cin >> n >> m;
  
  int a[50], b[50];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int c[50], d[50];
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  
  long long  x, y;
  vector<vector<long long> > ans(n, vector<long long>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
		if(a[i] > c[j]) {
      		x = (long long) a[i] - c[j];
    	}
    	else {
      		x = (long long) c[j] - a[i];
    	}
    
   	 	if(b[i] > d[j] > 0) {
      		y = (long long) b[i] - d[j];
    	}
    	else {
      		y = (long long) d[j] - b[i];
    	}
      ans[i][j] = x+y;
    }
  }
  int tmp;
  for (int i = 0; i < n; i++) {
    long long mini = LLONG_MAX;
    for(int j = 0; j < m; j++) {
		if (mini > ans[i][j]) {
          mini = ans[i][j];
          tmp = j;
        }
    }
    cout << tmp + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#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++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,K;

int main(){
    cin>>N>>K;
    if(N%2==1)N++;
    if(N/2>=K)out("YES");
    else out("NO");
}


Measured memory_bytes: 256
#include<stdio.h> 
#include<stdlib.h> 
int main() 
{ 
int a,b,c,d,x,y,z; 
scanf("%d%d%d%d",&a,&b,&c,&d); 
x=abs(a-b); 
y=abs(b-c); 
z=abs(c-a); 
if((x<=d&&y<=d)||z<=d)printf("Yes\n"); 
else printf("No\n"); 
return 0; 
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	vector<ll> x(3);
	cin >> x[0] >> x[1] >> x[2];
	sort(x.begin(), x.end());
	cout << x[0]*x[1]/2 << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c, k = list(map(int, input().split()))

num_one_cards = min(a, k)
num_zero_cards = min(b, k - num_one_cards)
num_minus_one_cards = k - num_one_cards - num_zero_cards

score = 1 * num_one_cards + 0 * num_zero_cards + (-1) * num_minus_one_cards

print(score)


Measured memory_bytes: 9076
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>a(n-1);
  vector<int>b(n+1);
  for(int i = 0;i<n-1;i++){
    cin >> a[i];
    b[a[i]]++;
  }
  for(int i = 1;i<n+1;i++) cout <<b[i]<<endl;
  return 0;
}

Measured memory_bytes: 4844
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let ans = if k == 1 {
        0
    } else {
        n-k
    };

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


Measured memory_bytes: 4352
def A(x):
  return 1000 - x % 1000 if x % 1000 != 0 else 0


def B(s, t):
  pass


def C(n, m, k, a, b):
  pass


def main():
  n = int(input())
  print(A(n))


if __name__ == '__main__':
  main()


Measured memory_bytes: 9148
use std::collections::HashMap;
fn main() {
    let n = read::<usize>();
    let mut hm = HashMap::new();
    for _ in 0..n {
        let a = read::<String>();
        let c = hm.entry(a).or_insert(0);
        *c += 1;
    }

    let max = *hm.clone().values().max().unwrap();
    let mut ss = vec![];
    for (k, v) in hm {
        if v == max {
            ss.push(k.clone());
        }
    }
    ss.sort();
    for s in ss {
        println!("{}", s);
    }
}

#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
	int n;
	scanf("%d",&n);
	int nowt=0,nowx=0,nowy=0;
	for(int i=1;i<=n;i++){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		int pst=t-nowt;
		int psx=a-nowx,psy=b-nowy;
		int dis=abs(psx)+abs(psy);
		//printf("%d %d %d %d\n",t,a,b,dis);
		if(((dis&1)==(pst&1))&&(dis<=pst));
		else{
			printf("No");
			return 0;
		}
		nowt=t;
		nowx=a,nowy=b;
	}
	printf("Yes");
	return 0;
}

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

struct city {
  int order;
  int pref;
  int year;
  int yearord;
};

bool cmp1(const city &a, const city &b) {
  if(a.pref < b.pref) {
    return true;
  } else if (a.pref > b.pref){
    return false;
  } else {
    return a.year < b.year;
  }
}

bool cmp2(const city &a, const city &b) {
  return a.order < b.order;
}

int main() {
  int N, M, P, Y;
  
  cin >> N >> M;
  vector<city> A(M);
  
  for(int i=0; i<M; i++) {
    cin >> P >> Y;
    A[i].order = i;
    A[i].pref = P;
    A[i].year = Y;
  }
  
  sort(A.begin(), A.end(), cmp1);
  
  int j = 1;
  int i = 1;
  for(city &a:A) {
    while(a.pref!=i) {
      i++;
      j = 1;
    }    
    if(a.pref==i) {
      a.yearord = j;
      j++;
    }
  }
  
  sort(A.begin(), A.end(), cmp2);
  
  for(city a:A) {
    string pref_S = to_string(a.pref);
    string year_S = to_string(a.yearord);
    
    while(pref_S.size()<6) {
      pref_S = '0' + pref_S;
    }
    while(year_S.size()<6) {
      year_S = '0' + year_S;
    }
    
    cout << pref_S << year_S << endl;
  }
   
  return 0;
}

Measured memory_bytes: 3072
s=input()
while len(s)>7:
    if s[-7:]=="dreamer":
        s=s[:-7]
    elif s[-5:]=="dream":
        s=s[:-5]
    elif s[-6:]=="eraser":
        s=s[:-6]
    elif s[-5:]=="erase":
        s=s[:-5]
    else:
        break
if s in ["dreamer","dream","eraser","erase"]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define f(i,s,e) for(int i=s;i<e;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
int n,k,dp[100005],arr[100005];

int func(int ind){
    if(ind==n-1)return 0;

    if(dp[ind]!=-1)return dp[ind];

    int ans=INT_MAX;

    for(int i=1;i<=k;i++){
        if(ind+i<n)
            ans=min(ans,func(ind+i)+abs(arr[ind]-arr[ind+i]));
    }

    return dp[ind]=ans;
}
int main(){
    fast;

    cin>>n>>k;

    f(i,0,n)cin>>arr[i];

    memset(dp,-1,sizeof(dp));
    cout<<func(0);
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	
	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};

int main() {
	int n;
	string s;
	cin >> n >> s;
	map<char, int> mp;
	rep(i, n) mp[s[i]]++;
	mint ans = 1;
	for(auto t: mp) {
		int now = t.second;
		ans *= 1+ now;
	}
	cout << ans.x-1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s1;
	int x = 0, k = 0, i;

	cin >> s1;
	x = s1.size();

	for (i = 0; i < x; i++) {
		if (s1[i] != s1[x - 1 - i]) k++;
	}
	cout << k/2 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    // static int INF = (1 << 30) - 1;
    // static long L_INF = (1L << 62) - 1;
    // static long MOD = (long) 1e9 + 7;

    static class UfTree {
        int[] par;
        int[] sizes;

        UfTree(int n) {
            par = new int[n];
            sizes = new int[n];
            for (int i = 0; i < n; i++) {
                par[i] = i;
                sizes[i] = 1;
            }
        }

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

        void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) {
                return;
            }
            if (sizes[x] < sizes[y]) {
                int tmp = x;
                x = y;
                y = tmp;
            }
            par[y] = x;
            sizes[x] += sizes[y];
        }

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

        int size(int x) {
            return sizes[find(x)];
        }
    }

    static class Solver {
        int n, q;

        // write your code
        void solve(InputReader in, PrintWriter out) {
            n = in.nextInt();
            q = in.nextInt();
            UfTree uf = new UfTree(n);
            for (int i = 0; i < q; i++) {
                int com = in.nextInt();
                int xi = in.nextInt();
                int yi = in.nextInt();
                if (com == 0) {
                    uf.unite(xi, yi);
                } else {
                    out.println(uf.same(xi, yi) ? 1 : 0);
                }
            }
        }

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

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}



Measured memory_bytes: 59516
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int quantity = sc.nextInt();
        Set<Integer> numSet = new HashSet<>();
        
        String result = "YES";
        for (int i = 0; i < quantity; i++){
            if (!numSet.add(sc.nextInt())) {
                result = "NO";
                break;
            }
        }
        System.out.println(result);
    }

}

Measured memory_bytes: 98508
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int s[7];
int k;
string c;
void  f(int k)
{
    if(c[k]=='S')
    {
       int t=s[1];
       s[1]=s[3];
       s[3]=s[6];
       s[6]=s[2];
       s[2]=t;
    }
      if(c[k]=='N')
    {
       int t=s[3];
       s[3]=s[1];
       s[1]=s[2];
       s[2]=s[6];
       s[6]=t;
    }
        if(c[k]=='W')
    {
       int t=s[1];
       s[1]=s[5];
       s[5]=s[6];
       s[6]=s[4];
       s[4]=t;
    }
          if(c[k]=='E')
    {
       int t=s[1];
       s[1]=s[4];
       s[4]=s[6];
       s[6]=s[5];
       s[5]=t;
    }
}
int main()
{
        cin>>s[1];
        cin>>s[2];
        cin>>s[5];
        cin>>s[4];
        cin>>s[3];
        cin>>s[6];
 
//  for(int i=1;i<=6;i++)  cout<<s[i]<<' ';
    cin>>c;
    for(int i=0;i<c.size();i++)
    {
        f(i);
    }
    cout<<s[1]<<endl;
    return 0;
}




Measured memory_bytes: 3212
#include <stdio.h>
#include <string.h>
int main(){
    char s[11];
    char t[12];
    int n;
    scanf("%s%s",s,t);
    n = strlen(s);
    for(int i=0;i<n;i++){
        if(s[i]!=t[i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll a,b;
    cin >> a >> b;
    if(a==0 || b==0) cout << "Zero" << endl;
    else if(a<0 && b>0) cout << "Zero" << endl;
    else if(a>0 && b>0) cout << "Positive" << endl;
    else if(a<0 && b<0){
        a = abs(a);
        b = abs(b);
        if((a-b)%2 == 0)cout << "Negative" <<endl;
        else            cout << "Positive" <<endl;
    }
}

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

int main() {
    int n, k;
    long long p, res, sum = 0;
    vector<long long> s;
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> p;
        s.push_back(p);
        sum += p;
    }
    res = sum;
    p = -1;
    int flag = 0;
    long long left = 0, right = sum;
    while (left+1 < right){
        p = (left + right) / 2;
        int num = 0, j = 0;
        //long long nw = p;//当前容量
        for (int i = 0; i < k; i++){
            long long nw = p;
            while (s[j] <= nw && j < s.size()){
                nw -= s[j];
                num++;
                j++;
            }
        }
        //cout << num << " " <<left<<" " << p <<" " << right <<endl ;
        if (num == n){
            right = p;
            res = p;
        }
        else
            left = p;
    }
    //cout <<endl;
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3924
L, R = map(int, input().split())

l = L % 2019
r = R % 2019

ans = 2019*2019

if L // 2019 == R // 2019:
    # print(l,r)
    for i in range(l, r):
        # print('i', i)
        for j in range(i+1,r+1):
            # print('j', j)

            ans = min(ans, (i*j)%2019)
else:
    ans = 0

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
using namespace std;
int n,q,tree[100010];

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

int main(){

  while(1){
    cin>>n>>q;
    if(!n&&!q)break;


    char ch[100010];
    int num[100010],par[100010];
    tree[1]=par[1]=1;

    for(int i=2;i<=n;i++)scanf("%d",&tree[i]),par[i]=tree[i];
    

    for(int i=0;i<q;i++){
      cin>>ch[i]>>num[i];
      if(ch[i]=='M'&&tree[num[i]]==num[i])i--,q--;
      else if(ch[i]=='M')tree[num[i]]=num[i];
    }

    long long ans=0;
    for(int i=q-1;i>=0;i--){
      if(ch[i]=='M') tree[num[i]]=par[num[i]];
      if(ch[i]=='Q') ans+=find(num[i]);
    }

    cout <<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 2620
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
const int MAX = 1000000;
bool prime[1000001];
bool dp[1000001];

void Init(){
	memset(dp, false, sizeof(dp));
	dp[0] = true;
}

void era(){
	prime[0] = prime[1] = false;
	for(int i = 2; i <= MAX; i++){
		if(prime[i]){
			for(int j = i*2; j <= MAX; j+=i) prime[j] = false;
		}
	}
}

int main(){
	int n, limit;
	memset(prime, true, sizeof(prime));
	era();
	while(cin >> n >> limit && ((n!=0)||(limit!=0))){
		Init();
		int maxc = 0;
		for(int i = 1; i <= n; i++){
			int tmp;
			cin >> tmp;
			dp[tmp] = true;
			for(int j = 0; j+tmp <= limit; j++){
				if(dp[j]){
					dp[j+tmp] = true;
					if(prime[j+tmp]&&maxc<j+tmp) maxc = j+tmp; 
				}
			}
		}
		if(!maxc) cout << "NA" << endl;
		else cout << maxc << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
template<typename T>void read(T &x){
	x=0;int f(1);char c(getchar());
	for(;!isdigit(c);c=getchar())if(c=='-')f=-f;
	for(; isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c-'0');
	x*=f;
}
template<typename T>void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)write(x/10),x%=10;
	putchar(x+'0');
}
int main(){
	long long A,B,N;
	read(A),read(B),read(N);
	if(N>=B-1)write(A*(B-1)/B);
	else write(A*N/B);
	return 0;
}


Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;




	class contest
	{
				
		
		static void Main(string[] args)
		{

		  
            string s = Console.ReadLine();
            var que = new Queue<char>();
            bool ok = false;
            for(int i=0; i<s.Length; i++)
            {
                if (s[i] == 'C' && que.Count<1)
                    que.Enqueue(s[i]);

                if (que.Count == 1 && s[i] == 'F')
                    ok = true;
            }

            if (ok) Console.WriteLine("Yes");
            else Console.WriteLine("No");
 
           



		
        }
		
		
			
	}


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

using ll = long long;

void solve(long long N, long long D, std::vector<long long> X, std::vector<long long> Y){
    int ans = 0;
    for(int i = 0;i < N;i++){
        if(X[i] * X[i] + Y[i] * Y[i] <= D * D){
            ans++;
        }
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    std::vector<long long> X(N);
    std::vector<long long> Y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
    }
    solve(N, D, std::move(X), std::move(Y));
    return 0;
}


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


int main()
{
	int A,B;
	cin>>A>>B;
	if(A>9||B>9)
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<A*B<<endl;
	return 0;
}


Measured memory_bytes: 256