akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int n = ReadInt();
        var a = new int[100000];
        long sum = 0;
        foreach (var x in ReadInt(n))
        {
            a[x - 1]++;
            sum += x;
        }
        int q = ReadInt();
        for (int i = 0; i < q; i++)
        {
            int b = ReadInt();
            int c = ReadInt();
            sum += a[b - 1] * (c - b);
            a[c - 1] += a[b - 1];
            a[b - 1] = 0;
            Console.WriteLine(sum);
        }
    }
}


static class Scanner
{
    static Queue<string> que = new Queue<string>();

    public static string Read()
    {
        if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s);
        return que.Dequeue();
    }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());
    public static decimal ReadDecimal() => decimal.Parse(Read());

    public static IEnumerable<string> Read(long n)
    {
        for (long i = 0; i < n; i++) yield return Read();
    }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
    public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse);
    public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}

Measured memory_bytes: 50280
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
	int a,b;
  cin >> a >> b;
  if(a%2==1&&b%2==1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int a = scan.nextInt();
     int b = scan.nextInt();
     
     if( a < b ) {
    	 System.out.println("a < b");
     }else if( a > b ){
    	 System.out.println("a > b");
     }else{
    	 System.out.println("a == b");
     }
    }
}



Measured memory_bytes: 25964
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, a[212345];

int main() {

	cin >> N;
	rep(i, N) cin >> a[i];

	int C = 0;
	int cur = 1;

	rep(i, N) {
		if (a[i] == cur) {
			C++;
			cur++;
		}
	}

	if (C) cout << N - C << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="SUN") puts("7");
	if(s=="MON") puts("6");
	if(s=="TUE") puts("5");
	if(s=="WED") puts("4");
	if(s=="THU") puts("3");
	if(s=="FRI") puts("2");
	if(s=="SAT") puts("1");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int h, w, d;
    cin >> h >> w >> d;
    int as[h*w+1][2];
    int r[h*w+1];
    int a;
    as[0][0] = 0;
    as[0][1] = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a;
            as[a][0] = i;
            as[a][1] = j;
        }
    }
    for(int i = 0; i < d; i++){
        r[i] = 0;
    }
    for(int i = d+1; i <= h*w; i++){
        r[i] = r[i-d]+(abs(as[i-d][0]-as[i][0])+abs(as[i-d][1]-as[i][1]));
    }

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int L,R;
        cin >> L >> R;
        cout << r[R]-r[L] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    int q;
    cin >> q;
    rep(zz,q){
        int a,b,c,d;
        int cnt = 0;
        cin >> a >> b >> c >> d;
        a--;
        b--;
        c--;
        d--;
        for(int i=a;i<=c;i++){
            for(int j=b;j<=d;j++){
                if(i%2==0&&j%2==1){

                }else{
                    cnt++;
                }
            }
        }
        cout << cnt << "\n";
    }


    return 0;
}


Measured memory_bytes: 3076
n=int(input())
sl=list(input())

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "#":
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**6
for i in range(n-1):
	if (sl[i]=="#" and sl[i+1]==".") or (sl[i]=="." and sl[i+1]=="#") :
		c = b[i] + w[n-1]-w[i]
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w[0]==1:
	for i in range(n-1):
		if w[i]==w[i+1]:
			w0=w[n-1]-w[i]
			break
if b[n-1]-b[n-2]==1:
	for i in range(n-1):
		if b[n-1-i]==b[n-1-i-1]:
			b0=b[n-1-i]
			break

if w0<res:
	res=w0
if b0<res:
	res=b0

print(res)

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

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  int n, k; cin >> n >> k;
  vl v(n);

  rep(i, n) cin >> v[i];
  sort(all(v));

  ll ans = linf;

  for(int i = 0; i <= n - k; i++){
    chmin(ans , v[i + k - 1] - v[i]);
  }

  pr(ans);

  return 0;
}


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

namespace _067_TheNumberofIsland
{
	class Program
	{
		const char Exist = '1';
		const char NotExist = '0';

