akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        int l, r;
        cin >> l >> r;
        ans += ( r - l + 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int N;
long long M;
std::vector<long long > A(100000);
std::vector<long long > kumisuu(200000, 0); // A_i>=x を満たすiの数
std::vector<long long > souwa(200000, 0); // A_i>=x を満たすiについてA_iの総和

long long get_possible_count(int value){ // 値がvalue以上となる組み合わせ総数を求める
  long long count = 0;
  for (int i=0; i<N; i++){
    count += kumisuu[std::max(value-A[i], (long long)0)];
  }
  return count;
}

int main(){
  scanf("%d",&N);
  scanf("%lld",&M);

  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
    kumisuu[A[i]]++;
  }
  sort(A.begin(), A.end(), std::greater<long long>());

  for (int i=0; i<N; i++){
    souwa[i+1] = souwa[i] + A[i];
  }

  /*  累積和を求める */
  for (int i=200000; i>0; i--){
    kumisuu[i-1] += kumisuu[i];
  }

  int left = 0;
  int right = 200001;
  int mid;
  long long ans;
  std::map<long long, long long > mp;
  while(right-left>1){
    ans = 0;
    mid = (left+right)/2;
    if (get_possible_count(mid)>=M){ // 
      left = mid;
    } else {
      right = mid;
    }
    mp[mid] = get_possible_count(mid);
    for (int i=0; i<N; i++){
      ans += souwa[kumisuu[std::max(mid-A[i],(long long)0)]];
      ans += A[i]*kumisuu[std::max(mid-A[i],(long long)0)];
    }
  }

  if (left == mid){
    //std::cout << ans-abs(M-get_possible_count(left))*left << std::endl;
    std::cout << ans-abs(M-mp[left])*left << std::endl;
  } else if (right==mid){
    /*long long ans;
    for (int i=0; i<N; i++){
      ans += souwa[kumisuu[std::max(right-A[i],(long long)0)]];
      ans += A[i]*kumisuu[std::max(right-A[i],(long long)0)];
      }*/
    //std::cout << ans+abs(M-get_possible_count(right))*left << std::endl;
    std::cout << ans+abs(M-mp[right])*left << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4224
def examA():
    N = I()
    ans = ((N+1)//2)/N
    print(ans)
    return

def examB():
    N, K = LI()
    H = [I()for _ in range(N)]
    H.sort()
    ans = inf
    for i in range(N-K+1):
        cur = H[i+K-1]-H[i]
        if ans>cur:
            ans = cur
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    ans = [0]*N
    C = Counter(A)
    base = 0
    for c in C.values():
        base += c*(c-1)//2
    #print(C)
    #print(base)
    for i in range(N):
        ans[i] = base - (C[A[i]]-1)
    for v in ans:
        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 30268
#include<iostream>
#include<cstdio>

using namespace std;

int main(void){
  double xa[3],ya[3],xb[3],yb[3];

  while(true){
    for(int i=1;i<3;i++)
      if(scanf("%lf %lf",&xa[i],&ya[i])==EOF)return 0;
    
    for(int i=1;i<3;i++)
      scanf("%lf %lf",&xb[i],&yb[i]);

    if(xa[2]>=xb[1] && xb[2]>=xa[1] && ya[2]>=yb[1] && yb[2]>=ya[1])cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	int n;
	string taro, hanako;
	int x1 = 0, x2 = 0;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> taro >> hanako;
		if(taro == hanako){
			x1++;
			x2++;
		}
		else if(taro < hanako) x2 += 3;
		else  x1 += 3;
	}
	
	cout << x1 << " " << x2 << endl;
	
	return 0;
}

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

using namespace std;
typedef long long int ll;

#define rep(x, a, b) for (int x = a; x < b; x++)

int
main()
{
  int n, a, b;

  cin >> n >> a >> b;

  int cnt = 0;

  rep (i, 0, n) {
    int t;

    cin >> t;

    if (t < a || t >= b)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

int main()
{
    int t, min_r, r, profit = -1 * INF;
    cin >> t >> min_r;
    repi(i, t-1, 0)
    {
        cin >> r;
        profit = max(profit, r - min_r);
        min_r = min(min_r, r);
    }
    cout << profit << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long

using namespace std;

int a[300005],n,k,len,del;

int main(){
  cin>>k>>n;
  if (k==1){
    for (RG int i=1;i<=(n+1)>>1;++i) printf("%d ",1);
    return 0;
  }
  if (!(k&1)){
    printf("%d ",k>>1);
    for (RG int i=2;i<=n;++i) printf("%d ",k); return 0;
  }
  if (n==1) printf("%d",(k+1)>>1),exit(0);
  for (RG int i=1;i<=n;++i) a[i]=(k+1)>>1; len=n,del=n>>1;
  for (;del;--del){
    if (a[len]==1){ --len; continue; }
    for (--a[len];len!=n;++len) a[len+1]=k;
  }
  for (RG int i=1;i<=len;++i) printf("%d ",a[i]); return 0;
}


Measured memory_bytes: 3456
#include<cstdio>
#include<iostream>

using namespace std;
int main()
{
    char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','k','r','s','t','u','v','w','x','y','z'};
    string A;
    cin>>A;
    for(int i=0;i<26;i++)
    {
        int f=1;
        for(int j=0;j<A.size();j++)
        {
            if(A[j]==a[i]) f=0;
        }
        if(f==1) 
        {cout<<a[i]<<endl;return 0;}
    }
    cout<<"None"<<endl;
    return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	cin >> n;

	cout << n / 2 - (n % 2 == 0 ) << endl;



	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
#define fi first
#define se second
using namespace std;
typedef long long i64;
typedef pair<int, i64> pii;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 3e2+5;
int n, k, P, f[N][N][N];
int main()
{
	n = read(), k = read(), P = read();
	f[0][1][0] = 1;
	for(int i = 0; i <= n; ++i)
		for(int j = 1; j <= k; ++j)
			for(int p = i; ~p; --p)
			{
				if(p) f[i][j][p-1] = (f[i][j][p-1]+f[i][j][p])%P;
				else f[i][j+1][i] = (f[i][j+1][i]+f[i][j][p])%P;
				f[i+1][j][p] = (f[i+1][j][p]+(1ll+p)*f[i][j][p])%P;
			}
	printf("%d\n", f[n][k+1][n]);
	return 0;
}

Measured memory_bytes: 110720
#include <iostream>

int main()
{
    char b;
    std::cin >> b;
    if(b == 'A') std::cout << "T" << std::endl;
    else if(b == 'T') std::cout << "A" << std::endl;
    else if(b == 'C') std::cout << "G" << std::endl;
    else if(b == 'G') std::cout << "C" << std::endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] ary = new int[n];
		for(int i=0; i<n; i++){
			ary[i] = sc.nextInt();
		}

		double[] result = new double[n];
		for(int i=0; i<n; i++){
			result[i] = (ary[i] * (1 + ary[i])) / (2.0 * ary[i]);
		}

		double maxTotal = 0;
		for(int i=0; i<k; i++) {
			maxTotal = maxTotal + result[i];
		}
		double nowTotal = maxTotal;
		int count = 0;
		for(int i=k; i<n; i++){
			double total = nowTotal + result[i] - result[count];
			maxTotal = Math.max(maxTotal, total);
			nowTotal = total;
			++count;
		}
		System.out.println(maxTotal);
	}
}


Measured memory_bytes: 65376
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_set>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int f(int n) {
  return (n % 2 == 0) ? n / 2 : n * 3 + 1;
}

int main(int argc, char* argv[]) {
  int s;
  cin >> s;

  std::unordered_set<int> m;

  int a = s;
  int i = 1;
  while (m.find(a) == m.end()) {
    m.insert(a);
    a = f(a);
    i++;
  }

  cout << i;

  return 0;
}


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



public class Main {
	public static void main( String[] args ) throws IOException
    {
        BufferedReader br = new BufferedReader(
                                new InputStreamReader( System.in ) );
        double N = Integer.parseInt(br.readLine());
        String s = br.readLine();
        int result = 0;
        double sum = 0;
        String d[] = s.split(" ",0);
        int a[] = new int[d.length];
        for(int i = 0; i < d.length; i++){
        	a[i] = Integer.parseInt(d[i]);
        	sum += a[i];
        }
        int x = (int)Math.round(sum/N);
        for(int i = 0; i < a.length; i++){
        	result += (x-a[i])*(x-a[i]);
        }
        System.out.println(result);
	}
}


Measured memory_bytes: 8020
import java.util.*;


class Student {

    private int number;
    private double weight;
    private double height;
    private double bmi;

    Student(int number, double weight, double height) {
        this.number = number;
        this.weight = weight;
        this.height = height;
        this.bmi = weight / (height * height);
    }

    int getNumber() {
        return this.number;
    }

    double getBmi() {
        return this.bmi;
    }

}

class Main {

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            String [] line = sc.nextLine().split(",");
            Student s = new Student( Integer.parseInt(line[0]), Double.parseDouble(line[1]), Double.parseDouble(line[2]) );
            if (s.getBmi() >= 25) {
                System.out.println(s.getNumber());
            }
        }

    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> card(n);
  for(int i=0; i<n; i++){
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  //カードに書かれた番号を大きい順にした
  
  int ans = 0;
  int turn = 1; //Alice：1、Bob：-1
  
  for(int i=0; i<n; i++){
    ans += card.at(i) * turn;
    turn *= -1;
  }
  
  cout <<ans <<endl;
}


Measured memory_bytes: 256
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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


int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> v;
  string tmp;
  for (int i = 0; i < h; i++)
  {
    cin >> tmp;
    v.push_back(tmp);
  }
  
  for (int i = 0; i < h; i++)
  {
    cout << v[i] << endl;
    cout << v[i] << endl;
  }
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = [np.array(input().split(), dtype=np.int64) for _ in range(N)]
ans = 0
inf = 10**10
result = 0
for i in range(N):
    A[i][i] = inf

for i in range(N-1):
    for j, d1 in enumerate(A[i][i+1:], start=i+1):
        d2 = np.min(A[i]+A[j])
        if d1 >= d2:
            if d1 > d2:
                print(-1)
                exit()
        else:
            result += d1

print(result)


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

int main(void)
{
  int n;
  int *np;
  scanf("%d\n", &n);
  np = (int *)malloc(n * sizeof(int));

  for (int i = 0; i < n; i++)
  {
    int num;
    scanf("%d", &num);
    np[num-1] = i+1;
  }
  
  for (int i = 0; i < n; i++)
  {
	printf("%d", np[i]);
    if (i == n-1)
      putchar('\n');
    else
      putchar(' ');
  }
  
  free(np);
  return 0;
}

Measured memory_bytes: 1152
import java.math.BigInteger;
import java.util.Scanner;

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

        while (sc.hasNext()) {
            BigInteger a = sc.nextBigInteger();
            BigInteger b = sc.nextBigInteger();

            BigInteger gcd = a.gcd(b);
            BigInteger lcm = a.multiply(b).divide(gcd);
            System.out.println(gcd + " " + lcm);
        }
    }
}

Measured memory_bytes: 26092
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y,z;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x<a.x;
//        return z>a.z;
    }
};

vector<int> v[100055];
//bitset<4001000> b;
int a,c,i,b,k,d,n,m,e;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[110515];
int o[111000];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,-1,1,-1,1},dz[10]={0,0,0,0,1,-1};

