akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  int c=0;
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  for(int i=1; i<N-1; i++){
    if(vec.at(i-1)<vec.at(i) && vec.at(i)<vec.at(i+1)){
      c++;
    }
    else if(vec.at(i-1)>vec.at(i) && vec.at(i)>vec.at(i+1)){
      c++;
    }
  }
  cout << c << endl;
}

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

int main(){
  int n,sum1=0,sum2=0,j;
  cin >> n;
  vector<int> s(n);
  for(int i=0;i<n;i++){
    cin >> s.at(i);
    sum1+=s.at(i);
  }
  for(int i=0;sum1>=sum2*2;i++){
    sum2+=s.at(i);
    j=i;
  }
  cout << min(abs(sum1-2*sum2),abs(sum1-2*(sum2-s.at(j)))) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
  char n[5],a[5],b[5];
  int sum,i;
  while(scanf("%s",n),strcmp(n,"0000")!=0){
    
    if(n[0]==n[1]&&n[1]==n[2]&&n[2]==n[3]){
      puts("NA");
      continue;
    }
    
    for(i=0;i<1000;i++){
      
      if(strcmp(n,"6174")==0){
	printf("%d\n",i);
	break;
      }
      
      strcpy(a,n);
      sort(a,a+4);
      reverse(a,a+4);
      strcpy(b,n);
      sort(b,b+4);
      sum = atoi(a)-atoi(b);
      
      n[0] = sum/1000 + '0';
      n[1] = sum/100%10 + '0';
      n[2] = sum/10%10 + '0';
      n[3] = sum%10 + '0';
    }
    
  }
  return(0);
}