		static void Main ( string[] args )
		{
			string[] inputStr = new string[14];
			inputStr[0] = new string (NotExist, 14);
			inputStr[13] = new string (NotExist, 14);

			do
			{
				for (int lp = 1; lp < inputStr.Length - 1; lp++)
				{
					inputStr[lp] = NotExist + Console.ReadLine () + NotExist;
				}

				int result = IsLandCount (inputStr);

				Console.WriteLine (result);

			} while ((inputStr[1] = Console.ReadLine ()) != null);
		}

		static int IsLandCount ( string[] state )
		{
			char[][] map = new char[state.GetLength (0)][];

			int limit = state.Length;
			int limit2 = state[0].Length;

			for (int lp = 0; lp < limit; lp++)
			{
				map[lp] = state[lp].ToCharArray ();
			}

			//delete area
			Stack<Point> mapPoint = new Stack<Point> (10);
			int count = 0;

			Point[] offset = { 
				 new Point (1, 0), 
				 new Point (-1, 0), 
				 new Point (0, 1), 
				 new Point (0, -1), 
			};

			for (int col = 1; col < limit - 1; col++)
			{
				for (int row = 1; row < limit2 - 1; row++)
				{
					if (map[col][row] == Exist)
					{
						mapPoint.Push (new Point (col, row));

						while (mapPoint.Count != 0)
						{
							Point item = mapPoint.Pop ();
							map[item.X][item.Y] = NotExist;

							for (int lp = 0; lp < offset.Length; lp++)
							{
								Point p = item.Offset (offset[lp]);

								if (map[p.X][p.Y] == Exist)
								{
									mapPoint.Push (p);
								}
							}
						}

						count++;
					}
				}
			}

			return count;
		}

		class Point
		{
			public Point ( int x, int y )
			{
				this.X = x;
				this.Y = y;
			}

			public int X { private set; get; }
			public int Y { private set; get; }

			public Point Offset ( Point ob )
			{
				return new Point (X + ob.X, Y + ob.Y);
			}
		}

	}
}

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

int main(){
  long long N,cnt=1,ans=0;
  string s;
  cin >> N;
  vector<string> vec(N+1);
  for(long long i=0;i<N;i++){
    cin >> s;
    sort(s.begin(),s.end());
    vec[i]=s;
  }
  vec[N]="zzzzzzzzzzz";
  sort(vec.begin(),vec.end());
  for(long long j=1;j<N+1;j++){
    if(vec[j]==vec[j-1]){
      cnt++;
    }
    else{
      ans+=(cnt*(cnt-1))/2;
      cnt=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
#include <cstdio>
constexpr long long MOD = 1000000007;
int as[100000];
int n;

long long dfs(int m, int a, int b, int c)
{
  if (m >= n)
  {
    return 1;
  }
  int d = 0;
  int first = -1;
  if (as[m] == a)
  {
    ++d;
    first = 0;
  }
  if (as[m] == b)
  {
    ++d;
    if (first < 0) first = 1;
  }
  if (as[m] == c)
  {
    ++d;
    if (first < 0) first = 2;
  }
  switch (first)
  {
    case -1:
      return 0;
    case 0:
      return d * dfs(m + 1, a + 1, b, c) % MOD;
    case 1:
      return d * dfs(m + 1, a, b + 1, c) % MOD;
    case 2:
      return d * dfs(m + 1, a, b, c + 1) % MOD;
  }
}

int main()
{
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", as + i);
  }
  printf("%lld\n", dfs(0, 0, 0, 0));
}


Measured memory_bytes: 2048
import statistics
n = int(input())

a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
ans = 0

for i in range(n):
    a[i],b[i] = map(int,input().split())

ma = statistics.median(a)
mb = statistics.median(b)

if(n%2 == 1):
    ans = mb-ma + 1
else:
    ans = 2*(mb-ma) + 1

print(int(ans))


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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

const int MAX_V = 300;

struct edge{int to, cap, rev; };

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, 0, G[from].size()-1});
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty()){
		int v = que.front(); que.pop();
		for(int i = 0; i < G[v].size(); i++){
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v]+1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v, int t, int f){
	if(v == t) return f;
	for(int &i = iter[v]; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]){
			int d = dfs(e.to, t, min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		bfs(s);
		if(level[t] < 0) return flow;
		memset(iter,0, sizeof(iter));
		int f;
		while((f = dfs(s, t, INF)) > 0){
			flow += f;
		}
	}
}