long long x,y,z[200100],mod=1000000007;
P u[100161];
int j[10100];

stack<int> s;
queue<int> q;
priority_queue<long long, vector<long long>,greater<long long> > q1;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int > p;
//list<int> l;
string r,r2;
//char r[10];


bool as(P a,P b)
{
   // if(a.x!=b.x)
        return a.x<b.x;
    //return a.y>b.y;
}

long long g(long long a,long long b)
{
    if(b==0) return 1;
    long long u=g(a,b/2);
    u*=u;
    u%=mod;
    if(b&1) u*=a;
    u%=mod;
    return u;
}

long long f(long long a,long long b)
{
    a+=b;
    return z[a]*g(z[b],mod-2)%mod*g(z[a-b],mod-2)%mod;
}

int main()
{
    z[0]=1;
    for(int t=1;t<=200000;z[t]=z[t-1]*t,z[t]%=mod,t++);
    long long a,b,c,d;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    for(int t=1;t<=a-c;t++)
    {
        x+=f(a-t,b-d-1)*f(t-1,d-1)%mod,x%=mod;
        //printf("%lld %lld\n",a-t,b-d-1);
    }
    printf("%lld",x);
}


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

//2つの正整数の最大公約数を求める
ll gcd(ll a, ll b) {
    const ll LARGE = max(a,b);
    const ll SMALL = min(a,b);
    ll x = LARGE;
    ll y = SMALL;
    ll r = x % y;

    while(r!=0){
        x = y;
        y = r;
        r = x % y;
    }

    return y;
}