Measured memory_bytes: 2756
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int a, b;

	cin >> a >> b;

	if (a % b == 0) {
		cout << 0;
	}
	else {
		cout << 1;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define digit(x) floor(log10(x))+1
#define mod 1000000007
#define endl "\n"
#define int long long
typedef long double ld;
typedef vector<vector<int> > matrix;
typedef vector<int> arr;
typedef vector<string> vs;
typedef vector<pair<int,int> > pv;
#define test() int t;cin>>t;while(t--)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
int bx[]={0,0,1,-1,1,-1,-1,1};
int by[]={1,-1,0,0,1,-1,1,-1};

//=================================================================//
int dp[101][100001];
int KS(int *weight, int *price,int N, int W) {
    if(N==0 || W==0) return 0;

    int &ans = dp[N][W];
    if(ans != -1) return ans;

    int op1 = INT_MIN, op2 = INT_MIN;
    if(weight[N]<=W)
    op1 = price[N] + KS(weight, price, N-1, W-weight[N]);
    op2 = KS(weight, price, N-1, W);

    return ans = max(op1,op2);
} 


#undef int
int main(){
#define int long long 
    fast;
    int Ni,Wb;
    cin>>Ni>>Wb;
    int weight[Ni+1], val[Ni+1];
    FOR(i,1,Ni) cin>>weight[i]>>val[i];
    
    memset(dp, -1, sizeof dp);
    cout<<KS(weight, val, Ni, Wb);
    return 0;
}

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

using namespace std;

int main(){
    int n, i, j, k;
    scanf("%d %d", &n, &k);
    int height[n+5];
    for(i = 1; i<=n; i++){
        scanf("%d", &height[i]);
    }
    int dp[n+5];
    for(i = 0; i <=n+5; i++) dp[i] = 1e9;
    dp[1] = 0;
    for(i = 2; i <= n; i++){
        if(i > 1) dp[i] = dp[i-1] + abs(height[i] - height[i-1]);
        if(i > 2) {
            for(j = 1; j <= k && j < i; j++){
                dp[i] = min(dp[i], dp[i-j] + abs(height[i] - height[i-j]));
            }
        }
    }

    printf("%d", dp[n]);

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
    //ofstream cout("output2.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long A[3];
    cin>>A[0]>>A[1]>>A[2];
    sort(A,A+3);
    cout<<A[0]+A[1];
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(c > a && c < b){
		printf("Yes\n");
	}
	else if(c < a || c > b){
		printf("No\n");
	}
	else if(c == a && c == b){
		printf("Yes\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll ;
int main() {
    int n,k;
    cin>>n>>k;
    ll dp[n],a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    {
        dp[0]=0;
        for(int i=1;i<=k,i<n;i++)dp[i]=abs(a[0]-a[i]);
        for(int i=k+1;i<n;i++)
        {
            int x=k;
            dp[i]=1e15;
            while(x)
            {
                dp[i]=min(dp[i],dp[i-x]+abs(a[i]-a[i-x]));
                x--;
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>dp(3,0);
    for(int d=0;d<n;d++){
        vector<int>c(3);
        vector<int>new_dp(3);
        for(auto&i :c)cin>>i;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(i!=j)
                    new_dp[j]=max(new_dp[j],dp[i]+c[j]);
            }
        }
        dp=new_dp;
    }
    cout<<max(dp[0],max(dp[1],dp[2]));
}

Measured memory_bytes: 256
import sys
import copy
input = sys.stdin.readline
H, W = [int(x) for x in input().strip().split()]
masu = [0 for h in range(H+2)]
masu[0] = ['#' for _ in range(W+2)]
masu[H+1] = ['#' for _ in range(W+2)]
init = 0
for h in range(1, H + 1):
    w = list(input().strip())
    init += w.count('#')
    masu[h] = ['#'] + w + ['#']

def bfs(Q, c, masu):
    nextq = []
    ans = 10 ** 9 +7
    for q in Q:
        h, w = q
        if w == W and h == H:
            return c
        ans = 10 ** 9 + 7
        for ww, hh in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            if masu[h+hh][w+ww] == '#':
                continue
            masu[h+hh][w+ww] = '#'
            nextq.append([h+hh, w+ww])

    if len(nextq):
        ans = min(ans, bfs(nextq, c+1, masu))

    return ans
masu[1][1] = '#'
ans = bfs([(1, 1)], 1, masu)
if ans == 10 ** 9 + 7:
    print(-1)
else:
    print(H*W-ans-init)

Measured memory_bytes: 3800
#include <stdio.h>
#include <inttypes.h>

int n, m, l;
int64_t a[100][100], b[100][100], c[100][100];

int main(void) {
	int i, j, k;
	if (scanf("%d%d%d", &n, &m, &l) != 3) return 1;
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if (scanf("%"SCNd64, &a[i][j]) != 1) return 1;
		}
	}
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			if (scanf("%"SCNd64, &b[i][j]) != 1) return 1;
		}
	}
	for (i = 0; i < n; i++) {
		for (k = 0; k < m; k++) {
			for (j = 0; j < l; j++) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			if (j > 0) putchar(' ');
			printf("%"PRId64, c[i][j]);
		}
		putchar('\n');
	}
	return 0;
}




Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define N 333333
#define rev(a) reverse(a+1,a+n+1)
#define ll long long
 
int n,t,a[N];
long long s[N],l[N],r[N],f[N],g[N],h[N],q[N];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
ll sum(int n){return (ll)n*(n+1)/2;} 
double slope(int x,int y){return (double)(g[x]-g[y])/(x-y);}
void pop(int x){for (;t>1&&slope(q[t-1],q[t])<=x;t--);}
void push(int x){
	for (;t>1&&slope(q[t-1],q[t])<=slope(q[t],x);t--);q[++t]=x;
}
void init_s(){for (int i=1;i<=n;i++) s[i]=s[i-1]+a[i];}
void calc(ll *f){
	int i;q[t=1]=0;init_s();
	for (i=1;i<=n;i++){
		pop(i);f[i]=max(f[i-1],f[q[t]]+sum(i-q[t])-s[i]+s[q[t]]);
		g[i]=f[i]+sum(i-1)+s[i];push(i);
	}
}
 
void solve(int x,int y){
	if (x==0&&y==n) for (int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
	if (x==y) return;
	int mid=(x+y)/2;t=0;
	for (int i=x;i<=mid;i++){
		g[i]=l[i]+1ll*i*(i-1)/2+s[i];
		push(i);
	}
	for (int i=mid+1;i<=y;i++){
		pop(i);
		h[i]=g[q[t]]-1ll*i*q[t]+1ll*i*(i+1)/2-s[i]+r[i+1];
	}
	for (int i=y-1;i>mid;i--) h[i]=max(h[i],h[i+1]);
	for (int i=mid+1;i<=y;i++) f[i]=max(f[i],h[i]);
	solve(x,mid);solve(mid+1,y);
}
 
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(),f[i]=-1e18;
	calc(l);rev(a);calc(r);rev(a);rev(r);
	solve(0,n);rev(a);rev(f);rev(l);rev(r);swap(l,r);
	solve(0,n);rev(a);rev(f);rev(l);rev(r);swap(l,r);
	for (int m=read();m;m--){
		int p=read(),x=read();
		printf("%lld\n",max(l[p-1]+r[p+1],a[p]+f[p]-x));
	}
}

Measured memory_bytes: 19968
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int h, mx;
    bool f = true;
    for(int i=0;i<n && f;i++){
        cin >> h;
        if(i == 0) mx = h;
        else {
            if(h < mx - 1) f = false;
            mx = max(mx, h);
        }
    }
    cout << (f?"Yes":"No") << endl;
}

Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = [0] * D
for i in range(D):
  S[i] = list(map(int, input().split()))
         
         
t = [0] * D
for i in range(D):
  t[i] = int(input())
  
last = [0] * (26)
score = 0
for i in range(1, D + 1):
  now = t[i - 1] - 1
  score += S[i - 1][now]
  last[now] = i
  for j in range(26):
    score -= C[j] * (i - last[j])
    
  print(score)
    
    
    
    

Measured memory_bytes: 9180
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct edge{int to,cost;};
typedef pair<int,int> P;

