akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    long N, M; cin >> N >> M;
    vector<pair<long, long>> p(N);
    for (int i = 0; i < N; i++) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());

    long ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(M-p[i].second>0){
            M -= p[i].second;
            ans += p[i].first * p[i].second;
        } else {
            ans += p[i].first * M;
            M = 0;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.*;

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

Measured memory_bytes: 26480
#include <stdio.h>

void bubbleSort(int *,int);

int main(){
  int i,n,a[100];
  scanf("%d",&n);
  if(n<1||n>100)fprintf(stderr,"ERRER\n");
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  bubbleSort(a,n);
}


void bubbleSort(int *a,int n){
  int flag,count=0,x,i,j;
  flag=1;
  for(i=0;flag;i++){
    flag=0;
    for(j=n-1;j>=i+1;j--){
      if(a[j]<a[j-1]){
	x=a[j];
	a[j]=a[j-1];
	a[j-1]=x;
	flag=1;
	count++;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",count);
}
      
	
  



Measured memory_bytes: 2140
#include<stdio.h>

int main()
{

  int N,A[100],i,j,minj,a,c=0;
  
  scanf("%d",&N);

  for(i=0;i<N;i++)
    {
      scanf("%d",&A[i]);
    }
  
  for(i=0; i < N; i++)
    {
      minj = i;
      
      for(j=i; j < N; j++)
	{
	  if(A[j] < A[minj]) minj = j;
	}

      if(A[i] > A[minj]){
	a = A[i];
	A[i] = A[minj];
	A[minj] = a;
	c++;
      }
    }

  for(i=0; i < N; i++)
    {
      printf("%d",A[i]);
      if(i < N-1)printf(" ");
    }

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



Measured memory_bytes: 2100
import sys
N,Y=map(int,input().split())

Man=Y//10000
for x in range(Man+1)[::-1]:
	zanM=Y-x*10000
	Gos=zanM//5000
	for y in range(Gos+1)[::-1]:
		zanG=zanM-y*5000
		z=zanG//1000
		if zanG%1000==0 and x+y+z==N:
			print('{} {} {}'.format(x,y,z))
			sys.exit()
print('{} {} {}'.format(-1,-1,-1))

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

int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a = 0;
		int b = 0;
		for(int i=0;i<n;i++){
			int c,d;
			cin >> c >> d;
			if(c==d){
				a += c;
				b += c;
			}
			else if(c>d) a += c+d;
			else b += c+d;
		}
		cout << a << " " << b << endl;
	}
}

Measured memory_bytes: 1160
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
prv = As[0]
ans = 0
for i in range(N):
    if Bs[i] > prv:
        ans += prv
        if Bs[i] - prv >= As[i+1]:
            ans += As[i+1]
            prv = 0
        else:
            ans += Bs[i] - prv
            prv = As[i+1] - (Bs[i]-prv)
    else:
        ans += Bs[i]
        prv = As[i+1]
print(ans)
            

Measured memory_bytes: 19156
n,m = map(int, input().split(" "))
a = [list(map(int, input().split(" "))) for i in range(n)]
b = [list(map(int, input().split(" "))) for i in range(m)]

for ax, ay in a:
  c = []
  for bx, by in b:
    c.append(abs(bx-ax)+abs(by-ay))
  print(c.index(min(c)) + 1)

Measured memory_bytes: 8944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC175B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] Linput = Console.ReadLine().Split(' ');
            long[] L = new long[N];
            for(int i = 0; i < N; i++)
            {
                L[i] = long.Parse(Linput[i]);
            }
            //Array.Sort(L);
            //Array.Reverse(L);
            int count = 0;
            for(int i = 0; i < N-2; i++)
            {
                for(int j = i + 1; j < N-1; j++)
                {
                    for(int k = j + 1; k < N; k++)
                    {
                        if (L[i] != L[j] & L[i] != L[k])
                        {
                            if (L[j] != L[k])
                            {
                                if (L[i] + L[j] > L[k] & L[i] + L[k] > L[j])
                                {
                                    if (L[k] + L[j] > L[i])
                                    {
                                        count += 1;
                                        //Console.WriteLine("{0}{1}{2}", L[i], L[j], L[k]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  int ans=0;
  rep(i,n){
    if(i==a[a[i]])ans++;
  }
  ans/=2;
  cout << ans << endl;
}

Measured memory_bytes: 640
def main():
    n = int(input())
    # h = [int(s) for s in input().split()]
    ans = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(ans[n-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GS(S);
  map<char, int> list;
  FOR(i, 4) { list[S[i]]++; }
  vector<int> list2;
  for (pair<char, int> p : list) {
    list2.push_back(p.second);
  }
  if (list2.size() == 2 && list2[0] == 2 && list2[1] == 2) {
    print("Yes");
  } else {
    print("No");
  }
  return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 2", "4 1 5" ].solve == 3 );
	assert( [ "13 17", "29 7 5 7 9 51 7 13 8 55 42 9 81" ].solve == 6 );
	assert( [ "10 400000000", "1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000" ].solve == 25 );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	// as[ 0 .. i + 1 ]の和の余りを集計
	auto t = 0L;
	auto rs = [ 0L:1L ];
	foreach( i, a; as )
	{
		t += a;
		rs[ t % m ]++;
	}
	
	// 式変形：( as[0..r+1] - as[0..l+1] ) % m == 0	-->	( as[0..r+1] % m == as[0..l+1] ) % m
	// 余りが同じ範囲から2つ選んだときの組み合わせ数を計算
	auto ans = 0L;
	foreach( r; rs )
	{
		ans += r * ( r - 1 ) / 2;
	}
	return ans;
}


Measured memory_bytes: 9652
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        //int N = s.length();
        String[] array = s.split("");
        
        int start = 0;
        int end = 0;
        String A = "A";
        String Z = "Z";
        for(int i = 0; i < s.length(); i++){
            String a = array[i];
            if(a.equals(A)){
                start = i;
                break;
            }
        }
        for(int i = start; i < s.length(); i++){
            String b = array[i];
            if(b.equals(Z)){
                end = i;
            }
        }

        System.out.println(end-start+1);
        
    }
}

Measured memory_bytes: 54372
#include <iostream>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <complex>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int N = 1e5 + 5, inf = 1e9, mod = 1e9 + 7;

using namespace std;

int main()
{
    IO
    int n, m, a;
    ll sum = 0, ans = 0;
    map<int, int>mp;
    cin >> n >> m;
    mp[0] = 1;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        sum = (sum + a) % m;
        ans += mp[sum];
        mp[sum]++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 6396
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int h = x / 3600;
		int m = (x-h*3600) / 60;
		int s = x - (h*3600) - (m*60);
		
		System.out.println(h+":"+m+":"+s);
		
		
	}

}

Measured memory_bytes: 17168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    if(N % 2 == 0){
        cout << N / 2 - 1 << endl;
    } else {
        cout << N / 2<< endl;
    }
}


Measured memory_bytes: 256
import itertools
import pprint
import numpy as np

def main():
    N, M = map(int, input().split())

    data = list()
    for _ in range(M):
        status = [0 for i in range(N)]
        tmp = list(map(int, input().split()))
        for i in tmp[1:]:
            status[i-1] = 1
        data.append(status)

    bulbs_on = list(map(int, input().split()))

    seq = (0, 1)
    candidates = list(itertools.product(seq, repeat=N))

    result = 0
    for candi in candidates:
        candi = np.array(candi)
        
        i = 0
        for bulb in data:
            bulb = np.array(bulb)
            tmp = list(bulb * candi)
            if sum(tmp)%2 != bulbs_on[i]:
                result -= 1
                break
            i+=1
        result += 1
    
    print(result)
            

if __name__ == "__main__":
    main()

Measured memory_bytes: 12492
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  vector<pair<int64_t,int64_t>>p(N);
  for(int i=0;i<N;i++){
    int64_t x,y;
    cin>>x>>y;
    p[i]=make_pair(x+y,x-y);
  }
  sort(p.begin(),p.end());
  int cnt=1;
  int64_t B=p[0].first;
  for(int i=0;i<N;i++){
    if(i>0&&p[i].second>=B){cnt++;B=p[i].first;}
  }
  cout<<cnt<<endl;
  return 0;
}

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

using namespace std;

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		long long ans = 0;
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) continue;
			if (i % 5 == 0) continue;
			ans += i;
		}
		cout << ans << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int> a = { 3, 5, 7 };
    int result = 0;
    for (int k = 3; k <= 9; k++) {
        int f = pow(3, k);
        rep(i, f)
        {
            int d = i;

            int b = 0;
            vector<int> cnt(3, 0);
            rep(j, k)
            {
                cnt[d % 3]++;
                b = 10 * b + a[d % 3];
                d /= 3;
            }
            if (b <= n && cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0) {
                result++;
            }
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = c - (a - b);
  if (ans >= 0) cout << ans << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<endl
template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

template<class T> inline void chmin(T& a, T b) {
  if (a > b) a = b;
}

const long long INF = 1LL << 60;
int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0 || i % 5 == 0 || (i % 3 == 0 && i % 5 == 0)) continue;
    else ans += i;
  }
  COUT(ans);
  return 0;

}

Measured memory_bytes: 3624
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    map<ll, int> ac;
    for (int i = 0; i < n; i++) ac[a[i]]++;
    int c2 = 0;
    ll eat = 0;
    for (P<ll, int> acc: ac) {
        if (acc.second == 1) continue;
        else if (acc.second > 1) {
            if (acc.second & 1) eat += acc.second / 2 * 2;
            else eat += (acc.second - 2), c2++;
        }
    }
    eat += (c2 * 2 + 3) / 4 * 2;
    cout << n - eat << '\n';
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b)
{
    return((a<b)?a:b);
}
int main()
{
    int n,i;
    cin>>n;
    int h[n];
    int dp[n];
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    {
        dp[i]=min((dp[i-1]+(abs(h[i]-h[i-1]))),(dp[i-2]+abs(h[i]-h[i-2])));
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
# from collections import Counter
# from functools import *

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

s=input()
# a=LI()
# print(a)
t=input()
n=len(s)
for i in range(n):
    if s[i]!=t[i]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,i,j,a[N];
char c[N];
bool ck1(){
	int tot=0;
	for(i=1;i<=n;++i)tot^=a[i]&1&(((n-1)&(i-1))==i-1);
	return tot==1;
}
bool ck2(){
	int tot=0;
	for(i=1;i<=n;++i)if(a[i]&1)return 0;
	for(i=1;i<=n;++i)tot^=(a[i]&2?1:0)&(((n-1)&(i-1))==i-1);
	return tot==1;
}
int main(){
	scanf("%d%s",&n,c+1);for(i=1;i<n;++i)a[i]=abs(c[i]-c[i+1]);--n;
	printf("%d\n",ck1()?1:ck2()?2:0);
}

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

int main() {
  string P, R;
  cin >> P >> R;
  
  int ans = 0;
  for (int i=0; i<3; i++) {
    if (P.at(i) == R.at(i)) {
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint ans;

    if(n==0){
        cout<<0<<endl;
        return 0;
    }

    ll cnt = 0;
    while(n != 0){
        if(n%(2ll<<cnt)==0){
            ans.push_back(0);
        }else{
            ans.push_back(1);
            ll delta = 1ll<<cnt;
            if(cnt%2) delta *= -1;
            n -= delta;
        }
        cnt++;
    }
    reverse(ALL(ans));
    for(auto e:ans) cout<<e;
    cout<<endl;

    return 0;

}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

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

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


signed main(){
    int N, A, B;
    cin >> N >> A >> B;
    PRINT(min(N * A, B));
    return 0;
}

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

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()

    def sieve(num):
        isPrime = [True] * (num+1)
        isPrime[0] = isPrime[1] = False
        for i in range(2, num+1):
            if i * i > num: break
            if not isPrime[i]: continue
            for j in range(i, num+1):
                if i * j > num: break
                isPrime[i * j] = False
        return isPrime

    ps = []
    cs = []
    s = sieve(N)
    for i in range(N+1):
        if s[i]: ps.append(i)
    for p in ps:
        cc, q = 0, p
        while N//q > 0:
            cc += N//q
            q *= p
        cs.append(cc)

    ans = set()
    for i in range(len(cs)):
        if cs[i] >= 74: ans.add((pow(ps[i], 74)))

    for i in range(len(cs)):
        for j in range(len(cs)):
            if i == j: continue
            if cs[i] >= 24 and cs[j] >= 2:
                ans.add(pow(ps[i], 24) * pow(ps[j], 2))
            if cs[i] >= 14 and cs[j] >= 4:
                ans.add(pow(ps[i], 14) * pow(ps[j], 4))

    for i in range(len(cs)):
        for j in range(len(cs)):
            for k in range(len(cs)):
                if i == j or j == k or k == i: continue
                if cs[i] >= 4 and cs[j] >= 4 and cs[k] >= 2:
                    ans.add(pow(ps[i], 4) * pow(ps[j], 4) * pow(ps[k], 2))
    print(len(ans))

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9264
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

abc = inpl()
abc.sort()

print(abc[2]*10+abc[0]+abc[1])


Measured memory_bytes: 4324
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

const ll next_d = 17;
ll n_up(ll now, ll n, vector<vector<ll>>& next)
{
  for (ll i = next_d; i >= 0; --i) {
    if (n & (1 << i)) {
      now = next.at(i).at(now);
    }
  }
  return now;
}

int main()
{
  ll N;
  cin >> N;
  vector<vector<ll>> next(next_d, vector<ll>(N, -1));
  vector<vector<ll>> connection(N);
  for (ll i = 0; i < N; ++i) {
    ll K;
    cin >> K;
    for (ll j = 0; j < K; ++j) {
      ll c;
      cin >> c;
      connection.at(i).push_back(c);
      next.at(0).at(c) = i;
    }
  }


  //深さを求める--------------------------
  vector<ll> depth(N, 0);
  queue<ll> q;
  q.push(0);
  while (!q.empty()) {
    ll now = q.front();
    ll now_d = depth.at(now);
    q.pop();
    for (ll i = 0; i < connection.at(now).size(); ++i) {
      depth.at(connection.at(now).at(i)) = now_d + 1;
      q.push(connection.at(now).at(i));
    }
  }
  // for (ll i = 0; i < N; ++i) {
  //   cout << depth.at(i) << " ";
  // }
  // cout << "\n";
  //----------------------------------------

  //ダブリング--------------------------
  for (ll i = 0; i < next_d - 1; ++i) {
    for (ll j = 0; j < N; ++j) {
      ll temp = next.at(i).at(j);
      if (temp == -1) {
        next.at(i + 1).at(j) = -1;
      }
      else {
        next.at(i + 1).at(j) = next.at(i).at(temp);
      }
    }
  }
  // cout << "next" << "\n";
  // for (ll i = 0; i < next_d; ++i) {
  //   for (ll j = 0; j < N; ++j) {
  //     cout << next.at(i).at(j) << " ";
  //   }
  //   cout << "\n";
  // }
  //----------------------------------------

  // ans------------------------------------
  ll Q;
  cin >> Q;
  for (ll i = 0; i < Q; ++i) {
    ll u, v;
    cin >> u >> v;
    ll ud = depth.at(u), vd = depth.at(v);
    if (vd > ud) {
      swap(vd, ud);
      swap(v, u);
    }
    u = n_up(u, ud - vd, next);
    ud = vd;
    ll l = -1, r = ud + 1;
    ll ans, temp;
    while (l + 1 != r) {
      ll m = (l + r) / 2;
      temp = n_up(u, m, next);
      if (temp == n_up(v, m, next)) {
        r = m;
        ans = temp;
      }
      else {
        l = m;
      }
    }
    cout << ans << "\n";
  }
  //----------------------------------------
}



Measured memory_bytes: 22304
#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<list>
#include<set>
#include<iomanip>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<sstream>
#include<algorithm>
using namespace std;
#define MAXN 10005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
typedef long long ll;


int main()
{
	string a,b;
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	//cout<<a<<" "<<b<<endl;
	if(a<b)
	cout<<"Yes\n";
	else
	cout<<"No\n";
	return 0;
}















Measured memory_bytes: 256
import heapq
N = int(input())
v = list(map(int, input().split()))
heapq.heapify(v)
for i in range(N-1):
  v1 = heapq.heappop(v)
  v2 = heapq.heappop(v)
  heapq.heappush(v, (v1 + v2) / 2)
print(v[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long long LINF=1e18;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  vector<int> w(n+1,0);
  for(int i=0;i<n;i++)w[i+1]=w[i]+v[i];
  int sum=w[n];
  int ans=LINF;
  for(int i=0;i<=n;i++){
    int a=w[i];
    int b=sum-a;
    chmin(ans,abs(a-b));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    string s; cin >> s;
    int k; cin >> k;
    int zint = 'z' - 'a';
    rep(i, s.size()) {
        int sint = s[i] - 'a';
        if (sint == 0) continue;
        int fora = zint - sint + 1;
        if (fora <= k) {
            s[i] = 'a';
            k -= fora;
        }
    }
    int mk = s[s.size()-1] - 'a' + k;
    mk %= 26;
    s[s.size() - 1] = char('a' + mk);
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)

int main()
{
    int n;
    double a,ans=0;
    cin>>n;
    REP(i,n)
    {
        cin>>a;
        ans+=1.0/a;
    }
    printf("%.10f\n",1.0/ans);
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
ans = 0

for i in range(1,len(p)-1):
	if p[i-1] <= p[i] and p[i] <= p[i+1]:
		ans += 1
	elif p[i-1] >= p[i] and p[i] >= p[i+1]:
		ans += 1

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory>
#include<cmath>
#include<algorithm>
#include<vector>
int main(){
    int N;
    std::vector<int> vec;



    std::cin>>N;
    
    if(N==0){
        std::cout<<0<<std::endl;
        return 0;
    }
    
    while(N!=0){
        vec.emplace_back(abs(N%2));
        N-=abs(N%2);
        N/=-2;
    }

    
    for(int i=vec.size()-1;0<=i;i--) std::cout<<vec[i];
    std::cout<<std::endl;

    return 0;
}

Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 998244353LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        if (n<r||n<0||r<0) return 0;
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<300000, ll, MOD> fact;

int main() {
    fastio();
    ll N, A, B, K, ans = 0;
	cin >> N >> A >> B >> K;
    ll g = gcd(A, B);
    if(K%g==0) {
        ll s, ca=B/g, cb=A/g;
        int i, j;
        for (i=0, j=N; i<=N && i*A<=K; i++) {
            while ((s=i*A+j*B)>K) j--;
            if (s==K) break;
        }
        while(i<=N && j>=0) {
            ans = (ans+fact.comb(N,i)*fact.comb(N,j))%MOD;       
            i += ca; j -= cb;
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct segment_tree{
	int N;
	vector<T> ST;
	function<T(T, T)> f;
	T E;
	segment_tree(){
	}
	segment_tree(int n, function<T(T, T)> f, T E): f(f), E(E){
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, E);
	}
	void update(int k, T x){
		k += N - 1;
		ST[k] = x;
		while (k > 0){
			k = (k - 1) / 2;
			ST[k] = f(ST[k * 2 + 1], ST[k * 2 + 2]);
		}
	}
	T query(int L, int R, int i, int l, int r){
		if (r <= L || R <= l){
			return E;
		} else if (L <= l && r <= R){
			return ST[i];
		} else {
			int m = (l + r) / 2;
			return f(query(L, R, i * 2 + 1, l, m), query(L, R, i * 2 + 2, m, r));
		}
	}
	T query(int L, int R){
		return query(L, R, 0, 0, N);
	}
};
template <typename T>
struct euler_tour_path_query_commutative{
	vector<T> A;
	vector<int> left;
	vector<int> right;
	T E;
	function<T(T, T)> f;
	function<T(T)> inv;
	segment_tree<T> ST;
	void dfs(int v, vector<vector<int>> &c){
		left[v] = A.size();
		A.push_back(E);
		for (int w : c[v]){
			dfs(w, c);
		}
		right[v] = A.size();
		A.push_back(E);
	}
	euler_tour_path_query_commutative(vector<vector<int>> &c, function<T(T, T)> f, function<T(T)> inv, T E): f(f), inv(inv), E(E){
		int N = c.size();
		left = vector<int>(N);
		right = vector<int>(N);
		dfs(0, c);
		ST = segment_tree<T>(A.size(), f, E);
	}
	void update(int v, T x){
		A[left[v]] = x;
		ST.update(left[v], x);
		ST.update(right[v], inv(x));
	}
	T query(int v){
		return ST.query(0, left[v] + 1);
	}
};
long long add(long long a, long long b){
  return a + b;
}
long long neg(long long a){
  return -a;
}
int main(){
  int n;
  cin >> n;
  vector<int> p(n, -1);
  vector<vector<int>> c(n);
  for (int i = 0; i < n; i++){
    int k;
    cin >> k;
    c[i] = vector<int>(k);
    for (int j = 0; j < k; j++){
      cin >> c[i][j];
      p[c[i][j]] = i;
    }
  }
  euler_tour_path_query_commutative<long long> ET(c, add, neg, 0);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++){
    int t;
    cin >> t;
    if (t == 0){
      int v;
      long long w;
      cin >> v >> w;
      ET.update(v, ET.A[ET.left[v]] + w);
    }
    if (t == 1){
      int u;
      cin >> u;
      cout << ET.query(u) << endl;
    }
  }
}


Measured memory_bytes: 18012
N,M = map(int, input().split())
H_list =  [0] + [int(e) for e in input().split()]

best_observatories_higher = {i:H_list[i] for i in range(1,N+1)}
same_higher_observatories_flag = {i:False for i in range(1,N+1)}

for i in range(M):
    A,B = map(int, input().split())

    if H_list[A] > H_list[B]:
        if best_observatories_higher[B] < H_list[A]:
            best_observatories_higher[B] = H_list[A]

    elif H_list[A] < H_list[B]:
        if best_observatories_higher[A] < H_list[B]:
            best_observatories_higher[A] = H_list[B]

    elif H_list[A] == H_list[B]:
        if best_observatories_higher[A] == H_list[B]:
            same_higher_observatories_flag[A] = True
        if best_observatories_higher[B] == H_list[A]:
            same_higher_observatories_flag[B] = True

ans = 0

for i in range(1,N+1):
    if best_observatories_higher[i] == H_list[i] and same_higher_observatories_flag[i] == False:
        ans += 1

#愚直解　TLEする
#connected_observatories_dict = {i:set() for i in range(1,N+1)}

#for i in range(M):
#    A,B = map(int, input().split())
#    connected_observatories_dict[A].add(B)
#    connected_observatories_dict[B].add(A)

#ans = 0

#for i in range(1,N+1): #10**5
#    best_H = max([H_list[connected_observatory] for connected_observatory in connected_observatories_dict[i]])
#    if H_list[i] < best_H:
#        ans += 1

print(ans)

Measured memory_bytes: 34864
#include <stdio.h>

int main(void)
{
    int m, nmin, nmax;
    int P[2001];
    int min;
    int i, j;
    int out;
    
    while (1){
        scanf("%d%d%d", &m, &nmin, &nmax);
        if (m == 0 && nmin == 0 && nmax == 0){
            break;
        }
        for (i = 0; i < m; i++){
            scanf("%d", &P[i]);
        }
        min = 10000;
        for (i = nmin; i <= nmax; i++){
            if (min >= P[i] - P[i - 1]){
                min = P[i] - P[i - 1];
                out = i;
            }
        }
        
        printf("%d\n", out);
    }
    
    return (0);
}



Measured memory_bytes: 2036
package main

import "fmt"

func main() {
	var a, b, c int
	kawaisou := 0
	fmt.Scan(&a, &b, &c)
	if a == b {
		kawaisou++
	}
	if b == c {
		kawaisou++
	}
	if c == a {
		kawaisou++
	}
	if kawaisou == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int A = sc.nextInt();
	    int B = sc.nextInt();
		int C = sc.nextInt();
		int a = 0, b = 0;

		if(A == 5) a++;
		else if(A == 7) b++;

		if(B == 5) a++;
		else if(B == 7) b++;

		if(C == 5) a++;
		else if(C == 7) b++;

		if(a == 2 && b == 1) System.out.println("YES");
		else System.out.println("NO");
	}
}


Measured memory_bytes: 22612
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

k = ni()
x, y = na()

def go(x, y, k):
    if (x+y) % 2 != 0 and k % 2 == 0:
        return None
    if x < 0:
        res = go(-x, y, k)
        for u in res:
            u[0] = -u[0]
        return res
    if y < 0:
        res = go(x, -y, k)
        for u in res:
            u[1] = -u[1]
        return res

    ops = []
    while x+y >= 2*k and x >= k:
        ops.append([k, 0])
        x -= k
    while x + y >= 2 * k and y >= k:
        ops.append([0, k])
        y -= k
    if (x+y) % k == 0:
        while x >= k:
            ops.append([k, 0])
            x -= k
        while y >= k:
            ops.append([0, k])
            y -= k
        if x > 0 and y > 0:
            ops.append([x, y])
        return ops

    if (x+y) % 2 == 0:
        mid = (x + y) // 2
        if mid <= x:
            ops.append([mid, -(k-mid)])
            ops.append([x-mid, y+(k - mid)])
        else:
            ops.append([x+(k-mid), mid-x])
            ops.append([-(k-mid), y-(mid-x)])
        return ops

    if x >= k:
        ops.append([k, 0])
        res = go(x-k, y, k)
        ops.extend(res)
        return ops

    ops.append([x, k-x])
    res = go(0, y-(k-x), k)
    ops.extend(res)
    return ops

res = go(x, y, k)
if not res:
    print(-1)
    sys.exit(0)

print(len(res))
cx, cy = 0, 0
for o in res:
    cx += o[0]
    cy += o[1]
    print(cx, cy)

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

bool f(string x){
  int n = x.size();
  for(int i = 0; i < n/2 ; i++){
    if(x.at(i) != x.at(n - 1 - i)){
      return false;
      break;
    }
  }
  return true;
}
    
int main(){
  string S;
  cin >> S;
  
  bool m = false;
  int n = S.size();
    
  
  string s1;
  string s2;
  
  if(f(S)){
    s1 = S.substr(0,(n - 1)/2);
    s2 = S.substr((n + 1)/2);
    
    if(f(s1)){
      if(f(s2)){
        m = true;
      }
    }
  }
  
  if(m) cout << "Yes" << endl;
  if(!m) cout << "No" << endl;
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("src/aoj2102/input.txt"));
			System.setOut(new PrintStream(new FileOutputStream("src/aoj2102/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}



	Scanner sc;
	void run() {
		sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T-->0) {
			int[] num = new int[9];
			String colors = "RGB";

			int[][] hand = new int[3][9];
			for (int i = 0; i < 9; i++) num[i] = sc.nextInt() - 1;
			for (int i = 0; i < 9; i++) {
				String coler = sc.next();
				int idx = colors.indexOf(coler.charAt(0));
				hand[idx][num[i]]++;
			}

			int done = 0;
			for (int coler = 0; coler < 3; coler++) {
				for (int i = 0; i + 2 < 9; i++) while (hand[coler][i] > 0 && hand[coler][i+1] > 0 && hand[coler][i+2] > 0) {
					hand[coler][i]--; hand[coler][i+1]--; hand[coler][i+2]--;
					done += 3;
				}
				for (int i = 0; i < 9; i++) while (hand[coler][i] >= 3){
					hand[coler][i] -= 3;
					done += 3;
				}

			}
			System.out.println(done == 9 ? 1 : 0);
		}
	}


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

Measured memory_bytes: 12000
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, K = in.nextInt
  val Mod = 1_000_000_007
  def sum(min: Long, max: Long): Long = (min + max) * (max - min + 1) / 2
  val ans = (K to N + 1).foldLeft(0L){(s, k) =>
    (s + sum(N + 1 - k, N) - sum(0, k - 1) + 1) % Mod
  }
  println(ans)
}

Measured memory_bytes: 56868
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll a,b,c;cin>>a>>b>>c;
    ll k=0;
    while(k<=c){
        if(b<=k&&k<=c)dame("OK");
        k+=a;
    }
    out("NG");
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back


int main() {
  ll a,b,n; cin>>a>>b>>n;
  cout<<a*min(b-1,n)/b<<endl;
}


Measured memory_bytes: 3632
<?php
list($n, $m) = explode(" ", trim(fgets(STDIN)));
for($i = 0; $i < $n; $i++){
    $line = trim(fgets(STDIN));
    for($j = 0; $j < $n; $j++){
        $map[$i][$j] = $line[$j];
    }
}
for($i = 0; $i < $m; $i++){
    $line = trim(fgets(STDIN));
    for($j = 0; $j < $m; $j++){
        $map2[$i][$j] = $line[$j];
    }
}
for($X = 0; $X <= $n - $m; $X++){
    for($Y = 0; $Y <= $n - $m; $Y++){
        $flag = true;
        for($x = 0; $x < $m; $x++){
            for($y = 0; $y < $m; $y++){
                if($map[$X+$x][$Y+$y] != $map2[$x][$y]){
                    $flag = false;
                }
            }            
        }
        if($flag == true){
            echo "Yes";exit;
        }
    }
}
echo "No";

Measured memory_bytes: 4728
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int q;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> q;
    while (q-->0) {
        string x, y; cin >> x >> y;
        vvll dp(x.size() + 1, vll(y.size() + 1, 0));
        for (int xi = 0; xi < x.size(); xi++) {
            for (int yi = 0; yi < y.size(); yi++) {
                if (x[xi] == y[yi]) dp[xi + 1][yi + 1] = dp[xi][yi] + 1;
                else dp[xi + 1][yi + 1] = max(dp[xi][yi + 1], dp[xi + 1][yi]);
            }
        }
        cout << dp[x.size()][y.size()] << '\n';
    }
    return 0;
}



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

using namespace std;

int main()
{
	string str, left, right;
	int m, h;

	while (1) {
		cin >> str;
		if (str == "-") break;

		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> h;
			left = str.substr(0, h);
			right = str.substr(h);
			str = right + left;
		}
		cout << str << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
from collections import defaultdict
from bisect import *

def into_dict(dics,x,y,u):
  x,y = int(x),int(y)
  insort(dics[u+'_x'][x],y)
  insort(dics[u+'_y'][y],x)
  insort(dics[u+'_xpy'][x+y],x)
  insort(dics[u+'_ymx'][y-x],x)
  return dics

def para(dics,dic1,dic2):
  ans = float('inf')
  for k,v in dics[dic1].items():
    for zahyou in v[1:-1]:
      ind = bisect_right(dics[dic2][k],zahyou)
      dis = zahyou-dics[dic2][k][ind-1]
      ans = min(ans,dis)
  return ans

import sys; input=sys.stdin.readline
def solve():
  ans = []
  N = int(input())
  dics = defaultdict(lambda: defaultdict(lambda: [-float('inf'),float('inf')]))
  for i in range(N):
    dics = into_dict(dics,*input().split())
  lis1 = [['L_y','R_y'],['D_x','U_x']]
  lis2 = [['L_ymx','U_ymx'],['U_xpy','R_xpy'],['L_xpy','D_xpy'],['D_ymx','R_ymx']]
  for arg in lis1:
    ans.append(para(dics,*arg)*5)
  for arg in lis2:
    ans.append(para(dics,*arg)*10)
  ans = min(ans)
  return ans if ans<float('inf') else 'SAFE'
print(solve())

Measured memory_bytes: 249984
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    while(1){
        ll n; cin >> n;
        if(!n) break;
        vvl t(n,vl(n+1));
        rep(i,n) rep(j,n+1) cin >> t[i][j];
        vl dp(1<<n,inf);
        dp[0] = 0;
        rep(bit,1<<n){
            rep(nxt,n){
                if(bit>>nxt & 1) continue;
                ll mn = t[nxt][0];
                rep(i,n){
                    if(bit>>i & 1) chmin(mn, t[nxt][i+1]);
                }
                chmin(dp[bit | (1<<nxt)], dp[bit] + mn);
            }
        }
        cout << dp[(1<<n)-1] << "\n";
    }
}


Measured memory_bytes: 3668