//2つの正整数の最小公倍数を求める
ll lcm(ll a,ll b){
  ll y = gcd(a,b);
  return a * (b / y);
}

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

  vector<ll> t(n);
  rep(i,n) cin >> t[i];

  ll ans = 1;
  rep(i,n) ans = lcm(t[i],ans);

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
	
	public static void main (String[] args)
	{
		Scanner sc = new Scanner (System.in);
		int nums = sc.nextInt();
		long[] arr = new long[2];
		long[] sticks = new long[nums];
		for (int i= 0; i < nums; i++)
			sticks[i]=sc.nextInt();
		Arrays.sort(sticks);
		int count = 0;
		//for (int i = nums - 1; i >= 1; i--)
		while(-- nums >= 1)
		{
			if (sticks[nums]==sticks[nums-1])
			{
				arr[count]= sticks[nums];
				nums--;
				count++;
			}
			if (count==2)
				break;
		}
			System.out.println(arr[0]*arr[1]);
		
	}
	
	
	
}


Measured memory_bytes: 60432
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    m = II()
    print(48-m)
    return

#B
def B():
    a, _ = LI()
    s = S()
    ans = list(map(str, range(10)))
    for num, si in enumerate(s):
        if num != a:
            if si in ans:
                continue
            print("No")
            return
        else:
            if si == "-":
                continue
            print("No")
            return
    print("Yes")
    return

