akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define THE using
#define DARK namespace
#define ONE std
#define dbg(x) cout << #x << " = " << x << endl

THE DARK ONE;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("out.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
    int64_t n, sum = 0, maxv = -1, v;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> v;
        sum += v;
        maxv = max(maxv, v);
    }
    sum -= (maxv / 2);
    cout << sum << endl;
    return 0;
}



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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    string s; cin >> s;
    int n = s.length();

    vector<vector<ll>> dp(n, vector<ll>(2, linf));
    int dn = s[n - 1] - '0';
    dp[n - 1][0] = dn,  dp[n - 1][1] = 10 - dn;
    for (int i = n - 1; i > 0; i--) {
        int d = s[i - 1] - '0';
        for (int j = 0; j < 2; j++) {
            dp[i - 1][0] = min(dp[i - 1][0], dp[i][j] + d + j);
            dp[i - 1][1] = min(dp[i - 1][1], dp[i][j] + 10 - (d + j));
        }
    }

    ll ans = min(dp[0][0], dp[0][1] + 1);
    cout << ans << endl;
    return 0;
}

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

static class CodeJam
{
    class Edge
    {
        public readonly int A;
        public readonly int B;
        public readonly int C;
        public Edge(int[] args)
        {
            A = args[0] - 1;
            B = args[1] - 1;
            C = args[2];
        }
    }

    class Solver
    {
        private const long INF = long.MaxValue / 2;
        private long[][] memo2;

        private static void WarshallFloyd(long[][] memo, int N)
        {
            for (int p = 0; p < N; ++p)
            {
                for (int i = 0; i < N; ++i)
                {
                    for (int j = 0; j < N; ++j)
                    {
                        memo[i][j] = Math.Min(memo[i][p] + memo[p][j], memo[i][j]);
                    }
                }
            }
        }

        public Solver(int N, int M, int L, Edge[] edges)
        {
            var memo1 = new long[N][];
            memo2 = new long[N][];
            for (int i = 0; i < N; ++i)
            {
                memo1[i] = Enumerable.Repeat(INF, N).ToArray();
                memo2[i] = Enumerable.Repeat(INF, N).ToArray();
                memo1[i][i] = 0;
                memo2[i][i] = 0;
            }
            foreach (var edge in edges)
            {
                int a = edge.A;
                int b = edge.B;
                int c = edge.C;
                memo1[a][b] = c;
                memo1[b][a] = c;
            }
            WarshallFloyd(memo1, N);
            for (int i = 0; i < N; ++i)
            {
                for (int j = 0; j < N; ++j)
                {
                    if (i != j && memo1[i][j] <= L)
                    {
                        memo2[i][j] = 1;
                    }
                }
            }
            WarshallFloyd(memo2, N);
        }

        public long Solve(int s, int t)
        {
            return (memo2[s][t] < INF) ? memo2[s][t] - 1 : -1;
        }
    }

    static void Main(string[] args)
    {
        var V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int N = V1[0], M = V1[1], L = V1[2];
        var edges = new Edge[M];
        for (int i = 0; i < M; ++i)
        {
            var V2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            edges[i] = new Edge(V2);
        }
        var solver = new Solver(N, M, L, edges);
        int Q = int.Parse(Console.ReadLine());
        var queries = new int[Q][];
        for (int i = 0; i < Q; ++i)
        {
            queries[i] = Array.ConvertAll(Console.ReadLine().Split(), s => int.Parse(s) - 1);
        }
        foreach (var q in queries)
        {
            Console.WriteLine(solver.Solve(q[0], q[1]));
        }
    }
}


Measured memory_bytes: 23364
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    int N; cin >> N;
    vec C(N); readv_m1(C);
    vec C2;
    REP(i, N) if(i == 0 || C2[SZ(C2) - 1] != C[i]) C2.pb(C[i]);
    N = SZ(C2);

    int dp[200000] = {};
    int ans = 1;
    REP(i, N){
        int tmp = ans;
        Add(tmp, dp[C2[i]]);
        Add(dp[C2[i]], ans);
        ans = tmp;
        //debug(C2[i]);
        //debug(dp[C2[i]]);
        //debug(ans);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5104
#include <iostream>

int main() {

	int n = 0, i = 0, j = 0, v = 0, count = 0;
	std::cin >> n;

	int a[100];

	for (i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	for (count = 0; count < n-1; count++) {
		std::cout << a[count] << " ";
			}
	std::cout << a[n-1]<<std::endl;

	for (i = 1; i < n; i++) {
		v = a[i];
		j = i - 1;

		while ((j >= 0) && (a[j] > v)) {
			a[j + 1] = a[j];
			j--;
		}

		a[j + 1] = v;

		for (count = 0; count < n-1; count++) {
			std::cout << a[count] << " ";

		}
		std::cout <<a[n-1]<< "\n";

	}


	return 0;


}


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int A, B, C, K;
		cin >> A >> B >> C >> K;

		bool ans = false;
		for( int i = 0; i < K; ++i ) {
			if( B <= A ) { B *= 2; }
			else if( C <= B ) { C *= 2; }

			if( A < B && B < C ) { ans = true; }
		}

		cout << (ans ? "Yes" : "No") << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


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

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] A = new long[N];
            long[] B = new long[N];

            for(int i=0; i<N; i++)
            {
                String S = Console.ReadLine();
                String[] line = S.Split(' ');
                A[i] = int.Parse(line[0]);
                B[i] = int.Parse(line[1]);
            }

            Array.Sort(B, A);

            long t = 0;
            String Ans = ("Yes");

            for(int i=0; i<N; i++)
            {
                t = t + A[i];
                if(t > B[i])
                {
                    Ans = "No";
                    break;
                }
            }

            Console.WriteLine(Ans);
        }



    }
}