int n;
int a[100], b[100];
int c[100], d[100];

int main() {
    cin >> n;
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,n) cin >> c[i] >> d[i];
    rep(i,n) add_edge(2*n, i, 1);
    rep(i,n) add_edge(n+i, 2*n+1, 1);
    rep(i,n) {
        rep(j,n) {
            if (a[i] < c[j] && b[i] < d[j]) {
                add_edge(i, j+n, 1);
            }
        }
    }
    cout << max_flow(2*n, 2*n+1) << endl;
}
































Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{

    int a,b;
    int d,r;
    double f;

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

    d = a / b;
    r = a % b;
    f = 1.0 * a / b;

    printf("%d %d %.6f\n",d,r,f);
    
    return 0;
}


Measured memory_bytes: 2768
// A. 

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	int prev = -1, cnt = 0, ans = 0;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		if (prev == a) {
			++cnt;
		} else {
			ans += cnt / 2;
			cnt = 1;
		}
		prev = a;
	}
	ans += cnt / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
ans = []

while True:
    n, x = [int(x) for x in input().split()]
    if n == 0 and x == 0: break
    s = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                s += (i + j + k == x)
    ans.append(s)

for s in ans:
    print(s)



Measured memory_bytes: 5604
import sys
sys.setrecursionlimit(1000000000)

def main():
    N,M = map(int,input().split())
    e = [[] for i in range(N)]
    t = 0
    a = []
    for i in range(M):
        r,l,d = map(int,input().split())
        e[r-1].append((l-1,d))
        e[l-1].append((r-1,-d))
        a.append(r-1)
        a.append(l-1)
        t = r-1

    col = [ float("inf") for i in range(N) ]
    def dfs(i,c):
        for node in e[i]:
            if col[node[0]] == float("inf"):
                col[node[0]] = c + node[1]
                dfs(node[0],c+node[1])
            elif col[node[0]] != c + node[1]:
                print("No")
                exit()


    dfs(t,0)
    a = list(set(a))
    for i in a:
        if col[i] == float("inf"):
            dfs(i,0)


    print("Yes")


if __name__ == '__main__':
    main()


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

int main()
{
  string a, b;
  cin >> a >> b;
  for (i64 i = 1; i < 4; i++)
  {
    string s = to_string(i);
    if (s != a && s != b)
    {
      cout << s << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b = rm()
print(a/b)














Measured memory_bytes: 26600
#!/usr/bin/env python3


def exchange(x):
    num500, rest1 = divmod(x, 500)
    num5 = rest1 // 5
    return num500 * 1000 + num5 * 5


def main():
    x = int(input())
    print(exchange(x))


if __name__ == "__main__":
    main()


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

int main(void) {

  int num;
  char buf[150];
  int i,j;
  
  while(fgets(buf,sizeof(buf),stdin)!=NULL) {

    buf[strlen(buf)-1]='\0';
    //printf("%d",strlen(buf));
    for(i=0;i<strlen(buf);i++) {
     
      if(i<strlen(buf)-2 && buf[i]=='@') {
	num=buf[i+1]-'0';
	//printf("\n%d\n",num);
	for(j=0;j<num;j++) printf("%c",buf[i+2]);
	i=i+2;
      }
      else printf("%c",buf[i]);
    }

    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int h = Integer.parseInt(str[0]);
		int w = Integer.parseInt(str[1]);

		int c[][] = new int[10][10];
		int a[][] = new int[h][w];

		for (int i = 0; i < 10; i++) {
			str = br.readLine().split(" ");
			for (int j = 0; j < 10; j++) {
				c[i][j] = Integer.parseInt(str[j]);
			}
		}
		for (int i = 0; i < h; i++) {
			str = br.readLine().split(" ");
			for (int j = 0; j < w; j++) {
				a[i][j] = Integer.parseInt(str[j]);
			}
		}
		int b[][] = warshallFloyd(c);
		int ans = 0;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i][j] != -1) {
					ans += b[a[i][j]][1];
				}
			}
		}
		System.out.println(ans);
	}

	static int[][] warshallFloyd(int dp[][]) {
		int b[][] = dp;

		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					b[i][j] = Math.min(b[i][j], b[i][k] + b[k][j]);
				}
			}
		}
		return b;
	}
}

