akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    wss <- replicateM n f
    m <- readLn
    map (solve wss) <$> replicateM m f >>= mapM_ putStrLn
    main
  where
    f = map read <$> words <$> getLine

solve :: [[Int]] -> [Int] -> String
solve wss ots
  | any (inout ots) wss = "Safe"
  | any (obstacle ots) wss = "Safe"
  | otherwise = "Danger"

inout :: [Int] -> [Int] -> Bool
inout [tx, ty, sx, sy] [wx, wy, r] = lt2 > r2 && ls2 < r2 || lt2 < r2 && ls2 > r2
  where
    lt2 = (tx - wx) ^ 2 + (ty - wy) ^ 2
    ls2 = (sx - wx) ^ 2 + (sy - wy) ^ 2
    r2 = r ^ 2

outout :: [Int] -> [Int] -> Bool
outout [tx, ty, sx, sy] [wx, wy, r] = lt2 > r2 && ls2 > r2
  where
    lt2 = (tx - wx) ^ 2 + (ty - wy) ^ 2
    ls2 = (sx - wx) ^ 2 + (sy - wy) ^ 2
    r2 = r ^ 2

obstacle :: [Int] -> [Int] -> Bool
obstacle [tx, ty, sx, sy] [wx, wy, r] = outout [tx, ty, sx, sy] [wx, wy, r] &&
                                        dotv1v2 >= 0 &&
                                        dotv1v2 <= l2v1 &&
                                        len2 (dotv1v2 * (fst v1) - l2v1 * (fst v2), dotv1v2 * (snd v1) - l2v1 * (snd v2)) <= l2v1 ^ 2 * r ^ 2
  where
    dot (x1, y1) (x2, y2) = x1 * x2 + y1 * y2
    len2 (x, y) = x ^ 2 + y ^ 2
    v1 = (sx - tx, sy - ty)
    v2 = (wx - tx, wy - ty)
    l2v1 = len2 v1
    dotv1v2 = dot v1 v2



Measured memory_bytes: 4984
import math
total_time = 0
los_ari = False
min_los = 9

for i in range(5):
  T=int(input())
  total_time = total_time + 10 * math.ceil(T/10)
  if T%10!=0:
    los_ari = True
    if T%10<min_los:
      min_los = T%10
      
if los_ari:
  total_time = total_time - (10-min_los)
print('{:.0f}'.format(total_time))

Measured memory_bytes: 3060
#include <iostream>
#include<algorithm>

using namespace std;

int rsw[1000002];