Measured memory_bytes: 20396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int arr[100001];

int main() {
    int k;
    cin>>k;
    int num=0;
    int ans=0;
    for(int i=1;i<=k;i++)
    {
        num= (num*10 +7)%k;
        if(num==0)
        {
            ans=i;
            break;
        }
    }
    if(ans==0)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<ans<<endl;
    }
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "YES";
const string NO = "NO";

int main(){
    int n, m;
    cin >> n;
    vi d(n);
    rep(i, n) cin >> d[i];
    cin >> m;
    vi t(m);
    rep(i, m) cin >> t[i];
    map<int, int> mpd, mpt;
    rep(i, n) mpd[d[i]]++;
    rep(i, m) mpt[t[i]]++;
    rep(i, m) {
        if (mpd[t[i]] < mpt[t[i]]) {
            cout << NO << endl;
            return 0;
        }
    }
    cout << YES << endl;
    return 0;
    return 0;
}


Measured memory_bytes: 23364
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[100000];
int n;
string s;
cin>>n>>s;
s=s+s;
for(int i=0;i<2;i++)
  for(int j=0;j<2;j++)
  {
  	a[0]=i;
  	a[1]=j;
  	for(int i=2;i<=n+1;i++)
  	{
  		if(a[i-1]&&s[i-1]=='o')a[i]=a[i-2];
  		if(!a[i-1]&&s[i-1]=='o')a[i]=1-a[i-2];
  		if(a[i-1]&&s[i-1]=='x')a[i]=1-a[i-2];
  		if(!a[i-1]&&s[i-1]=='x')a[i]=a[i-2];
	}
	if(a[0]==a[n]&&a[1]==a[n+1])
	{
		for(int i=0;i<n;i++)cout<<(a[i]?"S":"W");
		return 0;
	}
  }
  cout<<-1;
return 0;
}

Measured memory_bytes: 1052
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long d = sc.nextLong();
		d *= d;
		int ans = 0;
		for(int i = 0; i < n; i++) {
			long x = sc.nextLong();
			long y = sc.nextLong();
			if(d>=x*x+y*y) ans++;
		}
		System.out.println(ans);
    }
}

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

typedef long long ll;
int MOD = 1e9 + 7;
ll solve(int n, int m, vector<string> &grid)
{
  vector<vector<ll>> dp(n, vector<ll>(m));
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (grid[i][j] == '.')
      {
        if (i && grid[i - 1][j] == '.')
          dp[i][j] += dp[i - 1][j], dp[i][j] %= MOD;
        if (j && grid[i][j - 1])
          dp[i][j] += dp[i][j - 1], dp[i][j] %= MOD;
      }
  return dp[n - 1][m - 1];
}

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

  int n, m;
  vector<string> grid;
  string str;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
  {
    cin >> str;
    grid.push_back(str);
  }
  cout << solve(n, m, grid);
}