signed main (){
    int n,k;
    cin>>n>>k;
    vector<int> x(n),y(n);
    rep(i,0,n){
        cin>>x[i]>>y[i];
    }
    vector<int> X=x,Y=y;
    Sort(x);
    Sort(y);
    int ans=4*1e18;
    rep(i,0,n){
        rep(j,i+1,n){
            rep(p,0,n){
                rep(q,p+1,n){
                    int cnt=0;
                    rep(k,0,n){
                        if(x[i]<=X[k]&&X[k]<=x[j] &&y[p]<=Y[k]&&Y[k]<=y[q])cnt++;
                    }
                    if(cnt>=k)ans=min(ans,(x[j]-x[i])*(y[q]-y[p]));
                }
            }
        }
    }
    cout<<ans<<endl;
    
}
/*

*/


Measured memory_bytes: 256
//Bi-smi llāh

#include<bits/stdc++.h>
using namespace std;
#define ll long long



int main(){
	map<string, int> mp;
	int n; cin >> n;
	for(int i = 0; i < n; ++i){
			string s; cin >> s;
			mp[s]++;
		}
	cout << mp.size();
	return 0;
	}


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

Measured memory_bytes: 572
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    auto L = readln.chomp.map!(c => c == '1').array;
    auto N = L.length.to!int;

    auto dp = new long[][](N + 1, 2);
    dp[0][0] = 1;

    foreach (i ; 0 .. N) {
        if (L[i]) {
            dp[i + 1][0] = dp[i][0] * 2 % mod;
            dp[i + 1][1] = (dp[i][0] + dp[i][1] * 3 % mod) % mod;
        }
        else {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1] * 3 % mod;
        }
    }

    auto ans = (dp[N][0] + dp[N][1]) % mod;
    writeln(ans);
}














void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 8088
def chk(area):
    num=0
    l=len(area)
    cnt=[0 for _ in range(l)]

    for i in range(w):
        for j in range(h):
            cnt[area[j]]+=choko[i][j]

        if max(cnt)>k:
            if i>0: num+=1
            cnt=[0 for _ in range(l)]
            for j in range(h):
                cnt[area[j]]+=choko[i][j]
            if max(cnt)>k: return 10**10

    return num

h,w,k=map(int,input().split())
s=[input() for _ in range(h)]
choko=[[int(s[i][j]) for i in range(h)] for j in range(w)]

area=[0 for i in range(h)]
ans=10**10

for v in range(0,2**(h-1)):
    p=bin(v)[2:].zfill(h-1)
    for i in range(h-1):
        if p[i]=="1": area[i+1]=area[i]+1
        else: area[i+1]=area[i]

    tmp1=sum([int(p[i]) for i in range(h-1)])+chk(area)
    ans=min(ans,tmp1)

print(ans)

Measured memory_bytes: 49244
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		String ans = "Yes";

		int t = 0;
		int x = 0;
		int y = 0;
		for (int i = 0; i < N; i++) {
			t = reader.nextInt() - t;
			x = Math.abs(reader.nextInt() - x);
			y = Math.abs(reader.nextInt() - y);
			int gap = x + y;
			if (gap > t || gap % 2 != t % 2) {
				ans = "No";
			}
		}


		System.out.println(ans);
		reader.close();
	}
}





Measured memory_bytes: 86580
//Compiler optimization
#pragma GCC optimize("Ofast")

//include
#include <bits/stdc++.h>
using namespace std;

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ': ' << x << endl

//const
const  ll INF = 1e18;

ll n,k;
vl a;