#C
def C():
    n = II()
    csf = LIR(n - 1)
    for i in range(n - 1):
        b = 0
        for k in range(i, n - 1):
            c, s, f = csf[k]
            if b <= s:
                b = s + c
            else:
                b += c + (-b % f)
        print(b)
    print(0)
    return

#D
def D_():
    a = II()
    ans = inf
    b = 0
    for _ in range(1, 10 ** 5):
        b += a
        ans = min(ans, sum(list(map(int, list(str(b))))))
    print(ans)
    return

def D():
    q = II()
    def primes(n):
        """ Input n>=6, Returns a list of primes, 2 <= p < n """
        """ 6以上の数であれば p (素数) <= n のlistを返す """
        n, correction = n-n%6+6, 2-(n%6>1)
        sieve = [True] * (n//3)
        for i in range(1,int(n**0.5)//3+1):
            if sieve[i]:
                k=3*i+1|1
                sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
                sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
        return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]
    primelis = primes(10 ** 5)
    d = defaultdict(int)
    for i in primelis:
        d[i] += 1
    dp = [0]
    for i in range(3, 10 ** 5, 2):
        dp.append(dp[-1] + (1 if (d[i] and d[(i + 1) // 2]) else 0))
    for i in range(q):
        l, r = map(lambda x: x // 2, LI())
        if l == 0:
            print(dp[r])
            continue
        print(dp[r] - dp[l - 1])



#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 60248
#include<cstdio>
#include<iostream>
using namespace std;
int a,b,c,tot;
int main()
    {
        cin>>a>>b>>c;
        tot=100*a+10*b+c;
        if(tot%4) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,n1,n2,n3,n4;
    cin >> N;

    n1 = N / 1000;
    n2 = (N - n1 * 1000) / 100;
    n3 = (N - (n1 * 1000) - (n2 * 100)) / 10;
    n4 = (N - (n1 * 1000) - (n2 * 100)  - (n3 * 10));

    if ((n1 == n2 && n2 == n3) || (n2 == n3 && n3 == n4)){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

INF = float('inf')  ###
maxMoney = 2502  ### *2?
#maxMoney = 20

N, M, S = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(M):
    u, v, coin, tm = map(int, input().split())
    u, v = u-1, v-1
    adjL[u].append((v, coin, tm))
    adjL[v].append((u, coin, tm))
moneys, tms = [], []
for _ in range(N):
    money, tm = map(int, input().split())
    moneys.append(money)
    tms.append(tm)

# 単一始点最短経路を求める（Dijkstra法）
def Dijkstra(adjList):
    numV = N * (maxMoney+1)
    numUsed = 0
    costss = [[INF]*(maxMoney+1) for _ in range(N)]
    costss[0][S] = 0
    PQ = []
    heappush(PQ, (0, 0, S))
    while PQ:
        cNow, vNow, moneyNow = heappop(PQ)
        if cNow > costss[vNow][moneyNow]: continue
        numUsed += 1
        if numUsed == numV: break
        for v2, coin, tm in adjList[vNow]:
            if moneyNow < coin: continue
            c2 = cNow + tm
            m2 = moneyNow - coin
            if c2 < costss[v2][m2]:
                costss[v2][m2] = c2
                heappush(PQ, (c2, v2, m2))
        c2 = cNow + tms[vNow]
        m2 = moneyNow + moneys[vNow]
        if m2 > maxMoney:
            m2 = maxMoney
        if c2 < costss[vNow][m2]:
            costss[vNow][m2] = c2
            heappush(PQ, (c2, vNow, m2))
    return costss

S = min(S, maxMoney)
costss = Dijkstra(adjL)
#for i in range(N):
#    print(i, costss[i])

anss = [min(costss[t]) for t in range(1, N)]
print('\n'.join(map(str, anss)))


Measured memory_bytes: 96040
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int M = 1e9 + 7;

int c[200005], pw[200005];

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=1;i<=n;i++) cin >> c[i];
	sort(c+1, c+n+1, greater<int>());
	pw[0] = 1;
	for(int i=1;i<=n;i++)
		pw[i] = pw[i-1] * 2 % M;
	int ans = 0;
	for(int i=1;i<=n;i++) {
		int cur = 0;
		if(i - 2 >= 0) cur = (i + 1) * pw[i - 2] % M;
		else cur = (i + 1) / 2 * pw[i - 1] % M;
		cur = cur * pw[n - i] % M;
		cur = cur * c[i] % M;
		ans = (ans + cur) % M;
	}
	ans = ans * pw[n] % M;
	cout << ans << endl;
}





Measured memory_bytes: 3328
local ior = io.input()
local n, m = ior:read("*n", "*n")

local parent = {}
local groupsize = {}
for i = 1, n do parent[i] = i end
for i = 1, n do groupsize[i] = 1 end

local function getroot(idx)
  while(parent[idx] ~= idx) do
    idx = parent[idx]
  end
  return idx
end

for i = 1, m do
  local x, y, z = ior:read("*n", "*n", "*n")
  local xroot, yroot = getroot(x), getroot(y)
  if(groupsize[xroot] < groupsize[yroot]) then
    groupsize[yroot] = groupsize[xroot] + groupsize[yroot]
    parent[x] = yroot
    parent[xroot] = yroot
    parent[y] = yroot
  else
    groupsize[xroot] = groupsize[xroot] + groupsize[yroot]
    parent[x] = xroot
    parent[yroot] = xroot
    parent[y] = xroot
  end
end
local grouplist = {}
local cnt = 0
for i = 1, n do
  local r = getroot(i)
  if(grouplist[r] == nil) then
    grouplist[r] = true
    cnt = cnt + 1
  end
end
print(cnt)


Measured memory_bytes: 3456
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int t=0,total=0,m,s;
    for(int i=0;i<4;i++){
        cin>>t;
        total+=t;
    }
    m=total/60;
    s=total%60;
    cout<<m<<endl;
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 3100
/**
* 氏名: 阿部寛之
* 学籍番号: 170441004
***/


#include<stdio.h>

int main(void)
{
	int W, H, x, y, r;
	
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (0 <= x - r &&  x + r <= W && 0 <= y - r && y + r <= H)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2140
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    string s;
    cin >> s;
    ll u = 0;
    ll v = 0;
    for (int i = 0; i < N; ++i) {
        if(s[i]=='c'){
            cout << "No" << endl;
            continue;
        }
        if(s[i] == 'a'){
            if(A+B > u){
                cout << "Yes" << endl;
                u++;
                continue;
            }
        }else if(s[i]=='b'){
            if(A + B > u && B > v){
                cout << "Yes" << endl;
                u++;v++;
                continue;
            }
        }
        cout << "No" << endl;
    }
}


Measured memory_bytes: 896
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 1e5 + 10;
int a[maxn];
int n, x, y;

int read() {
  if (scanf("%d%d%d", &n, &x, &y) < 3) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  return 1;
}

void solve() {
  long long res = 0;
  for (int i = 1; i < n; ++i) {
    int delta = a[i] - a[i - 1];
    res += min((long long) delta * x, (long long) y);
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 640
#include<iostream>

int main()
{
	const char SHARP = '#';
	int h, w;
	while(std::cin >> h >> w)
	{
		if(h == 0 && w == 0) break;

		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				std::cout << SHARP;
			}
			std::cout << '\n';
		}
		std::cout << '\n';
	}
	
	return 0;
}

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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

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

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};
typedef Point<ll> P;
vector<P> convexHull(vector<P> pts) {
	if (sz(pts) <= 1) return pts;
	sort(all(pts));
	vector<P> h(sz(pts)+1);
	int s = 0, t = 0;
	for (int it = 2; it--; s = --t, reverse(all(pts)))
		trav(p, pts) {
			while (t >= s + 2 && h[t-2].cross(h[t-1], p) <= 0) t--;
			h[t++] = p;
		}
	return {h.begin(), h.begin() + t - (t == 2 && h[0] == h[1])};
}

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

    int n;
    cin >> n;
    vector<P> hull;
    hull.push_back(P(0, 0));

    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;

        P p(x, y);

        int k = hull.size();
        for (int j = 0; j < k; ++j) {
            hull.push_back(hull[j] + p);
        }

        hull = convexHull(hull);
    }

    double res = 0.0;
    for (auto& p : hull) {
        res = max(res, p.dist());
    }

    cout << fixed << setprecision(20) << res << '\n';
    
    return 0;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._

  val n = readInt
  val macho = Array.tabulate(n){_ ⇒
    val Array(c, w) = readLine.trim.split(' ').map(_.toInt)
    Macho(c, w)
  }

  println(countMin(macho))
  def countMin(macho: Array[Macho]): Int = {
    val min = Array.tabulate(macho.length + 1){i ⇒ macho.length - i}
    val canBeOne = calCanBeOne(macho)
    for (right ← min.indices.tail.reverse; left ← 0 until right if canBeOne(left)(right - 1)){
      min(left) = math.min(min(left), min(right) + 1)
    }
    min(0)
  }
  def calCanBeOne(macho: Array[Macho]): Array[Array[Boolean]] = {
    val res = Array.tabulate(macho.length){_ ⇒ Array.tabulate(macho.length){_ ⇒ false}}
    val weights = (0 +: macho.map(_.weight)).also{a ⇒ a.indices.tail.foreach(i ⇒ a(i) += a(i - 1))}

    def subWeight(from: Int, to: Int): Int ={
      weights(to + 1) - weights(from)
    }
    def sub(from: Int, to: Int, cache: Boolean = false): Boolean = {
      if (cache) res(from)(to)
      else {
        if (from == to) res(from)(to) = true
        else res(from)(to) = (res(from)(to - 1) && subWeight(from, to - 1) <= macho(to).power) || (res(from + 1)(to) && subWeight(from + 1, to) <= macho(from).power)
        res(from)(to)
      }
    }
    for (length ← 0 until n; a ← 0 until n - length) {
      sub(a, a + length)
    }
    res
  }

  case class Macho(power: Int, weight: Int)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}



Measured memory_bytes: 69888
#create date: 2020-03-28 21:01

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    x = ni()
    l = x % 100
    print(1000*(x//500) + 5*((x % 500)//5))

if __name__ == "__main__":
    main()


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

int main()
{
  int w, h, x, y, r;

  cin >> w >> h >> x >> y >> r;
  
  if (0 <= x-r && x+r <= w && 0 <= y-r && y+r <= h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}




Measured memory_bytes: 3116
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "limits.h"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
using namespace std;

int n,a[1000],mem;
ll ans;


int main(){
	lp(1000)
		a[i] = 1;
	cin >> n;
	lp(n) {
		mem = i + 1;
		for (int j = 2; j <= i + 1; j++) {
			if (mem%j == 0) {
				mem = mem / j;
				j--;
				a[j]++;
			}
			if (mem == 1)break;
		}
	}
	ans = 1;
	lp(1000) {
		ans = (ans*a[i]) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String s = sc.next();
			int k = 0;
			int start = 0;
			while(s.codePointAt(k)!=43) k++;
			String a = s.substring(start, k);
			k++;
			start = k;
			while(s.codePointAt(k)!=61) k++;
			String b = s.substring(start, k);
			String c = s.substring(k+1, s.length());
			
			start = 0;
			if(a.codePointAt(0)==88 && a.length()>1 || b.codePointAt(0)==88 && b.length()>1 || c.codePointAt(0)==88 && c.length()>1){
				start = 1;
			}
			
			String x, y, z;
			boolean flag = false;
			for(int i=start;i<10;i++){
				x = a;
				y = b;
				z = c;
				x = x.replaceAll("X", Integer.toString(i));
				y = y.replaceAll("X", Integer.toString(i));
				z = z.replaceAll("X", Integer.toString(i));
				BigInteger p = new BigInteger(x);
				BigInteger q = new BigInteger(y);
				BigInteger r = new BigInteger(z);
				
				if(p.add(q).compareTo(r)==0){
					System.out.println(i);
					flag = true;
					break;
				}
			}
			if(flag==false) System.out.println("NA");
		}
	}	
}

Measured memory_bytes: 23164
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

class DisjointSet{
    public:
        vector<int> rank, p;//rank:??¨????????? p:??????????????????
        DisjointSet(){}
        DisjointSet(int size){//???????????°
            rank.resize(size, 0);
            p.resize(size, 0);
            rep(i, size) makeSet(i);
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        //????????¨??????????????????????????????????????????
        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }
        // ??¨?????????????????£?????????
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
        //??¨??????????????????????????¨?????????????????£?????????
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x] == rank[y]) rank[y]++;
            }
        }
        //????????¢????????????????????§???
        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main(void){
    int n, w, h;
    bool cornerw = false, cornerh = false;//?£??????????????????????????????????????¨???¶????????????????????°
    cin >> n >> w >> h;
    //?????????????????????????????\???????????¨?????¨????????????????????????????????¨???????????§????????????????????\??£?????????????????????????¢????????????????
    vector<int> memoX(w, -1);//???
    vector<int> memoY(h, -1);//???
    DisjointSet ds = DisjointSet(n);

    rep(i, n){
        int x, y;
        scanf("%d %d", &x, &y);
        x--; y--;//0origin
        if(x == 0 || x == w - 1) cornerw = true;
        if(y == 0 || y == h - 1) cornerh = true;
        //?????¨?¨??????§?????????????????????
        //????????????????????????????????????x??§?¨???¨y??§?¨??????±???????????????????????£?????????????????¨?????§??????
        if(memoX[x] < 0) memoX[x] = i;//???????????????????????????????????\??£????????¨???????????°X[???]=????????????????????\??????
        else ds.unite(i, memoX[x]);//?????§????????????????????????????????\??£???????????°???????????????????????¨?????£?????????
        if(memoY[y] < 0) memoY[y] = i;
        else ds.unite(i, memoY[y]);
    }

    set<int> sum;
    rep(i, w){
        if(memoX[i] != -1) sum.insert(ds.findSet(memoX[i]));//??????????¨±??????????????????set????????¨
    }

    int m = sum.size();//??£??????????????????????????°???????????????????????°

    if(m > 1){
        if(cornerw == true || cornerh == true){
            printf("%d\n", n + m - 2);//?£?????????£?????????????????£????????????1?????\?????????????????§????????????-1
        }else{
            printf("%d\n", n + m - 1);
        }
    }else{//??????????????°?????????????????????????????????
        printf("%d\n", n - 1);
    }
    return 0;
}

Measured memory_bytes: 3388
#include <cstdio>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int y = 1;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == y) {
      ++y;
    }
  }
  printf("%d\n", y == 1 ? -1 : n - y + 1);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N];