Measured memory_bytes: 12176
#include<iostream>
using namespace std;
int main(){
    int n; cin>>n;
    char c[100000];
    for(int i=0;i<n;++i) cin>>c[i];
    for(int i=1;i<n;++i){
	if(c[i-1]=='T'&&c[i]=='F') c[i]='F';
	else c[i]='T';
    }
    cout<<c[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 3216
#include<stdio.h>
int main()
{
    char s[100];
    scanf ("%s",&s);//a0 k1 a2 s3 a4 k5 a6
    int l=strlen(s),i,j,d=0,a=1;//l=7
    for (int i=0;i<l/2;i++)
    {
        if (s[i]!=s[l-i-1])
        {
            d=9;
        }
    }
    for (i=(l-1)/2 -1,j=(l+3)/2 -1;i>=((l-1)/2 -1)/2;i--,j++)//i=2,j=4]i=1,j=5]i=0,j=6
    {
        if (s[i]!=s[(l-1)/2 -1-i])//s2#s(2-2)/s2#s0,]s1 s1]s0 =
        {
            d=9;
            break;
        }
        if (s[j]!=s[l-a])//s4#s6]s5#s5]
        {
            d=9;
            break;
        }
        a++;

    }
    if (d==0)
    {
        printf ("Yes");
    }
    else
    {
        printf ("No");
    }
}



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

int main(){
    long long a, b, c, k; cin >> a >> b >> c >> k;
    if (a>=k){
        cout << k << endl;
        return 0;
    } else {
        k-=a;
    }
    k-=b;
    if (k>=0){
        cout << a-k << endl;
    } else {
        cout << a << endl;
    }
    return 0;
}

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

int n,ans,a[1000],b[1000];

inline int get(int x){
	int now=0;
	for(int i=1;i<=x;i++)now+=a[i];
	for(int i=x;i<=n;i++)now+=b[i];
	return now;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<=n;i++){
		ans=max(ans,get(i));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [""] * N
for n in range(N):
    S[n] = input()
from collections import defaultdict
dct = defaultdict(int)
for s in S:
    sorted_s = "".join(sorted(s))
    dct[sorted_s] += 1
ans = 0
for k,v in dct.items():
    ans += v*(v-1)//2
print(ans)


Measured memory_bytes: 25324
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]

now = 0
point = 1
mod = 10**9+7

def fib(n,mod):
    a, b = 1, 1
    for _ in range(n):
        a, b = b %mod, (a + b)%mod
    return a%mod

for i in range(1,m):
    if a[i-1]+1 == a[i]:
        print(0)
        exit()

for i in a:
    point *= fib((i-1-now),mod)
    point %= mod
    now = i+1
    if now == n:
        break

point *= fib(n-now,mod)
point %= mod

print(point)

Measured memory_bytes: 7076
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[200005];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
	    cin>>a[i];
	}
	for(int i=1;i<=n-k;i++){
	    if(a[i+k]>a[i]){
	        cout<<"Yes"<<endl;
	    }
	    else cout<<"No"<<endl;
	}
}


Measured memory_bytes: 4408
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
using namespace std;