bool judge(ll x){
    ll t = 0;
    fr(i,n){
        t+=(a[i]-1)/x;
    }
    if(t<=k)return true;
    return false;
}
int main(){
    cin >> n >> k;
    fr(i,n){
        ll x;cin >> x;
        a.push_back(x);
    }
    ll ok = 1e9;
    ll ng = 0;
    ll mid;
    while(ok - ng > 1){
        mid = (ok+ng)/2;
        if(judge(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 5288
import math
x = int(input())
res = False
for i in range(math.floor(x / 105), math.floor(x / 100) + 1):
    target = x - 100 * i
    if target < 0:
        continue
    if 0 <= target <= 5 * i:
        res = True
        break
    else:
        continue
if res:
    print("1")
else:
    print("0")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;
 
#define for01(n)  for (ll i=0; i<n; i++)
#define for02(n)  for (ll j=0; j<n; j++)
#define for03(n)  for (ll k=0; k<n; k++)
#define for11(n)  for (ll i=1; i<=n; i++)
#define for12(n)  for (ll j=1; j<=n; j++)
#define for13(n)  for (ll k=1; k<=n; k++)

#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define F first
#define S second
#define pp pair <ll, ll>
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
#define deci(n)  fixed<<setprecision(n)

#define p0(a) cout << a << " "
#define p1(a) cout << a << endl

#define MAX LLONG_MAX
#define MIN LLONG_MIN

using namespace std;



int main()
{
  ll A,B;
  cin >> A >> B;
  ll f = A;
  int i = 1;
  if(B==1)
    p1(0);
  else
  {
    while(1)
  	{
    	if(f>=B)
      		break;
		f = f + (A-1);
    	i++;
 
  	}
  	p1(i);
  }
  return 0;
}

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

void solve() {
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i, n) cin >> w[i];
  int ans = 100000;
  for(int t = 0; t < n; t++) {
    int s1 = 0;
    int s2 = 0;
    rep(j, n) {
      if (j <= t) s1 += w[j];
      else s2 += w[j];
    }
    ans = min(ans, abs(s1-s2));
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

const int INF=1001001001001001001ll;

int H,W,K;
int X[200000],Y[200000];

vpint row[100000],column[100000];

int to[200000][4];
int cc[200000][4];
int dist[200000][2];

signed main(){
    scanf("%lld%lld%lld",&W,&H,&K);
    rep(i,K)scanf("%lld%lld",&X[i],&Y[i]),X[i]--,Y[i]--;

    rep(i,K){
        row[Y[i]].pb(pint(X[i],i));
        column[X[i]].pb(pint(Y[i],i));
    }

    rep(i,H)sort(all(row[i]));
    rep(i,W)sort(all(column[i]));

    memset(to,-1,sizeof(to));

    rep(i,H){
        rep(j,row[i].size()){
            if(j){
                to[row[i][j].se][3]=row[i][j-1].se;
                cc[row[i][j].se][3]=row[i][j].fi-row[i][j-1].fi;
            }
            if(j+1!=row[i].size()){
                to[row[i][j].se][1]=row[i][j+1].se;
                cc[row[i][j].se][1]=row[i][j+1].fi-row[i][j].fi;
            }
        }
    }

    rep(i,W){
        rep(j,column[i].size()){
            if(j){
                to[column[i][j].se][0]=column[i][j-1].se;
                cc[column[i][j].se][0]=column[i][j].fi-column[i][j-1].fi;
            }
            if(j+1!=column[i].size()){
                to[column[i][j].se][2]=column[i][j+1].se;
                cc[column[i][j].se][2]=column[i][j+1].fi-column[i][j].fi;
            }
        }
    }
    if(column[0].size()==0){
        puts("-1");
        return 0;
    }
    int start=column[0][0].se;
    fill_n(*dist,200000*2,INF);
    dist[start][0]=Y[start];
    priority_queue<pair<int,pint> >que;
    que.push(mp(-Y[start],pint(start,0)));

    while(que.size()){
        int c=-que.top().fi;
        int v=que.top().se.fi;
        int d=que.top().se.se;
        que.pop();
        if(dist[v][d]<c)continue;

        if(dist[v][1-d]>c+1){
            dist[v][1-d]=c+1;
            que.push(mp(-dist[v][1-d],pint(v,1-d)));
        }

        rep(i,4){
            if(to[v][i]==-1)continue;
            if(i%2!=d)continue;
            int u=to[v][i];
            int cost=cc[v][i];
            if(dist[u][d]<=c+cost)continue;
            dist[u][d]=c+cost;
            que.push(mp(-dist[u][d],pint(u,d)));
        }
    }

    int ans=INF;
    rep(i,K){
        //cout<<i<<" "<<dist[i][0]<<" "<<dist[i][1]<<endl;
        if(X[i]!=W-1&&Y[i]!=H-1)continue;
        rep(j,2){
            int cost=W-1-X[i]+H-1-Y[i];
            if((X[i]==W-1&&j==1)||(Y[i]==H-1&&j==0))cost++;
            chmin(ans,dist[i][j]+cost);
        }
    }
    if(ans==INF)puts("-1");
    else printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 36432
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))

#define rdi(i) ll i; scanf("%lld", &i)
#define rds(s) string s; cin >> s
#define rdc(c) char c; cin >> c

#define INF 10000000000
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> ns(n);
    vector<vector<ll>> vs(n);
    rep(i, n) {
        cin >> ns[i];
    }
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        vs[a].push_back(b);
        vs[b].push_back(a);
    }
    ll cnt = 0;
    rep(i, n) {
        bool flag = true;
        rep(j, vs[i].size()) {
            if (ns[i] <= ns[vs[i][j]]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

signed main(void)
{
	long long n, k;
	long long sum;
	vector<long long> h;

	sum = 0;
	cin >> n >> k;
	rep(i, n) {long long a; cin >> a; h.push_back(a);}
	sort(h.begin(), h.end());
	reverse(h.begin(), h.end());
	for (long long i = k; i < n; i++)
		sum += h.at(i);
	cout << sum << endl;
	return 0;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    cout << endl;
    return 0;
}


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

int main() {
  int D,G;
  cin>>D>>G;
  if(D==1&&G==2 || D==2&&G==1)cout<<3<<endl;
  if(D==3&&G==2 || D==2&&G==3)cout<<1<<endl;
  if(D==1&&G==3 || D==3&&G==1)cout<<2<<endl;
  }


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

vl operator*(const vl &p, const vl &q) {
	vl r(sz(p));
	FOR(i,0,sz(p)) r[i] = p[q[i]];
	return r;
}

vl power(vl p, ll k) {
	vl r(sz(p));
	iota(all(r),0);
	while (k) {
		if (k & 1) r = r * p;
		p = p * p;
		k /= 2;
	}
	return r;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl x(n);
	FOR(i,0,n) cin >> x[i];
	
	vl d(n-1);
	FOR(i,0,n-1) d[i] = x[i+1]-x[i];

	vl p(n-1);
	iota(all(p),0);

	ll m, k; cin >> m >> k;
	vl a(m);
	FOR(i,0,m) cin >> a[i];
	
	FOR(i,0,m) {
		swap(p[a[i]-2],p[a[i]-1]);
	}
	p = power(p,k);
	
	FOR(i,0,n-1) x[i+1] = x[i] + d[p[i]];
	
	FOR(i,0,n) cout << x[i] << "\n";// " \n"[i+1 == n];

}



Measured memory_bytes: 5760
#include <iostream>
#include <map>
#define hash gnbiwnibwucmombdishuviwhvuaomvamiwqc
using namespace std;
map<long long,int>m;
long long c[200];
long long hash(string s){
	long long ans=0;
	for(int i=0;i<10;i++){
		ans+=c[s[i]];
	}
	return ans;
}
int main(){
	c['a']=1;
	for(int i='b';i<='z';i++){
		c[i]=c[i-1]*10;
	}
	int n;long long ans=0;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		long long h=hash(s);
		ans+=(m[h]++);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  string s;
  cin >>s;
  for(int i=0;i<3;i++){
    if(s[i] == '1') s[i] = '9';
    else if(s[i] == '9') s[i] = '1';
  }
  cout <<s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>
#include<stack>
#include <cstdlib>


using namespace std;

int main() {
	string str,ans;
	cin >> str;
	if (str == "ABC") {
		ans = "ARC";
	}
	else {
		ans = "ABC";
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 3128
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
const int N=2e5 + 5;
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a;
    cin>>a;
    ll ans=0;
    ll n=a;
    for(ll i=2;i*i<=a;i++){
        if(n%i==0){
            ll co=0;
            while(n%i==0){n/=i;co++;}
            //cout<<i<<" "<<co<<" ";
            ll sum=1,num=1;
            while(sum<=co){
                sum=(num*(num+1))/2;num++;
            }
            //cout<<num<<endl;
            ans+=num-2;
        }
    }
    if(n>1)ans++;
    cout<<ans;


    return 0;
}


Measured memory_bytes: 3660
import itertools
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
cnt = [i for i in range(n)]
ans = 10**12
ok = False
for i in range(1,n+1):
    for conb in itertools.combinations(cnt, i):
        z = [0]*(m+1)
        for j in conb:
            for k in range(m+1):
                z[k] = z[k] + ca[j][k]
            if sum(l >= x for l in z[1:]) == m:
                ans = min(ans, z[0])
                ok = True
if ok:
    print(ans)
else:
    print(-1)


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

int main()
{
    int n, d, x;
    cin >> n >> d >> x;

    int a[n];
    for (int& x: a) cin >> x;

    int cnt = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= d; j += a[i]) {
            cnt++;
        }
    }
    cout << cnt + x << endl;

    return 0;
}


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

int main(){
    string a,b;
    cin>>a>>b;
    if(a.size()==b.size()){
       for(int i=0;i<a.size();i++) cout<<a.at(i)<<b.at(i);
       cout<<endl;
    }
    else{
        for(int i=0;i<b.size();i++) cout<<a.at(i)<<b.at(i);
        cout<<a.at(a.size()-1)<<endl;
    }
}

Measured memory_bytes: 256
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(n)]

    t = 0
    x = 0
    y = 0
    flag = True
    for i in range(n):
        if (A[i][0] % 2 == 0 and (A[i][1] + A[i][2]) % 2 != 0) or (A[i][0] % 2 == 1 and (A[i][1] + A[i][2]) % 2 != 1):
            flag = False
            break
        elif abs(A[i][1] - x) + abs(A[i][2] - y) > (A[i][0] - t):
            flag = False
            break
        else:
            t = A[i][0]
            x = A[i][1]
            y = A[i][2]

    if flag == True:
        print("Yes")
    else:
        print("No")


resolve()

Measured memory_bytes: 60760
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;


int main()
{
	string str;
	cin>>str;
	int n = str.size();
	int num0=0,num1=0;
	rep(i,n){
		if(str[i] == '0') num0++;
		if(str[i] == '1') num1++;
	}
	cout<< min(num0,num1)*2<<endl;
	return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
 
#define pow2(x) ((x)*(x))
#define N 100
 
class UnionFind {
    int parent[N];
public:
    void init(int n) {
        for(int i=0; i<n; ++i) parent[i] = i;
    }
    int root(int x) {
        if(x==parent[x]) return x;
        return parent[x] = root(parent[x]);
    }
    bool issame(int x, int y) {
        return root(x)==root(y);
    }
    int unite(int x, int y) {
        if(root(x)==root(y)) return root(x);
        if(root(x)<root(y)) {
            parent[root(x)] = parent[root(y)];
        }else {
            parent[root(y)] = parent[root(x)];
        }
        return root(y);
    }
};
 
struct Edge {
    int from, to;
    double cost;
    bool operator<(const Edge& e) const {
        return cost < e.cost;
    }
        bool operator>(const Edge& e) const {
        return cost > e.cost;
    }
};
 
int main() {
    int n, c;
    UnionFind uf;
    double x[N], y[N], z[N], r[N], ans;
    priority_queue<Edge, vector<Edge>, greater<Edge> > q;
    while(cin >> n && n) {
        while(!q.empty()) q.pop();
        uf.init(n); ans = 0.0; c = 0;
        for(int i=0; i<n; ++i) cin >> x[i] >> y[i] >> z[i] >> r[i];
        for(int i=0; i<n; ++i) {
            for(int j=i+1; j<n; ++j) {
                double rr = pow2(x[j]-x[i]) + pow2(y[j]-y[i]) + pow2(z[j]-z[i]);
                if(rr <= pow2(r[j]+r[i])) {
                    q.push((Edge){i, j, 0.0});
                }else {
                    q.push((Edge){i, j, sqrt(rr)-r[i]-r[j]});
                }
            }
        }
        while(!q.empty() && c<n-1) {
            Edge e = q.top(); q.pop();
            if(!uf.issame(e.from, e.to)) {
                uf.unite(e.from, e.to);
                ans += e.cost;
                ++c;
            }
        }
        //cout << ans << endl;
        printf("%.3f\n", ans);
    }
    return 0;
}

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  int cnt1 = 0, cnt2 = 0, cnt4 = 0;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    if (a % 4 == 0)
      cnt4++;
    else if (a % 2 == 0)
      cnt2++;
    else
      cnt1++;
  }
  if ((cnt2 > 0 && cnt1 <= cnt4) || (cnt2 == 0 && cnt1 <= cnt4 + 1))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAX_N = 1000000;

char S[MAX_N];

int main() {
	scanf("%s", S);
	int cnt_j = 0, cnt_o = 0, cnt_i = 0;    //J????????°
	int ma = 0;
	int i = 0;
	int n = strlen(S);
	while (i < n) {
		while (i < n && S[i] != 'J') i++;
		cnt_j = 0;
		while (i < n && S[i] == 'J') {
			i++;
			cnt_j++;
		}
		if (cnt_j <= ma) {
			//??°?¨?????????´??°??§?????????????????????
			continue;
		}
		cnt_o = 0;
		while (i < n && S[i] == 'O') {
			cnt_o++;
			i++;
		}
		if (cnt_j < cnt_o) {
			continue;
		}
		cnt_i = 0;
		while (i < n && S[i] == 'I') {
			cnt_i++;
			i++;
		}
		if (cnt_i >= cnt_o) {
			ma = max(ma, cnt_o);
		}
	}
	printf("%d\n", ma);
	return 0;

}

Measured memory_bytes: 3712
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  if(v<=w){
    cout<<"NO"<<endl;
    return 0;
  }

  lint diff=v-w;
  lint dist=abs(a-b);

  if(diff*t>=dist){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }


  return 0;
}




Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef unsigned long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n, k;
    cin >>n >> k;
    vector<ll> h(200010);
    rep(i,0,n) cin >> h[i];

    sort(h.begin(), h.end(), greater<ll>());

    rep(i,0,k) h[i] = 0;

    ll cnt(0);
    rep(i,k,n) cnt += h[i];

    cout << cnt << endl;

    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll x;
  cin >> x;

  ll ans = 1;
  for(ll b = 2; b*b <= x; b++){
    for(ll p = 2; pow(b, p) <= x; p++)
      ans = max(ans, (ll)pow(b, p));
  }

  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n,k,left,right;
    long long total(0);
    cin >> n;

    vector<int> v_a(n+1);
    vector<int> v_b(n);
    for(int i=0; i<n+1; i++) cin >> v_a[i];
    for(int j=0; j<n; j++) cin >> v_b[j];

    for(int k = 0; k < n; k++){
        left = min(v_a[k], v_b[k]);
        total += left;
        v_a[k] -= left;
        v_b[k] -= left;
        
        right = min(v_a[k+1], v_b[k]);
        total += right;
        v_a[k+1] -= right;
        v_b[k] -= right;
    }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

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

    string s1, s2;
    getline(cin, s1);
    getline(cin, s2);
    vector<vector<int>> v(26);
    for (int i = 0; i < s1.size(); i++)
        v[s1[i] - 'a'].push_back(i);
    long ans = 0, cur = 0;
    bool flag = true;
    for (int i = 0; i < s2.size(); i++) {
        int c = s2[i] - 'a';
        if (v[c].size() == 0) {
            flag = false;
            break;
        }
        int pos = lower_bound(v[c].begin(), v[c].end(), cur) - v[c].begin();
        if (pos == v[c].size()) {
            ans += (s1.size() - cur);
            cur = 0;
            i--;
        } else {
            ans += ((v[c][pos] - cur) + 1);
            cur = v[c][pos] + 1;
        }
    }
    (flag) ? cout << ans << endl : cout << -1 << endl;
}


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

const int M = 301000;

int n, both, res;
long long L, x[M], t;
bool oL[M], oR[M];

int main(void) {
  scanf("%d%lld", &n, &L);
  for(int i = 1; i <= n; i++) {
    scanf("%lld", &x[i]);
  }
  long long ans = 2 * L;
  for(int i = 1; i <= n; i++) {
    scanf("%lld", &t);
    ans += 2 * L * ((t + 2 * L - 1) / (2 * L));
    t %= 2 * L;
    if(t > 0 && t <= 2 * x[i]) oL[i] = 1;
    if(t > 0 && t <= 2 * (L - x[i])) oR[i] = 1;
  }
  for(int i = 1; i < n; i++) {
    if(res && oR[i]) {
      if(oL[i]) both++;
      res--;
      ans -= 2 * L;
    } else if(!oL[i] && oR[i]) {
      if(both)
	both--, res++;
    } else if(oL[i])
      res++;
  }
  if(oR[n]) ans -= 2 * L;
  printf("%lld\n", ans);
}


Measured memory_bytes: 3200
// AOJ ITP1_1_C Rectangles
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
int cnt[55][30];
int a[30];
string s[55];
int n;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
    	cin >> s[i];
    	for(int j=0;j<s[i].size();j++){
    		cnt[i][s[i][j]-'a']++;
    	}
    }
    for(int i=0;i<26;i++){
    	a[i]=10000;
    	for(int j=0;j<n;j++){
    		a[i]=min(a[i],cnt[j][i]);
    	}
    }
    for(int i=0;i<26;i++){
    	for(int j=0;j<a[i];j++)printf("%c",'a'+i);
    }
	printf("\n");
    return 0;
}

Measured memory_bytes: 256
# 文字列の取得しリストに格納
S = str(input())
S_list = list(S)

# 隣接する文字列を比較し結果を出力
if S_list[0] != S_list[1]\
or S_list[1] != S_list[2]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8924
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a,b;
  cin>>a>>b;
  if(a==1&&b==2){
  	
  	cout<<"3"<<endl;
  	
  }
  
  else if(a==2&&b==1){
  	
  	cout<<"3"<<endl;
  	
  }
  
  else if(a==2&&b==3){
  	
    cout<<"1"<<endl;
  	
  }
  
  else if(a==3&&b==2){
  	cout<<"1"<<endl;
  	
  }
  
  else if(a==1&&b==3){
  	cout<<"2"<<endl;
  }
  
  
  else if(a==3&&b==1){
  	cout<<"2"<<endl;
  	
  }
  
  return 0;
}

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