Measured memory_bytes: 27476
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define N 200010
#define ll long long
using namespace std;
struct node{
	ll a,b;
	int c;
	bool operator <(const node d)const{return a<d.a;}
}v[N];
bool vis[N];
int s[N];
int main()
{
	int n,t=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&v[t+1].a,&v[t+2].a);
		v[t+1].b=v[t+2].b=i;
		v[t+1].c=0,v[t+2].c=1;
		t+=2;
	}
	sort(v+1,v+t+1);
    long long res=0;
    bool have=false;
    for(int i=1;i<=n;i++)
	{
		s[v[i].c]++;
		res+=v[i].a;
		if(vis[v[i].b]) have=true;
		else vis[v[i].b]=true;
	}
	if(have || s[0]==n || s[1]==n){printf("%lld\n",res);return 0;}
	res+=v[n+1].a-v[n].a;
	s[v[n].c]--,s[v[n+1].c]++;
	if(s[0]==n || s[1]==n){printf("%lld\n",res);return 0;}
	if(v[n].b==v[n+1].b) res+=min(v[n+2].a-v[n+1].a,v[n].a-v[n-1].a);
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 7996
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,g;
	cin>>n>>g;
	vl p(n),c(n);
	rep(i,n){
		cin>>p[i]>>c[i];
	}
	ll ans=LINF;
	rep(s,1ll<<n){
		ll score=0,other=-1,cnt=0;
		rep(i,n){
			if(s&(1ll<<i)){
				score+=100*(i+1)*p[i]+c[i];
				cnt+=p[i];
			}else chmax(other,i);
		}
		if(g-score>0 and other!=-1){
			int need=ceil((g-score)/(100.0*(other+1)));
			if(need<p[other]){
				score+=100*(other+1)*need;
				cnt+=need;
			}
		}
		if(score>=g)chmin(ans,cnt);
	}
	puta(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  vector<string> W(N);
  rep(i, N) cin >> W[i];
  map<string, ll> cnt;

  cnt[W[0]]++;

  rep2(i, 1, N){
    if(W[i - 1][W[i - 1].size() - 1] != W[i][0]){
      cout << "No\n";
      return 0;
    }
    if(cnt[W[i]] > 0){
      cout << "No\n";
      return 0;
    }

    cnt[W[i]]++;    
  }

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


Measured memory_bytes: 3636
'use strict'

const main = input => {
	const n = input.trim()
	if (n[0] === n[1] && n[1] === n[2]) console.log('Yes')
	else if (n[1] === n[2] && n[2] === n[3]) console.log('Yes')
	else console.log('No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

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

	int ans = 0;
	ll cur = n;

	for(ll i = 2LL; i * i <= n; ++i) {
		if (cur % i) continue;
		int num = 0;
		while(cur % i == 0) cur /=i, num++;

		int coef = 1;
		while(num - coef >= 0) ans++, num -= coef, coef++;
	}

	if(cur != 1) ans++;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3612
N,M=gets.split.map(&:to_i)
as=gets.split.map(&:to_i)
bs=gets.split.map(&:to_i)
MOD=1000000007
as.unshift(nil)
bs.unshift(nil)
dp=Array.new(N+1){Array.new(M+1,1)}
1.upto(N) do |i|
  1.upto(M) do |j|
    if as[i]==bs[j]
      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD
    else
      dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
    end
  end
end
puts dp[N][M]%MOD

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

  sort(a.rbegin(), a.rend());

  ll ans = a[0];
  rep(i, (n - 2) / 2) { ans += (ll)a[1 + i] * 2; }
  if (n % 2 == 1) ans += a[1 + (n - 2) / 2];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <algorithm>
int main(int argc, char** argv)
{
    int N;
    std::cin >> N;

    std::vector<int> A(N);
    std::vector<int> B(N);

    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
        B[i] = A[i];
    }

    std::sort(std::begin(B), std::end(B));

    for (int i = 0; i < N; i++) {
        if (A[i] != B[N-1]) {
            std::cout << B[N-1] << std::endl;
        }
        else {
            std::cout << B[N-2] << std::endl;
        }
    }

    return 0;
}

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


void solve(long long N, long long K){
    auto a = N % K;
    auto b = K - a;
    cout << min(a, b) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
s = readline().rstrip().decode('utf-8')
res = s.count(".")
ans = res
for i in range(n):
    if s[i] == "#":
        res += 1
    else:
        res -= 1
    ans = min(ans,res)

print(ans)

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

typedef long long ll;

const int maxn = 3000;
int n, arr[maxn];
ll dp[maxn][maxn][2];

ll dfs(int s, int e, int t) {
    if (s > e) return 0;
    if (dp[s][e][t] != 0x3f3f3f3f3f3f3f3f) return dp[s][e][t];
    ll ans;
    if (!t) {
        ans = max(arr[s] + dfs(s + 1, e, !t), arr[e] + dfs(s, e - 1, !t));
    } else {
        ans = min(-arr[s] + dfs(s + 1, e, !t), -arr[e] + dfs(s, e - 1, !t));
    }
    return dp[s][e][t] = ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    memset(dp, 0x3f, sizeof dp);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }

    ll ans = dfs(0, n - 1, 0);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 141184
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;

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

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){

   	int n;
   	scanf("%d", &n);
   	vector<vector<int> > m(n, vector<int>(3));
   	vector<vector<int> > dp(n+1, vector<int>(3, 0));
   	for(int i = 0; i < n; i++){
   		for(int j = 0; j < 3; j++){
   			scanf("%d", &m[i][j]);
   		}
   	}

   	dp[0][0] = m[0][0];
   	dp[0][1] = m[0][1];
   	dp[0][2] = m[0][2];

   	for(int i = 1; i < n; i++){
   		for(int j = 0; j < 3; j++){
   			dp[i][j] = m[i][j] + max({dp[i-1][(3+j-1)%3], dp[i-1][(3+j+1)%3]});
   		}
   	}
	printf("%d\n", max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}));
	return 0;
}

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

