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

int main(){
    string s; cin >> s;
    int n = s.size();
    
    bool find_A = false;
    int a_index, ans;
   
    for(int i = 0; i < n; i++){
        if(s.at(i) == 'A' && !find_A){
            a_index = i;
            find_A = true;
        }else if(s.at(i) == 'Z' && find_A){
            ans = i - a_index + 1;
        }
    }
    
    cout << ans << endl;
        
                    
}




Measured memory_bytes: 640
n = int(input())
s = dict()
for _ in range(n):
  temp = input()
  try:
    s[temp] += 1
  except:
    s[temp] = 1

m = int(input())

for _ in range(m):
  temp = input()
  try:
    s[temp] -= 1
  except:
    s[temp] = 1


s = sorted(s.items(), key=lambda x: x[1], reverse=True)

if s[0][1] < 0:
  print(0)
else:
  print(s[0][1])



Measured memory_bytes: 9204
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int m = 100000;
		
		for(int i=0;i<n;i++){
			m = (int)(m * 1.05);
			if(m%1000!=0){
				m = (m/1000)*1000+1000;
			}
		}
		
		System.out.println(m);
	}
}

Measured memory_bytes: 17160
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int n,a[105],vis[105],ans[105];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=n;j>=1;j--)
		{
			if(vis[j]) continue;
			int cc=0;
			for(int k=1;k<j;k++) cc+=(!vis[k]);
			if(cc==a[j]-1)
			{
				vis[j]=1,ans[i]=a[j];
				break;
			}
		}
		if(!ans[i])
		{
			puts("-1");
			return 0;
		}
	}
	for(int i=n;i>=1;i--) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n,h,i;
    string s,ss;
    while(1) {
        cin >> s;
        if(s=="-") break;
        cin >> n;
        for(i=0;i<n;i++){
            cin >> h;
            ss=s.substr(0,h);
            s.erase(0,h);
            s+=ss;
        }
        cout << s <<endl;
    }
}



Measured memory_bytes: 3220
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

H, W, D = map(int, readline().split())
A = [list(map(int, readline().split())) for _ in range(H)]
Q = int(readline())
query = [tuple(map(int, readline().split())) for _ in range(Q)]