ll a[N],b[N];
map <int,int> mp;
ll vis[N];
ll ts=0;
void dfs(ll v){
    vis[v]=1;
    for (auto u : g[v]){
        if (!vis[u]) dfs(u);
    }
    return ;
}
int32_t main(){
    sync;
    ll n;
    cin >> n;
    ll x=0;
    vector <int> c,d;
    for (int i=1;i<=n;i++){
        cin >> a[i];
        x ^= a[i];
        c.pb(a[i]);
    }
    a[n+1]=x;
    c.pb(x);
    x=0;
    for (int i=1;i<=n;i++){
        cin >> b[i];
        x ^= b[i];
        d.pb(b[i]);
    }
    b[n+1]=x;
    n++;
    d.pb(x);
    sort(c.begin(),c.end());
    sort(d.begin(),d.end());
    for (int i=0;i<n;i++) if (c[i]!=d[i]) kill(-1);
    for (int i=0;i<n;i++) mp[c[i]]=i+1;
    for (int i=1;i<=n;i++) a[i]=mp[a[i]],b[i]=mp[b[i]];
    for (int i=1;i<n;i++){
        if (a[i]==b[i]) continue;
        g[b[i]].pb(a[i]);
        g[a[i]].pb(b[i]);
        ts++;
    }
    ts++;
    g[a[n]].pb(b[n]);
    g[b[n]].pb(a[n]);
    ll cnt=0;
    for (int i=1;i<=n;i++){
        if (g[i].size() && !vis[i]) dfs(i),cnt++;
    }
   // cout << cnt << endl;
    cnt--;
    ll ans=cnt+ts-1;
    if (ans==-1) ans=0;
    cout << ans << endl;


}