int main() {
	int n, k;
	while (cin >> n >> k, n + k) {
		rsw[0] = 0;
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			rsw[i + 1] = rsw[i] + a;
		}
		int MAX = rsw[k] - rsw[0];
		for (int i = 0; i < n - k + 1; i++) {
			MAX = max(MAX, rsw[i + k] - rsw[i]);
		}
		cout << MAX << endl;
		for (int i = 0; i < 1000002; i++) {
			rsw[i] = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 5064
#include <stdio.h>

int main(void) {
	int i, d, S;
	while (~scanf ("%d", &d)){
		S = 0;
		for (i=0; i<600/d; i++){
			S += ((i*d) * (i*d) * d);
		}
		printf ("%d\n", S);
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)

cnt = 0
for i in range(N):
    cnt += min(A[i], B[i])
    if A[i] < B[i]:
        if A[i+1] > (B[i] - A[i]):
            cnt += (B[i] - A[i])
            A[i+1] = A[i+1] - (B[i] - A[i])
        else:
            cnt += A[i+1]
            A[i+1] = 0
print(cnt)

Measured memory_bytes: 18476
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>

using namespace std;

void solve(int n, int y) {
  int max = y / 10000;
  for(int i=y;i>=0;i--) {
    for(int j=0;j<=2000;j++) {
      if(i+j>n || i*10000+j*5000>y) break;
      for(int k=0;k<=2000;k++){
        int sum = i*10000+j*5000+k*1000;
        int num = i+j+k;
        if(sum>y || num>n) break;
        if(sum==y && num==n) {
          cout << i << " " << j << " " << k << endl;
          return;
        }
      }
    }
  }
  cout << "-1 -1 -1";
}

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

  solve(n, y);
  return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,K;
int A[100010];

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

int main(){
	scanf("%d%d" , &N , &K);
	repp(i,0,N){
		scanf("%d" , A + i);
	}
	sort(A,A+N);
	if(A[N-1] < K){
		printf("IMPOSSIBLE\n");
		return 0;
	}
	int z = 0;
	repp(i,1,N){
		z = gcd(z,A[i]-A[i-1]);
	}
	if(z == 0){
		printf("%s\n" , A[0] == K ? "POSSIBLE" : "IMPOSSIBLE");
	}
	else printf("%s\n" , (A[N-1]-K)%z == 0 ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, A;
    cin >> H >> A;
    ll ans = (H + A - 1) / A;
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
	ll n; cin >> n;
	map<ll, ll> mp, mp2;
	for (int i = 0; i < n; ++i) {
		ll a; cin >> a;
		++mp[a - (i+1)];
		++mp2[-a - (i + 1)];
	}

	ll ans = 0;
	for (auto it : mp) {
		ll k = it.first;
		ll v = it.second;
		if (mp2.count(k)) {
			ans += v * mp2[k];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 26596
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int extract(string s){
    string ans = "" ;
    for(int i = 0; i < s.size(); i++){
        if ( s[i] == '.' ) continue ;
        ans.push_back(s[i]) ;
    }
    stringstream ss ;
    ss << ans ; 
    int x ;
    ss >> x ; 
    return x ;
}
signed main(){
    fastio
    int a ; 
    string b ; 
    cin >> a >> b ; 
    int c = extract(b) ; 
    int ans = a * c / 100 ; 
    cout << ans << endl; 
    return 0; 
}

Measured memory_bytes: 3644
A, B, C = gets.chomp.split(" ").map(&:to_i)
K = gets.to_i

wk, b, c = 0, B, C
until A < b do
  b *= 2
  wk += 1
end
until b < c do
  c *= 2
  wk += 1
end

puts wk <= K ? 'Yes' : 'No'


Measured memory_bytes: 14324
#include <stdio.h>
int main(){
int k,i,max=0,a=0;
scanf ("%d",&k);
char s[100];
scanf ("%s",s);
for (i=0;i<k;i++){
if (s[i]=='I'){
a++;
}
else if (s[i]=='D'){
a--;
}
if (max<a){
max=a;
}
}
  printf ("%d",max);
return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int n,m;
int w[100];

bool test(int wm){
  int d = 0;
  int s = 0;
  REP(i,n){
    if(s + w[i] > wm){
      s = 0;
      d++;
    }
    s += w[i];
  }
  return d < m;
}

int main(){
  while(scanf("%d%d",&m,&n), n+m){
    int low  = 0;
    int high = 0;
    int ltmp;
    REP(i,n){
      scanf("%d",&w[i]);
      low = max(low, w[i]);
      high += w[i];
    }
    ltmp = low;
    while(low < high){
      int mid = (low + high)/2;
      bool tmp = test(mid);
      if(tmp){
	high = mid - 1;
      }else{
	low  = mid + 1;
      }
    }
    for(int i = max(ltmp,low-2);; i++){
      if(test(i)){
	printf("%d\n",i);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

const ll MOD = 998244353;
// const ll MOD = 1e9+7;



int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll h,w,d;
  std::cin>>h>>w>>d;
  std::vector<ll> xp(h*w+1),yp(h*w+1),dis(h*w+1,0);
  rep(i,0,h){
    rep(j,0,w){
      ll a;
      std::cin>>a;
      xp[a]=i;yp[a]=j;
    }
  }
  rep(i,d+1,h*w+1){
    dis[i]=dis[i-d]+std::abs(xp[i]-xp[i-d])+abs(yp[i]-yp[i-d]);
  }
  ll q;
  std::cin>>q;
  rep(i,0,q){
    ll l,r;
    std::cin>>l>>r;
    std::cout<<dis[r]-dis[l]<<"\n";
  }
  return 0;
}

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

void solve(long long a, long long b, long long c){
	vector<long long> s = { a, b, c };
  sort(s.begin(), s.end());
  cout << s[0] + s[1] << endl;
}

int main(){	
	long long b;
	long long c;
	long long a;
	scanf("%lld",&a);
	scanf("%lld",&b);
	scanf("%lld",&c);
	solve(a, b, c);
	return 0;
}



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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n,m,a,b,cn,cm,fpn,fpm;
char ans[1010][1010];

void allocate(){
	if(fpn == 0){
		cout<<"NO\n";
		exit(0);
	}
	cn = (n/2+1-fpn)*2-2;
	cm = fpm*2-2;
	fpm-=1;
	if(fpm == 0)fpm = m/2,fpn-=1;
}

int main() {
	read(n);read(m);read(a);read(b);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ans[i][j] = '.';
		}
	}
	if(m%2 == 1){
		int p = 0;
		while(b && p+1<n){
			ans[p][m-1] = '^';
			ans[p+1][m-1] = 'v';
			p+=2;
			b-=1;
		}
	}
	if(n%2 == 1){
		int p = m-1;
		while(a && p-1>=0){
			ans[n-1][p] = '>';
			ans[n-1][p-1] = '<';
			p-=2;
			a-=1;
		}
	}
	fpn = n/2;
	fpm = m/2;
	while(a>1){
		allocate();
		ans[cn][cm] = '<';
		ans[cn][cm+1] = '>';
		ans[cn+1][cm] = '<';
		ans[cn+1][cm+1] = '>';
		a-=2;
	}
	while(b>1){
		allocate();
		ans[cn][cm] = '^';
		ans[cn+1][cm] = 'v';
		ans[cn][cm+1] = '^';
		ans[cn+1][cm+1] = 'v';
		b-=2;
	}
	if(a>0 && b>0 && n%2 == 1 && m%2 == 1){
		allocate();
		ans[n-1][0] = 'v';
		ans[n-2][0] = '^';
		ans[n-3][0] = '<';
		ans[n-3][1] = '>';
	}else{
		if(a>0){
			allocate();
			ans[cn][cm] = '<';
			ans[cn][cm+1] = '>';
		}
		if(b>0){
			allocate();
			ans[cn][cm] = '^';
			ans[cn+1][cm] = 'v';
		}
	}
	cout<<"YES\n";
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}


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

namespace ARC79_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            var a = new int[m][];
            var c = new Dictionary<int, bool>();
            var d = new Dictionary<int, bool>();

            for (int i = 0; i < n; i++)
            {
                c[i] = false;
                d[i] = false;
            }

            for (int i = 0; i < m; i++)
            {

                a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (a[i][0] == 1) c[a[i][1]] = true;
                if (a[i][1] == n) d[a[i][0]] = true;
            }
            for (int i = 0; i < n; i++)
            {
                if (c[i] && d[i])
                {
                    Console.WriteLine("POSSIBLE");
                    return;
                }
            }
            Console.WriteLine("IMPOSSIBLE");
            
        }
    }
}


Measured memory_bytes: 43604
import scala.io.StdIn

object Main extends App {
  val input = StdIn.readLine().split(" ").map(_.toInt)
  var a = input(0)
  var b = input(1)
  var ret = 0
  ret = exec
  ret += exec
  println(ret)

  def exec() = {
    var ret = 0
    if (a > b) {
      ret = a
      a -= 1
    } else {
      ret = b
      b -= 1
    }
    ret
  }
}

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


int main(){
    ll N, K;
    cin>>N>>K;
    vector<ll> H(N);
    for(ll i=0; i<N; i++){
        cin>>H[i];
    }
    sort(H.begin(), H.end());
    ll Sum=0;
    if(K-N>=0){
        cout<<0<<endl;
    }
    else{
        for(ll i=0; i<N-K; i++){
            Sum+=H.at(i);
        }
        cout<<Sum<<endl;
    }
}



Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

odds = []
bai4 = []

for i in range(N):
    odds.append(A[i]%2 == 1)
    bai4.append(A[i]%4 == 0)
    
odd = sum(odds)
bi4 = sum(bai4)
bi2 = N - odd - bi4

if odd + bool(bi2) > bi4+1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 14228
package main

import (
	"fmt"
)

func main(){
	var x int
	HarsNum := 0
	fmt.Scanf("%d",&x)
	n := x
	for(n > 0){
		r := n % 10
		HarsNum = HarsNum + r
		n = n / 10
	}
	//fmt.Printf("%d\n",HarsNum)
	
	if x % HarsNum == 0{
		fmt.Printf("%s\n","Yes")
	} else {
		fmt.Printf("%s\n","No")
	}
}

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


int main() {
	int N;
	cin >> N;
	int tmpN = N;
	int memo = 0;
	while (tmpN != 0) {
		memo += tmpN % 10;
		tmpN /= 10;
	}
	if (0 == N%memo) {
		cout <<"Yes" <<endl;
	}
	else {
		cout << "No"<<  endl;
	}
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
string s;
int main()
{
	cin>>s;
	if(s.size()==2)
	{
		cout<<s;
	}
	else
	{
		cout<<s[2]<<s[1]<<s[0];
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 8
#define NOT_FREE 1
#define FREE 0
void putQueen(int);
void printBoard(void);
int M[N][N],row[N],col[N],dneg[2*N-1],dpos[2*N-1];
int main(){
  int k,i,j,r,c;
  scanf("%d",&k);
  for(i=0; i<N; i++){                            //
    col[i] = row[i] = dneg[i] = dpos[i] = FREE;  //
    for(j=0; j<N; j++){                          //
      M[i][j] = 0;                               //
    }                                            //
  }                                              //
  for(j=N; j<(N*2-1); j++){                      //
    dneg[j] = dpos[j] = FREE;                    //
  }                                              //
  for(i=0; i<k; i++){
    scanf("%d%d",&r,&c);
    M[r][c] = 1;
  }
  putQueen(0);
  return 0;
}

void putQueen(int i){
  int j;
  if(i == N){
    printBoard();
    return;
  }
  for(j=0; j<N; j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    putQueen(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}
void printBoard(void){
  int i,j;
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(M[i][j] && row[i] != j) return;
    }
  }
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      printf((row[i] == j ? "Q" : "."));
      if(j == N-1) printf("\n");
    }
  }
}

Measured memory_bytes: 588
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}

signed main(){
	int n;cin>>n;
	string s;cin>>s;
	map<char,int> mp;
	rep(i,n) mp[s[i]]++;
	int ans=1;
	itr(i,mp) {
		ans*=i->second+1;
		ans%=mod;
	}
	cout<<ans-1<<endl;
}


Measured memory_bytes: 512
import java.math.BigDecimal;
import java.util.*;

public class Main {
    public static void main(String[] args){
        ABC160A();
    }
    private static void ABC160A() {
        // no comment, no error check
        final int INPUT_LINES_CNT = 1;
        final String DATA_SPLIT_SPACE = " ";

        ArrayList<String> inputLines = getStdInMultiLines(INPUT_LINES_CNT);

        if (inputLines.size() == 0) {
            System.out.println(0);
            return;
        }

        String outputStr;
        try {
            List<String> inputLineList= 
            Arrays.asList((inputLines.get(0)).split(DATA_SPLIT_SPACE));

            String str = inputLineList.get(0);

            if (str.substring(2,3).equals(str.substring(3,4))
                && str.substring(4,5).equals(str.substring(5,6))) {
                    outputStr = "Yes";
                }
            else {
                outputStr = "No";
            }
        }
        catch (Exception ex) {
            outputStr = "No";
        }

        System.out.println(outputStr);
        return;
    }

    private static int getStdInNum() {
        String line1 = getStdInSingleLine();
        if (isNumber(line1)) {
            return Integer.parseInt(line1);
        }
        return 0;
    }

    private static ArrayList<String> getStdInMultiLines() {
        int cnt = 0; 
        int max = 0;

        Scanner cin = new Scanner(System.in);
        ArrayList<String> list = new ArrayList<String>();
        for (;cin.hasNext();) {
            list.add(cin.nextLine());
            if (cnt++ == 0) {
                max = Integer.parseInt((list.get(0)).split(" ")[0]);
            }
            else if (cnt == max + 1) {
                break;
            }
        }
        cin.close();
        return list;
    }
    private static ArrayList<String> getStdInMultiLines(int inputLinesCnt) {
        int cnt = 0; 

        Scanner cin = new Scanner(System.in);
        ArrayList<String> list = new ArrayList<String>();
        for (;cin.hasNext();) {
            list.add(cin.nextLine());
            if (++cnt == inputLinesCnt) {
                break;
            }
        }
        cin.close();
        return list;
    }

    private static String getStdInSingleLine() {
        Scanner cin = new Scanner(System.in);

        for (;cin.hasNext();) {
            cin.close();
            return cin.nextLine();
        }

        cin.close();
        return "";
    }

    private static boolean isNumber(String val) {
        try {
            Integer.parseInt(val);
            return true;
        }
        catch (NumberFormatException nfex) {
            return false;
        }
    }

}


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

int main(void) {
    int n, m;
    cin >> n >> m;
    long long a[n];
    rep(i, n) cin >> a[i];

    reps(i, 1, n) a[i] += a[i-1];
    rep(i, n) a[i] %= m;

    long long cnt = 0;
    map<int, int> dp;
    rep(i, n) {
        cnt += dp[a[i]];
        dp[a[i]]++;
        cnt += a[i] == 0;
    }

    cout << cnt << endl;

}


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

int main() {
    int c[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) cin >> c[i][j];
    }

    bool ans = true;

    // 下向きに差が一定かチェック
    for (int i = 1; i < 3; i++) {
        int diff[3];
        for (int j = 0; j < 3; j++) {
            diff[j] = c[i][j] - c[i - 1][j];
        }
        if (diff[0] != diff[1] || diff[0] != diff[2]) {
            ans = false;
            break;
        }
    }

    // 右向きにも同じことをする
    for (int j = 1; j < 3; j++) {
        int diff[3];
        for (int i = 0; i < 3; i++) {
            diff[i] = c[i][j] - c[i][j - 1];
        }
        if (diff[0] != diff[1] || diff[0] != diff[2]) {
            ans = false;
            break;
        }
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
first=[]
second=[]
for m in range(M):
    a,b=map(int,input().split())
    if a==1:
        first.append(b)
    elif b==N:
        second.append(a)
first_and_second=set(first)&set(second)
if len(first_and_second)==0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')


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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    int64_t K;
    cin >> N;
    cin  >> K;

    int a, b;
    multimap<int, int> m;
    for (int i = 0; i < N; i++) {
        cin >> a;
        cin >> b;
        m.emplace(a, b);
    }
    
    int64_t sum_b = 0;
    for (auto p: m) {
        sum_b += p.second;
        if (sum_b >= K) {
            cout << p.first << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4992
#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 x,a,b;cin >> x >> a >> b;
  a *= -1;
  if(a+b <= 0)cout << "delicious" << endl;
  else if(a+b > 0&& a+b <= x)cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    ll C;
    cin >> C;
    if((C-A-B)*(C-A-B)-4*A*B>0&&C-A-B>=0)prt("Yes");
    else prt("No");
    return 0;
}



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

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

int ans = 0 ;
int in;
int memo;

for(int i=0;i<n;i++){
  if(i==0){
    cin >> in;
    ans += in;
    memo = in;
  }else if(i < n-1){
    cin >> in;
    if(memo <= in){
      ans += memo;
    }else{
      ans += in;
    }
    memo = in;
  }else if(i == n-1){
    ans += in;
  }
}

cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N;
    cin >> N;
    ll a[N];
    for(ll i = 0; i < N; i++) cin >> a[i];
    ll po[N][30] = {};
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < 30; j++) po[i][j] = 0;
        for(ll j = 0; ; j++){
            if(a[i] < (1 << j)) break;
            if((a[i] & (1 << j))) po[i][j]++;
        }
        if(i){
            for(ll j = 0; j < 30; j++) po[i][j] += po[i - 1][j];
        }
    }
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ll ok = i, ng = N;
        while(ng - ok > 1){
            ll mid = (ok + ng) / 2;
            bool f = 1;
            for(ll j = 0; j < 30; j++){
                if(po[mid][j] - (i ? po[i - 1][j] : 0) >= 2) f = 0;
            }
            if(f) ok = mid;
            else ng = mid;
        }
        ans += ok - i + 1;
    }
    cout << ans << endl;
    return 0;
}

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

bool AC[100100];
int WA[100100];

int ac,wa;

int main(){
  int n,m; cin >> n >> m;
  //初めてACが出るまでのWAの数と、ACの被らない数
  for(int i = 0; i < m; i++){
    int p; string s; cin >> p >> s;
    if( AC[p] ){ continue;} //一度ACしていたら問題なし
    else{
      
      if( s == "WA" ){ WA[p]++;} //
      else{
        AC[p] = true;
      }
    }
  }
  
  for(int i = 0; i < 100100; i++){
    if(AC[i]){ ac++; wa += WA[i];}
  }
  
  cout << ac << " "<< wa << endl;
  
  return 0;
}
  

Measured memory_bytes: 768
x,y=map(int,input().split())
ans=0
if x==1:
    ans+=300000
elif x==2:
    ans+=200000
elif x==3:
    ans+=100000

if y==1:
    ans+=300000
elif y==2:
    ans+=200000
elif y==3:
    ans+=100000

if x==1 and y==1:
    ans+=400000
print(ans)

Measured memory_bytes: 3316
#include <stdio.h>
int main(){
	int a,b,c,count=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b && a==c) printf("1");
	else if(a==b && a!=c) printf("2");
	else if(b==c && b!=a) printf("2");
	else if(a==c && a!=b) printf("2");
	else printf("3");
}

Measured memory_bytes: 128
import fractions
n,x = map(int,input().split())
li = list(map(int,input().split()))
lia = []
for i in range(n):
    lia.append(abs(li[i]-x))
a = lia[0]
for i in range(n-1):
    a = fractions.gcd(a,lia[i+1])
print(a)

Measured memory_bytes: 16284
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

// Implementation according to Solution 1 in the editorial

#[fastout]
fn main() {
    input! {
        n: usize,
        xyp: [(isize, isize, usize); n],
    }
    macro_rules! pow2 (($i:expr) => (1 << $i));
    let mut pow3vec: Vec<usize> = Vec::with_capacity(n + 1);
    let mut tmp = 1;
    for _ in 0..=n {
        pow3vec.push(tmp);
        tmp *= 3;
    }
    let _ = tmp;
    let pow3vec = pow3vec;
    macro_rules! pow3 (($i:expr) => (pow3vec[$i]));
    macro_rules! has_railway (($bits:expr, $i:expr) => ($bits & pow2!($i-1) != 0));
    // Precompute the distances
    let mut tate_costs: Vec<Vec<usize>> = vec![vec![0; n]; pow2!(n)];
    for bits in 0..pow2!(n) {
        for i in 1..=n {
            let (x, y, p) = xyp[i - 1];
            let mut min_dist = x.abs().min(y.abs()) as usize;
            for j in 1..=n {
                if has_railway!(bits, j) {
                    let (xx, _yy, _pp) = xyp[j - 1];
                    let dist = (xx - x).abs() as usize;
                    min_dist = min_dist.min(dist);
                }
            }
            tate_costs[bits][i - 1] = min_dist * p;
        }
    }
    let mut yoko_costs: Vec<Vec<usize>> = vec![vec![0; n]; pow2!(n)];
    for bits in 0..pow2!(n) {
        for i in 1..=n {
            let (x, y, p) = xyp[i - 1];
            let mut min_dist = x.abs().min(y.abs()) as usize;
            for j in 1..=n {
                if has_railway!(bits, j) {
                    let (_xx, yy, _pp) = xyp[j - 1];
                    let dist = (yy - y).abs() as usize;
                    min_dist = min_dist.min(dist);
                }
            }
            yoko_costs[bits][i - 1] = min_dist * p;
        }
    }
    // Check patterns
    let mut min_costs: Vec<usize> = vec![10000 * 1000000 * 15; n + 1];
    for either_railways in 0..pow2!(n) {
        let num_railways = (either_railways as u64).count_ones() as usize;
        let mut yoko_railways = either_railways+1;
        while yoko_railways > 0 {
            yoko_railways -= 1;
            yoko_railways &= either_railways;
            let tate_railways = either_railways - yoko_railways;
            let mut cost = 0;
            for j in 1..=n {
                cost += tate_costs[tate_railways][j - 1].min(yoko_costs[yoko_railways][j - 1]);
            }
            // Update
            min_costs[num_railways] = min_costs[num_railways].min(cost);    
        }
    }
    for c in min_costs {
        println!("{}", c);
    }
}


Measured memory_bytes: 11764
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) FOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int h,w;
string s[100];


bool search(){
  rep(i,h){
    rep(j,w){
      if(s[i][j]!='#') continue;
      int c=0;
      rep(k,4){
        int x=j+vx[k],y=i+vy[k];
        if(0<=x&&x<=w&&0<=y&&y<=h){
          if(s[y][x]=='#') c++;
        }
      }
      if(!c) return false;
    }
  }

  return true;
}


int main(){
  cin>>h>>w;
  rep(i,h){
    cin>>s[i];
  }

  if(search()){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 2e2 + 2;
const int M = 1e7 + 7;
int n;
int x[N];
int arr[N];
int siz;
bool p[M];
void pre(){
	for(int i = 2 ; i * i < M ; ++i){
		if(!p[i]){
			for(int j = i * i ; j < M ; j += i){
				p[j] = 1;
			}
		}
	}
	p[0] = 1;
	p[1] = 1;
	p[2] = 1;
}
vector < int > v[N];
int lft , rgt;
int match[N];
int timer;
int visited[N];
bool dfs(int node){
	if(visited[node] == timer){
		return 0;
	}
	visited[node] = timer;
	for(int next : v[node]){
		if(!match[next] || dfs(match[next])){
			match[next] = node;
			return 1;
		}
	}
	return 0;
}
int main(){
	pre();
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , x + i);
	}
	int cur = x[1];
	int str = x[1];
	for(int i = 2 ; i <= n ; ++i){
		if(cur + 1 != x[i]){
			arr[++siz] = str;
			arr[++siz] = cur + 1;
			str = x[i];
			cur = x[i];
		}
		else{
			++cur;
		}
	}
	arr[++siz] = str;
	arr[++siz] = cur + 1;
	n = siz;
	for(int i = 1 ; i <= n ; ++i){
		if(arr[i] & 1){
			++lft;
		}
		else{
			++rgt;
		}
	}
	for(int i = 1 ; i <= n ; ++i){
		if(arr[i] & 1){
			for(int j = 1 ; j <= n ; ++j){
				if(!p[abs(arr[j] - arr[i])]){
					v[i].emplace_back(j);
				}
			}
		}
	}
	int tot = 0;
	for(int i = 1 ; i <= n ; ++i){
		if(arr[i] & 1){
			++timer;
			tot += dfs(i);
		}
	}
	int ans = 0;
	ans += tot;
	ans += ((lft - tot) >> 1) << 1;
	ans += ((rgt - tot) >> 1) << 1;
	ans += ((lft - tot) & 1) * 3;
	printf("%d\n" , ans);
}

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

using namespace std;

void solve1() {
	int N;
	cin >> N;

	//calculate
	string ans = "No";
	if (N >= 21) {
		ans = "Yes";
	} else {
		if (N % 4 == 0) {
			ans = "Yes";
		} else {
			for (int i = 0; i < 2; ++i) {
				N -= 7;
				if (N < 0) {
					ans = "No";
					break;
				} else if (N % 4 == 0) {
					ans = "Yes";
					break;
				}
			}
		}
	}

	//print
	cout << ans << '\n';
}

void solve2() {
	int N;
	cin >> N;

	//calculate
	int ans = 0;

	//print
	cout << ans << '\n';
}

void solve3() {
	int N;
	cin >> N;

	//calculate
	string ans = "";
	do {
		if (N % 2 == 0) {
			N /= -2;
			ans = "0" + ans;
		} else {
			N -= 1;
			N /= -2;
			ans = "1" + ans;
		}
	} while (N != 0);

//print
	cout << ans << '\n';
}

void solve4() {
	int N;
	cin >> N;

//calculate
	int ans = 0;

//print
	cout << ans << '\n';
}

int main() {
	solve3();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
 int  N;
  cin >> N;
  string A , B , C;
  cin >> A >> B >> C;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == B.at(i) && B.at(i) == C.at(i)) {
      
    } else if (A.at(i) == B.at(i) || B.at(i) == C.at(i) || C.at(i) == A.at(i)) {
      count++;
    } else {
      count += 2;
    }
  }
  cout << count << endl;
  return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    string n;
    cin >> n;
    if(n[0]=='7'||n[1]=='7'||n[2]=='7'){
        c("Yes");
    }else
        c("No");
    return 0;
}


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

