akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000

int main(){
  int n,l;
  vector<string> vec;

  cin >> n >> l;

  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    vec.push_back(s);
  }

  sort(vec.begin(),vec.end());

  for(int i=0;i<n;i++){
    cout << vec[i];
  }
  cout << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
N, Q = map(int,input().split())
S = [1 if i=='1' else 0 for i in input().replace("AC","10")]
s = list(accumulate(S))
lr = []
for i in range(Q):
    lr.append(tuple(map(int,input().split())))
for i in lr:
    l = s[i[0]-2] if i[0]-2 >= 0 else 0
    r = s[i[1]-2] if i[1]-2 >= 0 else 0
    print(r-l)

Measured memory_bytes: 22160
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        try(Scanner sc  = new Scanner(System.in)){
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for(int i=0;i<values.length;i++){
                values[i] = i+1;
            }
            for(int i=0;i<n;i++){
                String str = sc.next();
                String[]ab = str.split(",");
                int a = Integer.parseInt(ab[0])-1;
                int b = Integer.parseInt(ab[1])-1;
                int value = values[a];
                values[a] = values[b];
                values[b] = value;
            }
            for(int i=0;i<values.length;i++){
            System.out.println(values[i]);
            }
        }
    }
}


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

int gcd(int x, int y)
{
	if (y == 0) return x;
	gcd(y, x%y);
}
signed main(void)
{
	int n, ans;
	cin >> n;
	int a[n];

	rep(i, n) cin >> a[i];
	ans = gcd(a[0], a[1]);
	for(int i = 1; i < n - 1; i++)
	{
		ans = gcd(a[i], ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<math.h>
#include<algorithm>
using namespace std;
 
int main() {
    int ans=1;
int a=1;
int n,p;
cin>>n;
for(int i=0;i<n;i++){
cin>>p;
if(p==1){a++;ans=max(ans,a);}
else{a=1;}
}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3124
#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;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD1 998244353
#define MOD2 1000000007

#ifdef LL
const ll INF = 1e18;
#else 
const ll INF = 1e9;
#endif

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

high_resolution_clock::time_point setTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T mod){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=mod;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T max3(T a, T b, T c) { return max((max(a,b), max(b,c))); }
template <typename T>
T min3(T a, T b, T c) { return min((min(a,b), min(b,c))); }
template <typename T>
T mid3(T a, T b, T c) { return a+b+c-max3(a,b,c)-min3(a,b,c); }
template <typename T>
T mid(T a, T b) { return min(a,b)+((max(a,b)-min(a,b))/2); }
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T to_upper(T s){ return transform(s.begin(), s.end(), s.begin(), ::toupper); }
template <typename T>
T to_lower(T s){ return transform(s.begin(), s.end(), s.begin(), ::tolower); }

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = setTime();

    int n,k;
    cin>>n>>k;

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

    vector<bool> dp(k+1);
    for(int i=0;i<=k;i++)
    {
        for(int x : a)
        {
            if(i>=x&&!dp[i-x]) 
            {
                dp[i]=true;
            }
        }
    }

    cout<<(dp[k] ? "First" : "Second")<<endl;
    auto stopTime = setTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


Measured memory_bytes: 3652
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]


for i in range(N - M + 1):
    for j in range(N - M + 1):
        check = True
        count = 0
        for k in range(M):
            if (A[i + k][j: j + M] == B[k]):
                # print(A[i + k][j:j + M], B[k])
                count += 1
                continue
            else:
                check = False
                break

        if (check and count == M):
            print('Yes')
            exit()

print('No')


Measured memory_bytes: 9096
"use strict"

const arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8').split(' ')
const a = arg_str[0]
const b = arg_str[1]
const x = arg_str[2]

if(x <= (1/2)*a*a*b){
    const rad = Math.atan(a*b*b/2/x)
    console.log(rad * 180 / Math.PI)
}else{
    const rad = Math.atan(2/a/a/a*(a*a*b-x))
    console.log(rad * 180 / Math.PI)
}



Measured memory_bytes: 21064
#
# File    : C.rb
# Author  : Kazune Takahashi
# Created : 12/7/2018, 10:08:13 PM
# Powered by Visual Studio Code
#

n = gets.to_i
ary = []
n.times{
  ary << gets.chomp.split(" ").map{|i| i.to_i}
}

takahashi = 1
aoki = 1

ary.each{|t, a|
  n = [(takahashi + t - 1)/t, (aoki + a - 1)/a].max
  takahashi = t * n
  aoki = a * n
}

puts takahashi + aoki

Measured memory_bytes: 1916
#include<stdio.h>

int main(void){
        int h, w, fie[52][52], dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
        for(int i=0; i<52*52; i++) fie[i/52][i%52] = 0;
        scanf("%d %d", &h, &w);

        for(int i=1; i<=h; i++){
                char s[w+1];
                scanf("%s", s);
                for(int j=1; j<=w; j++){
                        fie[i][j] = (s[j-1]=='#');
                }
        }

        int yes = 1;
        for(int i=1; i<=h; i++){
                for(int j=1; j<=w; j++){
                        if(!fie[i][j]) continue;
                        int can = 0;
                        for(int k=0; k<4; k++){
                                if(fie[i+dx[k]][j+dy[k]]) can = 1;
                        }
                        if(!can) yes = 0;
                }
        }

        if(yes) puts("Yes");
        else puts("No");
        return 0;
}

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

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

ll dp[110000];

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> h(110000);
	rep(i, n) cin >> h[i];

	rep(i, 110000) dp[i] = INF;
	dp[0] = 0;
	rep(i, n) {
		for(int j=1;j<=k;j++){
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}

	cout << dp[n-1] << endl;
}

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

typedef long long ll;

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

    int n;
    cin >> n;

    vector<int> a(n);

    for(int i = 0; i < n; i++) cin >> a[i];

    for(int i = n - 2; i >= 0; i--) {
        if(a[i] > a[i + 1]) {
            a[i]--;
            if(a[i] > a[i + 1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

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

using namespace std;

int main()
{
	string s;
	cin>>s;
	int len=s.size(),i,j,cnt=0;
	for(i=0,j=0;j<len&&i<len;j++)
	{
		if(s[j]!='T'&&s[j]!='A'&&s[j]!='C'&&s[j]!='G')
		{
			cnt=max(cnt,j-i);
		//	cout<<j<<" "<<i<<endl;
			i=j+1;
		}
	}
	//cout<<j<<" "<<i<<endl;
	cnt=max(cnt,j-i);
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
public static class Program {
    public static void Main() {
        var sampleText = Console.ReadLine().Split(' ').ToArray();
           var a = int.Parse(sampleText[0]);
        var b = int.Parse(sampleText[1]);
        
        Console.WriteLine(a * b);
    }
}

Measured memory_bytes: 28016
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/

ll GCD(ll a, ll b) {
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main() {

	ll a, b, c, d; cin >> a >> b >> c >> d;

	ll x = (a - 1) / c;
	ll e = b / c;

	ll y = (a - 1) / d;
	ll f = b / d;


	ll s = (a - 1) / ((c * d) / GCD(c, d));
	ll t = b / ((c * d) / GCD(c, d));

	cout << (b - a + 1) + t - s - (e - x) - (f - y) << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <map>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    while(n--) {
        int w, h;
        cin >> h >> w;
        vector<string> v(h);
        for(int i=0; i<h; ++i) {
            cin >> v[i];
        }
        map<char, int> L, R, T, B;
        for(int i=0; i<h; ++i) {
            for(int j=0; j<w; ++j) {
                char c = v[i][j];
                if(c == '.') {
                    continue;
                }
                if(L.count(c) == 0) {
                    L[c] = R[c] = j;
                    T[c] = B[c] = i;
                } else {
                    L[c] = min(L[c], j);
                    R[c] = max(R[c], j);
                    T[c] = min(T[c], i);
                    B[c] = max(B[c], i);
                }
            }
        }
        // order[i][j] := j is on i
        array<array<bool, 26>, 26> order;
        for(int i=0; i<26; ++i) {
            for(int j=0; j<26; ++j) {
                order[i][j] = false;
            }
        }
        bool ok = true;
        for(auto p : L) {
            char c = p.first;
            int l = p.second, r = R[c], t = T[c], b = B[c];
            for(int i=t; i<=b; ++i) {
                for(int j=l; j<=r; ++j) {
                    if(v[i][j] == '.') {
                        ok = false;
                    } else if(v[i][j] != c) {
                        order[c-'A'][v[i][j] - 'A'] = true;
                    }
                }
            }
        }
        for(int k=0; k<26; ++k) {
            for(int i=0; i<26; ++i) {
                for(int j=0; j<26; ++j) {
                    order[i][j] |= order[i][k] & order[k][j];
                }
            }
        }
        for(int i=0; i<26; ++i) {
            for(int j=0; j<26; ++j) {
                if(order[i][j] && order[j][i]) {
                    ok = false;
                }
            }
        }
        cout << (ok ? "SAFE" : "SUSPICIOUS") << endl;
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read(){ll x=0,f=1;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;return x*f;}
inline void write(ll x){if(x>9)write(x/10);putchar('0'+x%10);}
inline void writeln(ll x){write(x);puts("");}
map<int,int>a;
int n,x,ans;
int main()
{
	n=read();
	for(int i=1;i<=n;i++){
		x=read();
		if(a[x]){
			ans--;
			a[x]=0;
		}
		else{
			ans++;
			a[x]=1;
		}
	}
	writeln(ans);
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
    int i,count=0,bc=0;
    char input[1005],word[13],word2[13];
    char box[20],end[]="END_OF_TEXT";
    scanf("%s",word);
    for(i=0;;i++){
        word2[i] = toupper(word[i]);
        if (word2[i] == '\0') break;
    }
    while (1){
        scanf("%s",input);
        if (strcmp(input,end) == 0) {
            break;
        }
        for(i=0; ;i++){
            if (input[i] == ' ' || input[i] == '"' || input[i] == '.' ){
                box[bc] = '\0';
                bc = 0;
                if (strcmp(box,word2) == 0){
                    count++;
                }
            }
            else if (input[i] == '\0'){
                box[bc] = '\0';
                bc = 0;
                 if (strcmp(box,word2) == 0){
                    count++;
                 }
                break;
            }
            else {
            box[bc] = toupper(input[i]);
            bc++;
            }
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
#include <unordered_map>
constexpr int64_t MOD = 998244353;
int main(void){
	int n;
	std::cin >> n;
	std::string s;
	std::cin >> s;
	int64_t ans = 1;
	int cnt[3] = {0, 0, 0};
	std::vector<int> buf(3);
	for(int i=0;i<s.size();i++){
		char c = s[i];
		int x = 0;
		if(c == 'R')x=0;
		if(c == 'G')x=1;
		if(c == 'B')x=2;
		for(int j=0;j<3;j++)buf[j] = cnt[j];
		std::sort(buf.begin(), buf.end());
		if(cnt[x] == buf[2]){
			ans *= n - buf[2];
			ans %= MOD;
		}
		else if(cnt[x] == buf[1]){
			ans *= buf[2] - buf[1];
			ans %= MOD;
		}
		else{
			ans *= buf[1] - buf[0];
			ans %= MOD;
		}
		cnt[x]++;
	}
	std::cout << ans << std::endl;
}

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

int main(){
 int A,B,ans = 0;
  
 scanf("%d %d",&A,&B);
  
 if(A>=13){
   ans = B;
 }else if(A>=6){
   ans = B/2;
 }else ans = 0;
  
  
 printf("%d",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include<queue>
#include<vector>
using namespace std;
int main()
{
	long long int n, sum, ans;
	sum = 0;
	long long int sumsum = 0;
	ans = 0;
	priority_queue<int> v;
	cin >> n;
	int ab[100005][2] = { 0 };
	for (int i = 1; i <= n; i++) {
		cin >> ab[i][0];
	}
	for (int i = 1; i <= n; i++) {
		cin >> ab[i][1];
		if (ab[i][0] > ab[i][1]) {
			v.push(ab[i][0] - ab[i][1]);
			sumsum += (ab[i][0] - ab[i][1]);
		}
		if (ab[i][0] < ab[i][1]) {
			sum += (ab[i][0] - ab[i][1]);
			ans++;
			//cout << 1744 << endl;
		}
	}
	if (sum + sumsum < 0) cout << -1 << endl;
	else {
		while (sum < 0) {
			sum += v.top();
			v.pop();
			ans++;
			//cout << 57 << endl;
		}
		cout << ans << endl;
	}

}


Measured memory_bytes: 1408
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    init();
    int n = sc.nextInt();
    String x = sc.next();
    char[] xc = x.toCharArray();
    int baseCount = 0;
    for (int j = 0, len = x.length(); j < len; j++) {
      if (xc[j] == '1') {
        baseCount++;
      }
    }
    BigInteger xB = new BigInteger(x, 2);
    int count1 = baseCount - 1;
    int count2 = baseCount + 1;
    int rem1 = count1 == 0 ? 0 : xB.remainder(BigInteger.valueOf(count1)).intValue();
    int rem2 = xB.remainder(BigInteger.valueOf(count2)).intValue();
    initMod(n, count1, count2);
    for (int i = 1; i <= n; i++) {
      char tmp = xc[i - 1];
      int count = tmp == '1' ? count1 : count2;
      int r = tmp == '1' ? rem1 : rem2;
      if (count == 0) {
        System.out.println(0);
        continue;
      }
      int rem;
      if (tmp == '1') {
        rem = count1 - modMap1.get(n - i);
      } else {
        rem = modMap2.get(n - i);
      }
      System.out.println(map.get(
          (rem + r) % count
      ) + 1);
    }
  }

  private static Map<Integer, Integer> map = new HashMap<>();
  private static void init() {
    int limit = 200000;
    map.put(0, 0);
    map.put(1, 1);
    for (int i = 2; i <= limit; i++) {
      String b = Integer.toString(i, 2);
      int count = 0;
      for (int j = 0, len = b.length(); j < len; j++) {
        if (b.charAt(j) == '1') {
          count++;
        }
      }
      int t = map.get(i % count);
      map.put(i, t + 1);
    }
  }

  private static final BigInteger TWO = BigInteger.ONE.add(BigInteger.ONE);
  private static Map<Integer, Integer> modMap1 = new HashMap<>();
  private static Map<Integer, Integer> modMap2 = new HashMap<>();
  private static void initMod(int n, int count1, int count2) {
    int i1 = 1;
    int i2 = 1;
    for (int i = 0; i <= n; i++) {
      modMap1.put(i, i1);
      modMap2.put(i, i2);
      i1 = count1 == 0 ? 0 : (i1 * 2) % count1;
      i2 = (i2 * 2) % count2;
    }
  }
}


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

int main() {
	int N, L, R;
	double count = 0, ans = 0;
	pair<double, double> P[100];
	map<double, double> mpL, mpR, mp;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> P[i].first;
		count += P[i].first;
		if (i != 0) P[i].first += P[i - 1].first;
	}
	for (int i = 0; i < N; i++) {
		cin >> P[i].second;
	}
	L = 0, R = N - 1;
	mpL[0] = 0, mpR[count] = 0;
	for (double i = 0.5; i <= count; i += 0.5) {
		double maxS = P[L].second;
		mpL[i] = mpL[i - 0.5] + 0.5;
		mpL[i] = min(mpL[i], maxS);
		if (i == P[L].first) L++;
	}
	for (double i = count - 0.5; i >= 0; i -= 0.5) {
		double maxS = P[R].second;
		mpR[i] = mpR[i + 0.5] + 0.5;
		mpR[i] = min(mpR[i], maxS);
		if (R != 0 && i == P[R - 1].first) R--;
	}
	for (double i = 0; i <= count; i += 0.5) {
		mp[i] = min(mpL[i], mpR[i]);
	}
	for (double i = 0; i < count; i += 0.5) {
		ans += (mp[i] + mp[i + 0.5]) / 4;
	}
	printf("%.8f", ans);
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 998244353;

ll h, w, k, sx, sy, ex, ey;
vector<vector<char>> mat;
vector<vector<ll>> dist, vis;

void bfs(ll r, ll c) {
    queue<pair<ll, ll>> q;
    vis[r][c] = 1;
    dist[r][c] = 0;
    q.push({r, c});
    while(!q.empty()) {
        pair<ll, ll> node = q.front();
        q.pop();
        ll x = node.first, y = node.second;
        for(ll i = 1; i <= k; i++) {
            if(x + i <= h && mat[x + i][y] != '@') {
                if(!vis[x + i][y]) {
                    vis[x + i][y] = 1;
                    dist[x + i][y] = dist[x][y] + 1;
                    q.push({x + i, y});
                }
                else if(dist[x][y] + 1 > dist[x + i][y]) break;
            }
            else break;
        }
        for(ll i = 1; i <= k; i++) {
            if(x - i >= 1 && mat[x - i][y] != '@') {
                if(!vis[x - i][y]) {
                    vis[x - i][y] = 1;
                    dist[x - i][y] = dist[x][y] + 1;
                    q.push({x - i, y});
                }
                else if(dist[x][y] + 1 > dist[x - i][y]) break;
            }
            else break;
        }
        for(ll i = 1; i <= k; i++) {
            if(y + i <= w && mat[x][y + i] != '@') {
                if(!vis[x][y + i]) {
                    vis[x][y + i] = 1;
                    dist[x][y + i] = dist[x][y] + 1;
                    q.push({x, y + i});
                }
                else if(dist[x][y] + 1 > dist[x][y + i]) break;
            }
            else break;
        }
        for(ll i = 1; i <= k; i++) {
            if(y - i >= 1 && mat[x][y - i] != '@') {
                if(!vis[x][y - i]) {
                    vis[x][y - i] = 1;
                    dist[x][y - i] = dist[x][y] + 1;
                    q.push({x, y - i});
                }
                else if(dist[x][y] + 1 > dist[x][y - i]) break;
            }
            else break;
        }
    }
}

void solve() {
    cin >> h >> w >> k;
    cin >> sx >> sy >> ex >> ey;
    mat = vector<vector<char>> (h + 1, vector<char> (w + 1, '.'));
    vis = dist = vector<vector<ll>> (h + 1, vector<ll> (w + 1, 0));
    for(ll i = 1; i <= h; i++) {
        for(ll j = 1; j <= w; j++) {
            cin >> mat[i][j];
        }
    }
    bfs(sx, sy);
    if(dist[ex][ey]) cout << dist[ex][ey];
    else cout << "-1\n";
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;   
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 44376
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	lzero = [0]*62
	lone = [0]*62
	for v in al:
		for i in range(62):
			if v & (2**i) > 0:
				lone[i] += 1
			else:
				lzero[i] += 1
	ret = 0
	for i, (n_one, n_zero) in enumerate(zip(lone, lzero)):
		t = pow(2, i, mod) * n_one * n_zero
		ret += t
		ret %= mod
		
	print(ret)
		
			
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 124508
/*created by tanishk gupta*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define repl(i,a,n) for(long long int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef vector<int> VI;
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll MOD=1e9+7;
const ll mod=1e9+7;
//const llint MOD;
const ll N=(ll)(1e6+1);
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll add(ll a,ll b){return ((a%MOD)+(b%MOD))%MOD;}
ll mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll sub(ll a,ll b){return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll binpow(ll x, ll y){ll z = 1;while(y){if(y & 1) z = mul(z, x);x = mul(x, x);y >>= 1;}return z;}
ll inv(int x){return binpow(x, MOD - 2);}
ll divide(ll x, ll y){return mul(x, inv(y));}
ll fact[N];
void precalc(){fact[0] = 1;for(ll i = 1; i < N; i++)fact[i] = mul(fact[i - 1], i);}
ll C(ll n, ll k){return divide(fact[n], mul(fact[k], fact[n - k]));}
//bool prime[N];
//void sieve() {for(int i=2;i<N;i++) {prime[i]=true;}for (int p=2; p*p<=N; p++){if (prime[p] == true){for (int i=p*p; i<=N; i += p)prime[i] = false;}}}
ll legendpow(ll n, ll p){ll total = 0;while (n){n /= p;total += n;}return total;}

//head==================================================================================
//ll dp[1024][1024];
int main()
{

int n;
cin>>n;
ll a[n];
rep(i,0,n) cin>>a[i];
int ans=0;
//sort(a,a+n);
rep(i,0,n-2)
{
//ll tot=a[i];
    rep(j,i+1,n-1)
    {
  //      tot+=a[j];
        rep(k,j+1,n)
        {  ll tot=a[i]+a[j];
            ll tot2=a[k]+a[j];
            ll tot3=a[k]+a[i];
            if (a[i]!=a[k] && a[i]!=a[j] && a[j]!=a[k]){
            if (tot>a[k])
            {
                if(tot2>a[i])
                {
                    if (tot3>a[j])
                    {
                        ans++;
                    }
                }
            }}
        }
    }
}
cout<<ans;
}


Measured memory_bytes: 3636
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			Deque<Pair> deque = new ArrayDeque<Pair>();
			deque.push(new Pair(scanner.nextInt(), 1));
			for (int i = 2; i <= n; i++) {
				int a = scanner.nextInt();
				if (deque.peek().clr == a)
					deque.peek().num++;
				else {
					if (i % 2 == 0) {
						int num = deque.poll().num + 1;
						if (deque.isEmpty())
							deque.push(new Pair(a, num));
						else
							deque.peek().num += num;
					} else {
						deque.push(new Pair(a, 1));
					}
				}
			}
			int wcnt = 0;
			while (!deque.isEmpty()) {
				Pair p = deque.poll();
				wcnt += p.clr == 0 ? p.num : 0;
			}
			System.out.println(wcnt);
		}
	}

	class Pair {
		int clr, num;

		public Pair(int clr, int num) {
			super();
			this.clr = clr;
			this.num = num;
		}

		@Override
		public String toString() {
			return "Pair [clr=" + clr + ", num=" + num + "]";
		}

	}
}

Measured memory_bytes: 64012
#include <stdio.h>

int main(){
  int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  
  int L = A + B;
  int R = C + D;
  
  if(L>R){
    printf("Left");
  }else if(L == R){
    printf("Balanced");
  }else{
    printf("Right");
  }
}
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
int main()
{
    int a,b,c,d,co=0,flag=0;
    cin>>a>>b;
    vector<long long> v(a);
    map<long long, long long>mp;
    for(int i=0; i<a; i++)
    {
        cin>>v[i];
        mp[i+1]=v[i];
    }
    vector<long long>v1[a+1];
    for(int i=0; i<b; i++)
    {
        cin>>c>>d;
        v1[c].push_back(d);
        v1[d].push_back(c);
    }
    for(int i=1; i<=a; i++)
    {
        if(v1[i].size()==0)
        {
            co++;
            continue;
        }
        flag=0;
        for(int j=0; j<v1[i].size(); j++)
        {
            if(mp[i]<=mp[v1[i][j]])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
            co++;
    }
    cout<<co<<endl;
    return 0;
}




Measured memory_bytes: 16104
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
  
    string s;
    cin>>s;
    ll ans=0;
    ll preb=0;
    
    for(int i=0;i<s.size();i++){
        if(s[i]=='B'){
            preb++;
        }else{
            ans+=preb;
        }
    }
    
    cout<<ans<<endl;
return 0;
}


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

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

    string s; cin >> s;
    long long ans = 0;
    map<int, vector<int>> occ;
    vector<int> pref(1);
    vector<int> contrib(1);
    occ[0].push_back(0);

    for (char c: s) {
        if (c == '-') {
            int cur = pref.back();
            ans -= contrib.back();

            pref.pop_back();
            contrib.pop_back();
            occ[cur].pop_back();
        } else if (c == '(') {
			int cur = pref.back();
			int id = pref.size();

			pref.push_back(cur + 1);
			occ[cur + 1].push_back(id);
			contrib.push_back(0);
		} else if (c == ')') {
			int cur = pref.back() - 1;
			int id = pref.size();

			int last = -1;
			if (!occ[cur - 1].empty()) {
				last = occ[cur - 1].back();
			}

			int ctb = occ[cur].size() - (upper_bound(occ[cur].begin(), occ[cur].end(), last) - occ[cur].begin());
			pref.push_back(cur);
			contrib.push_back(ctb);
			occ[cur].push_back(id);

			ans += ctb;
		}
		cout << ans << '\n';
    }
    //cout << pref << '\n';

    return 0;
}



Measured memory_bytes: 26528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int ans[200000];
int main(void)
{
	int n,x,l,r,num=1,i;
	scanf("%d%d",&n,&x);
	if(x==1||x==2*n-1) puts("No");
	else{
		puts("Yes");
		if(n==2) printf("1\n2\n3\n");
		else{
			if(x==2){
				ans[n-2]=3,ans[n-1]=1,ans[n]=2,ans[n+1]=4;
				l=1,r=4;
			}else{
				ans[n-2]=x-1,ans[n-1]=x+1,ans[n]=x,ans[n+1]=x-2;
				l=x-2,r=x+1;
			}
			FOR(i,0,2*n-1){
				if(!ans[i]){
					while(l<=num&&num<=r) num++;
					ans[i]=num++;
				}
			}
			FOR(i,0,2*n-1) printf("%d\n",ans[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>

using namespace std;


bool check(int k[],int N){
	for(int i = 0;i < N;i++){
		if(k[i] > 1){
			return false;
		}
	}
	return true;
}
			

int main(){
	int N;
	while(cin >> N){
		if(N == 0){
			break;
		}
		int* k = new int[N];
		for(int i = 0; i < N;i++){
			cin >> k[i];
		}
		//???????????????
		if(check(k,N)){
			cout << "NA" << endl;
			continue;
		}
		//?????????
		int n = N;
		for(int i = 0;i < N;i++){
			if(k[i] == 0){
				--n;
			}
		}
		cout << n + 1 << endl;
		delete[] k;	
	}	
	return 0;
}


Measured memory_bytes: 3244
public class Main {
  public static void main(String[] args) {
    int s = new java.util.Scanner(System.in).nextInt();
    int ss = s / 60;
    int sss = s % 60;
    int h = ss / 60;
    int m = ss % 60;
    System.out.println(h + ":" + m + ":" + sss);
  }
}

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

int main(){
    int N;cin>>N;
    vector<ll> a(N);
    for(int i=0;i<N;i++)cin>>a.at(i);
    sort(a.begin(),a.end(),greater<ll>());
    a.push_back(0);
    ll p=a.at(0),count=0,ans=0,m=0,n=0;
    for(int i=0;i<N;i++){
        if(a.at(i)==p)count++;
        else {
            count=1;
            p=a.at(i);
            continue;
        }

        if(count==2 and m==0){
            m=p;
            count=0;
            p=a.at(i+1);
        }
        else if(count==2 and n==0){
            n=p;
            break;
        }
    }
    ans=m*n;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  cin >> s;
  int sn = 0;
  for(char c: s) {
    if(c == 'S') {
      sn++;
    }
    else {
      if(sn)
        sn--;
      else
        ans++;
    }
  }
  cout << ans * 2 << endl;
  return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,k,i;
    cin>>a>>b>>k;
    int x=0;
    for(i=a;i>=1;i--)
    {
        if(a%i==0 && b%i==0)
            x++;
        if(x==k)
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  while(true){
    int ret = 0;
    int n,x;cin>>n>>x;
    if(n+x == 0)break;
    for(int i = 1; n >= i; i++){
      for(int j = i+1; n >= j; j++){
        for(int k = j+1; n >= k; k++){
          if(i+j+k == x)ret++;
        }
      }
    }
    cout << ret << endl;
  }
}


Measured memory_bytes: 3052
#define MINUS -99999999
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  int n,a[5010],j;
  long long int  sum[5010] = {0},max;
  while(1){
    max = MINUS;
    cin >> n;
    if(n == 0)break;
    for(int i = 1; i <= n; i++){
      cin >> a[i];
      sum[i] = sum[i-1] + a[i];
    }
    for(int i = 0; i < n; i++){
      for(int j = i + 1; j <= n; j++){
	if(max < sum[j] - sum[i]){
	  max = sum[j] - sum[i];
	} 
      }
    }
    printf("%lld\n",max);
  }
}

Measured memory_bytes: 1212
n = gets.chomp.to_i
array = gets.split(" ").map(&:to_i)
ans = 0

(n-2).times do |i|
    if array[i] < array[i+1] && array[i+1] < array[i+2]
        ans += 1
    elsif array[i+2] < array[i+1] && array[i+1] < array[i] 
        ans += 1
    end
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  vector<int> H(S.size() + 1, 0);
  for (int i = 0; i < S.size(); i++){
    if (S[i] == '/'){
      H[i + 1] = H[i] + 1;
    } else if (S[i] == '_'){
      H[i + 1] = H[i];
    } else {
      H[i + 1] = H[i] - 1;
    }
  }
  vector<int> l(S.size() + 1, 0);
  l[0] = H[0];
  for (int i = 0; i < S.size(); i++){
    l[i + 1] = max(l[i], H[i + 1]);
  }
  vector<int> r(S.size() + 1, 0);
  r[S.size()] = H[S.size()];
  for (int i = S.size() - 1; i >= 0; i--){
    r[i] = max(r[i + 1], H[i]);
  }
  vector<int> F(S.size() + 1, 0);
  for (int i = 0; i <= S.size(); i++){
    F[i] = min(l[i], r[i]);
  }
  vector<int> W(S.size(), 0);
  for (int i = 0; i < S.size(); i++){
    W[i] = (F[i] - H[i]) + (F[i + 1] - H[i + 1]);
  }
  int A = 0;
  for (int i = 0; i < S.size(); i++){
    A += W[i];
  }
  A /= 2;
  cout << A << endl;
  int k = 0;
  for (int i = 0; i < S.size(); i++){
    if (W[i] == 1){
      k++;
    }
  }
  k /= 2;
  cout << k;
  if (k > 0){
    vector<int> L(k);
    int f = 0;
    for (int i = 0; i < S.size(); i++){
      L[f] += W[i];
      if (S[i] == '/' && W[i] == 1){
        f++;
      }
    }
    for (int i = 0; i < k; i++){
      cout << ' ' << L[i] / 2;
    }
  }
  cout << endl;
}


Measured memory_bytes: 3520
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;



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

	long long n, i, j, k, ans, x, y, z;
	string s;

	cin >> n >> s;
	vector<vector<long long>> ct(n + 1, vector<long long>(3, 0));
	for (i = 1; i <= n; i++) {
		if (s[i - 1] == 'R') x = 0;
		else if (s[i - 1] == 'G') x = 1;
		else if (s[i - 1] == 'B') x = 2;

		ct[i] = ct[i - 1];
		ct[i][x]++;
	}

	ans = 0;
	for (i = 1; i <= n; i++) {
		if (s[i - 1] == 'R') x = 0;
		else if (s[i - 1] == 'G') x = 1;
		else if (s[i - 1] == 'B') x = 2;

		y = (x + 1) % 3;
		z = (y + 1) % 3;
		ans += ct[i][y] * (ct[n][z] - ct[i][z]);
		ans += ct[i][z] * (ct[n][y] - ct[i][y]);

		for (j = 1; (i - 1 - j >= 0) && (i - 1 + j < n); j++) {
			if ((s[i - 1 - j] != s[i - 1]) && (s[i - 1 + j] != s[i - 1]) && ((s[i - 1 - j] != s[i - 1 + j]))) ans--;
		}
	}
	cout << ans << "\n";

	return 0;
}


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

ll a, b, c, x, y, ans = 0;

int main()
{
	scanf( "%d%d%d%d%d", &a, &b, &c, &x, &y );
	
	while( x != 0 || y != 0 )
	{
		if( y == 0 )
		{
			ans += min( 2 * c, a );
			x --; continue;
		}
		
		if( x == 0 )
		{
			ans += min( 2 * c, b );
			y --; continue;
		}
		
		ans += min( 2 * c, a + b );
		x --; y --; 
	}
	
	printf( "%lld\n", ans );
	
	return 0;
}

Measured memory_bytes: 256
(let* ((len (read))
       (n (read))
       (arr (make-array n
                        :initial-contents
                        (loop repeat n
                              collect (read))))
       (lst (loop for i below (1- n)
                  collect (- (aref arr (1+ i))
                             (aref arr i)))))
      (format t "~A" (- len (max (+ (aref arr 0)
                                    (- len (aref arr (1- n))))
                                 (apply #'max lst)))))

Measured memory_bytes: 63712
#include<iostream>
using namespace std;
int N,M;
int L[1000];
int ans[2000];
 
bool solve(){
   
  for(int i=0;i<(1<<M);i++){
    int sum=0;
    bool flg=true;
    for(int j=0;j<M;j++){
      ans[j] = (i>>j) & 1;
      sum+=ans[j];
    }
    if(sum!=L[0])continue;
 
    for(int j=M;j<N+M-1;j++){
      sum-=ans[j-M];
      if(sum==L[j-M+1])ans[j]=0;
      else if(sum+1==L[j-M+1])ans[j]=1;
      else flg= false;
      sum+=ans[j];
    }
    if(flg)return true;
  }
  return false;
}
 
int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    for(int i=0;i<N;i++)cin>>L[i];
 
    if(solve()){
      for(int j=0;j<N+M-1;j++)cout<<ans[j];
      cout<<endl;
    }else{
      cout<<"Goofy"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

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

int main() {
    string s,t;
    cin>>s>>t;
    vector<vector<int> >a(26);
    for(int i=0;i<s.size();i++){
        a.at(s.at(i)-'a').push_back(i);
    }
    for(int i=0;i<s.size();i++){
        a.at(s.at(i)-'a').push_back(i+s.size());
    }
    //繰り返し2回文字列

    //ここからlower_bound
    ll ans=0;//答え
    ll p=0;//今は繰り返し2回文字列の中のどこにいるのかを持っておく値
    for(int i=0;i<t.size();i++){
        if(a.at(t.at(i)-'a').size()==0){
            cout<<"-1"<<endl;
            return 0;
        }

        p = *lower_bound(a.at(t.at(i)-'a').begin(),a.at(t.at(i)-'a').end(),p)+1;

        if(p>=s.size()){
            ans+=s.size();
            p-=s.size();
        }
    }

    cout<<ans+p<<endl;




    return 0;
}


Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
long long n,i,j,ans,lef;

int main()
{
    cin>>n;
    lef = n-1;
    long long a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,greater<int>());
    for(i=0;i<n-1;i++)
    {
        if(i==0)
            ans+=a[i], lef--;
        else
        {
            if(lef>=2)
                ans+=(2*a[i]),lef-=2;
            else if(lef==1)
                ans+=a[i],lef--;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 5172
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    string s;
    cin >> s;
    
    int* check = new int[3];

    for(int i = 0; i < 3; ++i) {
        check[s[i] - 'a']++;
    }

    for (int c = 0; c < 3; ++c) {
        if (check[c] != 1) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

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

    int n; cin >> n;
    double t, a; cin >> t >> a;
    vector<double> h(n);
    for(int i=0; i<n; ++i) cin >> h[i];

    double ans = 1e9;
    int id;

    for(int i=0; i<n; ++i){
        double tmp = t - h[i]*0.006;
        if(ans > abs(tmp-a)){
            ans = abs(tmp-a);
            id = i+1;
        }
    }

    cout << id << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

ll n, q;
vector<vector<ll>> edge;
vector<ll> cost(n, 0);
vector<bool> check(n);

void dfs(ll now)
{
    check[now] = true;
    for (ll next : edge[now])
    {
        if (check[next])
        {
            continue;
        }
        cost[next] += cost[now];
        dfs(next);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    cin >> n >> q;
    ll a, b, p, x;
    cost.resize(n);
    edge.resize(n);
    rep(i, n - 1)
    {
        cin >> a >> b;
        a--;
        b--;
        edge[a].pb(b);
        edge[b].pb(a);
    }
    rep(i, q)
    {
        cin >> p >> x;
        cost[p - 1] += x;
    }
    check.resize(n);
    dfs(0); //dfs

    rep(i, n)
    {
        cout << cost[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 24320