Measured memory_bytes: 25864
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
char s[maxn];
int  is[maxn];
bool solve(int x, int y, int len)
{
      int i, j;
      is[0]=x;
      is[1]=y;
      for(i=2; i<=len+1; i++)
      {
	 if(is[i-1])
	 {
	    if(s[i-1]=='o')is[i]=is[i-2];
	    else is[i]=!is[i-2];
	 }
	 else  //前面的人说了假话
	 {
	    if(s[i-1]=='o')is[i]=!is[i-2];
	    else is[i]=is[i-2];
	 }
      }
	  /* for(i=0; i<len+2; i++)
	   {
	      printf(is[i]?"S":"W");
	   }
	   printf("\n");
	   */
      if(is[len]== is[0] && is[len+1]==is[1])
      {
	   for(i=0; i<len; i++)
	   {
	      printf(is[i]?"S":"W");
	   }
	   printf("\n");
	   return 1;
      }
      return 0;

}

int main()
{
   int n;
   scanf("%d", &n);
   int i;
   scanf("%s", s);
   int len=strlen(s);
   s[len]=s[0];
   s[len+1]=s[1];
   s[len+2]='\0';
   int j;
   for(i=0; i<2; i++)
   {
     for(j=0; j<2; j++)
     {
	if(solve(i, j, len))return 0;
     }
   }
   printf("-1\n");
}


Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int INF=2e9;