path = [[(-1, -1)]*((H*W)//D+1) for _ in range(D)]
for i in range(H):
    for j in range(W):
        a = A[i][j]
        div, mod = divmod(a, D)
        path[mod][div] = (i, j)
path[0][0] = path[0][1]

cost = []
for i in range(D):
    tmp = [0]
    for l, r in zip(path[i][:-1], path[i][1:]):
        x, y = l
        z, w = r
        tmp.append(tmp[-1] + abs(z - x) + abs(w - y))
    cost.append(tmp)

ans = []
for L, R in query:
    vl, md = divmod(L, D)
    vr = R // D

    tmp = cost[md][vr] - cost[md][vl]
    ans.append(tmp)

print(*ans, sep="\n")


Measured memory_bytes: 51168
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	long long int n;
	scanf("%lld",&n);
	long long int a,b;
	for(long long int i=1;i*i<=n;i++){
		if(n%i==0){
			a = i;
			b = n/i;
		}
	}
	int keta_a = log10((double)a);
	int keta_b = log10((double)b);

	printf("%d\n",max(keta_a+1,keta_b+1));
	return 0;
}


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

int main() {
    long long k, a, b; cin >> k >> a >> b;
    long long bis = 1;
    long long c = b - a;
    if (c >= 2) {
        long long t = min(k, a-1);
        k -= t; bis += t;
        if (bis == a) {
            bis += (k % 2) + (k / 2) * c;
        }
    } else {
        bis += k;
    }
    cout << bis << endl;
    return 0;
}

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

int main(){
    ll n, t;
    cin >> n >> t;
    ll t_first = 0;
    ll t_last = 0;
    ll sum = 0;
    rep(i, n) {
        ll tmp_t;
        cin >> tmp_t;
        if ( tmp_t >= t_last ) {
            sum += ( t_last - t_first );
            t_first = tmp_t;
            t_last = tmp_t + t;
        }
        else {
            t_last += t - ( t_last - tmp_t );
        }
    }
    sum += t_last - t_first;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
S=int(input())

S_top = S // 100
S_bottom = S % 100

if 1 <= S_top <= 12 and 1 <= S_bottom <= 12:
  print("AMBIGUOUS")
elif 1 <= S_top <= 12:
  print("MMYY")
elif 1 <= S_bottom <= 12:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	string str;
	cin>>str;
	if(str=="Sunny")
		cout<<"Cloudy"<<endl;
	else if(str=="Cloudy")
		cout<<"Rainy"<<endl;
	else
		cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
array = []
for i in range(c):
	array.append(int(input()))

point = [b] * a
 
for i in range(c):
	point[array[i]-1] = point[array[i]-1] + 1
            
for i in range(len(point)):
	if (point[i]-c) > 0 :
		print('Yes')
	else:
		print('No')

Measured memory_bytes: 56024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

int main(){
    ll a;
    double c;
    cin >> a;
    cin >> c;
    int x = c*100 + 0.00001;
    cout << ll(a*x) / 100 << endl;
}

Measured memory_bytes: 3704
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var ans = long.MaxValue;
            for (long i = 1; i * i <= N; ++i)
            {
                if (N % i == 0)
                {
                    var A = i;
                    var B = N / i;
                    ans = Min(ans, Max(A.ToString().Length, B.ToString().Length));
                }
            }
            WriteLine(ans);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27940
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T,class U>
ostream& operator << (ostream& os,pair<T,U>& p){
	os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
	is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		os << vec[i];
		if(i+1<vec.size())os << ' ';
	}
	return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
	for(int i=0;i<vec.size();i++)is >> vec[i];
	return is;
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
P a,b;
int main(){
  cin >> a.sec >> b.sec >> a.fi >> b.fi;
  if(a.fi==-1||b.fi==-1){
    if(a.sec==b.sec)cout << "Draw" << endl;
    else if(a.sec<b.sec)cout << "Alice" << endl;
    else cout << "Bob" << endl;
    return 0;
  }
  a.sec *= -1;
  b.sec *= -1;
  if(a.fi==b.fi||a==b)cout << "Draw" << endl;
  else if(a<b)cout << "Bob" << endl;
  else cout << "Alice" << endl;
	return 0;
}



Measured memory_bytes: 3120
main(a,b,c,d,e,f,x,i){for(i=3;i--;printf("%d %d %d\n",x/3600,x/60%60,x%60))scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f),x=(d*3600+e*60+f)-(a*3600+b*60+c);return 0;}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
  string w;
  cin >> w;
  int n;
  for(char c='a'; c<='z'; c++){
    n = count(w.begin(),w.end(),c);
    if(n%2 != 0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	bool odd = false;
	for(int i = 0; i < n; i++) if(a[i] & 1) odd = true;
	if(odd) puts("first");
	else puts("second");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
char a[100100];
int main(){
    int i, N, cnt=0;
    scanf("%s", a);
    N = strlen(a);
    for(i=1; i<N; i++){
        if(a[i] != a[i-1]){
            cnt++;
        }
    }
    cout<<cnt;
}


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

int main() {
  long n;
  cin >> n;
  vector<long> t(n),a(n),x(n),y(n);
  for(long i=0;i<n;i++) cin >> t[i] >> a[i];
  x[0]=t[0],y[0]=a[0];
  for(long i=1;i<n;i++) {
    x[i]=((x[i-1]-1)/t[i]+1)*t[i];
    y[i]=((y[i-1]-1)/a[i]+1)*a[i];
    if(x[i]/t[i]<y[i]/a[i]) x[i]=y[i]/a[i]*t[i];
    else y[i]=x[i]/t[i]*a[i];
  }
  cout << x[n-1]+y[n-1] << endl;
}

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

using namespace std;

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

    map<int, int> m;

    for (int i = 0; i < N; i++)
    {
        int num;
        cin >> num;
        m[num] = i + 1;
    }

    for (int i = 1; i < N; i++)
    {
        cout << m[i] << " ";
    }

    cout << m[N] << endl;

    return 0;
}

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

int main()
{

    string s;
    cin >> s;

    int n, m;
    int count = 0;
    n = s.size();
    m = (n - 1) / 2;

    for (int i = 0; i < m; i++)
    {
        if (s[i] != s[n - 1 - i])
        {
            count = 1;
            break;
        }
    }

    if (count == 0)
    {
        if (n == 5)
        {
            if (s[0] != s[1] || s[n - 1] != s[n - 2])
                count = 1;
        }
        else
        {
            for (int i = 0; i < (m - 1) / 2; i++)
            {
                if (s[i] != s[m - 1 - i] || s[m + 1 + i] != s[2 * m - i])
                {
                    count = 1;
                    break;
                }
            }
        }
    }

    if (count == 0)
        cout << "Yes" << endl;
    if (count == 1)
        cout << "No" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    for(int a=0; a<=n; ++a){
        for(int b=0; a+b<=n; ++b){
            int c = n - a - b;
            int x = a * 10000 + b * 5000 + c * 1000;
            if(x == y){
                cout << a << ' ' << b << ' ' << c << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
    return 0;
}


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

int main() {
    char S[27];
    scanf("%s", S);

    for (int i = 0; i < strlen(S); i++) {
        for (int j = 0; j < i; j++) {
            if (S[i] == S[j]) {
                printf("no\n");
                return 0;
            }
        }
    }

    printf("yes\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////

void swap(char &a, char &b)
{
    char t = a;
    a = b;
    b = t;
}

int main()
{
    int N;
    io >> N;
    string c;
    io >> c;

    int l = 0, r = N - 1;
    int ans = 0;
    while (true)
    {
        while (c[l] == 'R' && l < r) ++l;
        while (c[r] == 'W' && l < r) --r;

        if (l == r) break;
        swap(c[l], c[r]);
        ++ans;
    }
    cout << ans << BR;
}

Measured memory_bytes: 3812
#include<stdio.h>
#include<math.h>
long int mindis(long int, long int, long int);

int main(void)
{
int h,w,a1,a2,a3,lng,shrt;
unsigned long int s1,s2,s3,d, min;

scanf("%d %d", &h, &w);

if(h%3==0 || w%3==0){
  printf("0\n");
}
else {

shrt = h;
lng = w;

//-----
a1 = lng / 3+ lng%3/2;
a2 = shrt / 2;

s1 = shrt * a1;
s2 = a2 * (lng - a1);
s3 = (shrt - a2) * (lng - a1);
min = mindis(s1,s2,s3);

//-----
a2 = (lng-a1) / 2;
a3 = lng - a1 - a2;
s1 = shrt * a1;
s2 = shrt * a2;
s3 = shrt * a3;

d = mindis(s1,s2,s3);
if(min > d) min=d;

shrt = w;
lng = h;

//-----
a1 = lng / 3+ lng%3/2;
a2 = shrt / 2;

s1 = shrt * a1;
s2 = a2 * (lng - a1);
s3 = (shrt - a2) * (lng - a1);

d = mindis(s1,s2,s3);
if(min > d) min=d;


//-----
a2 = (lng-a1) / 2;
a3 = lng - a1 - a2;
s1 = shrt * a1;
s2 = shrt * a2;
s3 = shrt * a3;

d = mindis(s1,s2,s3);
if(min > d) min=d;

printf("%ld\n", min);
}

return 0;
}

long int mindis(long int s1, long int s2, long int s3){
long int d;
if(s3 > s2) {
  if(s2 > s1) {
    d=s3-s1;
  }else{
    if(s3 > s1){
      d=s3-s2;
    }else{ 
      d=s1-s2;
    }
  }
}else{
  if(s1 > s2){
    d=s1-s3;
  }else{
    if(s1 < s3){
      d=s2 - s1;
    }else{
      d=s2 - s3;
    }
  }
}
return d;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, vector<long long> p){
	ll res = 0;
	rep(i, N-1) {
		if (p[i] == i+1) {
			ll s = p[i];
			p[i] = p[i+1];
			p[i+1] = s;
			res++;
		}
	}
	if (p[N-1] == N) {
		res++;
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> p(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&p[i]);
	}
	solve(N, p);
	return 0;
}



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

class Program
{
    private const int mod = 1000000007;

    //パスカルの三角形
    static long[,] pascalsTriangle = new long[4005, 4005];

    static void Main()
    {
        var nk = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var N = nk[0];
        var K = nk[1];
        
        pascalsTriangle[0,0] = 1;
        for (int i=0;i<=4000;i++)
        {
            for (int j=0;j<=4000;j++)
            {
                pascalsTriangle[i + 1, j] = (pascalsTriangle[i + 1, j] + pascalsTriangle[i, j]) % mod;
                pascalsTriangle[i + 1, j + 1] = (pascalsTriangle[i + 1, j + 1] + pascalsTriangle[i, j]) % mod;
            }
        }

        for (var i=1;i<=K;++i)
        {
            var blue = F(K,i);

            var red = 0L;
            //青の間
            red = (red + F(N - K, i - 1)) % mod;
            //青の間と左
            red = (red + F(N - K, i)) % mod;
            //青の間と右
            red = (red + F(N - K, i)) % mod;
            //青の間と両端
            red = (red + F(N - K, i + 1)) % mod;

            Console.WriteLine((blue * red) % mod);
        }
    }

    //0個のグループを許容する
    static long F(long whole, long parts)
    {
        if (whole < parts) return 0;
        if (whole == 0 && parts == 0) return 1;
        if (parts <= 0) return 0;
        return F2(whole-parts,parts);//=f(whole,parts)
    }

    //玉と仕切りを置く場所の選び方
    static long F2(long whole,long parts)
    {
        return pascalsTriangle[whole+parts-1,parts-1];
    } 
}


Measured memory_bytes: 138580
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

template <class... Args>
struct tuple_input_impl;
template <std::size_t i, std::size_t... tail>
struct tuple_input_impl<std::index_sequence<i, tail...>>
{
    template <class... Args>
    static void f(std::tuple<Args...>& x)
    {
        std::cin >> std::get<i>(x);
        tuple_input_impl<std::index_sequence<tail...>>::f(x);
    }
};
template <>
struct tuple_input_impl<std::index_sequence<>>
{
    static void f(...) {}
};

template <class... Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& x)
{
    tuple_input_impl<std::index_sequence_for<Args...>>::f(x);
    return in;
}
template <class T1, class T2>
std::istream& operator>>(std::istream& in, std::pair<T1, T2>& x) { return in >> x.first >> x.second; }

template <class T>
T read()
{
    T res;
    std::cin >> res;
    return res;
}
template <class T>
std::vector<T> read(std::size_t n)
{
    std::vector<T> res(n);
    for (std::size_t i = 0; i < n; ++i) std::cin >> res[i];
    return res;
}

template <class T>
void out_impl(T&& v) { std::cout << std::forward<T>(v); }
template <class T, class... Args>
void out_impl(T&& v, Args&&... args)
{
    std::cout << std::forward<T>(v) << ' ';
    out_impl(std::forward<Args>(args)...);
}
template <class... Args>
void out(Args&&... args)
{
    out_impl(std::forward<Args>(args)...);
    std::cout << '\n';
}
template <class... Args>
void out_noreturn(Args&&... args) { out_impl(std::forward<Args>(args)...); }

template <class T>
void print(const T& container)
{
    bool first = true;
    for (auto&& x : container) {
        if (!first) std::cout << ' ';
        std::cout << x;
        first = false;
    }
    std::cout << '\n';
}

void prog()
{
    int n, m;
    std::cin >> n >> m;
    if (m <= n) {
        out(0);
        return;
    }
    auto x = read<int>(m);
    std::sort(std::begin(x), std::end(x));

    std::vector<int> d(m - 1);
    for (auto i : boost::irange(0, m - 1)) {
        d[i] = x[i + 1] - x[i];
    }
    std::sort(std::begin(d), std::end(d));
    auto sum = std::accumulate(std::begin(d), std::end(d) - n + 1, 0);
    out(sum);
    // 1 2 10 12 14
    //  1 8  2  2
}

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    prog();
    return 0;
}


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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;


int main() {
    ll N,M;
    cin>>N>>M;
    vector<ll> X(N),Y(M);
    for(ll i = 0; i < N; i++) cin>>X[i];
    for(ll i = 0; i < M; i++) cin>>Y[i];
    ll x = 0LL, y = 0LL;
    for(ll i = 0; i < N-1; i++){
        x=(x+(((X[i+1]-X[i])*(N-i-1))%mod)*(i+1))%mod;
    }
    for(ll i = 0; i < M; i++){
        y = (y+(((Y[i+1]-Y[i])*(M-i-1))%mod)*(i+1))%mod;
    }
    cout<<(x*y)%mod<<endl;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<17;
	ll dp[1<<18];
	segtree(){
		memset(dp,0,sizeof(dp));
	}
	void update(int k,int v){
		k+=N-1;
		dp[k]+=v;
		dp[k]%=MOD;
		while(k>0){
			k=(k-1)/2;
			dp[k]=(dp[k*2+1]+dp[k*2+2])%MOD;
		}
	}

	ll query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		ll vl=query(a,b,k*2+1,l,mid);
		ll vr=query(a,b,k*2+2,mid,r);
		return (vl+vr)%MOD;
	}
};

segtree seg;
int n,m;
int x[100005],y[100005];
int pos[100005];
vector<int> id_l,id_r;
vector<int> query[100005];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%d",&y[i]);
	}
	for(int i=0;i<n;i++){
		int v=lower_bound(y,y+m,x[i])-y;
		if(v==0 || v==m){
			pos[i]=-1;
		}else{
			pos[i]=v;
			id_l.push_back(x[i]-y[v-1]);
			id_r.push_back(y[v]-x[i]);
		}
	}
	sort(id_l.begin(),id_l.end());
	id_l.erase(unique(id_l.begin(),id_l.end()),id_l.end());
	id_r.push_back(0);
	sort(id_r.begin(),id_r.end());
	id_r.erase(unique(id_r.begin(),id_r.end()),id_r.end());
	for(int i=0;i<n;i++){
		if(pos[i]==-1)continue;
		int vl=x[i]-y[pos[i]-1];
		int vr=y[pos[i]]-x[i];
		vl=lower_bound(id_l.begin(),id_l.end(),vl)-id_l.begin();
		vr=lower_bound(id_r.begin(),id_r.end(),vr)-id_r.begin();
		query[vl].push_back(vr);
	}
	seg.update(0,1);
	for(int i=0;i<id_l.size();i++){
		sort(query[i].begin(),query[i].end());
		query[i].erase(unique(query[i].begin(),query[i].end()),query[i].end());
		reverse(query[i].begin(),query[i].end());
		for(int j=0;j<query[i].size();j++){
			int v=query[i][j];
			ll val=seg.query(0,v);
			seg.update(v,val);
			//printf("%d %lld\n",v,val);
		}
	}
	printf("%lld\n",seg.query(0,n+1));
	return 0;
} 

Measured memory_bytes: 9716
#include <bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin >> q;
  deque<int> A;
  for (int i = 0; i < q; i++){
    int t;
    cin >> t;
    if (t == 0){
      int d, x;
      cin >> d >> x;
      if (d == 0){
        A.push_front(x);
      }
      if (d == 1){
        A.push_back(x);
      }
    }
    if (t == 1){
      int p;
      cin >> p;
      cout << A[p] << endl;
    }
    if (t == 2){
      int d;
      cin >> d;
      if (d == 0){
        A.pop_front();
      }
      if (d == 1){
        A.pop_back();
      }
    }
  }
}


Measured memory_bytes: 4680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  if (A == B && B != C) {
    printf("Yes\n");
  }
  else if (A != B && B == C) {
    printf("Yes\n");
  }
  else if (A != B && A == C) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
  return 0;
}

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