int main (){
    int N;
    cin>>N;
    vector<long long> A(N);
    for(int i=0; i<N; i++){
        cin>>A.at(i);
    }
    sort(A.begin(), A.end());
    cout<<A.at(N-1)-A.at(0)<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
edge = [list(map(int,input().split())) for _ in range(N-1)]

ad = [[] for _ in range(N)]

for u, v, w in edge:
    u -= 1; v -= 1
    ad[u].append((v,w))
    ad[v].append((u,w))

ans = [0]*N

def dfs(v=0,pv=-1,d=0):
    if d % 2 == 0:
        ans[v] = 1
    for nv,w in ad[v]:
        if nv != pv:
            dfs(nv,v,d+w)

dfs()

for a in ans:
    print(a)

Measured memory_bytes: 109116
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
#define PI 3.14159265359
using namespace std;

int main(void)
{
	double x1, y1, x2, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	cout << setprecision(10) << sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) << endl;

}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  string s;cin>>s;
  ll n;cin>>n;
  rep(i,0,n){
    string order;cin>>order;
    ll a,b;cin>>a>>b;
    if(order=="replace"){
      string re;cin>>re;
      rep(i,a,b+1)s[i]=re[i-a];
    }
    else if(order=="reverse"){
      reverse(s.begin()+a,s.begin()+b+1);
    }
    if(order=="print"){
      out(s.substr(a,b-a+1));
    }
  }

  return 0;
}