struct node{
	int id;
	struct node *parentNode;
	struct node *firstChild;
	struct node *nextSibling;
};

struct node* createNode(int);
struct node* searchNode(int);

struct node* nodes[100001];
int n;

int main(){

int i,j;
int id,k;
int tmpId;
int depth;
struct node* currentNode;
struct node* tmpNode;
struct node* prevNode;

scanf("%d",&n);
	
for(i=0;i<n;i++){
	scanf("%d",&id);
	currentNode = createNode(id);
	scanf("%d",&k);
	for(j=0;j<k;j++){
		scanf("%d",&tmpId);
		tmpNode = createNode(tmpId);
		tmpNode->parentNode = currentNode;
		if(j==0){ // firstChild
			currentNode->firstChild = tmpNode;
		}else{ // nextSibling
			prevNode->nextSibling = tmpNode;
		}
		prevNode=tmpNode;
	}
}
	
	for(i=0; i<n; i++){
		
		printf("node %d: ",nodes[i]->id);
		printf("parent = %d, ",(nodes[i]->parentNode?nodes[i]->parentNode->id:-1));
		
		depth = 0;
		tmpNode = nodes[i]->parentNode;
		while(tmpNode){
			depth++;
			tmpNode = tmpNode->parentNode;
		}
		printf("depth = %d, ",depth);
		
		if(nodes[i]->firstChild==NULL) printf("leaf");
		else if(depth==0) printf("root");
		else printf("internal node");
		
		printf(", [");
		
		tmpNode = nodes[i]->firstChild;
		while(tmpNode){
			printf("%d",tmpNode->id);
			tmpNode = tmpNode->nextSibling;
			if(tmpNode) printf(", ");
			else break;
		}
		
		printf("]\n");
	}

return 0;
}