int solve() {
  int N, M; std::cin >> N >> M;
  std::vector<int> s(M);
  std::vector<int> c(M);
  for (int i = 0; i < M; ++i) std::cin >> s[i] >> c[i];

  /* 全探索 */
  for (int n = 0; n < std::pow(10,N); ++n) {
    int digit = 1;      // 0は1桁
    std::vector<int> each_num(1, n%10); // 一の位
    int x = n/10;

    while (x) {
      digit++;
      each_num.push_back(x%10);
      x /= 10;
    }

    if (digit != N) continue; // 桁数の条件を満たさない

    std::reverse(each_num.begin(), each_num.end());

    bool ok = true; // 条件を満たす整数が存在するかどうか
    
    for (int i = 0; i < M; ++i)
      if (each_num[s[i]-1] != c[i]) ok = false; // 一つでも条件を満たさないものがあれば

    if (ok) return n; // 桁数とそれぞれの桁の数字が条件を満たす
  }
  
  return -1;
  
}

int main() {
  std::cout << solve() << std::endl;

  return 0;
}


Measured memory_bytes: 3992
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1) {

    for(int u : to[v]) {
        if(u == p) {
            continue;
        }
        ans[u] += ans[v];
        dfs(u, v);
    }
}

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

    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    ans.resize(n);

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0);

    rep(i, n) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 23424
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int count = 0;
		
		if(S.indexOf('A') == 0) {
			count++;
		}	
		
		if(S.replace("C", "").length() == (S.length() - 1)) {
			if((S.indexOf('C') >= 2) && (S.length() - S.indexOf('C') >= 2)) {
				count++;
			}
		}
		
		String SnA = S.replace("A", "");
		String SnAC = SnA.replaceAll("C", "");
		
		if(SnAC.toLowerCase() == SnAC) {
			count++;
		}
		
		if(count == 3) {
			System.out.println("AC");
		} else {
			System.out.println("WA");
		}
		
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int A, B, C;
    std::cin >> A >> B >> C;

    int max;
    max = std::max({A, B, C});

    int sum = A + B + C;
    int ans = 3*max - A - B - C;

    if (ans % 2 == 0) {
        std::cout << ans / 2 << std::endl;
    } else {
        std::cout << ans / 2 + 2 << std::endl;
    }

    return 0;
}

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