Measured memory_bytes: 3204
import Control.Applicative
import Data.List

main = do
    [a,b,c] <- map read . words <$> getLine :: IO [Int]
    k <- readLn
    print $ solve a b c k

solve :: Int -> Int -> Int -> Int -> Int
solve a b c k = f*2^(k) + d + e
    where [d,e,f] = sort [a,b,c]

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

int main(void){
    // Your code here!
    int N;
    vector<int> d(110);
    cin >> N;
    for (int i = 0; i < N ; i++)  cin >> d.at(i);
    vector<int> num(110,0);
    for (int i = 0; i < N ; i++) {
        num.at(d.at(i))++;
    }
    
    int res = 0 ;
    for (int i = 0; i <= 100 ; i++) {
        if (num.at(i)) {
            res++;
        }
        }
        cout << res <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <string> 
using namespace std;
#include <string> 
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);
typedef long long ll;
#define MAX 1000000000
ll abs(ll a, ll b){
	return (a<b?b-a:a-b);
}

int main()
{
	fast;
	ll n,i,a[105],b[105],j,k,w;
	cin>>n>>k;
	for(i=0;i<n;i++)
		cin>>b[i]>>a[i];
	ll dp[n+1][k+1];
	for(i=0;i<=n;i++){
		for(w=0;w<=k;w++)
		{
			if(i==0||w==0)
				dp[i][w]=0;
			else if(b[i-1]<=w)
				dp[i][w]=max(a[i-1]+dp[i-1][w-b[i-1]],dp[i-1][w]);
			else
				dp[i][w]=dp[i-1][w];
		}
	}
	cout<<dp[n][k];

	return 0;
}