using namespace std;

int n;
long long x[200005], ans;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", x + i);
		if (i) {
			ans += max(0LL, x[i - 1] - x[i]);
			x[i] = max(x[i - 1], x[i]);
		}
	}
	printf("%lld\n", ans);
}

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

int main() {
  string s;
  cin >> s;

  int score=0;
  int gn=1, pn=0;
  if (s[0] == 'p') score -= 1;

  for (int i=1; i<s.size(); i++) {
    if (s[i] == 'p') {
      if (pn == gn) {
        score -= 1;
        gn += 1;
      } else {
        pn += 1;
      }
    } else {
      if (pn < gn) {
        score += 1;
        pn += 1;
      } else {
        gn += 1;
      }
    }
  }

  cout << score << endl;
  return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> A(N + 1), L(N + 1);
    for(int i = 1; i <= N; i++) cin >> A[i];

    L[0] = -1;
    int len = 0;
    for(int i = 1; i <= N; i++){
        if(L[len] < A[i]){
            len++;
            L[len] = A[i];
        } else {
            *lower_bound(L.begin(), L.begin() + len, A[i]) = A[i];
        }
    }

    cout << len << endl;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<ll> a(x), b(y), c(z), d, e, ans;
	FOR(i, x)cin >> a[i];
	FOR(i, y)cin >> b[i];
	FOR(i, z)cin >> c[i];
	
	FOR(i, x) {
		FOR(j, y)d.push_back(a[i] + b[j]);
	}
	SORT(d);
	int xy = x * y;
	int m = min(k, xy);
	for (int i = 0; i < m; i++)e.push_back(d[xy - 1 - i]);
	FOR(i, m) {
		FOR(j, z)ans.push_back(e[i] + c[j]);
	}
	SORT(ans);
	for (int i = 0; i < k; i++)cout << ans[ans.size() - 1 - i] << endl;

	return 0;
}