const int MAX=36;

int N;
pair<char, int> arr_bubble[MAX];
pair<char, int> arr_selection[MAX];

void bubble_sort();
void selection_sort();

int main(){
	
	char type;
	int number;
	
	cin >> N;
	
	for(int i=0; i<N; i++){
		cin >> type;
		cin >> number;
		
		arr_bubble[i].first = type;
		arr_bubble[i].second = number;
		
		arr_selection[i].first = type;
		arr_selection[i].second = number;
	}
	
	bubble_sort();
	selection_sort();
	
	for(int i=0; i<N; i++){
		if(i==0){
			cout << arr_bubble[i].first << arr_bubble[i].second;
		}
		else{
			cout << " " << arr_bubble[i].first << arr_bubble[i].second;
		}
	}
	cout << endl;
	
	cout << "Stable" << endl;
	
	bool is_stable = true;
	for(int i=0; i<N; i++){
		if(arr_selection[i].first != arr_bubble[i].first) {
			is_stable = false;
			break;
		}
	}
	
	
	for(int i=0; i<N; i++){
		if(i==0){
			cout << arr_selection[i].first << arr_selection[i].second;
		}
		else{
			cout << " " << arr_selection[i].first << arr_selection[i].second;
		}
	}
	cout << endl;
	
	if(is_stable){
		cout << "Stable" << endl;
	}
	else{
		cout << "Not stable" << endl;
	}
}