int main(){
	int N,C;
	cin>>N>>C;
	int D[31][31];
	rep1(i,C)rep1(j,C){
		cin>>D[i][j];
	}
	int a[3][31];
	rep(i,N)rep(j,N){
		int k;
		cin>>k;
		a[(i+j)%3][k]++;
	}
	
	int ans=INF;
	//0を色iに,1を色jに,2を色kにしたときの違和感の値
	rep1(i,C)rep1(j,C)rep1(k,C){
		int st=0;
		if(i==j||j==k||k==i)st=INF;
		else{
			rep1(l,C){
				st+=a[0][l]*D[l][i];
			}
			rep1(l,C){
				st+=a[1][l]*D[l][j];
			}
			rep1(l,C){
				st+=a[2][l]*D[l][k];
			}
		}
		ans=min(st,ans);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<int> cnt(n+1);
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                int w=x*x+y*y+z*z+x*y+y*z+z*x;
                if(w<=n) cnt[w]++;
            }
        }
    }
    for(int i=1;i<=n;i++) cout<<cnt[i]<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(fabs(a - b) <= d && fabs(c - b) <= d || fabs(a - c) <= d)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    return 0;
}

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

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define ff first
#define ss second
#define err stderr
#define out stdout

typedef long long int ll;
typedef long double ld;
typedef short int sh;