Measured memory_bytes: 43272
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;
const int MAX_N = 100000;
const int MAX_V = 1000000000;
int N;
int X[MAX_N];
int L[MAX_N];
void input(){
scanf("%d", &N);
for(int i = 0; i < N; ++i){
scanf("%d%d", X + i, L + i);
}
}
P ps[MAX_N];
int solve(){
for(int i = 0; i < N; ++i){
ps[i] = P(X[i] + L[i], X[i] - L[i]);
}
sort(ps, ps + N);
int cur = -MAX_V;
int ans = 0;
for(int i = 0; i < N; ++i){
if(cur <= ps[i].second){
ans++;
cur = ps[i].first;
}
}
return ans;
}
int main(){
input();
int ans = solve();
printf("%d\n", ans);
return 0;
}

Measured memory_bytes: 1664
x,y = map(int,input().split())

A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]
ans = 'No'
if (x in A) and (y in A):
  ans ='Yes'
elif (x in B) and (y in B):
  ans ='Yes'
elif (x in C) and (y in C):
  ans ='Yes'
  
print(ans)

Measured memory_bytes: 9104
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

vector<int> dz = {-1,0,1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll h,w,n;
  cin>>h>>w>>n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n) cin>>a[i]>>b[i];
  map<int,map<int,int>> mp;
  rep(i,n) {
    mp[a[i]][b[i]]=1;
  }
  set<pair<int,int>> ps;
  vector<ll> c(10);
  ll s=0;
  rep(i,n) {
    rep(j,3) {
      rep(k,3) {
        int aa=a[i]+dz[j];
        int bb=b[i]+dz[k];
        if(2<=aa&&aa<=h-1&&2<=bb&&bb<=w-1) 
          ps.insert(make_pair(aa,bb));
      }
    }
  }
  c[0]=static_cast<ll>(h-2)*static_cast<ll>(w-2)-ps.size();
  for(auto& p : ps) {
    int aa,bb;
    tie(aa,bb)=p;
    int t=0;
    rep(i,3) {
      rep(j,3) {
        int aaa=aa+dz[i];
        int bbb=bb+dz[j];
        if(aaa<=0||h<aaa||bbb<=0||w<bbb) {
          goto F;
        }
        t+=mp[aaa][bbb];
      }
    }
    c[t]++;
    F:;
  }
  rep(i,10) {
    cout << c[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 207232
#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)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,m;cin>>n>>m;
    vin a(n);rep(i,n)cin>>a[i];
    vpii d(m);
    int b,c;
    rep(i,m){
        cin>>b>>c;
        d[i]=mp(c,b);
    }
    sort(all(a));
    sort(all(d));reverse(all(d));
    int j=0;int res;
    rep(i,m){
        res=0;
        while(res<d[i].second&&a[j]<d[i].first){
            a[j]=d[i].first;
            j++;
            res++;
        }
        if(res!=d[i].second)break;
    }
    ll sum=0;
    rep(i,n)sum+=(ll)a[i];
    cout<<sum<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
// constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){ return a/gcd(a, b)*b; };
 
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Unique(a) a.erase(unique(Range(a)), a.end());
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(string, s);
    Unique(s);
    Cout(s.size() - 1);
}


Measured memory_bytes: 512
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
win = [True] * len(T)

dic = {'r':P, 's':R, 'p':S}

sum = 0
for i in range(K):
  sum += dic[T[i]]
for i in range(K, len(T)):
  if T[i] == T[i - K] and win[i - K]:
    win[i] = False
  else:
    sum += dic[T[i]]
print(sum)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
 
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
 
#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
 
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  int N, K;
while(
  cin >> N >> K,N){
  VI xs(N);
  REP(i,N) cin >> xs[i];
 
  SORT(xs);
  set<int> ans;
  do{
	int s = 0;
	REP(i,K){
	  s = s * (xs[i] >= 10? 100: 10) + xs[i];
	}
	ans.insert(s);
  }while(next_permutation(ALL(xs)));
 
  cout << SZ(ans) << endl;
 }
  return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}