void bubble_sort(){
		for(int i=0; i<N; i++){
			for(int j=N-1; j>i; j--){
				if(arr_bubble[j-1].second > arr_bubble[j].second){
					pair<char, int> tmp;
					tmp = arr_bubble[j];
					arr_bubble[j] = arr_bubble[j-1];
					arr_bubble[j-1] = tmp;
				}
			}
		}
	}
	
void selection_sort(){
		for(int i=0; i<N; i++){
			int mini = i;
			for(int j=i; j<N; j++){
				if(arr_selection[mini].second > arr_selection[j].second){
					mini = j;
				}
			}
			pair<char, int> tmp;
			tmp = arr_selection[i];
			arr_selection[i] = arr_selection[mini];
			arr_selection[mini] = tmp;
		}
	}
	

Measured memory_bytes: 1168
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
// int const mod = 998244353;
long long const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            // res = res*a;
            res = (res*a)%m;
        }
        a=(a*a)%m;
        // a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x , int m){
    return power(x,m-2,m);
}


int const N = 2005;
int const inf = 1e18;

int dp[N];

void solve(){
    int i,j;
    int n;
    cin>>n;

    dp[0] = 1;

    for(i=3;i<=n;i++){
        for(j=3;j<=i;j++){
            dp[i] += dp[i-j];
            dp[i] %= mod;
        }
    }
    cout<<dp[n]<<endl;
}   


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;  
    for(int tt=1;tt<=t;tt++){
        // cout << "Case #"<<tt<<": ";
        solve();
    }
    return 0;
}