Measured memory_bytes: 79232
#include <iostream>
#include <vector>
#include <string>

typedef long long ll;

using namespace std;

vector<int> balls(10);

bool flag;

void dfs(int i, int left, int right) {
    if (i == 10) {
        flag = true;
        return;
    }
    int num = balls[i];
    if (left < num) {
        dfs(i+1, num, right);
    }
    if (right < num) {
        dfs(i+1, left, num);
    }
}

void solve() {
    flag = false;
    for (int i = 0; i < 10; i++) {
        cin >> balls[i];
    }
    dfs(0, 0, 0);
    string ans = flag ? "YES": "NO";
    cout << ans << endl;
}

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

    int N = 0;
    cin >> N;

    for (int i = 0; i < N; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int m, n[4], mi[4], ma[4], na;
	int	max_int = 0, min_int = 0, n_int, ans;
	bool same;
				
	while (1){
		ans = 0;
		same = false;

		scanf("%d", &n_int);
		if (n_int == 0) break;
		if (n_int % 1111 == 0){
		 cout << "NA" << endl;
		 same = true;
		}

		for (int i = 3; i >= 0; i--){
			n[i] = n_int / (int)(pow(10, i)) % 10;
		}

		while (n_int != 6174){
			if (same) break;
			max_int = min_int = 0;

			for (int i = 3; i >= 0; i--){
				n[i] = n_int / (int)(pow(10, i)) % 10;
			}
			sort(n, n + 4);

			for (int i = 0; i < 4; i++){
				mi[3 - i] = n[i];
				ma[i] = n[i];
			}

			for (int i = 0; i < 4; i++){
				max_int += ma[i] * (int)(pow(10, i));
				min_int += mi[i] * (int)(pow(10, i));
			}
			n_int = max_int - min_int;
			
			ans++;
		}

		if (!same) cout << ans << endl;
	}
return (0);
}