int main(){  
  int k;
  cin >> k;
  
  int ans = 0;

  for(int i=1; i<=k; ++i){
    for(int j=1; j<=k; ++j){
      for(int h=1; h<=k; ++h ){
        ans += gcd(gcd(i,j),h);
      }
    }
  }

  cout << ans;

   return 0;

}

Measured memory_bytes: 3632
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  string s,t;
  cin >> s >> t;

cout << t << s;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for(int i = 0; i < 3; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		if(a[0] == 5 && a[1] == 5 && a[2] == 7) System.out.println("YES");
		else System.out.println("NO");
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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

Measured memory_bytes: 21844
/* Author : bhavye9499 - Bhavye Anand Gupta */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define endl "\n"
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define showArr(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i] << " "; cout << endl;}
#define showPair(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i].fi << " " << A[i].se << endl;}

const ll MOD = 1e9 + 7;

ll dp[100100][3], A[100100], B[100100], C[100100], n;

ll fun(ll i, ll j);

int main() {
    ios::sync_with_stdio(false);
    memset(dp, -1, sizeof(dp));
    memset(A, -1, sizeof(A));
    memset(B, -1, sizeof(B));
    memset(C, -1, sizeof(C));
    cin >> n;
    for(int i = 0; i < n; i++) {
    	cin >> A[i] >> B[i] >> C[i];
    }
    ll ans = max(A[0] + fun(1, 0), max(B[0] + fun(1, 1), C[0] + fun(1, 2)));
    cout << ans << endl;
}

ll fun(ll i, ll j) {
	if(dp[i][j] != -1)
		return dp[i][j];
	if(i >= n)
		return dp[i][j] = 0;
	if(j == 0)
		return dp[i][j] = max(B[i] + fun(i + 1, 1), C[i] + fun(i + 1, 2));
	if(j == 1)
		return dp[i][j] = max(A[i] + fun(i + 1, 0), C[i] + fun(i + 1, 2));
	if(j == 2)
		return dp[i][j] = max(A[i] + fun(i + 1, 0), B[i] + fun(i + 1, 1));
}

Measured memory_bytes: 9600
#line 1 "main_e.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 n,x,m;
  std::cin>>n>>x>>m;

  if(n<=m){
    i64 ans=0;
    i64 a=x;
    rep(i,0,n){
      ans+=a;
      a=(a*a)%m;
    }
    std::cout<<ans<<"\n";
    return 0;
  }

  std::vector<i64> itr(m,-1);

  i64 prev=x;

  i64 start,end;

  rep(i,0,n){
    if(itr[prev]!=-1){
      start=itr[prev];
      end=i;
      break;
    }
    itr[prev]=i;
    prev=(prev*prev)%m;
  }

  i64 ans=0;
  i64 a=x;
  rep(i,0,start){
    ans+=a;
    a=(a*a)%m;
  }

  i64 sum=0;
  rep(i,start,end){
    sum+=a;
    a=(a*a)%m;
  }
  
  ans+=sum*((n-start)/(end-start));
  i64 mod=(n-start)%(end-start);
  rep(i,start,start+mod){
    ans+=a;
    a=(a*a)%m;
  }

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


Measured memory_bytes: 3988
#include <cstdio>
#include <stack>
#define NUM 10
using namespace std;

int N;