struct node* createNode(int id){
	struct node *newNode = searchNode(id);
	//static int nodesLength = 0;
	if(newNode) return newNode;
	newNode = (struct node*)malloc(sizeof(struct node));
	newNode->id=id;
	newNode->parentNode = NULL;
	newNode->firstChild = NULL;
	newNode->nextSibling = NULL;
	//nodes[nodesLength++] = newNode;
	nodes[id] = newNode;
	return newNode;
}

struct node* searchNode(int id){
	if(nodes[id]) return nodes[id];
	return NULL;
	/*
	int i;
	for(i=0; i<n; i++){
		
		if(nodes[i]==NULL) break;
		if(nodes[i]->id==id){
			return nodes[i];
		}
	}
	return NULL;
	*/
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;

char g[30][30];
lint dist[30][30];
P dir[4] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };

// (i, j) からの最短距離
lint bfs(lint i, lint j) {
    fill(&dist[0][0], &dist[30][0], 1e18);

    queue<P> que;
    que.push({i, j});
    dist[i][j] = 0;

    lint res = -1e18;
    while(!que.empty()) {
        lint ci, cj;
        tie(ci, cj) = que.front(); que.pop();

        for(auto d : dir) {
            lint di, dj;
            tie(di, dj) = d;
            
            if(g[ci+di][cj+dj] == '#')  continue;
            if(dist[ci+di][cj+dj] != 1e18)  continue;
            dist[ci+di][cj+dj] = dist[ci][cj] + 1;
            que.push({ci+di, cj+dj});

            res = max(res, dist[ci+di][cj+dj]);
        }
    }
    return res;
}