/* 


*/

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

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll M = 1000000000000000000;



int main(int argc, const char * argv[]) {
    long double A;
    long double B;
    cin >> A >>B;
    long long ans = A * B;
    
    cout << ans << endl;
    
}




Measured memory_bytes: 3732
import java.util.*;

class Main{
    
    int INF=Integer.MAX_VALUE;
    boolean debug=false;
    
    char[] in;
    int pp; // prime
    int p; // in[p]
    
    void solve(){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            String[] line = sc.nextLine().split(":");
            if(line[0].equals("0")) break;
            
            pp = Integer.parseInt(line[0]);
            
            int cnt = 0;
            for(int i=0; i<line[1].length(); i++){
                if(line[1].charAt(i)!=' ') cnt++;
            }
            
            in = new char[cnt];
            p = 0;
            int idx = 0;
            for(int i=0; i<line[1].length(); i++){
                if(line[1].charAt(i)!=' ') in[idx++] = line[1].charAt(i);
            }
            
            int ans = expr();
            if(ans==INF) System.out.println("NG");
            else{
                StringBuffer sb = new StringBuffer();
                for(int i=0; i<in.length; i++){
                    sb.append(in[i]);
                }
                sb.append(" = " + ans + " (mod "+pp+")");
                System.out.println(sb.toString());
            }
        }
    }
    
    int expr(){
        int a = term();
        if(a==INF) return INF;
        while(true){
            if(p>=in.length || (in[p]!='+' && in[p]!='-')) break;
            boolean add = in[p++] == '+';
            
            int b = term();
            if(b==INF) return INF;
            if(add) a = calc(a, b, '+');
            else a = calc(a, b, '-');
        }
        return a;
    }
    
    int term(){
        int a = factor();
        if(a==INF) return INF;
        while(true){
            if(p>=in.length || (in[p]!='*' && in[p]!='/')) break;
            boolean mul = in[p++] == '*';
            
            int b = factor();
            if(b==INF) return INF;
            if(mul) a = calc(a, b, '*');
            else{
                if(b==0) return INF;
                else a = calc(a, b, '/');
            }
        }
        return a;
    }
    
    int factor(){
        if(p<in.length && in[p]=='('){
            p++;
            int res = expr();
            p++;
            return res;
        }else return digit();
    }
 
    int digit(){
        int res = 0;
        while(p<in.length && Character.isDigit(in[p])) res = (res * 10 + in[p++] - '0') % pp;
        return res;
    }
 
    int calc(int a,int b,char op){
        if(op=='/' && b==0){return INF;}
     
        int val=-1;
        switch(op){
        case '+':{val = (a+b) % pp; break;}
        case '-':{val = (a+(pp-b)) % pp;  break;}
        case '*':{val = (a*b) % pp; break;}
        case '/':{val = a * pow(b, pp-2) % pp;}
        }
        
        return val % pp;
    }
 
    int pow(int b, int po){
        if(po==0) return 1;
        if(po==1) return b;
        int a = pow(b, po/2) % pp;
        if(po%2==1) return a * a % pp * b % pp;
        else return a * a % pp;
    }
 
    public static void main(String[] args){
        new Main().solve();
    }
}

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

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

    char ch;
    cin >> ch;

    if(isupper(ch))
    {
        cout << 'A' << endl;
    }
    else
    {
        cout << 'a' << endl;
    }

}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>

int main() {
  std::string C1, C2;
  std::cin >> C1 >> C2;

  std::string D1 = C1;
  std::string D2 = C2;
  std::reverse(D1.begin(), D1.end());
  std::reverse(D2.begin(), D2.end());
  if (C1 == D2 && C2 == D1) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
}

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