int main()
{
	//freopen("in","r",stdin);
	scanf("%d",&N);
	while(N--){
		int tmp;
		bool sol=true;
		stack<int> B,C;
		for(int i=0;i<NUM;i++){
			
			scanf("%d",&tmp);
			if(B.empty())
				B.push(tmp);
			else if(tmp>B.top())
				B.push(tmp);
			else if(C.empty())
				C.push(tmp);
			else if(tmp>C.top())
				C.push(tmp);
			else
				sol = false;
		}
		if(sol)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 1016
# from math import factorial
# from collections import defaultdict, deque
#  from heapq import heappush, heappop

# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]

N = int(input())
Hs = [int(i) for i in input().split(" ")]

ans = 0
c = 0
for i in range(1, N):
 if Hs[i-1] >= Hs[i]:
    c += 1
    ans = max(ans, c)
 else:
    c = 0
print(ans)


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

int main(void) {
	int num = 0;
	cin >> num;
	while (num != 0) {
		vector<vector<int>> member(100);
		vector<int> data;
		int a = 0, b = 0;
		bool check[100];
		int betrayer = -1;
		bool isthere = false;
		for (int i = 0; i < num; i++) {
			cin >> a;
			member[i].push_back(a);
			for (int j = 0; j < a; j++) {
				cin >> b;
				member[i].push_back(b);
			}
			sort(member[i].begin()+1, member[i].end());
		}
		int pnum = 0;
		cin >> pnum;
		data.push_back(pnum);
		for (int i = 0; i < pnum; i++) {
			cin >> b;
			data.push_back(b);
		}
		sort(data.begin()+1, data.end());
		for (int i = 0; i < num; i++) {
			int chck = 1;
			for (int k = 0; k < 100; k++) {
				check[k] = false;
			}
			for (int j = 1; j <= member[i][0]; j++) {
				if(chck <= data[0]){
				if (data[chck] == member[i][j]) {
					check[chck] = true;
					chck++;
				  }
				}
			}
			if (check[data[0]]) {
				if (!isthere) {
					betrayer = i + 1;
					isthere = true;
				}
				else {
					betrayer = -1;
				}
			}


		}
		cout << betrayer << endl;
		cin >> num;
	}
}

Measured memory_bytes: 3152
#include <iostream>
#include <stdio.h>
#include <set>
#include<bits/stdc++.h>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
long long int dp[105][300005];
int main(){
    for(int i = 0;i<105;i++){
        for(int j = 0;j<300005;j++ ){
            dp[i][j] = -1;
        }
    }
    vector <long long int > v;
    vector <long long int > u;u.push_back(0);
    v.push_back(0);
    /// v is for weight and u is for value
    int n , w;
    cin>>n>>w;
    for(int i = 0;i<n;i++){
        long long int z , x;
        cin>>z>>x;
        v.push_back(z);
        u.push_back(x);
    }
    for(int i = 0;i<105;i++){
        dp[i][0] = 0;
    }
    dp[1][u[0] ] = v[0];
    for(int i = 1;i<=n;i++){
        for(long long int j = 0;j<=100000;j++){
            if(dp[i-1][j]==-1 ){continue;}
            if(dp[i][j]==-1 ){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = min(dp[i-1][j],dp[i][j] );
            }
            if(v[i]+dp[i-1][j]  <=w ){
                if(dp[i][u[i]+j  ]==-1 ){
                    dp[i][u[i]+j  ] = dp[i-1][j]+v[i];
                }
                else{
                    dp[i][u[i]+j  ] = min(dp[i][u[i]+j ],dp[i-1][j ]+v[i]   );
                }
            }
        }
    }
    int answer = 0;
    for(int i = 1;i<=100;i++){
        for(int j = 0;j<=100000;j++){
            if(dp[i][j] >0 ){
                answer = max(answer , j );
            }
        }
    }
    cout<<answer;
}


Measured memory_bytes: 246400
#include <iostream>
#include<math.h>
#include <climits>

using namespace std;

int main() {
    long long int n,ans[100005] = {0},w, x, y, z=0;
    cin>>n>>w;
    for(int i=0;i<n;i++) {
        cin>>x>>y;
        for(int j = w-x;j>=0;j--)
        ans[j+x]=max(ans[j+x],ans[j]+y);
    }
    for(int i=0;i<=w;i++)
    z=max(z,ans[i]);
    cout<<z;
}


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

int main(){
  int N;
  cin >> N;
  set<char> s;
  rep(i,N){
    char c;
    cin >> c;
    if(!s.count(c)){
      s.insert(c);
    }
  }
  if(s.count('Y')){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

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

    cout<<3*r*r<<endl;




    return 0;
}


Measured memory_bytes: 256