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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int n, m, k;

int main() {
	
	FAST;
	
	cin >> n >> m >> k;
	vector <int> x(k + 1), y(k + 1);
	vector <int> prefx(n + 2), prefy(m + 2);
	for (int i = 1; i <= k; i ++) {
		cin >> x[i] >> y[i];
		prefx[x[i]] ++;
		prefx[x[i] + 1] --;
		prefy[y[i]] ++;
		prefy[y[i] + 1] --;
	}
	for (int i = 1; i <= n; i ++) prefx[i] += prefx[i - 1];
	for (int i = 1; i <= m; i ++) prefy[i] += prefy[i - 1];
	int maxx = -1, maxy = -1;
	for (int i = 1; i <= n; i ++) maxx = max(maxx, prefx[i]);
	for (int i = 1; i <= m; i ++) maxy = max(maxy, prefy[i]);
	int ans = maxx + maxy;
	int cntx = 0, cnty = 0;
	for (int i = 1; i <= n; i ++) {
		if (prefx[i] == maxx) cntx ++;
	}
	for (int i = 1; i <= m; i ++) {
		if (prefy[i] == maxy) cnty ++;
	}
	int allcnt = 0;
	for (int i = 1; i <= k; i ++) {
		if (prefx[x[i]] + prefy[y[i]] == ans) allcnt ++;
	}
	if (1LL * allcnt == 1LL * cntx * cnty) {
		cout << ans - 1 << '\n';
	}
	else {
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 7944
from collections import deque
h,w,n = map(int,input().split())
factrys = [None] * (n + 1)
ss = ["X" * (w + 2)]
append = ss.append
for i in range(h):
  s = "X" + input() + "X"
  if "S" in s:
    factrys[0] = (i + 1, s.index("S"))
  for j in range(len(s)):
    if s[j] != 'S' and s[j] != '.' and s[j] != 'X':
      factrys[int(s[j])] = (i + 1, j)
  append(s)
append("X" * (w + 2))

def bfs(i):
  mp = [[None] * (w + 2) for j in range(h + 2)]
  x,y = factrys[i]
  que = deque()
  append = que.append
  popleft = que.popleft
  append((x, y))
  for count in range(10000000):
    sz = len(que)
    for loop in range(sz):
      (x,y) = popleft()
      if ss[x][y] == 'X' or not mp[x][y] is None:
        continue
      if (x,y) == factrys[i + 1]:
        return count
      mp[x][y] = count
      append((x + 1, y))
      append((x - 1, y))
      append((x, y + 1))
      append((x, y - 1))

ans = 0
for i in range(n):
  ret = bfs(i)
  if ret is None:
    ans += 0
  else:
    ans += (ret)
print(ans)


Measured memory_bytes: 18160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class BIT {
    int n;
    vector<ll> node;

public:
    BIT(int N) : n(N), node(N + 1) {}
    void add(int i, ll x) {
        for (++i; i <= n; i += i & -i) { node[i] += x; }
    }
    ll sum(int i) {
        ll s = 0;
        for (; i > 0; i -= i & -i) { s += node[i]; }
        return s;
    }
};
class RSQ {
    int n;
    BIT a, b;

public:
    RSQ(int N) : n(N), a(N), b(N) {}
    void add(int l, int r, ll x) {
        int t = r - l;
        a.add(l, -l * x);
        a.add(r, r * x);
        b.add(l, x);
        b.add(r, -x);
    }
    ll sum(int i) { return a.sum(i) + i * b.sum(i); }
};

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

    int N, K;
    cin >> N >> K;
    RSQ rsq(N);
    for (int b = 1; b <= N; ++b) {
        int q = N / b;
        int r = N % b;
        rsq.add(0, b, q);
        rsq.add(1, r + 1, 1);
    }
    cout << rsq.sum(N) - rsq.sum(K) << endl;

    return 0;
}


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

#define ll long long

int main() {
  double r;
  double pi = 3.141592653589;

  cin >> r;
  
  printf("%.7f %.7f\n", r * r * pi, 2 * pi * r);
  return 0;
}
  

Measured memory_bytes: 1228
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n,ans =0; cin >> n;
	int a[15],x[15][15];
	bool y[15][15];
	rep(i, n) {
		cin >> a[i];
		rep(j, a[i]) {
			cin >> x[i][j] >> y[i][j];
			x[i][j]--;
		}
	}
	rep(bit, (1 << n)) {
		int sum = 0; bool b = true;
		rep(i, n) {
			if ((bit >> i) & 1) { // honest
				sum++;
				rep(j, a[i]) {
					if (((bit >> x[i][j]) & 1) != y[i][j]) b = false;
				}
			}
			else continue;
		}
		if (b) {
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
##13日後のやつを10日後に
d=int(input())
*c,=map(int, input().split())
s=[]
for _ in range(d):
    *si,=map(int, input().split())
    s.append(si)
last=[-1]*26

ss=0
for i in range(d):
    ind=-1
    smx=-10**10
    for j in range(26):
        ssj=ss+s[i][j]
        for k in range(26):
            if k!=j:
                ssj-= c[k]*(i-last[k]+min(10,d-i-1))
        if smx<ssj:
            smx=ssj
            ind=j
    last[ind]=i
    ss+=s[i][ind]
    for k in range(26):
        if k!=ind:
            ssj-= c[k]*(i-last[k])
    print(ind+1)








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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	ll r,d,x;
	cin>>r>>d>>x;
	rep(i,0,10){
		x=r*x-d;
		cout<<x<<endl;
	}	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,a[100000];
    scanf("%d",&n);
    for(i = 0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    int temp;
    for(i = 0;i<n;i++)
    {
        for(int j = i+1;j<n;j++)
        {
            if(a[i]>=a[j])
            {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    int sum = 0;
    for(i = 0;i<n-1;i++)
    {
        sum += a[i];
    }
    if(sum <= a[n-1])
        printf("No\n");
    else
        printf("Yes\n");

}


Measured memory_bytes: 1620
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)

std::map<long long, long long> prime_factor(long long n) {
  std::map<long long, long long> ret; // ret.first:prime_number, ret.second:count
  for(long long i = 2; i * i <= n; ++i) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1; // if n is prime number.
  return ret;
}

int main() {
  ll N, M;
  cin >> N >> M;

  ll div = N;
  map<ll, ll> primes = prime_factor(M);
  for (const auto prime : primes) {
    if (prime.first > N) {
      div = prime.first;
      break;
    }
  }
  if (div < 10e7) {
    div = N;
    while (M%div != 0) {
      div++;
    }
  }
  ll ans = M/div;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

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

using namespace std;
using vi=vector<int>;

vector<int> m(8, -1);
vector<int> ans(8, -1);

bool valid() {
	bool board[8][8] = {0};
	rep(i, 8) {
		if(m[i] == -1) continue;
		board[i][m[i]] = true;
	}
	const int dr[4] = {1, 1, 0, -1};
	const int dc[4] = {0, 1, 1, 1};
	rep(i, 8) {
		if(m[i] == -1) continue;
		rep(j, 4) {
			int q_r = i+dr[j], q_c = m[i]+dc[j];
			while(0<=q_r && q_r<8
					&&0<=q_c && q_c<8) {
				if(board[q_r][q_c]) return false;
				q_r += dr[j], q_c += dc[j];
			}
		}
	}
	return true;
}

void dfs(int r) {
	if(r == 8) {
		ans = m;
		return;
	}

	if(m[r] != -1) {
		dfs(r+1);
		return;
	}

	rep(i, 8) {
		m[r] = i;
		if(valid()) dfs(r+1);
		m[r] = -1;
	}
}

int main(void){
	int k; cin >> k;
	rep(i, k) {
		int r, c; cin >> r >> c;
		m[r] = c;
	}
	dfs(0);
	// rep(i, 8) {
	// 	cerr << ans[i] << " ";
	// }
	char board[8][8] = {0};
	rep(i, 8) rep(j, 8) board[i][j] = '.';
	rep(i, 8) {
		board[i][ans[i]] = 'Q';
	}
	rep(i, 8) {
		rep(j, 8) {
			cout << board[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3136
n, *a = map(int, open(0).read().split())
zero = 0
minus = 0
for i in a:
        if i==0: zero += 1
        if i<0: minus += 1
b = [abs(i)for i in a]

if minus%2==0 or zero>0: print(sum(b))
else: print(sum(b)-min(b)*2)

Measured memory_bytes: 14116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    ll N;
    cin>>N;
    if(N==1){cout<<0<<endl;return 0;}
    ll ans=0;
    for(ll i=1;i*i<=N;i++){
        if(N%i>0)continue;
        ll x=N/i-1;
        //cout<<x<<" ";
        if(x>N/x){
            ans+=x;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long LL;
const int maxn = 1e9 + 1;
int main()
{
	LL a,temp;
	cin>>a;
	for(int i = 1; i <= maxn; i++){
		if((i*i <= a) && ((i+1)*(i+1) > a)){ temp = i*i; break;}
		else continue;
	}
	cout<<temp<<endl;
	return 0;
}

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

min_value = 2019

for i in range(L, R+1):
	for j in range(L, R+1):
		if i >= j:
			continue

		value = (i * j) % 2019
		if value < min_value:
			min_value = value

		if min_value == 0:
			print(min_value)
			exit()

print(min_value)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    map<ll,ll>m;
    ll num[n];
    for(ll i=0;i<n;i++)
    {
        cin>>num[i];
        m[num[i]]+=1;
    }
    ll ans=0;
    for(auto i=m.begin();i!=m.end();i++)
    {
        ans+=((i->second)*(i->second-1)/2);
    }
    for(ll i=0;i<n;i++)
    {
        cout<<ans-m[num[i]]+1<<endl;
    }
}

Measured memory_bytes: 11008
import java.util.*;


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

    int N = scanner.nextInt();
    long[] p = new long[100001];
    int[] a = new int[N]; 
    for (int i=0; i<N; i++){
      a[i] = scanner.nextInt();
      p[a[i]] += 1;
    }
    int Q = scanner.nextInt();
    int[] b = new int[Q];
    int[] c = new int[Q];
    for(int i=0; i<Q; i++){
      b[i] = scanner.nextInt();
      c[i] = scanner.nextInt();
    }

    long sum = 0;
    for(int j=0; j<N; j++){
      sum += a[j];
    }    
    for(int i =0; i< Q; i++){
      sum = sum - b[i]*p[b[i]] + c[i]*p[b[i]];
      p[c[i]] += p[b[i]];
      p[b[i]] = 0;
      
      System.out.println(sum);
    }
    scanner.close();
    return;
  }
}


Measured memory_bytes: 61636
package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scanf("%s", &S)
	smap := make(map[byte]int)
	sg := make([]int, len(S))
	g := 1
	for i := 0; i < len(S); i++ {
		if smap[S[i]] == 0 {
			smap[S[i]] = g
			g++
		}
		sg[i] = smap[S[i]]
	}
	var T string
	fmt.Scanf("%s", &T)
	tmap := make(map[byte]int)
	tg := make([]int, len(T))
	g = 1
	for i := 0; i < len(T); i++ {
		if tmap[T[i]] == 0 {
			tmap[T[i]] = g
			g++
		}
		tg[i] = tmap[T[i]]
	}
	for i := 0; i < len(S); i++ {
		if sg[i] != tg[i] {
			fmt.Println("No")
			return
		}
	}
	if g < 26 {
		fmt.Println("Yes")
		return
	}
	d := 0
	for i := 0; i < 26; i++ {
		if smap[byte(i)+97] != tmap[byte(i)+97] {
			d++
		}
	}
	if d%2 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 6528
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<list>
#include<stack>
#include<sstream>
#define lli unsigned long long int
#define h 100
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL) ;
  lli t, n, i, flag=0, sum, x, a, b, j;
  cin>>a>>b;
  sum=0;
  for(x=a;x<=b;x++) 
  {
  	stringstream ss;
  	string y;
  	ss<<x;
  	ss>>y;
  	i=0;
  	flag=0;
  	j=y.size()-1;
  	for(;i<(y.size()/2);j--,i++) 
  	if(y[i]!=y[j]) {flag=1;break;} 
  	if(flag) continue;
  	else sum+=1;
  } 
  cout<<sum<<endl;
  return 0;
} 


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


int main(){
  string s;
  cin >> s;
  int ans = 0;
  if (s == "SSS") ans = 0;
  else if (s[1] == 'S') ans = 1;
  else if (s == "SRS") ans = 1;
  else if (s == "SRR") ans = 2;
  else if (s == "RRS") ans = 2;
  else ans = 3;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  char a,b;
  cin >> a >> b;
  if(a=='H')  cout << b << endl;
  else if(b=='H') cout << 'D' << endl;
  else if(b=='D') cout << 'H' << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        int a = in.ni();
        int b = in.ni();
        int c = in.ni();
        out.println(Math.max(a,Math.max(b,c))*10+(a+b+c-Math.max(a,Math.max(b,c))));
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> City(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    City.at(a-1)++;
    City.at(b-1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << City.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define     ff 				first
#define 	ss 				second
#define 	pb 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
// vll pwx(32);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

bool check(vector<ll> &a, ll x, ll k){
    ll req = 0;

    for(ll i = 0 ; i < a.size() ; i++){
        if(a[i] > x)
            req += a[i]/x;
    }

    if(req > k)
        return false;
    return true;
}

void solve(){
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);

    rep(i, 0, n)
        cin >> a[i];

    ll ans = 0;
    
    ll low = 1, high = 1e18, mid;

    while(low <= high){
        mid = (low+high)/2;

        // cout << low << ws << mid << ws << high << nl;;

        if(check(a, mid, k)){
            ans = mid;
            high = mid-1;   
        }
        else{
            low = mid+1;
        }
    }

    cout << ans << nl;
    
}
 
int main(){
    // boost;
    // cal(2);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 4844
N = int(input())
a = [0 for i in range(N)]
S = 0
st = input().split()
for i in range(N):
    a[i] = int(st[i])
    S += a[i]
m = 4 * 10**14
T = 0
for i in range(0, N-1):
    T += a[i]
    M = abs(S-2*T)
    if M < m:
        m = M
print(m)


Measured memory_bytes: 25336
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
n, m = map(int, input().split())
edge = []
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    edge.append((a - 1, b - 1))

ans = n * (n - 1) // 2
ans_list = []
for i in range(m)[::-1]:
    ans_list.append(ans)
    if not uf.same(edge[i][0], edge[i][1]):
        ans -= uf.size(edge[i][0]) * uf.size(edge[i][1])
    uf.union(edge[i][0], edge[i][1])
    
print(*ans_list[::-1], sep="\n")

    

    

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

using namespace std;

int dist(int x, int y, int _x, int _y)
{
    return abs(x - _x) + abs(y - _y);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> pts(n);
    vector<pair<int, int>> cts(m);
    for (auto &i : pts)
        cin >> i.first >> i.second;
    for (auto &i : cts)
        cin >> i.first >> i.second;
    for (auto i : pts)
    {
        int idx, min = 1000000000;
        for (int j = 0; j < m; j++)
            if (dist(i.first, i.second, cts[j].first, cts[j].second) < min)
            {
                min = dist(i.first, i.second, cts[j].first, cts[j].second);
                idx = j;
            }
        cout << idx + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, K, score;
	double ans = 0, tmp;

	cin >> N >> K;

	repc(i, 1, N) {
		score = i;
		tmp = 1;
		
		while (score < K) {
			score *= 2;
			tmp *= 0.5;
		}

		ans += tmp / N;
	}

	printf("%.12lf\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int N=1e6+5;
int n,ans,m;
priority_queue<double>q;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)q.push(1.0*read());
	while(m--)
	{
		double u=q.top();q.pop();
		u=1.0*u/2.0;
		q.push(u);
	}
	for(int i=1;i<=n;i++)
	{
//		printf("%.2lf\n",q.top());
		ans+=(int)(q.top());q.pop();
	}
	cout<<ans;
}

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

int main() {
  int N, M;
  cin >> N;
  
  int Alice=0, Bob=0;
  vector<int> a(N);
  for (int i=0; i<N; i++)
    cin >> a.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i=0; i<N ; i++) {
    if (i%2==0) 
      Alice += a.at(i);
    else 
      Bob += a.at(i);
  }
  
  cout << Alice - Bob << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <queue>
#include <vector>
#include <string>

using namespace std;

int n;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;

int cir_time(string str){
    int h = stoi(str.substr(0, 2));
    int m = stoi(str.substr(3, 2));
    int s = stoi(str.substr(6, 2));
    s+= h*60*60+m*60;
    return s;
}

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    while(1){
        cin >> n;
        if(n==0)break;
        for(int i=0; i<n; i++){
            string str1, str2;
            cin >> str1 >> str2;
            q.push(make_pair(cir_time(str1), 0));
            q.push(make_pair(cir_time(str2), 1));
        }
        int cnt=0;
        int ans=0;
        while(!q.empty()){
            pair<int, int> f = q.top();
            q.pop();
            int t = f.first;
            int type = f.second;
            if(type == 0){
                cnt++;
                if(!q.empty() && q.top().first == t){
                    continue;
                }
                ans = max(ans, cnt);
            }
            else{
                cnt--;
                if(!q.empty() && q.top().first != t){
                    ans=max(ans, cnt);
                }
            }
        }
        
        cout << ans << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int maxn = 100003;

int n, gq, qm, tot, head[maxn], ver[maxn * 2], nxt[maxn * 2];
int dep[maxn], kk[maxn], fa[maxn], ans, now;

void dfs(int u, int f)
{
	dep[u] = kk[u] = dep[f] + 1, fa[u] = f;
	for (int i = head[u]; i; i = nxt[i])
	{
		int v = ver[i];
		if (v == f) continue;
		dfs(v, u);
		kk[u] = max(kk[u], kk[v]);
	}
}

inline void add(int u, int v)
{
	ver[++tot] = v, nxt[tot] = head[u], head[u] = tot;
}

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi(), gq = gi(), qm = gi();
	for (int i = 1; i < n; i+=1)
	{
		int u = gi(), v = gi();
		add(u, v), add(v, u);
	}
	dfs(qm, 0);
	now = gq;
	while (1)
	{
		if (dep[gq] - dep[now] >= dep[now] - dep[qm]) break;
		ans = max(ans, kk[now] - 1);
		now = fa[now];
	}
	printf("%d\n", ans - 1);
	return 0;
}


Measured memory_bytes: 7168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = n;
		int num = 0;
		while (q > 0) {
			num += q % 10;
			q = q / 10;
		}
		
		if(n % num == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 23380
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 100010;
const int INF = 2147483600;

int nxt[MAXN+1][3];
LL f[MAXN+1]; char str[MAXN+1];
int a[MAXN+1];
LL sum;

inline int Tns(int x){
	return (x==2?1:2);
} int N; 
const int Mod = 1000000007LL;
LL s[MAXN+1]; int To[MAXN+1];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%s",str+1); bool pt=0; f[0]=1; N=strlen(str+1);
	for(int i=1;i<=N;i++) a[i]=(int)(str[i]-'a')+1,s[i]=s[i-1]+a[i]; 
	for(int i=N;i>=1;i--){
		nxt[i][1]=nxt[i+1][(1-a[i]+3)%3];
		nxt[i][2]=nxt[i+1][(2-a[i]+3)%3];
		nxt[i][0]=nxt[i+1][(3-a[i])%3];
		nxt[i][a[i]]=i; To[i]=To[i+1]; if(a[i]==a[i+1]) To[i]=i+1,pt=1;
	} if(!pt){
		puts("1"); return 0;
	}
	for(int i=1;i<=N;i++){
		(f[i]+=f[i-1])%=Mod; sum+=a[i];
		int d=(3+Tns(a[i])-(s[To[i]]-s[i-1])%3)%3;
		if(To[i]&&(nxt[To[i]+1][d]||!d)) 
			(f[(!d?To[i]:nxt[To[i]+1][d])]+=f[i-1])%=Mod;
	} LL ans=0; bool vis=0; sum=0;
	for(int i=N;i>=1;i--){
		if(!(sum%3)) (ans+=f[i])%=Mod;
		sum+=a[i];
	} printf("%lld\n",ans);
	return 0;
}




Measured memory_bytes: 3840
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	while (s.size() != 0) {
		if (s.substr(0, 5) == "maerd") {
			s = s.substr(5);
		}
		else if (s.substr(0, 7) == "remaerd") {
				s = s.substr(7);
			}
		else if (s.substr(0, 5) == "esare") {
			s = s.substr(5);
		}
		else if (s.substr(0, 6) == "resare") {
			s = s.substr(6);
		}
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

namespace AtCoderBS
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] hina = Console.ReadLine().Split(' ');
            string isIn = "";
            int type = 0;

            for(int i = 0; i < n; i++)
            {
                if(isIn.IndexOf(hina[i]) == -1)
                {
                    isIn += hina[i];
                    type++;
                }
            }

            if(type == 3)
            {
                Console.Write("Three");
            }
            else
            {
                Console.Write("Four");
            }

            Console.Read();
        }
    }
}

Measured memory_bytes: 11356
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(b[i]+a[i+1])
s = b
for i in range(n-1):
    for j in range(i,n-1):
        s.append(b[j+1]-b[i])
s.sort(reverse=True)
l = len(bin(s[0]))-2
d = 1<<l-1
t = 0
while d>0:
    s1 = []
    if s[k-1] >= d:
        t += d
        for i in s:
            if i >= d:
                s1.append(i)
            else:
                s=s1
                break
    d2 = d-1        
    for i in range(len(s)):
        if s[i] > d2:
            s[i] = s[i]&d2
        else:
            s.sort(reverse=True)
            break
    d = d>>1
print(t)

Measured memory_bytes: 27420
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long int N = 0, A[1000000] = { 0 }, B[1000000] = { 0 },Defeated=0,C=0;
int main()
{
	cin >> N;
	for (int i = 0; i < N+1; i++)
	{
		cin >> A[i];
	}
	for (int i = 0; i < N; i++)
	{
		cin >> B[i];
	}
	for (int i = 0; i < N; i++)
	{
		if (B[i] > A[i])
		{
			C = A[i + 1] - (B[i] - A[i]);
			if (C <= 0)
			{
				Defeated = Defeated + A[i]+A[i+1];
				A[i + 1] = 0;
			}
			else
			{
			Defeated +=B[i];	
			A[i + 1] = C;
			}
		}
		else
		{
			Defeated += B[i];
		}
		C = 0;
	}
	cout << Defeated;
	return 0;
}

Measured memory_bytes: 5120
from math import atan, degrees
a, b, x = [int(i) for i in input().split()]
angle = None

if x <= a*a*b/2: # 液体が容器の容量の半分以下なら
    c = x/a/b*2
    angle = degrees(atan(b/c))
else:
    c = 2*x/a/a-b
    angle = degrees(atan((b-c)/a))

print(angle)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = n; i > 1; i--)
#define rep3(i, s, n) for (int i = (s); i < (int)(n); i++)

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

    int f = 0;
    int large_num = 1;
    int small_num = 1;
    rep3(i, 1, 9) {
        large_num = int(pow(10, i));
        small_num = int(pow(10, i - 1));
        if (n < small_num) {
            break;
        } else {
            f += int((n % large_num) / small_num);
        }
    }

    if ((n % f) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
def main():
    N, A, B = (int(i) for i in input().split())
    S = input()
    c = 0
    ob = 0
    for s in S:
        if s == "a":
            if c+ob < A+B:
                c += 1
                print("Yes")
            else:
                print("No")
        elif s == "b":
            if c+ob < A+B and ob < B:
                ob += 1
                print("Yes")
            else:
                print("No")
        else:
            print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 50136
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    int n;
    cin>> n;
    int l[n];
    rep(i,n){
        cin>>l[i];
    }
    int ans=0;
    rep(i,n){
       for(int j=i+1;j<n;j++){
           for(int k=j+1;k<n;k++){
               if(l[i]!=l[j]&&l[j]!=l[k]&&l[k]!=l[i]){
                   if(abs(l[i]-l[j])<l[k]&&l[k]<l[i]+l[j]){
                       ans++;
                   }
               }
           }
       }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    for (ll i = 0; i < S.size()-1; i++) {
        if (S[i] == 'A' && S[i+1] == 'C') {
            Yes;
            return 0;
        }
    }

    No;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
int n,m;
bool a[100000+7];
ll scr[100000+7];

int main(){
	cin >> n >> m;
	FOR(i,1,m){
		int k; cin >> k;
		a[k] = true;
	}
	scr[0] = 1;
	if(a[1] == false) scr[1] = 1;
	else scr[1] = 0;
	FOR(i,2,n){
		scr[i] = (scr[i-2]*(1-a[i-2]) + scr[i-1]*(1-a[i-1])) % MOD;
	}
	cout << scr[n] << endl;
    return 0;
}


Measured memory_bytes: 1152
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N = int(input())
    AB = []
    for _ in range(N):
        ai, bi = map(int, input().split())
        AB.append((ai, bi))
    AB = sorted(AB, key=lambda x: x[0])
    ans = AB[0][0] - 1
    for i in range(N - 1):
        diff = AB[i + 1][0] - AB[i][0]
        ans += diff
    ans += AB[-1][1] + 1
    print(ans)    

if __name__ == '__main__':
    main()


Measured memory_bytes: 83620
fun main(args: Array<String>) {
    val (N, M, Q) = readLine()!!.split(' ').map { it.toInt() }

    val A = IntArray(N)
    val arr = Array(Q) {IntArray(4)}
    repeat(Q) {
        val (a, b, c, d) = readLine()!!.split(' ').map { it.toInt() }
        arr[it][0] = a
        arr[it][1] = b
        arr[it][2] = c
        arr[it][3] = d
    }

    fun check(): Long {
        var ret = 0L
        repeat(Q) {
            val a = arr[it]
            if(A[a[1]-1] - A[a[0]-1] == a[2]) {
                ret += a[3]
            }
        }
        return ret
    }

    var max = 0L
    fun create(n:Int, min:Int) {
        for (m in min .. M) {
            A[n]= m
            if (n+1 == N) {
                max = Math.max(max, check())
            } else {
                create(n+1, m)
            }
        }
    }

    create(0,1)
    println(max)
}


Measured memory_bytes: 38264
#include<bits/stdc++.h>
using namespace std;
char s[10][10]; 
int main(){
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			cin>>s[i][j];
	cout<<s[1][1]<<s[2][2]<<s[3][3]<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main{
	public static long mod(long x, long e, long m){
		String bi = Long.toBinaryString(e);
		long y = 1;
		for(int i = 0; i < bi.length(); i++){
			if(bi.charAt(i) == '1'){
				y = (y*y*x)%m;
				System.out.println(y);
			}else{
				y = (y*y)%m;
				System.out.println(y);
			}
		}
		return y;
	}
    
	public static void main(String[] $){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] S = new String[N];
		int AC = 0;
		int WA = 0;
		int TLE = 0;
		int RE = 0;
		for(int i = 0; i < N; i++){
			S[i] = sc.next();
			if(S[i].equals("AC")){
				AC++;
			}else if(S[i].equals("WA")){
				WA++;
			}else if(S[i].equals("TLE")){
				TLE++;
			}else{
				RE++;
			}
		}
		
		System.out.println("AC x " + AC);
		System.out.println("WA x " + WA);
		System.out.println("TLE x " + TLE);
		System.out.println("RE x " + RE);
		
	}
} 

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  ll n,m,d;
  cin >> n >> m >> d;
  cout << fixed << setprecision(20);
  if(d == 0){
    cout << (double)1/n*(m-1) << endl;
  }else{    
    if(2*d >= n){
      cout << (double)1/n*(m-1) << endl;
    }else{
      cout << (double)2*(n-d)/n/n*(m-1) << endl;
    }
  }





  return 0;
}

Measured memory_bytes: 256
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut ans = 0;
    
    {
        let mut k = 1;
        while k * k <= n - 1 {
            if (n - 1) % k == 0 {
                ans += if k == (n - 1) / k { 1 } else { 2 };
            }
            k += 1;
        }
        ans -= 1;
    }

    {
        let mut k = 2;
        while k * k <= n {
            if n % k == 0 {
                let mut x = n;
                while x % k == 0 { x /= k; }
                if x % k == 1 { ans += 1; }
                let l = n / k;
                if k != l {
                    let mut y = n;
                    while y % l == 0 { y /= l; }
                    if y % l == 1 { ans += 1; }    
                }
            }
            k += 1;
        }
        ans += 1;
    }

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

Measured memory_bytes: 2152
n = int(input())
result = 0

def count_divisor(num):
    count = 0
    for i in range(1,num+1):
        if(num % (i) == 0):
            count += 1
    return count

for i in range(1,n+1,2):
    if(count_divisor(i) == 8):
        result+=1
print(result)

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

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

int main()
{
    ll i,j;
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> l(n);
    for(i = 0;i < n;++i){
        l.at(i) = s.at(i) - '0';
    }
    const ll MOD = 1e9+7;
    ll dp[n][2];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    dp[0][1] = 2;
    for(i = 1;i < n;++i){
        if(l.at(i) == 1){
            dp[i][0] = 3*dp[i-1][0] + dp[i-1][1];
            dp[i][1] = 2*dp[i-1][1];
        }else{
            dp[i][0] = 3*dp[i-1][0];
            dp[i][1] = dp[i-1][1];
        }
        rep(j,3){
            dp[i][j] %= MOD;
        }
    }
    ll ans = dp[n-1][0] + dp[n-1][1];
    cout << ans%MOD << endl;
    return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,w,x;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	w=0; x=0;
	w=n/a;
	if(w*a<n){
		w=w+1;
	}
	x=n/c;
	if(x*c<n){
		x=x+1;
	}
	if(w*b<x*d){
		printf("%d\n",w*b);
	}
	else if(w*b>x*d){
		printf("%d\n",x*d);
	}
	else if(w*b==x*d){
		printf("%d\n",x*d);
	}
	return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_H=12,MAX_W=12;
int H,W;
string S[MAX_H],temp[MAX_H];
bool ans,rflg[MAX_H],cflg[MAX_W],cenf;
bool schk(int n,int m){
	REP(i,H){
		if (temp[i][n]!=temp[H-i-1][m]){
			return false;
		}
	}
	return true;
}
bool pal(int n){
	REP(i,H){
		if (temp[i][n]!=temp[H-i-1][n]){
			return false;
		}
	}
	return true;
}
void chk(){
	memset(cflg,false,sizeof(cflg));
	int cnt=0;
	bool cen=false;
	REP(w,W){
		if (!cflg[w]){
			cflg[w]=true;
			bool f=false;
			FOR(w2,w+1,W){
				if (!cflg[w2]){
					if (schk(w,w2)){
						cflg[w2]=true;
						cnt+=2;
						f=true;
						break;
					}
				}
			}
			if (!f){
				if (pal(w) && !cen){
					cen=true;
					cnt++;
				}
			}
		}
	}
	if (cnt==W){
		ans=true;
	}
}
void com(int n){
	if (n==H/2 && (H%2==0 || cenf)){
		chk();
	}else{
		int m=0;
		REP(i,H){
			if (!rflg[i]){
				m=i;
				break;
			}
		}
		rflg[m]=true;
		temp[n]=S[m];
		REP(i,H){
			if (!rflg[i]){
				rflg[i]=true;
				temp[H-n-1]=S[i];
				com(n+1);
				rflg[i]=false;
			}
		}
		if (!cenf && H%2){
			cenf=true;
			temp[H/2]=S[m];
			com(n);
			cenf=false;
		}
		rflg[m]=false;
	}
}
int main(){
	cin>>H>>W;
	REP(i,H){
		cin>>S[i];
	}
	REP(i,H){
		temp[i].resize(W);
	}
	com(0);
	cout<<(ans ? "YES" : "NO")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<deque>
#define FOR(i, a, b) for((i)=(a);(i)<(b);(i)++)
#define intq deque<long>
#define N (10000000000)

using namespace std;

int f(long a, long b) {
  int c, d;
  int r;
  int i;
  c = 1;
  d = 1;
  long u;
  long v;
  for(u = a; (u = u / 10); c++) {
  }

  for(v = b; (v = v / 10); d++) {
  }

  r = c;
  if(r < d)
    r = d;

  return r;
}

int main(void) {
  long n;
  scanf("%ld", &n);

  intq a;
  intq b;

  long i;
  a.push_back(1);
  b.push_back(n);

  for(i = 2; i * i < n + 1; i++) {
    if (!(n % i)) {
      a.push_back(i);
      b.push_back(n / i);
    }
  }

  int s;
  s = a.size();

  int r;

  int j;
  FOR(j, 0, s) {
    int t;
    t = f(a[j], b[j]);
    if(!j){
      r = t;
    } else {
      if(t<r){
        r = t;
      }
    }
  }

  printf("%d\n", r);




  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
const int N=100;

int k[3]={1,1,1};
char a[3][N+5];

int main()
{
	scanf("%s %s %s",a[0]+1,a[1]+1,a[2]+1);
	
	int p=0;
	while(true)
	{
		switch(a[p][k[p]++])
		{
			case 'a':
				p=0;
			break;
			case 'b':
				p=1;
			break;
			case 'c':
				p=2;
			break;
			default:
				switch(p)
				{
					case 0:
						puts("A");
					break;
					case 1:
						puts("B");
					break;
					case 2:
						puts("C");
					break;
				}
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
INF = 10**18


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    H = list(map(int, input().split()))
    ans = 1
    for i in range(N):
        for j in range(i):
            if H[j] > H[i]:
                break
            if i == j+1:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
from random import randrange
from heapq import heapify, heappush, heappop
from time import time
K = 60
rand = lambda: randrange(1 << K)
sTime = time()
N = int(input())
S, IS, C = [], [], []
for _ in range(N):
    s, c = input().split()
    S.append(s)
    IS.append(s[::-1])
    C.append(int(c))

D = {}
done = [set(), set()]
r = rand()
D[r] = (0, "", 0)
H = [r]
ans = 1 << K
while H:
    r = heappop(H)
    if time() - sTime > 1.7:
        break
    d, s, c = D[r]
    if s in done[d]: continue
    done[d].add(s)
    if d == 0:
        for ss, cc in zip(S, C):
            m = min(len(s), len(ss))
            if s[:m] == ss[:m]:
                if abs(len(s) - len(ss)) <= 1 or len(ss) > len(s) and ss[m:] == ss[m:][::-1]:
                    ans = min(ans, c + cc)
                else:
                    if len(s) < len(ss):
                        r = rand() + (c + cc << K)
                        D[r] = (1, ss[m:], c + cc)
                        heappush(H, r)
                    else:
                        r = rand() + (c + cc << K)
                        D[r] = (0, s[m:], c + cc)
                        heappush(H, r)
    else:
        for ss, cc in zip(IS, C):
            m = min(len(s), len(ss))
            if s[:m] == ss[:m]:
                if abs(len(s) - len(ss)) <= 1 or len(ss) > len(s) and ss[m:] == ss[m:][::-1]:
                    ans = min(ans, c + cc)
                else:
                    if len(s) < len(ss):
                        r = rand() + (c + cc << K)
                        D[r] = (0, ss[m:], c + cc)
                        heappush(H, r)
                    else:
                        r = rand() + (c + cc << K)
                        D[r] = (1, s[m:], c + cc)
                        heappush(H, r)

print(ans if ans < 1 << K - 2 else -1)


Measured memory_bytes: 79856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 30000 + 5;
int main(){
    int x;
    cin>>x;
    if(x>=400&&x<=599) cout<<8;
    if(x>=600&&x<=799) cout<<7;
    if(x>=800&&x<=999) cout<<6;
    if(x>=1000&&x<=1199) cout<<5;
    if(x>=1200&&x<=1399) cout<<4;
    if(x>=1400&&x<=1599) cout<<3;
    if(x>=1600&&x<=1799) cout<<2;
    if(x>=1800&&x<=1999) cout<<1;
    return 0;
}


Measured memory_bytes: 3620
import java.util.*;
import java.util.Arrays;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n;
		int count;		
		boolean[] flag = new boolean[1000001];
			
		Arrays.fill(flag,true);
			
		for(int i=2;i<=Math.sqrt(1000000)+1;i++){
			if(!flag[i])continue;
			for(int j=i*2;j<1000000;j+=i){
				flag[j] = false;
			}
		}
		
		while(sc.hasNext()){
			count = 0;
			n = sc.nextInt();
			
			for(int i=2;i<=n;i++){
				if(flag[i])++count;
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 22576