akhauriyash/Code-Regression huggingface dataset:
n = int(input())
towns = [int(s) for s in input().split()]
heros = [int(s) for s in input().split()]
p = 0
for i in range(n):
  rest = heros[i] - towns[i]
  if rest >= 0:
    p += towns[i]
    trest = towns[i + 1] - rest
    if trest < 0:
      p += towns[i + 1]
      towns[i + 1] = 0
    else:
      towns[i + 1] = trest
      p += rest
  else:
    p += heros[i]
print(p)

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            // 101 Problem A
            string input = Console.ReadLine();
            if (input == "++++"){ Console.WriteLine(4);}
            if (input == "-+++"  || input == "+-++" || input == "++-+" || input == "+++-") { Console.WriteLine(2); }
            if (input == "--++" || input == "-+-+" || input == "-++-" || input == "+--+" || input == "+-+-" || input == "++--") { Console.WriteLine(0); }
            if (input == "+---" || input == "-+--" || input == "--+-" || input == "---+") { Console.WriteLine(-2); }
            if (input == "----") { Console.WriteLine(-4); }
        }
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int A, B, C;
    int count = 0;
    cin >> A >> B >> C;
    while(A <= B) {
        B -= A;
        count++;
        if(count >= C) {
            break;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#include<bitset>

#define MOD 1000000007
using namespace std;

int main()
{
	int N;	cin >> N;
	int a, b, c, d;
	a = N / 1000;
	b = (N % 1000) / 100;
	c = (N % 100) / 10;
	d = N % 10;
	if (a == b || b == c || c == d)
		cout << "Bad";
	else
	{
		cout << "Good";
	}
	return 0;
}

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


int main() {
    int N, K;
    string S;
    char ch;
    cin >> N >> K >>S;

    ch = S[K-1];

    if(ch == 'A'){
        S[K-1] = 'a';
    }else if(ch == 'B'){
        S[K-1] = 'b';
    }else if(ch == 'C'){
        S[K-1] = 'c';
    }

    cout << S << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 251
int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i+1;}

int main()
{
  int h,i,a[MAX+1];
  scanf("%d",&h);
  for(i=1;i<=h;i++) scanf("%d",&a[i]);
  for(i=1;i<=h;i++){
    printf("node %d: key = %d, ",i,a[i]);
    if(parent(i)>=1) printf("parent key = %d, ",a[parent(i)]);
    if(left(i)<=h) printf("left key = %d, ",a[left(i)]);
    if(right(i)<=h) printf("right key = %d, ",a[right(i)]);
    printf("\n");
  }


  return 0;
}


Measured memory_bytes: 2104
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main(void) {
    int a, b, c, k;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    cin >> k;
    cout << a + b + c + max(a, max(b, c)) * ((int)pow(2.0, k) - 1) << "\n";
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
int a,b[100000],c[100000],d;
cin>>a;
  d=0;
  for(int i=0;i<a;i++){
     cin>>b[i];
    c[i]=b[i];
  }
  sort(c,c+a);
    for(int i=0;i<a;i++){
    if(c[i]!=b[i]){d++;}
    }
  if(d<3){cout<<"YES";}
  else cout<<"NO";
  }


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace aoj {
	struct Point {
		private double _x, _y;
		public Point(double x, double y) {
			_x = x;
			_y = y;
		}
		public double x { get { return _x; } set { _x = value; } }
		public double y { get { return _y; } set { _y = value; } }
		public static Point operator+(Point r, Point l) { return new Point(r.x + l.x, r.y + l.y); }
		public static Point operator-(Point r, Point l) { return new Point(r.x - l.x, r.y - l.y); }
		public static double Cross(Point p1, Point p2) { return p1.x * p2.y - p1.y * p2.x; }
	}
	class _0068 {
		static bool Turn2Right(Point p0, Point p1, Point p2) { return Point.Cross(p2 - p0, p1 - p0) > 0; }
		static int GrahamScan(Point[] ps) {
			Array.Sort(ps, (a, b) => (a.x < b.x) ? -1 : (a.x > b.x) ? 1 : 0);
			var p0 = ps[0];

			var args = new List<KeyValuePair<Point,double>>();
			for (int i = 1; i < ps.Length; i++) {
				var tp = ps[i] - p0;
				args.Add(new KeyValuePair<Point, double>(ps[i], Math.Atan2(tp.y, tp.x)));
			}
			args.Sort((a, b) => (a.Value < b.Value) ? -1 : (a.Value > b.Value) ? 1 : 0);
			for (int i = 1; i < ps.Length; i++)
				ps[i] = args[i - 1].Key;

			var s = new Stack<Point>();
			s.Push(ps[0]); s.Push(ps[1]); s.Push(ps[2]);
			for(int i = 3; i < ps.Length; i++) {
				var top = s.Pop();
				var n2t = s.Pop();
				while (Turn2Right(n2t, top, ps[i])) {
					top = n2t;
					n2t = s.Pop();
				}
				s.Push(n2t); s.Push(top); s.Push(ps[i]);
			}
			return ps.Length - s.Count;
		}
		public static void Main() {
			string str;
			while ((str = Console.ReadLine()) != "0") {
				var n = int.Parse(str);
				var points = new Point[n];
				for (int i = 0; i < n; i++) {
					var pos = Console.ReadLine().Split(',').Take(2).Select(double.Parse).ToArray();
					points[i].x = pos[0];	points[i].y = pos[1];
				}
				Console.WriteLine(GrahamScan(points));
			}
		}
	}
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e8
typedef long long ll;
typedef long double ld;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        if(a != c){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(a == c){
        if(a != b){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(b == c){
        if(a != b){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char bun[6];
  int i;
  
  for( i=0 ; i<6 ; i++ ){
    scanf("%c",&bun[i]);
  }
  
  if(bun[2] == bun[3] && bun[4] == bun[5]){
    printf("Yes");
  }
  else printf("No");
  return 0;
}


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

using namespace std;

#define endl '\n'

struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    std::vector<int> parent_or_size;
};

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
				cout<<1<<endl;
            } else {
                cout<<0<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>
#include <cfloat>
#include <array>


int main() {
	int a, b, c, d; std::cin >> a >> b >> c >> d;
	for (auto i = 0; (a > 0 && c > 0); ++i) {
		if ((i & 1) == 0) {
			c -= b;
		}
		else {
			a -= d;
		}
	}
	if (a > 0) {
		std::cout << "Yes\n";
	}
	else {
		std::cout << "No\n";
	}
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

#define M 1000000007

ll fastexp(ll a, ll b){
   ll ae=a, ans=1;
   for(int i=0; i<64; i++){
      if((b>>i)&1) ans=(ans*ae)%M;
      ae=(ae*ae)%M;
   }
   return ans;
}

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

   ll cn[100001];
   for(int g=k; g>=1; g--){
      cn[g]=fastexp(k/g, n);
      for(int i=g*2; i<=k; i+=g) cn[g]=(cn[g]-cn[i]+M)%M;
   }

   ll cnt=0;
   for(int i=1; i<=k; i++) cnt=(cnt+(i*cn[i])%M)%M;

   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 4324
from math import sqrt

results = []

while True:
    n = int(input())
    if n == 0:
        break
    points = list(map(int, input().split()))
    
    mid = sum(points) / n
    variance = 0
    for point in points:
        variance += (point - mid) ** 2
    variance /= n
    
    deviation = sqrt(variance)
    results.append(deviation)

for result in results:
    print(result)


Measured memory_bytes: 5700
import numpy as np
n,m = map(int,input().split())


h =  [-1]+list(map(int,input().split()))

s = np.full(n+1,1)
s[0]=0

for i in range(m):
    a,b=map(int,input().split())
    if h[a] == h[b]:
        s[a]=0
        s[b]=0
    elif h[a] < h[b]:
        s[a]=0
    elif h[a] > h[b]: 
        s[b]=0

print(sum(s))



Measured memory_bytes: 38404
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int n, m, p;
    string s;
    cin >> n >> m;
    vector<int> wa(n + 1, 0), ac(n + 1, 0);
    while (m--) {
        cin >> p >> s;
        if (s == "WA") {
            if (ac[p] == 0)
                wa[p]++;
        }
        else {
            ac[p] = 1;
        } 
    }
    int wav = 0, acv = 0;
    for (int i = 1; i <= n; ++i) {
        if (ac[i]) {
            acv++;
            wav += wa[i];
        }
    }
    cout << acv << " " << wav << endl;

    return 0;
}

Measured memory_bytes: 1024
import heapq

n, maxDays = map(int, input().split())
a = sorted([list(map(int, input().split())) for _ in range(n)])

pq = []
idx = 0
ret = 0
for day in range(maxDays + 1):
    while idx < n and a[idx][0] <= day:
        heapq.heappush(pq, -a[idx][1])
        idx += 1
    if pq:
        ret -= heapq.heappop(pq)

print(ret)

Measured memory_bytes: 31964
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;


int main() {
    int N; cin>>N;
    vector<int> a(N),place(N+2,-1);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
        place[a[i]]=i+1;
    }

    ll ans=0ll;;
    set<ll> used={0,N+1};

    for (int i = 1; i <= N; ++i) {
        ll r,l;
        auto itr=used.lower_bound(place[i]);
        r=*itr;
        --itr;
        l=*itr;
        ans+=i*(place[i]-l)*(r-place[i]);
        used.insert(place[i]);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <algorithm>
    #include <map>
    #include <iomanip>
    using namespace std;
    typedef pair<int,int> P;
     
     
    int main()
    {
      char A[4];
      for(int i=0;i<4;i++)cin>>A[i];
      int a[4];
      for(int i=0;i<4;i++)a[i]=A[i]-'0';
      bool flag=false;
     
      for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
          for(int k=0;k<2;k++){
    	int ans=a[0];
    	if(i)ans+=a[1];
    	else ans-=a[1];
    	if(j)ans+=a[2];
    	else ans-=a[2];
    	if(k)ans+=a[3];
    	else ans-=a[3];
     
    	if(ans==7){
    	  flag=true;
    	  cout<<a[0]<<(i==1?'+':'-')<<a[1]<<(j==1?'+':'-')<<a[2]<<(k==1?'+':'-')<<a[3]<<"=7"<<endl;
    	}
     
    	if(flag)break;
          }
    	if(flag)break;
        }
    	if(flag)break;
      }
      return 0;
    }

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

#define ll long long

int main(void){

    string a,b;
    cin>>a>>b;

    if(a.size()>b.size())cout<<"GREATER"<<endl;
    else if(a.size()<b.size())cout<<"LESS"<<endl;
    else if(a==b)cout<<"EQUAL";
    else{
        for(int i=0;i<a.size();i++){
            if(a[i]>b[i]){
                cout<<"GREATER"<<endl;
                return 0;
            }
            else if(a[i]<b[i]){
                cout<<"LESS"<<endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    static boolean[] ok;
    static int n;
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int[] num = new int[10];
	ok = new boolean[10];
	String line;
	int index;
	while (scan.hasNext()) {
	    Arrays.fill(num, 0);
	    Arrays.fill(ok, false);
	    line = scan.nextLine();
	    for (int i = 0; i < 13; i++) {
		index = Integer.parseInt(line.substring(i, i + 1));
		num[index]++;
	    }
	    for (int i = 1; i < 10; i++) {
		n = i;
		if (num[i] >= 4) {
		    continue;
		}
		num[i] += 1;
		for (int j = 1; j < 10; j++) {
		    if (num[j] >= 2) {
			num[j] -= 2;
			isPuzzle(num);
			num[j] += 2;
		    }
		}
		num[i] -= 1;
	    }
	    printResult(ok);
	}
    }

    public static void printResult (boolean[] result) {
	StringBuilder sb = new StringBuilder();
	boolean empty = true;
	for (int i = 1; i < 10; i++) {
	    if (ok[i] == true) {
		sb.append(i + " ");
		empty = false;
	    }
	}
	if (empty == true) {
	    sb.append(0);
	}
	System.out.println(sb.toString().trim());
    }
    public static void isPuzzle (int[] num) {
	if (isAllZero(num)) {
	    ok[n] = true;
	    return;
        }
	for (int i = 1; i < 10; i++) {
	    if (num[i] >= 3) {
		num[i] -= 3;
		isPuzzle(num);
		num[i] += 3;
	    }
	}
	for (int i = 1; i < 8; i++) {
	    if (num[i] > 0 && num[i + 1] > 0 && num[i + 2] > 0) {
		num[i] -= 1;
		num[i + 1] -= 1;
		num[i + 2] -= 1;
		isPuzzle(num);
		num[i] += 1;
		num[i + 1] += 1;
		num[i + 2] += 1;
	    }
	}
    }

    public static boolean isAllZero (int[] num) {
	for (int i = 1; i < 10; i++) {
	    if (num[i] > 0) {
		return false;
	    }
	}
	return true;
    }
}

Measured memory_bytes: 26924
/* Code by pedroslrey *
 *     march 8        *
 *    Sunday          */

#include <bits/stdc++.h>

using namespace std;

using lli = long long int;

const int INF = 1000000007;
const lli LLINF = 9223372036854775800;

#define debug(args...) fprintf(stderr, args)
#define show(x) fprintf(stderr, "[DEBUG] -> %d\n", x)

int as[100010];
int bs[100010];

int main() {
	int a, b, m;
	scanf("%d%d%d", &a, &b, &m);
	int menor = INF;
	for (int i = 0; i < a; ++i) {
		scanf("%d", &as[i]);
		if (as[i] < menor) menor = as[i];
	}
	int omenor = INF;
	for (int i = 0; i < b; ++i) {
		scanf("%d", &bs[i]);
		if (bs[i] < omenor) omenor = bs[i];
	}
	int min = INF;
	for (int i = 0; i < m; ++i) {
		int x, y, c;
		scanf("%d%d%d", &x, &y, &c);
		int k = as[x-1] + bs[y-1] - c;
		if (k < min) min = k;
	}
	if (omenor + menor < min) min = omenor + menor;
	printf("%d\n", min);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, k) ans += p[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
MOD = 10 ** 9 + 7

N = int(input())

ans = pow(10, N, MOD)
ans -= 2 * pow(9, N, MOD)
ans += pow(8, N, MOD)
ans %= MOD # 最後にMODを取り忘れないように気をつけましょう

print(ans)

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

int N;
int P[8];
int Q[8];

int E[8];

bool equal(int x[]){
    bool res=true;
    for(int i=0;i<N;i++){
        if(x[i]!=E[i]){
            res=false;
            break;
        }
    }
    return res;
}

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>P[i];
    }
    for(int i=0;i<N;i++){
        cin>>Q[i];
        E[i]=i+1;
    }

    int p=1,q=1;
    do{
        if(!equal(P))p++;
        else break;
    }while(next_permutation(E,E+N));
    sort(E,E+N);
    do{
        if(!equal(Q))q++;
        else break;
    }while(next_permutation(E,E+N));

    int ans=abs(p-q);
    
    cout<<ans;
}

Measured memory_bytes: 256
n = int(input())
ls = list(map(int,input().split()))

min = 1000001
for i in ls:
    if i < min:
        min = i

max = -1000001
for i in ls:
    if i > max:
        max = i

sum = 0
for i in ls:
    sum += i
    
print(min, max, sum)


Measured memory_bytes: 6584
#include <iostream>
#include <cmath>
using namespace std;
 
int main()
{
	string a,b;
	int x;
	int zh(string s);
	
	cin>>a>>b; 
	
	x=zh(a+b);
	
	if(int(sqrt(x))==sqrt(x))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}
 
int zh(string s)
{
	int tmp=0;
	
	for(int i=0;i<s.size();i++)
		tmp=tmp*10+(s[i]-'0');
	
	return tmp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int x;
    cin >> x;
    cout << !x << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
#include <vector>
#include <algorithm>

using namespace std;


int main() {
    constexpr double Pi = 3.14159265359;
    
    double r;
    cin >> r;

    
    
    cout << fixed << setprecision(8);
    cout << r *r * Pi << " " << 2 * Pi * r << endl;



    return 0;
} 

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

int main() {
    int a;
    string s;
    cin>>a>>s;
    string ans;
    ans = a<3200 ? "red" : s;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<ll>>;
#define MAX 1000000007

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    int four_div_num=0;
    int two_div_num=0;
    int one_div_num=0;
    rep(i,n){
        if(a[i]%4==0){
            four_div_num++;
        }else if(a[i]%2==0){
            two_div_num++;
        }else{
            one_div_num++;
        }
    }
    two_div_num%=2;
    if(two_div_num+one_div_num-1<=four_div_num){
        Yes;
    }else{
        No;
    }
}

Measured memory_bytes: 4052
sx,sy,tx,ty=map(int,input().split())

w=abs(sx-tx)
h=abs(sy-ty)

ans=''

for _ in range(h):
    ans+="U"
    # print("U")

for _ in range(w+1):
    ans+="R"
    #print("R")

for _ in range(h+1):
    ans+="D"
    #print("D")

for _ in range(w+1):
    ans+="L"
    #print("L")

ans+="UL"

for _ in range(h+1):
    ans+="U"

for _ in range(w+1):
    ans+="R"

for _ in range(h+1):
    ans+="D"

for _ in range(w):
    ans+="L"

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#include <stack>
#include <bitset>
#include <map>

using namespace std;

int solve();

int main(void) {
//	FILE *fpin = freopen("data.txt", "r", stdin);
	while (solve()) {}
	return 0;
}

int solve() {

	int N, M;
	cin >> N >> M;

	vector<int> ans(N+1, 0);

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		ans[a] ++;
		ans[b] ++;
	}

	for (int i = 1; i <= N; i++)
		cout << ans[i] << endl;


	return 0;
}

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

int n, cnt[26], ccnt[26];
char buf[52];

int main(){
	scanf("%d", &n);
	fill(cnt, cnt + 26, 51);
	for(int i = 0; i < n; i++){
		scanf("%s", buf);
		for(int j = 0; j < 26; j++) ccnt[j] = 0;
		for(int j = 0; buf[j]; j++){
			ccnt[buf[j] - 'a']++;
		}
		for(int j = 0; j < 26; j++) cnt[j] = min(cnt[j], ccnt[j]);
	}
	for(int i = 'a'; i <= 'z'; i++){
		while(cnt[i - 'a']--) putchar(i);
	}
	puts("");
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt(),m=sc.nextInt(),x=sc.nextInt(),a1=0,a2=0,t;
for(int i=0;i<m;i++)t=sc.nextInt()<x?a1++:a2++;
System.out.println(Math.min(a1, a2));
}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int n; cin >>n;
  map<string, int> score;
  int maxnum = 0;
  rep(i, n){
    string buf; cin >>buf;
    score[buf]++;
    maxnum = max(maxnum, score[buf]);
  }

  set<string> s;

  for (auto p : score){
    string k = p.first;
    int v = p.second;
    if (v == maxnum) s.insert(k);
  }

  for (auto ans : s){
    cout <<ans <<endl;
  }
}

Measured memory_bytes: 36608
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = scanInt()
	}
	sort.Ints(A)

	ans := 0
	cnt := 1
	for i := 1; i < N; i++ {
		if A[i] == A[i-1] {
			cnt++
		} else {
			if A[i-1] > cnt {
				ans += cnt
			} else {
				ans += (cnt - A[i-1])
			}
			cnt = 1
		}
	}
	if A[N-1] > cnt {
		ans += cnt
	} else {
		ans += (cnt - A[N-1])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4192
#include <stdio.h>
int main(){
	int n,i;
	int fib[45];
	fib[0] = 1;
	fib[1] = 1;

	for(i=2; i<=44; i++){
		fib[i] = fib[i-1]+fib[i-2];
	}
	scanf("%d\n",&n);
	printf("%d\n",fib[n]);
	return 0;
}



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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,sum=0;
	map<ll,ll> mp;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		mp[a]++;
		if(mp[a]>a){
			mp[a]--;
			sum++;
		}
	}
	for(auto p:mp){
		auto b=p.first;
		auto c=p.second;
		if(b!=c){
			sum+=c;
		}
	}
	cout<<sum<<endl;
	return 0;
}


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

#define MAX_N (300L)
#define MAX_A (300L)
#define NUM_MOD (998244353L)

long dp0ss[MAX_N + 1][2 * MAX_N * MAX_A + 1],
    dp1ss[MAX_N + 1][2 * MAX_N * MAX_A + 1];

long mod(long n, long k) { return n % k >= 0 ? n % k : n % k + k; }

int main(int argc, char *argv[]) {
  // read inputs
  long N, as[MAX_N];
  scanf("%ld", &N);
  for (long i = 0; i < N; i++) {
    scanf("%ld", &as[i]);
  }

  // solve dp
  // init
  dp0ss[0][0 + MAX_N * MAX_A] = 1;
  dp1ss[0][0 + MAX_N * MAX_A] = 1;
  // update
  for (long i = 0; i < N; i++) {
    const long a = as[i];
    for (long d = -MAX_N * MAX_A; d <= MAX_N * MAX_A; d++) {
      if (d - a >= -MAX_N * MAX_A) {
        dp0ss[i + 1][d - a + MAX_N * MAX_A] =
            mod(dp0ss[i + 1][d - a + MAX_N * MAX_A] +
                    2 * dp0ss[i][d + MAX_N * MAX_A],
                NUM_MOD);
        dp1ss[i + 1][d - a + MAX_N * MAX_A] = mod(
            dp1ss[i + 1][d - a + MAX_N * MAX_A] + dp1ss[i][d + MAX_N * MAX_A],
            NUM_MOD);
      }
      if (d + a <= MAX_N * MAX_A) {
        dp0ss[i + 1][d + a + MAX_N * MAX_A] = mod(
            dp0ss[i + 1][d + a + MAX_N * MAX_A] + dp0ss[i][d + MAX_N * MAX_A],
            NUM_MOD);
        dp1ss[i + 1][d + a + MAX_N * MAX_A] = mod(
            dp1ss[i + 1][d + a + MAX_N * MAX_A] + dp1ss[i][d + MAX_N * MAX_A],
            NUM_MOD);
      }
    }
  }
  // for (long i = 0; i < N; i++) {
  //   long s = 0;
  //   for (long d = -MAX_N * MAX_A; d <= MAX_N * MAX_A; d++) {
  //     s += dp0ss[i + 1][d + MAX_N * MAX_A];
  //   }
  //   printf("i = %ld, s = %ld\n", i, s);
  // }

  // subtract from 3^N to get answer
  long ans = 1;
  for (long i = 0; i < N; i++) {
    ans = mod(ans * 3, NUM_MOD);
  }
  for (long d = 0; d <= MAX_N * MAX_A; d++) {
    ans = mod(ans - 3 * dp0ss[N][d + MAX_N * MAX_A], NUM_MOD);
  }
  ans = mod(ans + 3 * dp1ss[N][0 + MAX_N * MAX_A], NUM_MOD);
  printf("%ld\n", ans);

  return 0;
}


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

int maxArr(int a[],int size){
	int ret=-1;
	for(int i=0;i<size;i++){
		if(a[i]>ret) ret=a[i];
	}
	return ret;
}

int minArr(int a[],int size){
	int ret=10000;
	for(int i=0;i<size;i++){
		if(a[i]<ret) ret=a[i];
	}
	return ret;
}

int main(void){
	int a[5],k;
	for(int i=0;i<5;i++) cin >> a[i];
	cin >> k;
	
	if(maxArr(a,5)-minArr(a,5)>k) cout << ":(";
	else cout << "Yay!";
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int r, c, i, j, num[101][101];
    scanf("%d%d", &r, &c);
    for (i = 0; i < r; i++) {
        num[i][c] = 0;
        for (j = 0; j < c; j++) {
            scanf("%d", &num[i][j]);
            num[i][c] += num[i][j];
        }
    }
    for (j = 0; j <= c; j++) {
        num[r][j] = 0;
        for (i = 0; i < r; i++) {
            num[r][j] += num[i][j];
        }
    }
    for (i = 0; i <= r; i++) {
        for (j = 0; j < c; j++) {
            printf("%d ", num[i][j]);
        }
        printf("%d\n", num[i][j]);
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n;
string s;
int ans = inf;
int ta, mu;

signed main() {
	cin >> n >> s;
	rep(i, s.size()) {
		if (s[i] == '.')mu++;
	}
	rep(i, s.size()) {
		ans = min(ans, ta + mu);
		if (s[i] == '#')ta++;
		else mu--;
	}
	ans = min(ans, ta + mu);
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

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

struct edge{int to,cost;};
	
int main(){
//	ios::sync_with_stdio(false);
//	cin.tie(0);

	int n,k;
	cin >> n >> k;

	int d[k];
	for(int i=0;i<k;i++){
		cin >> d[i];
	}
	for(int ans=n;;ans++){
		int tmp=ans;
		bool flag=true;
		while(tmp>=1){
//			printf("    %d\n",tmp);
			if(binary_search(d,d+k,tmp%10)) {
//				printf("searched %d\n",tmp%10);
				flag=false;
				break;
			}
			tmp/=10;
		}
		if(flag) {
			cout << ans << "\n";
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L



int main() {
    double p = 0, o = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 2) o++;
        else p++;
    }
    cout << fixed << setprecision(10) << (o / n);

    return 0;
}

Measured memory_bytes: 3780
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		final int DICE = 6;
		int n;
		int dice2[] = new int[DICE];
		int dice3[] = new int[DICE];
		int dice4[] = new int[DICE];
		boolean perfect = false;
		
		n = scan.nextInt();
		int dice[][] = new int[DICE][n];
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < DICE; j++) {
				dice[j][i] = scan.nextInt();
			}
		}
		
		for (int i = 0; i < n - 1; i++) {
			for ( int j = 0; j < DICE; j++) {
				dice2[j] = dice[j][i];
			}
			dice4 = dice2;
			 for ( int j = i + 1; j < n; j++) {
				 for ( int k = 0; k < DICE; k++) {
						dice3[k] = dice[k][j];
				}
				 
				 for ( int k = 0; k < DICE; k++) {
					 dice2 = dice4;
					 switch (k) {
						case 0:
							dice2 = Move("S", dice2);
							break;
						case 2:
							dice2 = Move("EN", dice2);
							break;
						case 3:
							dice2 = Move("ES", dice2);
							break;
						case 4:
							dice2 = Move("NN", dice2);
							break;
						case 5:
							dice2 = Move("N", dice2);
							break;
						default:
							break;
						}
					 perfect = Judge(dice3, dice2);
					 if (perfect == false) break;
				 }
				 if (perfect == false) break;
			 }
			 if (perfect == false) break;
			
		}
		scan.close();
		
		if (perfect == true) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
	
	public static int [] Move ( String direction, int str[]) {
		String dir = direction;
		int pro_dice[] = new int[6];
		
		for (int i = 0; i < dir.length(); i++) {
			switch(dir.charAt(i)) {
			case 'N':
				pro_dice[0] = str[1];
				pro_dice[1] = str[5];
				pro_dice[2] = str[2];
				pro_dice[3] = str[3];
				pro_dice[4] = str[0];
				pro_dice[5] = str[4];
				break;
			case 'E':
				pro_dice[0] = str[3];
				pro_dice[1] = str[1];
				pro_dice[2] = str[0];
				pro_dice[3] = str[5];
				pro_dice[4] = str[4];
				pro_dice[5] = str[2];
				break;
			case 'S':
				pro_dice[0] = str[4];
				pro_dice[1] = str[0];
				pro_dice[2] = str[2];
				pro_dice[3] = str[3];
				pro_dice[4] = str[5];
				pro_dice[5] = str[1];
				break;
			case 'W':
				pro_dice[0] = str[2];
				pro_dice[1] = str[1];
				pro_dice[2] = str[5];
				pro_dice[3] = str[0];
				pro_dice[4] = str[4];
				pro_dice[5] = str[3];
				break;
			default:
				break;
			}
			
			for ( int j = 0; j < 6; j++) {
				str[j] = pro_dice[j];
			}
		
		}
		
		return str;
	}
	
	public static boolean Judge (int str1[], int str2[]) {
		boolean judge = false;
		
		for (int i = 0; i < 4; i++) {
			judge = false;
			for (int j = 0; j < 6; j++) {
				if (str1[j] != str2[j]) {
					judge = true;
				}
			}
			if (judge == false) break;
			str2 = Move("E",str2);
		}
		
		return judge;
	}
}


Measured memory_bytes: 36432
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
using namespace std;

const int MAXN = 100005;

vector<int> G[MAXN];

int A[MAXN];

int N;

int main() {
	scanf("%d", &N);
	G[(A[1] = 1)].pb(1);
	for(int i = 1;; i++) {
		for(int j = 0; j < sz(G[i]); j++) {
			int n = G[i][j];
			if(!n) { printf("%d\n", i); return 0; }
			if(A[n] < i) continue;
			int ni = (n+1)%N;
			if(!A[ni] || i+1 < A[ni]) {
				A[ni] = i+1; G[i+1].pb(ni);
			}
			ni = n*10%N;
			if(!A[ni] || i < A[ni]) {
				A[ni] = i; G[i].pb(ni);
			}
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 3832
#include <stdio.h>

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int i,j,s[n];
	for(i=0;i<n;i++) scanf("%d",&s[i]);
	
	for(j=0;j<n;j++)
	for(i=0;i<n-1;i++)
	{
		if(s[i]>s[i+1])
		{
			int b=s[i];
			s[i]=s[i+1];
			s[i+1]=b;
		}
	}
	int sum=0;
	for(i=0;i<k;i++) sum+=s[i];
	
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 1700
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

int main(){
    long X, K , D;
    cin >> X >> K >> D;
    if(X < 0){X = -X;}
    long a = X/D;
    if(a >= K){
        cout << X-K*D << endl;
        return 0;
    }
    long kisu, gusu;
    if(a % 2 == 1){
        kisu = X - a*D;
        gusu = -(X - (a+1)*D);
    }else{
        gusu = X - a*D;
        kisu = -(X - (a+1)*D);
    }
    if(K % 2 == 0){
        cout << gusu;
    }else{
        cout << kisu;
    }



    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int N = 200000 + 5;
int a[N];

int main()
{
	ll h;
	cin >> h;
	ll t = 1,sum = 0;
	while(t <= h){
		sum += t;
		t = t * 2;
	}
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

int x, y;
bool flag;
int main() {
	cin >> x >> y;

	if(y%2 != 0) flag = true;
	if(!(2*x <= y && y <= 4*x)) flag = true;

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


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<string,int>mm;
vector<string>v;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        string h;
        cin>>h;
        mm[h]++;
    }
    int Max=0;
    for(map<string,int>::iterator it=mm.begin();it!=mm.end();it++)
    {
        if((it->second)>Max)Max=(it->second);
    }
    int a;
    for(map<string,int>::iterator it=mm.begin();it!=mm.end();it++)
    {
        if((it->second)==Max)v.push_back((it->first));
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<endl;
    }
}


Measured memory_bytes: 26868
N, D=map(int, input().split())
x=[list(map(int, input().split())) for i in range(N)]
ans = 0
d=0
for i in range(N-1):
    for j in range(i+1, N):
        for k in range(D):
            d+=(x[i][k]-x[j][k])**2
        if (d**(1/2))%1==0:
            ans += 1
        d=0
print(ans)


Measured memory_bytes: 3060
import java.util.*;

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

		int[] a = new int[6];

		a[0]  = ((n*10)+nn) + nnn;
		a[1]  = ((n*10)+nnn) + nn;
		a[2]  = ((nn*10)+nnn) + n;
		a[3]  = ((nn*10)+n) + nnn;
		a[4]  = ((nnn*10)+n) + nn;
		a[5]  = ((nnn*10)+ nn) + n;

		Arrays.sort(a);

		System.out.println(a[5]);


	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int n, a[10][5];

int f(){
    int ret = 0;
    rep(i, n){
        int l = 0;
        while(l < 5){
            int r = l;
            while(r < 5 && a[i][l] == a[i][r]) ++r;
            if(r-l >= 3){
                ret += a[i][l] * (r-l);
                For(j, l, r) a[i][j] = 0;
            }
            l = r;
        }
    }
    if(ret == 0) return 0;
    rrep(i, n)rep(j, 5)if(a[i][j] == 0){
        rrep(k, i)if(a[k][j]){
            a[i][j] = a[k][j];
            a[k][j] = 0;
            break;
        }
    }
    return ret;
}

int main(){
    while(scanf("%d", &n) && n){
        rep(i, n)rep(j, 5) scanf("%d", &a[i][j]);
        int ans = 0;
        while(true){
            int tmp = f();
            ans += tmp;
            if(tmp == 0) break;
        }
        printf("%d\n", ans);
    }
}


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

typedef long long ll;
typedef long double ld;
typedef pair<double,double> dd;
typedef pair<ll,ll> pll;
typedef pair<string,int> psi;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<ii> > vvip;
typedef vector<ii> vii;
typedef map<int,int> mpi;
#define pb push_back
#define F first
#define S second
#define MOD 1000000007
#define NA -1
#define ALL(v) v.begin(),v.end()
#define mp make_pair
#define rep(i, n) for (int (i) = 0; (i) < (n); (i) ++)
#define rep1(i, n) for (int (i) = 1; (i) <= (n); (i) ++)
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout<<#a<<" :";FOR(i123,x,y)cout<<setw(4)<<(a)[i123];cout<<endl;}
#define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); e++) 
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) int((x).size())
#define endl '\n'
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
#define sc(t) scanf("%d",&t)
// vector<string> split(const string &s, char delim) {
//     stringstream ss(s);
//     string item;
//     vector<string> tokens;
//     while (getline(ss, item, delim)) {
//         tokens.push_back(item);
//     }
//     return tokens;
// }
typedef pair<pll,ll> ppll;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define re return
ll o(ll x)
{
	ll _;
	_=0;
	while( x)
	{
		x/=10;
		_++;
	}
	re _;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	//     freopen("output.txt","w",stdout);;
	// #endif
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	//ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	
	ll n;
	cin>>n;
	ll x = (ll)sqrt(n);
	ll ans=INFL;
	for(int i=1;i<=x;i++)
	{
		if( i*i<=n && n%i == 0)
		{
			ll xx=i;
			ll yy =n/i;
			ans=min(ans,max(o(xx),o(yy)));
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import heapq

YES = "Yes"  # type: str
NO = "No"  # type: str

def isBlock(S,i):
    return S[i] == "#"

def hasContinuingSharp(S,A,B):
    prevSharp = False
    for i in range(A,B):
        if isBlock(S,i):
            if prevSharp:
                return True
            else:
                prevSharp = True
        else:
            prevSharp = False
    return False

def hasThreeContinueingNonSharp(S,A,B):
    nonBlockCount = 0
    for i in range(A,B):
        if isBlock(S,i):
            nonBlockCount = 0
        else:
            nonBlockCount += 1
            if nonBlockCount == 3:
                return True
    return False

def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    A-=1
    B-=1
    C-=1
    D-=1
    if hasContinuingSharp(S,A,C) or hasContinuingSharp(S,B,D):
        print(NO)
        return
    if C < D:
        print(YES)
        return
    if hasThreeContinueingNonSharp(S,B-1,D+2):
        print(YES)
    else:
        print(NO)
    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
*/

ll n,m,p,dp[2510],dp2[2510],t;
vector<ll> v[2510],c[2510];

void init(){
	cin>>n>>m>>p;
	rep(i,m){
		ll a,b,x;
		cin>>a>>b>>x;
		v[a].push_back(b);
		c[a].push_back(x-p);
	}
	reg(i,1,n){
		dp[i]=-1e18;
		dp2[i]=-1e18;
	}
	dp[1]=0;
}

int main(void){
	init();
	reg(cnt,1,2*n){
		reg(i,1,n){
			rep(j,v[i].size()){
				if(dp2[v[i][j]]<dp[i]+c[i][j]){
					dp2[v[i][j]]=dp[i]+c[i][j];
				}
			}
		}
		if(cnt==n-1)t=dp2[n];
		reg(i,1,n)dp[i]=dp2[i];
	}
	if(dp[n]>t){
		cout<<-1<<endl;
	}else{
		cout<<max(t,0LL)<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */
const int MOD = 1e9 +7;

int main() {
  int N, M; cin >> N >> M;
  vector<int> a(M); REP(i, M) cin >> a[i];

  vector<bool> ok(N, true);
  REP(i, M) ok[a[i]] = false;

  vector<ll> dp(N+1, 0);
  dp[0] = 1;
  REP(i, N){
    if(!ok[i]) continue;
    if(ok[i+1]){
      dp[i+1] += dp[i] %MOD;
      dp[i+1] %= MOD;
    }
    
    if(ok[i+2] && i != N-1) {
      dp[i+2] += dp[i] %MOD;
      dp[i+2] %= MOD;
    }
  }
  // REP(i, N+1){
  //   DUMP(i);
  //   DUMP(dp[i]);
  // }

  cout << dp[N] << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int main(){
	int N,K,X,Y;
	cin>>N>>K>>X>>Y;
	if(N<=K){
		cout<<N*X<<endl;
	}
	else{
		cout<<K*X+(N-K)*Y<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int MOD = 1e9 + 7;
int add(ll x, ll y) {return (x+y) % MOD;}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	vector<int> dp(n+1);
	dp[0] = 1;
	for (int i=0; i<n; i++) {
		for (int k=3; i+k<=n; k++) {
			dp[i+k] = add(dp[i+k], dp[i]);
		}
	}
	cout << dp[n] << '\n';
}

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

using namespace std;

const int N = 1e5 + 5;
int n, l[N], r[N];

pair<int, int> le[N], ri[N];


int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", l+i, r+i);
    le[i] = {l[i], i};
    ri[i] = {r[i], i};
  }
  l[0] = r[0] = 0;
  le[n] = {0, n};
  ri[n] = {0, n};
  sort(le, le+n+1);
  sort(ri, ri+n+1);
  reverse(le, le+n+1);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if (le[i].first < ri[i].first)
      break;
    ans += 2 * (le[i].first - ri[i].first);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,k;
    int l[51];
    scanf("%d%d",&n,&k);
    int i;
    for(i=0;i<n;i++){
        cin>>l[i];
    }
    int j;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(l[i]>l[j]){
                swap(l[i],l[j]);
            }
        }
    }
    int ans=0;
    for(i=n-k;i<n;i++){
        ans+=l[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
#define ALL(v) (v).begin(), (v).end()

int main()
{
  vector<int> x(3); cin >> x[0] >> x[1] >> x[2];


  int ans = 0;
  while (true) {
    int maxv = *max_element(ALL(x));
    int maxc = count(ALL(x), maxv);
    int maxi = find(ALL(x), maxv) - x.begin();

    int minv = *min_element(ALL(x));
    int minc = count(ALL(x), minv);
    int mini = find(ALL(x), minv) - x.begin();

    if (maxc == 3) break;

    // 最大値が２つで、
    // 1. 最小値との差が２以上であれば最小値を＋２，
    // 2. 最小値との差が１以上であれば最小値と最大値を＋１
    else if (maxc == 2) {
      if (maxv - minv >= 2) {
        x[mini] += 2;
      } else {
        x[mini]++;
        x[maxi]++;
      }
      ans++;
    } else {
      // 最大値以外の２値を＋１
      for (int i = 0; i < 3; ++i) {
        if (maxi == i) continue;
        x[i]++;
      }
      ans++;
    }

    // printf("%d, %d, %d, maxv: %d, maxi: %d\n", x[0], x[1], x[2], maxv, maxi);
  }

  cout << ans << endl;
}

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

int ans[110][110];

main()
{
	int n,m;
	int nl=0,nc=0,di=1;
	scanf("%d %d",&n,&m);
	int k;
	scanf("%d",&k);
	for(int i=0;i<k;i++)
	{
		int a;
		scanf("%d",&a);
		while(a>0)
		{
			ans[nl][nc]=i+1;
			if(nc+di>=m||nc+di<0)
			{
				nl++;
				if(di==1)di=-1;
				else di=1;
			}
			else
				nc+=di;
			a--;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			printf("%d ",ans[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 384