int main(){
  while(true){
    int h,w; cin >> h >> w;
    if(h == 0 && w == 0) break;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if((i+j) % 2 == 0) cout << '#';
        else cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3100
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
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 = 15, P = 1e9+7;
int n, m, f[1<<N|5], w[N*N], g[N], h[1<<N|5];
int main()
{
    n = read(), m = read(), f[0] = w[0] = 1;
    for(int i = 1; i <= m; ++i)
    {
        int x = read()-1, y = read()-1;
        g[x] |= 1<<y, w[i] = (w[i-1]<<1)%P;
    }
    for(int s = 1; s < 1<<n; ++s) h[s] = h[s^(s&-s)]+1;
    for(int s = 1; s < 1<<n; ++s)
        if((s&1) == (s>>1&1))
            for(int u = s; u; u = (u-1)&s)
                if((u&1) == (u>>1&1))
                {
                    int k = 1;
                    for(int i = 0; i < n; ++i)
                        if(s>>i&1)
                        {
                            if(u>>i&1) k = 1ll*k*w[h[g[i]&(s^u)]]%P;
                            else k = 1ll*k*(w[h[g[i]&u]]-1)%P;
                        }
                    f[s] = (f[s]+1ll*f[s^u]*k%P)%P;
                }
    printf("%d\n", (w[m]-f[(1<<n)-1]+P)%P);
    return 0;
}

Measured memory_bytes: 512
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#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 SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN3(a,b,c);
  OUT(min({a+b,b+c,c+a}));
}


Measured memory_bytes: 256
#include <iostream>

int main(){

  int i,j,x;
  char a[2][3]={};
  for(j=0;j<3;j++)scanf("%c",&a[0][j]);
  scanf("%d",&x);
  for(j=0;j<3;j++)scanf("%c",&a[1][j]);
  if(a[0][1]==a[1][1]&&a[0][0]==a[1][2]&&a[1][0]==a[0][2])puts("YES");
  else puts("NO");
}


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

int SumOfDigits(int n){
  int sum = 0;
  while(n > 0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  
  rep(i, N){
    int digits = SumOfDigits(i+1);
    if (digits >= A && digits <= B) ans += i+1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define foreach(a,A) for(auto &a:A)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

template<int MOD>
class Modint{
private:
    ll x;
public:
    constexpr Modint(ll value = 0) {x = value % MOD + (value >= 0 ? 0 : MOD);}
    constexpr Modint operator+(const Modint &rhs) const {return Modint(*this) += rhs;}
    constexpr Modint operator-(const Modint &rhs) const {return Modint(*this) -= rhs;}
    constexpr Modint operator*(const Modint &rhs) const {return Modint(*this) *= rhs;}
    constexpr Modint operator/(const Modint &rhs) const {return Modint(*this) /= rhs;}
    constexpr Modint operator+=(const Modint &rhs) {x += rhs.x; if(x >= MOD) x -= MOD; return *this;}
    constexpr Modint operator-=(const Modint &rhs) {x -= rhs.x; if(x < 0) x += MOD; return *this;}
    constexpr Modint operator*=(const Modint &rhs) {(x *= rhs.x) %= MOD; return *this;}
    constexpr Modint operator/=(const Modint &rhs) {return (*this) *= pow(rhs, -1);}
    constexpr static Modint pow(Modint a, ll p){
        Modint res = 1; p = p % (MOD - 1) + (p >= 0 ? 0 : MOD - 1);
        while(p){if(p & 1) res *= a; a *= a; p >>= 1;}
        return res;
    }
    constexpr void from_stream(istream &st) {st >> x;}
    constexpr void to_stream(ostream &st) const {st << x;}
};
template<int MOD> constexpr istream& operator>>(istream &st, Modint<MOD> &a){a.from_stream(st); return st;}
template<int MOD> constexpr ostream& operator<<(ostream &st, const Modint<MOD> &a){a.to_stream(st); return st;}
using mint = Modint<MOD>;

void solve(){
    ll n; cin >> n;
    vector<ll> C(n);
    rep(i, n) cin >> C[i];

    C.push_back(INF); // 1-indexed
    sort(C.begin(), C.end(), greater<ll>());

    mint res = 0;
    rep(i, 1, n + 1) res += (i + 1) * C[i];
    res *= mint::pow(4, n - 1);
    cout << res << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    vector<int> A(3);
    REP(i,3) cin>>A[i];
    sort(All(A));
    A.erase(unique(All(A)),A.end());
    if(A.size()==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

#define MAXN 300

int n;
ll d[MAXN][MAXN];
vector<vector<bool>> a;
bool ok = true;

void floyd() {
    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                if (i == j || j == k || i == k) continue;
                if (d[i][j] > d[i][k] + d[k][j]) ok = false;
                if (d[i][j] == d[i][k] + d[k][j]) {
                    a[i][j] = 1;
                }
            }
        }
    }
}

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

    cin >> n;
    rep(i, n) {
        rep(j, n) {
            cin >> d[i][j];
        }
    }

    a.assign(n, vector<bool>(n, 0));
    floyd();

    if (!ok) {
        cout << -1 << endl;
        return 0;
    }

    ll res = 0;
    rep(i, n) {
        rep(j, n) {
            if (a[i][j] == 1) continue;
            res += d[i][j];
        }
    }

    cout << res / 2 << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;

int H, W;
vector<int> f1{-1, -1, -1, 0, 0, 0, 1, 1, 1};
vector<int> f2{-1, 0, 1, -1, 0, 1, -1, 0, 1};
void dfs(Graph &G, int h, int w){
  G[h][w] = -1;
  rep(i, 9){
    int nh = h + f1[i];
    int nw = w + f2[i];
    if (nh < 0 || nw < 0 || nh >= H || nw >= W) continue;
    if (G[nh][nw] == -1 || G[nh][nw] == 0) continue;
    dfs(G, nh, nw);
  }
}

int main(){
  while(1){
    cin >> W >> H;
    if (H == 0 && W == 0) break;
    Graph G(H, vector<int>(W));
    rep(i, H)rep(j, W) cin >> G[i][j];
    int count = 0;
    rep(i, H)rep(j, W){
      if (G[i][j] == -1 || G[i][j] == 0) continue;
      dfs(G, i, j);
      count++;
    }
    cout << count << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
  
class Cube{
public:
 int f[6];
 Cube(){}
 void roll_z(){ roll(1,2,4,3);}
 void roll_y(){ roll(0,2,5,3);}
 void roll_x(){ roll(0,1,5,4);}
 void roll(int i,int j,int k,int l){
   int t=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
 }
};
  
int getRight( Cube c1,int f1,int f2 ){
 for(int i=0;i<6;i++){
   for(int j=0;j<4;j++){
     if( c1.f[0]==f1 && c1.f[1]==f2 ) return c1.f[2];
     c1.roll_z();
   }
   if( i%2 == 0 )c1.roll_y();
   else c1.roll_x();
 }
 return -1;
}
  
int main(){
 Cube c;
 int f1,f2;
 for(int i=0;i<6;i++)cin>>c.f[i];
 int q; cin>>q;
 for(int i=0;i<q;i++){
   cin>>f1>>f2;
   cout<<getRight(c,f1,f2)<<endl;
 }
 return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N;
    int data[1000];
 
    while (cin >> N, N != 0) {
        vector < int > vec;
        bool flag = false;
        N++;
        for ( int i = 0; i < N; i++ ) {
            cin >> data[i];
        }
 
        for ( int i = 0; i < N - 1; i++ ) {
            vec.push_back(data[i + 1] - data[i]);
        }
 
        sort(begin(vec), end(vec));
        vec.erase(unique(begin(vec), end(vec)), end(vec));
 
        for ( int i = 0; i < vec.size(); i++ ) {
            int d = vec[i];
            for ( int j = 0; j < N; j++ ) {  //naniwonukuka
                vector < int > dat;
                for ( int k = 0; k < N; k++ ) {
                    if ( k != j ) {
                        dat.push_back(data[k]);
                    }
                }
                int d = dat[1] - dat[0];
                bool differ = false;
                for ( int k = 1; k < N - 2; k++ ) { //mawasu
                    if ( d != (dat[k + 1] - dat[k]) ) {
                        differ = true;
                    }
                }
                if ( !differ ) {
                    cout << data[j] << endl;
                    flag = true;
                    break;
                }
            }
            if ( flag ) {
                break;
            }
        }
 
    }
    return ( 0 );
}


Measured memory_bytes: 3148
export default solve;

// =================================================
// ABC086C
// =================================================

// reader
readline();

// main
function main(lines) {
  console.log(solve(lines));
}

// solver
function solve(lines: string[]): string {
  const { destinations } = parseLines(lines);

  let canArrive = true;
  loop: for (let i = 0; i < destinations.length; i++) {
    const [step, x, y] = destinations[i];
    const [previousStep, previousX, previousY] = destinations[i - 1] || [0, 0, 0];
    const distance = step - previousStep;
    const stepsToArrive = Math.abs(x - previousX) + Math.abs(y - previousY);
    if (distance % 2 !== stepsToArrive % 2 || distance < stepsToArrive) {
      canArrive = false;
      break loop;
    }
  }
  return canArrive ? 'Yes' : 'No';
}

// helpers
function parseLines(lines: string[]) {
  const N = +lines[0];
  const destinations = lines.slice(1, 1 + N).map(line => line.split(' ').map(s => +s));
  const obj = { N, destinations };
  debug(obj);
  return obj;
}

// general helpers
function debug(message?: any, ...optionalParams: any[]) {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
}

function readline() {
  if (!process.env.LOCAL_DEBUG) {
    const { stdin: input, stdout: output } = process;
    input.resume();
    input.setEncoding('utf8');
    const lines = [];
    require('readline')
      .createInterface({ input, output })
      .on('line', line => lines.push(line))
      .on('close', () => main(lines));
  }
}


Measured memory_bytes: 55884
#include<iostream>


using namespace std;
static const int MAX = 100;

int main()
{
	int n, a[MAX];

	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
	cout << a[n - 1] << endl;
	for (int i = 1; i < n; i++) {
		int v = a[i];
		int j = i - 1;

		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		for (int i = 0; i < n; i++) {
			cout << a[i];
			if (i != n - 1) cout << " ";
			else cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1160
N = int(input())
A=list(map(int, input().split()))
from collections import Counter


c = Counter(A)
MOD = 10**9 + 7
if N % 2 == 0:
    is_ok = 1
    cnt = 0
    for num in range(1, N, 2):
        cnt += 1
        if c[num] != 2:
            is_ok=0
            break
    if not is_ok:
        print(0)
        exit()
    print(pow(2, cnt, MOD))
else:
    is_ok = 1
    cnt = 0
    if c[0] != 1:
        is_ok = 0
    for num in range(2, N, 2):
        cnt += 1
        if c[num] != 2:
            is_ok = 0
            break
    if not is_ok:
        print(0)
        exit()
    print(pow(2, cnt, MOD))

Measured memory_bytes: 92628
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
vector<int> a;
int L;

string intString(int n){
  stringstream ss;
  int keta = 1,tmp;
  tmp = n;
  while(tmp != 0){
    tmp /= 10;
    keta++;
  }
  for(int i = 0; i <= (L-keta);i++) ss << 0;

  ss << n;

  return ss.str() ;
}


int func(string str){
  sort(str.begin(),str.end());
  int low = stoi(str);
  sort(str.rbegin(),str.rend());
  int high = stoi(str);
  return high - low;
}

void solve(){
  //桁変更
  string str = intString(a[0]);
  for(int i = 1 ; ; i++){
    a.push_back(func(str));
    for(int j = 0; j < i; j++){
      if(a[i] == a[j]) {
        cout << j << ' ' << a[i] << ' '<< ( i - j ) << endl;
        a.clear();
        return;
      }
    }
    str = intString(a[i]);
  }

}




int main(){
  int a0;
  while(true){
    cin >> a0 >> L;
    if(a0 + L == 0) break;
    a.push_back(a0);
    solve();
  }
  return 0;
}



Measured memory_bytes: 3132
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

int main(void) {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> m;
  for (int i = 0; i < h; i++) {
    vector<int> v;
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '#')
        v.push_back(-1);
      else
        v.push_back(0);
    }
    m.push_back(v);
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (m[i][j] == 0) {
        int x = 0;
        int s = j;
        while (j < w and m[i][j] != -1) {
          x++;
          j++;
        }
        m[i][s] = x;
        if (j == w)
          j--;
      }
    }
    for (int j = 0; j < w; j++) {
      if (m[i][j] != -1) {
        int sum = m[i][j];
        while (j < w and m[i][j] != -1) {
          m[i][j] = sum;
          j++;
        }
        if (j == w)
          j--;
      }
    }
  }
  int ans = -1;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (m[j][i] != -1) {
        int x = 0;
        int s = j;
        while (j < h and m[j][i] != -1) {
          x++;
          j++;
        }
        for (; s < j; s++) {
          ans = max(ans, m[s][i] + x - 1);
        }
        if (j == h)
          j--;
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 16000
#include<stdio.h>
int main(void)
{
	int n=1;
	int syurui[10]={0};
	int kazu=0;
	int i=0,j=0;
	
	
	while (n!=0)
	{
		scanf("%d",&n);
		if (n==0)
		{
			break;
		}
		for (i=1;i<=n;i++)
		{
			scanf("%d",&kazu);
			syurui[kazu]++;
		}
		for (i=0;i<10;i++)
		{
			if (syurui[i]==0)
			{
				printf("-");
			}
			else
			{
				for (j=1;j<=syurui[i];j++)
				{
					printf("*");
				}
			}
			printf("\n");
			syurui[i]=0;
		}
	}
	return 0;
}

Measured memory_bytes: 1000
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define PI pair<int,int>
#define PL pair<long int,long int>
#define PLL pair<ll,ll>
#define Tcase int t;cin>>t;while(t--)
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int mini=INT_MAX,count_it=0;
  for(int i=0;i<n;i++){
  	if(mini>a[i]){
    	mini=a[i];
      }
    if(a[i]<=mini)
      count_it++;
  }
  cout<<count_it<<endl;
return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		for(;;){
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			if(n ==0  && m == 0){
				break;
			}
			int map[][] = new int[n+2][m+2];
			
			for(int i = 0 ; i< n ;i++){
				char[] chs = sc.next().toCharArray();
				for(int j = 0;j < m;j++){
					map[i+1][j+1] = chs[j];
				}
			}
			
			int dx[] = {1,0,-1,0};
			int dy[] = {0,1,0,-1};
			int d = 0;
			int i = 1;
			int j = 1;
			int count = 100;
			for(int c = 0;c < n*m*4*2; c++){
				if(i==1&&j==1 && d!= 0){
					break;
				}
//				System.out.println(i+" "+j+" "+ map[i][j] +" -> "+(i+dx[d])+" " +(j+dy[d])+" "+map[i+dx[d]][j+dy[d]]);
				if(map[i + dx[d]][j + dy[d]] == '.'){
					i = i + dx[d];
					j = j + dy[d];
					d = (d+3)%4;
					count++;
					map[i][j] = count;
				}else if(map[i + dx[d]][j + dy[d]] == count-1){
					map[i][j] = '#';
					i = i + dx[d];
					j = j + dy[d];
					d = (d+3)%4;
					d %= 4;
					count--;
				}else{
					d++;
					d %= 4;
				}
			}
			
			boolean ans = true;
			ans &= map[1][1] != '.';
			ans &= map[1][m] != '.';
			ans &= map[n][1] != '.';
			ans &= map[n][m] != '.';
			ans &= map[1][1] != '#';
			ans &= map[1][m] != '#';
			ans &= map[n][1] != '#';
			ans &= map[n][m] != '#';
			
			for(int ii =0; ii<n;ii++ ){
				for(int jj = 0; jj<m;jj++ ){
//					System.out.printf("%4d", map[ii+1][jj+1]);
				}
//				System.out.println();
			}
			System.out.println(ans?"YES":"NO");
		}
		
	}
}



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

int main(void){
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int m=0;
    
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            int ij=l[i]+l[j];
            int R=lower_bound(l.begin(),l.end(),ij)-l.begin();
            int L=j+1;
            // [L,R)
            m+=max(0,R-L);            
        }
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[305][305],par[305][305];
vector<int>vt;
void fun(ll n) {
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            par[i][j]=j;
            if(i==j)
                continue;
            ar[i][j]=1e18;

        }
    }
}

void path(ll u,ll v) {
    //printf("%d",u);
    vt.push_back(u);
    if(u!=v) {
        u=par[u][v];
        //cout<<u<<" "<<v<<endl;
        path(u,v);
    }
}
int main() {
    ll n,edge,u,v,ans,L,cnt;
    ll x,y,z,query;

    scanf("%lld",&n);
    fun(n);
    scanf("%lld %lld",&edge,&L);
    for(int i=1; i<=edge; i++) {
        scanf("%lld %lld %lld",&x,&y,&z);
        ar[x][y]=z;
        ar[y][x]=z;

    }
    for(int k=1; k<=n; k++) {
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                if(ar[i][j]>(ar[i][k]+ar[k][j])) {
                    ar[i][j]=ar[i][k]+ar[k][j];
                    par[i][j]=par[i][k];
                }
            }
        }
    }
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            ll ck=ar[i][j];
            if(i==j)ar[i][j]=0;
            if(ck>L) {
                ar[i][j]=1e18;
            } else {
                ar[i][j]=1;
            }
        }
    }
    for(int k=1; k<=n; k++) {
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                if(ar[i][j]>(ar[i][k]+ar[k][j])) {
                    ar[i][j]=ar[i][k]+ar[k][j];
                    par[i][j]=par[i][k];
                }
            }
        }
    }
    scanf("%lld",&query);
    while(query--) {
        scanf("%lld %lld",&u,&v);
        if(ar[u][v]>=1e18) {
            printf("-1\n");
        } else {
            ll ck=1,wa,ol;
            cnt=0,wa=L;
            /*path(u,v);
            //cout<<vt.size()<<endl;
            for(int i=0; i<(int)vt.size()-1; i++) {
                ol=ar[vt[i]][vt[i+1]];
                if(wa<ol&&wa==L) {
                    ck=0;
                    break;
                } else if(wa<ol) {
                    wa+=(L-wa);
                    cnt++;
                }
                wa-=(ol);
                if(wa<0) {
                    ck=0;
                    break;
                }
            }*/
            if(ar[u][v]>=1e18) {
                printf("-1\n");
            } else {
                printf("%lld\n",ar[u][v]-1);
            }
            vt.clear();
        }
    }
    return 0;
}