Measured memory_bytes: 3380
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define fo(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
const int N=2e5+11;
int n,a[N];
char s[N];
int main(){
	cin>>n>>s+1;
	rep(i,1,n)
		a[i]=a[i-1]+(s[i]=='#');
	int ans=n;
	rep(i,0,n){
		ans=min(ans,a[i]+(n-i-(a[n]-a[i])));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1280
import java.util.*;


public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        
        int yusha = s.nextInt();        // 勇者の数
        long monsters[] = new long[yusha + 1];    //　モンスターの数を格納する
        long strength[] = new long[yusha];        // 勇者の強さを格納する

        // モンスターを倒した数
        long count = 0;

        for (int i = 0; i < yusha+1; i++) {
            monsters[i] = s.nextInt();
        }

        for (int i = 0; i < yusha; i++) {
            strength[i] = s.nextInt();
        }

        // 勇者の数だけループ
        for (int i = 0; i < yusha; i++) {
            // 2つの街を守ろうとする
            for (int j = 0; j < 2; j++) {
                // 勇者よりモンスターが強い場合倒せる限り倒す
                if (monsters[i+j] >= strength[i]) {
                    count += strength[i];
                    monsters[i+j] = monsters[i+j] - strength[i];    // 残りモンスター数
                    strength[i] = 0;                // 勇者の余力
                } else {
                    count += monsters[j + i];   // 一つの街のモンスターをすべて倒す
                    strength[i] = strength[i] - monsters[i+j];  // 勇者の余力
                    monsters[i+j] = 0;    // 残りモンスター数
                }
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 80356
#include <bits/stdc++.h>
#define pb push_back
#define p push
#define ll long long
#define f first
#define s second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define plli pair<ll,int>
#define pill pair<ill>
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b, c; cin >> a >> b >> c;
    cout << min (c, b/a) << endl;
    return 0;
}



Measured memory_bytes: 3524
#include"bits/stdc++.h"
#include"math.h"
using namespace std;

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

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()

int main(){
  ll n;cin >> n;
  vector<pair<ll,ll>>s;
  for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			s.push_back(make_pair(i,n/i));
		}
	}
  ll x=1000000000000000;
  ll y=0;
  for(int i=0;i<s.size();i++){
    if(x>abs(s[i].first-s[i].second)){
      y=i;
   x= min(x,abs(s[i].first-s[i].second));
    }
  }
  cout << s[y].first+s[y].second - 2 << endl;}

  

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  long long n,x;
  cin>>n>>x;
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  
  long long f[n][n];
  REP(i,n){
    f[i][0] = a[i];
  }
  REP(i,n){
    REPP(j,n-1){
      f[i][j] = min(f[i][j-1], a[((i-j)%n+n)%n]);
    }
  }
  
  long long ans = INF;
  long long temp;
  REP(k,n){
    temp = 0;
    temp += k*x;
    REP(i,n){
      temp += f[i][k];
    }
    ans = min(ans, temp);
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 31488
package main

import "fmt"

func main(){
  var a,b,c,d int
  fmt.Scan(&a, &b, &c, &d)
  
  for {
  	c-=b
    if c <= 0{
      fmt.Println("Yes")
      return
    }
    a -= d
	if a <= 0 {
      fmt.Println("No")
      return
	}
  }
}

Measured memory_bytes: 1752
#include <iostream>
#include<cstring>
#include <string.h>
using namespace std;
int main(void){
    // Your code here!
    char str[6];

    while(cin >> str)
    
    if ( str[2] == str[3] && str[4] == str[5] ) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
int N;
vector<int> d;
vector<int> f;
int de = 0;
void dfs(int v,int p){
    d[v] = ++de;
    for(auto nv:G[v]){
        if(d[nv]!=-1) continue;
        dfs(nv,v);
    }
    f[v] = ++de;
}
signed main(){
    stack<int> st;
    cin >> N;
    G.resize(N);
    d.assign(N,-1);
    f.assign(N,-1);
    for(int i=0;i<N;i++){
        int id;cin >> id;
        int k;cin >> k;
        for(int j=0;j<k;j++){
            int a;cin >> a;a--;
            G[i].push_back(a);
        }
    }
    /*st.push(0);
    int dep=0;
    while(!st.empty()){
        int now = st.top();
        dep++;
        d[now] = dep;
        st.pop();
        for(int nv:G[now]){
            if(d[nv]!=-1) continue;
            st.push(nv);
        }
    }*/
    for(int i=0;i<N;i++){
        if(d[i]==-1) dfs(i,-1);
    }
    for(int i=0;i<N;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}


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

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

    int a[2][n];
    for (auto i = 0; i < 2; i++) {
        for (auto j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }

    int sum[n] = { 0 };
    for (auto i = 0; i < n; i++) {
        sum[i] += a[0][i];
        for (auto j = 0; j < n; j++) {
            if(i > j) sum[i] += a[0][j];
            else sum[i] += a[1][j];
        }
    }

    int max = 0;
    for (auto i = 0; i < n; i++) {
        if(max < sum[i]) max = sum[i];
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int h, a;
  cin >> h >> a; 
  
  cout << ceil(h / (double)a) << endl;
  return 0;
}

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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)

constexpr int mod = 1e9+7;
int main(){
  int N;
  cin >> N;
  bool exist = false;
  int s = 0;
  for(int i = 1; i*(i+1) <= 2*N; i++){
    if(i*(i+1) == 2*N){
      exist = true;
      s = i;
    }
  }
  vector<vector<int>> ans(s+1, vector<int>(s,-1));
  if(exist){
    int x = 1;
    REP(i, s+1){
      REP(j, i){
        //ans[i][j] = ans[j][i+j-1];
        ans[i][j] = ans.at(j).at(i-1);
      }
      FOR(j, i, s){
        ans[i][j] = x;
        x++;
      }
    }
  }
  if(exist){
    cout << "Yes" << endl;
    cout << s+1 << endl;
    REP(i, s+1){
      cout << s << " ";
      REP(j, s){
        cout << ans[i][j] << " ";
      }
      cout << endl;
    }
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 2176