int main() {
    lint h, w;
    cin >> h >> w;

    fill(&g[0][0], &g[30][0], '#');

    for(lint i=1; i<=h; i++)
    for(lint j=1; j<=w; j++) {
        cin >> g[i][j];
    }

    // 各点からBFS
    lint ans = -1e18;
    for(lint i=1; i<=h; i++)
    for(lint j=1; j<=w; j++) {
        if(g[i][j] == '#')  continue;
        ans = max(ans, bfs(i, j));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
string s;
int main(void){
    cin >> s;
    sort(s.begin(), s.end());
    rep(i, s.size()-1) {
        if (s[i] == s[i + 1]) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <queue>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define MN 2000
#define whole(xs) xs.begin(), xs.end()
#define INF (1<<28)

int N, M;

struct Edge {
    int u, v;
    int dist, cost;
    Edge(int u, int v, int dist, int cost) : 
        u(u), v(v), dist(dist), cost(cost) {}
};
typedef vector<Edge> Vertex;

vector<Vertex> Graph;
bool input() {
    scanf("%d %d", &N, &M);
    if (N == 0 && M == 0) return false;
    Graph.clear(); Graph.resize(N);
    for (int i = 0; i < M; i++) {
        int u, v, d, c; scanf("%d %d %d %d", &u, &v, &d, &c);
        u--; v--;
        Graph[u].push_back(Edge(u, v, d, c));
        Graph[v].push_back(Edge(v, u, d, c));
    }
    return true;
}

struct S {
    int v;
    int dist, cost, prev;
    S(int v, int dist, int cost, int prev) : v(v), dist(dist), cost(cost), prev(prev) {}
};
bool operator<(const S& a, const S& b) {
    return (a.dist == b.dist ? a.cost > b.cost : a.dist < b.dist);
}
bool operator>(const S& a, const S& b) {
    return (!(a < b));
}
ostream& operator<<(ostream& os, const S& s) {
    os << "v: " << s.v << " dist: " << s.dist << " cost: " << s.cost << " prev: " << s.prev;
    return os;
}
vector<S> CalcDist() {
    vector<S> V(N, S(0, INF, INF, -1));
    for (int i = 0; i < N; i++) V[i].v = i;
    priority_queue< S, vector<S>, greater<S> > PQ;
    PQ.push(S(0, 0, 0, -1));
    V[0].dist = 0; V[0].cost = 0; V[0].prev = -1;
    while (!PQ.empty()) {
        S cur = PQ.top(); PQ.pop();
        for (int i = 0; i < Graph[cur.v].size(); i++) {
            Edge& next = Graph[cur.v][i];
            if (V[next.v].dist == V[cur.v].dist + next.dist && V[next.v].cost > next.cost) {
                V[next.v].cost = next.cost;
                V[next.v].prev = cur.v;
                PQ.push(V[next.v]);
            } else if (V[next.v].dist > V[cur.v].dist + next.dist) {
                V[next.v].dist = V[cur.v].dist + next.dist;
                V[next.v].cost = next.cost;
                V[next.v].prev = cur.v;
                PQ.push(V[next.v]);
            }
        }
    }
    return V;
}

int main() {
    while (input()) {
        vector<S> V = CalcDist();
        int Ans = 0;
        for (int i = 0; i < N; i++) {
            Ans += V[i].cost;
        }
        cout << Ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2700