inline void readI(int *i)
{
	register int t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=(t*znak);
}
inline void readUI(int *i)
{
	register int t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=t;
}
inline void readL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak*=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=(t*znak);
}
inline void readUL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=t;
}
inline void writeL(ll l)
{
	if (l==0)
	{
		putchar(48);
	}
	else
	{
		if (l<0)
		{
		   l*=-1;
		   putchar(45);
		}
		int _tab[21];
		int wsk=0;
		while (l>0)
		{
			++wsk;
			_tab[wsk]=(l%10)+48;
			l/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeS(string s)
{
	int l=s.length();
	for (int i=0; i<l; ++i)
	{
		putchar(s[i]);
	}
}
inline void space()
{
	putchar(32);
}
inline void endl()
{
	putchar(10);
}

#define debug if(0)
#define debug2 if(1)
#define debug3 if(1)
#define debug4 if(1)
#define MAXK (int)(1e5)+5

int n, k, a, suma;
ll P=(1e9)+7;
ll dp[2][MAXK];

int main()
{
	readUI(&n);
	readUI(&k);
	for (int i=0; i<=k; ++i)
	{
		dp[0][i]=1;
	}
	for (int i=1; i<=n; ++i)
	{
		readUI(&a);
		suma+=a;
		suma=min(suma, k);
		for (int j=0; j<=a; ++j)
		{
			dp[i&1][j]=(dp[i&1^1][j]+(!j ? 0 : dp[i&1][j-1]))%P;
			debug
			{
				fprintf (err, "i=%d j=%d dp[i][j]=%lld\n", i, j, dp[i&1][j]);
			}
		}
		for (int j=a+1; j<=suma; ++j)
		{
			dp[i&1][j]=(dp[i&1^1][j]-dp[i&1^1][j-a-1]+P+dp[i&1][j-1])%P;
			debug
			{
				fprintf (err, "i=%d j=%d dp[i][j]=%lld\n", i, j, dp[i&1][j]);
			}
		}
		for (int j=suma+1; j<=k; ++j)
		{
			dp[i&1][j]=dp[i&1][j-1];
			debug
			{
				fprintf (err, "i=%d j=%d dp[i][j]=%lld\n", i, j, dp[i&1][j]);
			}
		}
	}
	fprintf (out, "%lld\n", (dp[n&1][k]-dp[n&1][k-1]+P)%P);
	return 0;
}
/*
*/




Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, M;
int A[112345];

int main() {
	cin >> N >> M;
	REP(i, N) scanf("%d", A + i);
	
	priority_queue<int> pq;
	REP(i, N) pq.push(A[i]);
	
	REP(i, M) if (!pq.empty()) {
		int cur = pq.top(); pq.pop();
		if (cur > 1) pq.push(cur / 2);
	}
	
	ll ans = 0;
	while (!pq.empty()) {
		int cur = pq.top(); pq.pop();
		ans += cur;
	}
	
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 1276
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);
$fusion = 0;
for ($i = 0; $i < $n-1; $i++) {
    if($s[$i] === $s[$i+1]) {
        $fusion++;
    }
}

echo $n - $fusion;

Measured memory_bytes: 4728
#include <iostream>
#include <vector>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N, M;
    cin >> N >> M;
    vector<vector<char>> A(N, vector<char>(N));
    vector<vector<char>> B(M, vector<char>(M));
    REP (i, 0, N) REP (j, 0, N) cin >> A[i][j];
    REP (i, 0, M) REP (j, 0, M) cin >> B[i][j];
    REP (i, 0, N - M + 1) {
        REP (j, 0, N - M + 1) {
            bool run = true;
            REP (a, 0, M) {
                REP (b, 0, M) {
                    if (A[i + a][j + b] != B[a][b]) run = false;
                }
            }

            if (run) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
data = list(map(int, input().split()))
order = list(input())

up = 1
front = 2
right = 3

move = "NSEW"

for m in order:
    i = move.index(m)
    if i == 0:
        up, front = front, 7 - up
    elif i == 1:
        up, front = 7 - front, up
    elif i == 2:
        up, right = 7 - right, up
    else:
        up, right = right, 7 - up

print(data[up - 1])

Measured memory_bytes: 7724