Measured memory_bytes: 1920
def resolve():
	S=input()
	Slist=[int(i) for i in list(S)]
	N=len(S)
	
	if N%2==0:
		s1='10'*(N//2)
		s2='01'*(N//2)
	else:
		s1='10'*(N//2)+'1'
		s2='01'*(N//2)+'0'
	s1List=[int(i) for i in list(s1)]
	s2List=[int(i) for i in list(s2)]
	
	print(min(sum([1 for i in range(N) if Slist[i]!=s1List[i]]),sum([1 for i in range(N) if Slist[i]!=s2List[i]])))

resolve()

Measured memory_bytes: 67448
#include<stdio.h>
#include<algorithm>
using namespace std;

int count = 0;

int partition(int A[], int p, int r) {
  int x = A[r];
  int i = p-1;
  for (int j = p; j < r; j++) {
    if (A[j] <= x) {
      i = i+1;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i+1;
}

int main() {
	int n;
  scanf("%d", &n);
  int A[n];
  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
  int c = partition(A, 0, n-1);
  for ( int i = 0; i < c; i++ ) printf("%d ", A[i]);
  if (c != n-1) {
    printf("[%d] ", A[c]);
  } else {
    printf("[%d]", A[c]);
  }
  for ( int i = c+1; i < n-1; i++ ) printf("%d ", A[i]);
  printf("%d\n", A[n-1]);

  return 0;
}



Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		while(n-->0){
			char[] c = bf.readLine().toCharArray();
			Arrays.sort(c);
			String s = new String(c);
			StringBuffer sb = new StringBuffer(s);
			int min = Integer.parseInt(new String(c),10);
			int max = Integer.parseInt(sb.reverse().toString(),10);
			System.out.println(max-min);
		}
	}
}

Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    string s;
    cin >> s;

    string res = "ABC";
    res += s;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;;
	vector<string> A(H);
	int res = 0;
	for (int i = 0; i < H; i++) {
		cin >> A[i];
	}
	bool f = true;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') {
				bool ok = false;
				for (int k = 0; k < 4; k++) {
					int ii = i + dx[k];
					int jj = j + dy[k];
					if (ii >= 0 && ii < H && jj >= 0 && jj < W) {
						if (A[ii][jj] == '#') {
							ok = true;
						}
					}
				}
				if (!ok) {
					f = false;
				}
			}
		}
	}
	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

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

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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  long long sum = 0;
  rep(i, N)
  {
    cin >> A[i];
    sum += A[i];
  }
  int MOD = 1000000007;

  long long sum2 = 0;
  rep(i, N)
  {
    sum -= A[i];
    long long tmp_sum = sum % MOD;
    long long tmp = (tmp_sum * A[i]) % MOD;
    sum2 += tmp;
    sum2 %= MOD;
  }

  cout << sum2 << endl;

  return 0;
}