using namespace std;
typedef long long ll;

void solve()
{
   ll x,y;
   cin>>x>>y;
   string ans="No";
   for(int i=0;i<=x;i++)
   {
       ll temp=x-i;
       if(i*2+temp*4==y)
       {
           ans="Yes";
           break;
       }

   }
   cout<<ans<<endl;

}
int main()
{

    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }



}





Measured memory_bytes: 3576
#include<cstdio>

int count=0;

int main()
{
	int ans_n=0;
	double ans_m=0.0;
	int n,m;
	while(scanf("%d,%d",&n,&m)!=EOF)
	{
		count++;
		ans_n+=n*m;
		ans_m+=m;
	}
	printf("%d\n%d\n",ans_n,(int)(ans_m/count+0.5));
	return 0;
}

Measured memory_bytes: 0
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;
    
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<ctype.h>

int main() {

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

    if (a > b) {
        a -= 1;
    }
    printf("%d", a);


    return 0;

}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }


vector<int> calc_required_level_to_rooms()
{
	int w, h, sx, sy;
	static int req[512][512];
	cin >> w >> h >> sx >> sy;
	--sx, --sy;
	for (int y = 0; y < h; ++y)
		for (int x = 0; x < w; ++x)
			cin >> req[y][x];

	vector<int> res;
	res.push_back(0);

	static bool visit[512][512];
	CLEAR(visit, 0);

	typedef pair<int, pint> P;
	priority_queue<P, vector<P>, greater<P> > q;
	q.push(P(1, pint(sx, sy)));
	while (!q.empty())
	{
		P tt = q.top(); q.pop();
		int level = tt.first;
		int x = tt.second.first, y = tt.second.second;
		if (visit[y][x])
			continue;

		visit[y][x] = true;
		res.push_back(level);

		for (int i = 0; i < 4; ++i)
		{
			int tx = x + dx[i], ty = y + dy[i];
			if (valid_pos(tx, ty, w, h) && !visit[ty][tx])
				q.push(P(max(level, req[ty][tx]), pint(tx, ty)));
		}
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(false);

	int r;
	while (cin >> r, r)
	{
		vector<int> a = calc_required_level_to_rooms();
		vector<int> b = calc_required_level_to_rooms();

		int res = 1e9;
		for (int i = min<int>(r, a.size() - 1); i >= 0 && r - i < b.size(); --i)
			min_swap(res, a[i] + b[r - i]);
		cout << res << endl;
	}
}

Measured memory_bytes: 0
from sys import stdin

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

m = []
p = []
z = 0

for i in range(n):
  if(an[i]<0):
    m.append(an[i])
  if(an[i]>0):
    p.append(an[i])
  if(an[i]==0):
    z=1

if ( z==1 ):
  ans = sum(p) - sum(m)
elif ( len(m) == 0):
    ans = sum(p)
else:
  if ( len(p) == 0):
    if ( len(m)%2 == 0):
      ans = - sum(m)
    else:
        minm = -max(m)
        ans = -sum(m) - (minm*2)
  else:
    if ( len(m)%2 == 0):
      ans = sum(p) - sum(m)
    else:
      minm = 0
      if ( min(p) < (-max(m)) ):
        minm = min(p)
      else:
        minm = -max(m)
      ans  = sum(p) - sum(m) - (minm*2)

print(ans)

Measured memory_bytes: 14496
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
int a[N],b[N],t[N],n,p[N],c[N];
vector<pair<int,int>>v;
set<pair<int,int>>s;
set<int>sa,sb;
int main()
{
	scanf("%d",&n);
	if(n<=12)
	{
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)
			scanf("%d",&b[i]);
		for(int i=1;i<=n;i++)
			p[i]=i;
		do
		{
			int fl=1;
			for(int i=1;i<=n;i++)
			{
				c[i]=b[p[i]];
				if(c[i]==a[i])
				{
					fl=0;
					break;
				}
			}	
			if(fl)
			{
				puts("Yes");
				for(int i=1;i<=n;i++)
					printf("%d ",c[i]);
				return 0;
			}
		}while(next_permutation(p+1,p+n+1));
		puts("No");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		sa.insert(x);
		a[x]++;
		t[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		sb.insert(x);
		b[x]++;
		t[x]++;
	}
	for(int i=1;i<=n;i++)
		if(t[i])
			s.insert(make_pair(-t[i],i));
	for(int zh=1;zh<=n;zh++)
	{
		int x=s.begin()->second;
		s.erase(s.begin());
		if(!s.size())
		{
			puts("No");
			return 0;
		}
		if(a[x]>b[x])
		{
			for(auto y:sb)
			{
				if(y!=x)
				{
					v.emplace_back(x,y);
					a[x]--;
					t[x]--;
					if(!a[x])
						sa.erase(x);
					if(t[x])
						s.insert(make_pair(-t[x],x));
					s.erase(make_pair(-t[y],y));
					b[y]--;
					t[y]--;
					if(!b[y])
						sb.erase(y);
					if(t[y])
						s.insert(make_pair(-t[y],y));
					break;
				}
			}
		}
		else
		{
			for(auto y:sa)
			{
				if(y!=x)
				{
					v.emplace_back(y,x);
					b[x]--;
					t[x]--;
					if(!b[x])
						sb.erase(x);
					if(t[x])
						s.insert(make_pair(-t[x],x));
					s.erase(make_pair(-t[y],y));
					a[y]--;
					t[y]--;
					if(!a[y])
						sa.erase(y);
					if(t[y])
						s.insert(make_pair(-t[y],y));
					break;
				}
			}
		}
	}
	sort(v.begin(),v.end());
	puts("Yes");
	for(auto i:v)
		printf("%d ",i.second);
	return 0;
}

Measured memory_bytes: 34116
def testcase_ends():
    s = input()
    if s == '.':
        return True

    t = input()

    if s == t:
        print('IDENTICAL')
        return False

    s0 = s.split('"')[0::2]
    s1 = s.split('"')[1::2]
    t0 = t.split('"')[0::2]
    t1 = t.split('"')[1::2]

    if s0 != t0:
        print('DIFFERENT')
        return False

    if len(s1) != len(t1):
        print('DIFFERENT')
        return False

    if len([(ss, tt) for ss, tt in zip(s1, t1) if ss != tt]) == 1:
        print('CLOSE')
    else:
        print('DIFFERENT')

    return False

def main():
    while not testcase_ends():
        pass

main()



Measured memory_bytes: 5584
#ABC122B パターン１　部分文字列全探索
S=input()
N=len(S)

ans=0
'''
for i in range(N):
    if S[i] in "ACGT":
        ans=1

for l in range(N-1):
    for r in range(l+1,N):
        for s in S[l:r]:
            if not s in "ACGT":
                break
        else:
            ans=max(ans,len(S[l:r])) 
'''

for i in range(N):
    for j in range(i,N):
        if all("ACGT".count(c)==1  for c in S[i:j+1]):
            ans=max(ans,j-i+1)

print(ans)

Measured memory_bytes: 3060
n, m = list(map(int,input().split(" ")))

l_max, r_min = list(map(int,input().split(" ")))

for _ in range(1,m):
    l, r = list(map(int,input().split(" ")))
    
    if l >= l_max:
        l_max = l
        
    if r <= r_min:
        r_min = r


        
print(len(range(l_max, r_min+1)))

Measured memory_bytes: 3064
def kakaka():
    a = list(map(int, input().split()))
    b = map(int, input().split())
    c = int(input())

def start_process():
    return
def main():
    a = list(input())
    data = a[0]
    count = 0
    dic = {'0': '1', '1':'0'
           }
    for i in range(1, len(a)):
        if a[i] == data:
            count += 1
        data = dic[data]
    print(count)





if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

//Boat Travel
public class Main{

	class E{
		int s, t, d;
		public E(int s, int t, int d) {
			this.s = s;
			this.t = t;
			this.d = d;
		}
	}

	int[] dist;

	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int k = sc.nextInt();
			if((n|k)==0)break;
			dist = new int[n+1];
			List<E>[] l = new ArrayList[n+1];
			for(int i=1;i<=n;i++)l[i]=new ArrayList<E>();
			while(k--!=0){
				int x = sc.nextInt();
				int a = sc.nextInt();
				int b = sc.nextInt();
				if(x==1){
					int d = sc.nextInt();
					l[a].add(new E(a,b,d));
					l[b].add(new E(b,a,d));
				}
				else{
					Arrays.fill(dist, 1<<30);
					dist[a] = 0;
					PriorityQueue<Integer> q = new PriorityQueue<Integer>(n, new Comparator<Integer>(){
						public int compare(Integer o1, Integer o2) {
							return dist[o1]-dist[o2];
						}
					});
					q.add(a);
					while(!q.isEmpty()){
						int v = q.poll();
						if(b==v)break;
						for(E e:l[v]){
							int w = dist[v] + e.d;
							if(w<dist[e.t]){
								q.remove(e.t);
								dist[e.t] = w;
								q.add(e.t);
							}
						}
					}
					System.out.println(dist[b]==1<<30?-1:dist[b]);
				}
			}
		}
	}

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,n) for(int i=a;i<n;i++)
#define ps(x) cout<<x<<" "
#define pn(x) cout<<x<<"\n"
#define sz(a) int((a).size())
#define pb push_back
typedef vector< int > vi;
typedef pair< int,int > pairs;

int main()
{
    ll n;
    cin>>n;
    string str;
    set<string> s;
    loop(i,0,n)
    {
        cin>>str;
        s.insert(str);
    }
    cout<<s.size();
    
}

Measured memory_bytes: 19252