Measured memory_bytes: 3952
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(void){
  int N;
  char S[10010];
  cin>>N;
  cin>>S;
  for(int i=0;S[i]!=0;i++){
    S[i]=(S[i]-'A'+N)%26+'A';
  }
  cout<<S<<endl;
}


Measured memory_bytes: 256
N, M, X = gets.split(/ /).map(&:to_i)
C = []
A = []
1.upto(N) do
  c, *a = gets.split(/ /).map(&:to_i)
  C << c
  A << a
end

I = (0..(N-1)).to_a
costs = []
1.upto(N) do |size|
  I.combination(size) do |c|
    sum = c.map {|i| A[i] }.transpose.map{|v| v.inject(:+) }
    if sum.all? {|v| v >= X }
      cost = 0
      c.each {|i| cost += C[i] }
      costs << cost
    end
  end
end
unless costs.empty?
  puts costs.min
  exit
else
  puts -1
end


Measured memory_bytes: 14688
N = int(input())
A = [int(v) for v in input().split()]
B = [int(v) for v in input().split()]
C = [int(v) for v in input().split()]

m = 0
for i in range(N):
    m +=  B[A[i] - 1]
    if i != 0:
        if A[i] - A[i - 1] == 1:
            m += C[A[i -1] - 1]
print(m)

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
vector<Q> vec;
ll n, a, b, ans;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> a >> b;
        vec.push_back(Q(a + b, P(a, b)));
    }
    sort(vec.begin(), vec.end());
    for (ll i = 1; i <= n; i++){
        if (i % 2 == 1){
            ans += vec[vec.size() - i].second.first;
        } else {
            ans -= vec[vec.size() - i].second.second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n,k;
  cin>>n>>k;
  int a[n];
  int co=0;
  rep(i,n){
      cin>>a[i];
      if(a[i]>=k){
          co++;
      }
  }
  cout<<co<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) (((long long)mod_x)%modulo)


int main(){
	
	int A,B;
	cin>>A>>B;
	
	if(A<B)cout<<0<<endl;
	else cout<<10<<endl;
	
	
	return 0;
}


Measured memory_bytes: 384
s = gets.chomp! + "R"
l = s.length - 1
ans = Array.new(l,0)
rl = {"R" => 0, "L" => 0}
pos = 0

l.times do |i|
    rl[s[i]] += 1
    if s[i] == "R" && s[i+1] == "L" then
        pos = i
    elsif s[i] == "L" && s[i+1] == "R"
        ans[pos] = rl["R"] / 2 + rl["L"] / 2 + rl["R"] % 2
        ans[pos+1] = rl["R"] / 2 + rl["L"] / 2 + rl["L"] % 2
        rl = {"R" => 0, "L" => 0}
    end
end

puts ans.join(" ")

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    int a;
    int cnt = 0,min = 9999999;
    rep(i,n){
        cin >> a;
        if(a %2==1){cout <<0<<endl; return 0;}
        while(a % 2 == 0){
            a /= 2;
            cnt++;
        }
        if(min >cnt)min = cnt;
        cnt = 0;
    }
    cout << min  << endl;


    return 0;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
A = list(map(int, input().split()))
D = [0]*n
for i in range(n):
    if i != n-1:
        D[i] = A[i+1]-A[i]
    if i == n-1:
        D[i] = A[0]+k-A[i]

#print(D)
ans = k - max(D)
print(ans)


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

int main(){
  int n,d,x;cin>>n>>d>>x;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    x+=(d-1)/a[i]+1;
  }
  cout<<x<<endl;
  return 0;
}


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

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

using namespace std;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

string S;

int main() {
    cin >> S;

    reverse(S.begin(), S.end());

    while (S.length() > 0) {
        if (S.substr(0, 7) == "remaerd") {
            S = S.substr(7, S.length() - 7);
        } else if (S.substr(0, 6) == "resare") {
            S = S.substr(6, S.length() - 6);
        } else if (S.substr(0, 5) == "maerd") {
            S = S.substr(5, S.length() - 5);
        } else if (S.substr(0, 5) == "esare") {
            S = S.substr(5, S.length() - 5);
        } else {
            cout << "NO" << endl;
            exit(0);
        }
    }

    cout << "YES" << endl;
}



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

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

  scanf("%lld %lld %lld",&n,&a,&b);

  long long int x[n];

  for (int i=0;i<n;i++) {
    scanf("%lld",&x[i]);
  }

  long long int ans=0;

  for (int i=0;i<n-1;i++) {
    long long int dif=x[i+1]-x[i];

    if (dif*a<b) {
      ans+=dif*a;
    } else {
      ans+=b;
    }
  }

  printf("%lld\n",ans);
  
  return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = s.length();
	int ans = 0;
	for (char c : s)
		ans += c - '0';
	int pref = 0;
	for (int i = 0; i < n; i++)
	{
		pref += s[i] - '0';
		if (s[i] - '0')
			ans = max(ans, pref - 1 + (n - i - 1) * 9);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;
int main(void){
    int n;
    long long m,b[100001],c=0;
    unordered_map<int,int> u;
    cin>>n>>m;
    b[0]=0;
    u[0]=1;
    for(int i=1;i<=n;i++){
        cin>>b[i];
        b[i]=(b[i]+b[i-1])%m;
        u[b[i]]++;
    }
    for(auto x=u.begin();x!=u.end();x++){
        long long y=x->second;
        c+=y*(y-1)/2;
        //cout<<x->first<<","<<x->second<<endl;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 4108
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int cel(int s, int n)
{
    if(s%n==0){return (s/n);}
    return ((s/n)+1);
}
signed main()
{
    speed
    int N=1000000000;
    int s;cin>>s;
    if(s<=N)
    {
        cout<<0<<" "<<0<<" "<<N<<" "<<1<<" "<<s<<" "<<0;return 0;
    }
    else
    {
        int y3=cel(s,N);
        int x3=(N*y3-s);
        cout<<0<<" "<<0<<" "<<N<<" "<<1<<" "<<x3<<" "<<y3;
    }
}

Measured memory_bytes: 256
N = int(input())
inp = [int (x) for x in input().split(" ")]

refs = [0 for _ in range(N)]
k = len(inp) - 1
rev = True
for i in range(N):
    refs[i] = k
    if k == 1 and rev:
        k = -2
        rev = False
    if k == 0 and rev:
        k = -1
        rev = False
    k = k - 2 if rev else k + 2

#print(" ".join([str(x) for x in refs]))


for i in range(N):
    refs[i] = inp[refs[i]]

print(" ".join([str(x) for x in refs]))


Measured memory_bytes: 29764