akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define EPS 0.00000000001
#define INF 1000000000
vector<pair<int,int> > Graph[MAX];
long long p[MAX],pinv[MAX];
long long int gcd(long long int a,long long int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
long long int egcd(long long int a, long long int b, long long int & x, long long int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    long long int x1, y1;
    long long int d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
long long int ModuloInverse(long long int a,long long int n)
{
    long long int x,y;
    x=gcd(a,n);
    a=a/x;
    n=n/x;
    long long int res = egcd(a,n,x,y);
    x=(x%n+n)%n;
    return x;
}
void initialize()
{
    long long s=2;
    long long inv=ModuloInverse(s,MOD);
    p[0]=pinv[0]=1;
    for(int i=1;i<MAX;i++)
    {
        p[i]=(p[i-1]*s)%MOD;
        pinv[i]=(pinv[i-1]*inv)%MOD;
    }
}
int dfs(int node,int n,int parent=-1)
{
    int i,ans=1;
    for(i=0;i<Graph[node].size();i++)
    {
        if(Graph[node][i].first==parent) continue;
        Graph[node][i].second=dfs(Graph[node][i].first,n,node);
        ans+=Graph[node][i].second;
    }
    for(i=0;i<Graph[node].size();i++)
    {
        if(Graph[node][i].first==parent)
        {
            Graph[node][i].second=n-ans;
            break;
        }
    }
    return ans;
}
int main()
{
    initialize();
    int n,i,j,u,v;
    scanf("%d",&n);
    pair<int,int> q;
    q.second=0;
    for(i=1;i<n;i++)
    {
        scanf("%d %d",&u,&v);
        q.first=v;
        Graph[u].push_back(q);
        q.first=u;
        Graph[v].push_back(q);
    }
    dfs(1,n);
    long long current,temp,ans=0;
    for(i=1;i<=n;i++)
    {
        if(Graph[i].size()==1) continue;
        current=1;
        for(j=0;j<Graph[i].size();j++)
        {
            temp=(p[Graph[i][j].second]-1+MOD)%MOD;
            current=(current+temp)%MOD;
        }
        current=(current*pinv[n-1])%MOD;
        current=(1-current)%MOD;
        current=(current+MOD)%MOD;
        ans=(ans+current)%MOD;
    }
    ans=(ans*pinv[1])%MOD;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 29224
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{
	ll x,y;
	cin>>x>>y;
	ll max_legs = x*4;
	ll fl = 0;
	for(int i=0;i<=x;i++)
	{
       ll no_crane = i;
       ll no_turtle = x-i;
       if(no_crane*2 + no_turtle*4 == y)
       {
       	  fl = 1;
       	  break;
       }
	}
	if(fl)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}


Measured memory_bytes: 3604
#include <stdio.h>
int main(){
  int i,j,a[3],n,tmp;
  scanf("%d",&n);
  while(0 < n){
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    if(a[0] > a[2]){
      tmp=a[0];
      a[0]=a[2];
      a[2]=tmp;
    }
    if(a[1] > a[2]){
      tmp=a[1];
      a[1]=a[2];
      a[2]=tmp;
    }
    if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
    n--;
  }
  return (0);
}

Measured memory_bytes: 580
from collections import defaultdict
INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for key in a:
    d[key] += 1

sd = sorted(d.items(), key=lambda x: x[0])

if N % 2 == 0:
    if sd[0][1] == 1:
        print(0)
        exit()
else:
    if sd[0][1] != 1:
        print(0)
        exit()
ans = 1
for i in range(N // 2):
    ans *= 2
    ans %= INF

print(ans)

Measured memory_bytes: 16096
using System;
using System.Collections;
using System.Linq;

namespace AtCoder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var r = Console.ReadLine().Split(' ').ToList();
            if (r[0][r[0].Length - 1] == r[1][0])
            {
                if (r[1][r[1].Length - 1] == r[2][0])
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11220
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int,ss_raw()))

X,Y,Z,K = ints_raw()

A = list(map(int, input().split()))
B= list(map(int, input().split()))
C= list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
def main():
    D = [a+b for a in A for b in B]
    D.sort(reverse=True)
    D = D[:K+1]
    E =[d+c for d in D for c in C]
    E.sort(reverse=True)
    for e in range(K):
        print (E[e])

main()


Measured memory_bytes: 161892
n, m= gets.split.map(&:to_i)

ar = n.times.map{gets.split.map(&:to_i)}
tot = 0

ar.sort_by{|a, b|a}.each do |a, b|
    tot += a * [b, m].min
    m -= [b, m].min
    break if m == 0
end

puts tot

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

int n,ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i+=2)
	{
	  int sum=0;
	  for(int j=1;j<=i;j++) if(i%j==0) sum++;
	  if(sum==8) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 100050

#define ll long long
#define ld long double
#define lli long long int

#define pb emplace_back
#define INF 1000000000000

#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define loop(i,n) for (lli i = 0; i < n; i++)
#define loopitr(xt,vec) for (auto xt : vec)
#define FOR(i,a,b) for (lli i = a; i < b; i+=1)
#define loop_rev(i,n) for (lli i = n-1; i >= 0; i--)
#define FOR_REV(i,a,b) for (lli i = a; i >= b; i--)
#define itr :: iterator it
#define WL(t) while(t --)

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>
#define vi vector<lli>
#define vbool vector<bool>
#define seti set<lli>
#define pii pair<lli,lli>
#define pcc pair<char , char>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

#define endl '\n'

template <typename T>
void print(T x){cout<<x<<endl;}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvector(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvector(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;

int main(){
	fastio
	lli n; cin>>n;
	vector<lli> arr(n);
	for(lli i=0;i<n;i++)
		cin>>arr[i];
	
	lli answer=0;
	queue<lli> q; q.push(arr[0]);
	lli idx=1;
	while(idx<n){
		if(q.front()<arr[idx]){
			q.pop(); q.push(arr[idx]);
			idx++;
		}
		else if(q.front() >arr[idx]){
			answer+=q.front()-arr[idx];
			idx++;
		}
		else idx++;
	}
	cout<<answer<<endl;

	return 0;
}

Measured memory_bytes: 4788
#include <iostream>

using namespace std;

int main(){
  long long N;
  int tmp, tmp_N, buf = 0;
  cin >> N;
  tmp_N = N;
  while (N > 0){
    buf += N % 10;
    N = N / 10;
  }
  cout << (tmp_N % buf == 0 ? "Yes" : "No") << endl;
  return 0;
}

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

int main() 
{ 
    ll n,x,t;
    cin>>n>>x>>t;
  ll sum=0;
  	while(n>0)
    {
    	sum+=t;
      	n-=x;
    }
    cout<<sum<<endl;
    return 0; 
}

Measured memory_bytes: 3592
using System;
using static System.Console;

namespace abc157
{
    class Program
    {
        static void Main()
        {
            var nm = ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            var sc = new int[m][];
            for (var q = 0; q < m; ++q)
            {
                sc[q] = ReadNumList();
                --sc[q][0];
            }
            WriteLine(Guess(n, sc));
        }
        static int Guess(int n, int[][] sc)
        {
            var ans = new int[n];
            for (var i = 0; i < ans.Length; ++i)
            {
                ans[i] = -1;
            }
            for (var q = 0; q < sc.Length; ++q)
            {
                if (n > 1 && sc[q][0] == 0 && sc[q][1] == 0)
                {
                    return -1;
                }
                if (ans[sc[q][0]] > -1 && ans[sc[q][0]] != sc[q][1])
                {
                    return -1;
                }
                ans[sc[q][0]] = sc[q][1];
            }
            for (var i = 0; i < ans.Length; ++i)
            {
                if (ans[i] == -1)
                {
                    if (n == 1 || i > 0)
                    {
                        ans[i] = 0;
                    }
                    else
                    {
                        ans[i] = 1;
                    }
                }
            }
            var result = 0;
            for (var i = 0; i < ans.Length; ++i)
            {
                result = result * 10 + ans[i];
            }
            return result;
        }
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
    }
}


Measured memory_bytes: 27384
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007

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

	long long int memo = pow(100, d);
	long long int ans = memo * n;
	if (n <= 99) {
		cout << ans << endl;
	} else {
		cout << memo * 101 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;

int main()
{
	int n;
	cin >> n;
	cout << (n + 1) / 2;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define int int128_t
#define alpha_size 26



int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    

    int x;
    cin >> x;
    int cur = 100;
    int timer = 0;
    while (cur < x) {
      cur = cur * 101;
      cur = cur / 100;
      timer++;
    }
    cout << timer << endl;
}

Measured memory_bytes: 3668
#import sys
#input = sys.stdin.readline
def main():
    H, W = map( int, input().split())
    ans = min(H,W)
    if H%3 == 0 or W%3 == 0:
        ans = 0
    for i in range(1,H):
        L = [W*i]
        L.append(W//2*(H-i))
        if W%2 == 1:
            L.append((W//2+1)*(H-i))
        if max(L) - min(L) < ans:
            ans = max(L) - min(L)
    for i in range(1,W):
        L = [H*i]
        L.append(H//2*(W-i))
        if H%2 == 1:
            L.append((H//2+1)*(W-i))
        if max(L) - min(L) < ans:
            ans = max(L) - min(L)
    print(ans)
if __name__ == '__main__':
    main()


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

using namespace std;

#ifdef Adrian
#include "debug.h"
#else
#define debug(...) 9999
#endif

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second
#define ii pair<ll,ll>
template <typename G>
struct triple{G F, S, T;};
#define iii triple<int>



int main()
{

#ifdef Adrian
    //freopen("test.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#endif


    const ll mod = 998244353;
    string s;
    int h;
    cin>>s>>h;

    int n = 0;
    for(auto &i:s)
        n += (i == '1');

    vector<int> v;
    for(int i=0, j=0; i<s.size(); i=j)
    {
        for(; j<s.size() && s[j] == '1'; j++);
        v.push_back(j - i);
        ++j;
    }

    int m = v.size();
    vector<vector<ll>> cur(n + 1, vector<ll>(n + 1));
    vector<vector<ll>> next(n + 1, vector<ll>(n + 1));
    for(int i=0; i<=n; i++)
        cur[i][0] = 1;

    vector<vector<ll>> ac1(2 * n + 1, vector<ll>(n + 2));
    vector<vector<ll>> ac2(n + 1, vector<ll>(n + 2));

    for(int i=1; i<m; i++)
    {
        for(int j=0; j<=n; j++)
            for(int k=0; k<=n; k++)
            {
                ac1[j + k][j + 1] = cur[j][k];
                ac2[k][j + 1] = cur[j][k];
            }

        for(auto &j:ac1)
            for(int k=1; k<j.size(); k++)
                j[k] = (j[k] + j[k - 1]) % mod;
        for(auto &j:ac2)
            for(int k=1; k<j.size(); k++)
                j[k] = (j[k] + j[k - 1]) % mod;

        for(int j=0; j<=n; j++)
            for(int k=0; k<=n; k++)
            {
                next[j][k] = ac1[j + k][min(n, j + min(v[i], k)) + 1] - ac1[j + k][j];
                next[j][k] += ac2[k][j];

                next[j][k] %= mod;
                if(next[j][k] < 0)
                    next[j][k] += mod;
            }

        swap(next, cur);
    }

    ll ans = 0;
    for(int i=0; i<=min(h, n); i++)
        ans = (ans + cur[0][i]) % mod;

    cout<<ans<<'\n';



    return 0;
}


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

#define int long long

using namespace std;

const int maxn = 3e5 + 10, mod = 1e9 + 7;
int a[maxn], tw[maxn], n;

signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;

    tw[0] = 1;
    for (int i = 1; i < 60; i++)
        tw[i] = tw[i - 1] * 2 % mod;

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

    int ans = 0;
    for (int i = 0; i < 60; i++)
    {
        int num[2] = {0, 0};
        for (int j = 0; j < n; j++)
            ++num[(bool)(a[j] >> i & 1)];
        
        (ans += num[0] * num[1] % mod * tw[i] % mod) %= mod;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int main(){
  
  int n,i;
long num,sum=0,max,min;
  cin>>n;
  if(n==0)return 0;
  
  for(i=0; i<n; i++){
  
    cin>>num;
    if(i==0)max=min=num;
    if(num>max)max=num;
    if(num<min)min=num;
    sum+=num;
   
  }
  
  cout<<min<<" "<<max<<" "<<sum<<"\n";
  
}

Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
struct state{
  int x,y,cost,dir;
  state(int x,int y,int cost, int dir) :
    x(x), y(y), cost(cost), dir(dir) {}
};
bool operator < (const state &u, const state &s){
  return u.cost > s.cost;
}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int main(void){
  int w,h;
  int c[4];
  int m[31][31];
  while(cin>>w>>h,w&&h){
    int shortest[31][31][4];
    memset(shortest,-1,sizeof(shortest));
    REP(y,h)REP(x,w)cin>>m[y][x];
    REP(i,4)cin>>c[i];
    priority_queue<state> que;
    que.push(state(0,0,0,0));
    while(!que.empty()){
      state s = que.top(); que.pop();
      if(shortest[s.y][s.x][s.dir]!=-1&&shortest[s.y][s.x][s.dir]<=s.cost){
        continue;
      }else{
        shortest[s.y][s.x][s.dir] = s.cost;
      }
      if(s.x==w-1&&s.y==h-1){
        cout<<s.cost<<endl;
        break;
      }
      REP(r,4){
        int nx = s.x + dx[s.dir];
        int ny = s.y + dy[s.dir];
        if(0<=nx&&0<=ny&&nx<w&&ny<h){
          if(m[s.y][s.x]==r){
            que.push(state(nx,ny,s.cost,s.dir));
          }else{
            que.push(state(nx,ny,s.cost+c[r],s.dir));
          }
        }
        s.dir = (s.dir+1)%4;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1052
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int M1, D1, M2, D2;
  int ans = 0;
  string s;


  cin >> M1 >> D1;
  cin >> M2 >> D2;

  if(M1 != M2 && D2 == 1){
    ans++;
  }
   cout << ans << endl;

}


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

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

int main() {
  int h, a;
  cin >> h >> a;
  if (h % a == 0) {
    cout << h / a << endl;
  }
  else {
    cout << h / a + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import qualified Data.Map as MP
import Data.Char

type Probs = MP.Map Int Int

step mp k = MP.insertWith (+) k 1 mp

solve :: Probs -> Probs -> String
solve mpd mpt 
  | solve' = "YES"
  | otherwise = "NO"
  where
    solve' = MP.foldlWithKey step True mpt
    step acc kt vt =
      case MP.lookup kt mpd of
        Just vd -> acc && (vd >= vt)
        Nothing -> False

main = do
  n <- readLn :: IO Int
  ds <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
  m <- readLn :: IO Int
  ts <- VU.unfoldrN m (B.readInt . B.dropWhile isSpace) <$> B.getLine
  let mpd = VU.foldl' step MP.empty ds
  let mpt = VU.foldl' step MP.empty ts
  putStrLn $ solve mpd mpt

Measured memory_bytes: 70012
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 2LL*1e18;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;
    
    vl w(n), d(n);
    rep(i, n) {
        cin >> w[i] >> d[i];
    }

    // 判定問題「位置x以下にk個以上花があるか？」を二分探索で解く
    ll left = -1;
    ll right = INF;
    while(right - left > 1) {
        ll x = (left + right)/2;
        ll cnt = 0;
        rep(i, n) {
            if(x < w[i]) {
                continue;
            }
            cnt++;
            cnt += (x - w[i])/d[i];
            if(cnt >= k) {
                break;
            }
        }
        if(cnt >= k) {
            right = x;
        }
        else {
            left = x;
        }
    }

    out(right);
    re0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

struct Image {
  int h, w;
  char p[111][111];
  vector< set<int> > graph;
  bool input() {
    rep(i, 111) rep(j, 111) p[i][j] = '.';
    cin >> h >> w;
    if(!h && !w) return false;
    reps(i, 1, h+1) reps(j, 1, w+1) cin >> p[i][j];
    //cout << "input finished" << endl;
    return true;
  }
  bool in(int y, int x) {
    return 0<=y&&y<=h+1&&0<=x&&x<=w+1;
  }
  void make() {
    int num[111][111];
    int sz = 0;
    memset(num, -1, sizeof(num));
    rep(i, h+2) rep(j, w+2) {
      if(~num[i][j]) continue;
      queue<Pi> que;
      que.emplace(i, j);
      num[i][j] = sz++;
      int lim = (p[i][j] == '#' ? 8 : 4);
      while(!que.empty()) {
	int y, x;
	tie(y, x) = que.front(); que.pop();
	rep(k, lim) {
	  int ny = y + dy[k], nx = x + dx[k];
	  if(in(ny, nx) && p[ny][nx] == p[i][j] && num[ny][nx] == -1) {
	    que.emplace(ny, nx);
	    num[ny][nx] = num[i][j];
	  }
	}
      }
    }
    graph.clear();
    graph.resize(sz);
    bool used[111][111];
    memset(used, false, sizeof(used));
    rep(i, h+2) rep(j, w+2) {
      assert(~num[i][j]);
      if(used[i][j]) continue;
      queue<Pi> que;
      que.emplace(i, j);
      used[i][j] = true;
      int lim = (p[i][j] == '#' ? 8 : 4);
      while(!que.empty()) {
	int y, x;
	tie(y, x) = que.front(); que.pop();
	rep(k, lim) {
	  int ny = y + dy[k], nx = x + dx[k];
	  if(in(ny, nx) && !used[ny][nx]) {
	    if(p[ny][nx] == p[i][j]) {
	      que.emplace(ny, nx);
	      used[ny][nx] = true;
	    } else {
	      graph[num[i][j]].insert(num[ny][nx]);
	    }
	  }
	}
      }
    }
  }
  string dfs(int v) {
    vector<string> ch;
    for(int u : graph[v]) {
      ch.push_back(dfs(u));
    }
    sort(all(ch));
    string res = "";
    for(string s : ch) res += s;
    return "0"+res+"1";
  }
  string hash() {
    //cout << "get hash" << endl;
    return dfs(0);
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Image im1, im2;
  while(im1.input()) {
    im1.make();
    im2.input(); im2.make();
    cout << (im1.hash() == im2.hash() ? "yes" : "no") << endl;
  }

  return 0;
}

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

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> a(3 * N), b(N + 1, 0), c(N + 1);
    rep (i, 3 * N) cin >> a[i];
    priority_queue<int> q;
    rep (i, N) {
        q.push(-a[i]);
        b[0] += a[i];
    }
    rep (i, N) {
        q.push(-a[N + i]);
        b[i + 1] = b[i] + q.top() + a[N + i];
        q.pop();
    }
    priority_queue<int> r;
    rep (i, N) {
        r.push(a[3 * N - 1 - i]);
        c[0] += a[3 * N - 1 - i];
    }
    rep (i, N) {
        r.push(a[2 * N - 1 - i]);
        c[i + 1] = c[i] - r.top() + a[2 * N - 1 - i];
        r.pop();
    }
    ll ans = b[0] - c[N];
    rep (i, N + 1) ans = max(ans, b[i] - c[N - i]);
    cout << ans << endl;
    //rep(i, N + 1) cout << b[i] << " " << c[i] << endl;
}

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

int main()
{
  int N,M;
  std::cin>>N>>M;
  
  std::vector<int> H;
  H.emplace_back();  
  for(int i=0;i!=N;i++)
  {
    int h;
    std::cin>>h;
    H.emplace_back(h);
  }
  
  struct p{int a,b;};
  std::vector<p> m;
  std::vector<bool> c(N+1);
  for(int i=0;i!=N+1;i++)
    c[i]=true;
  for(int i=0;i!=M;i++)
  {
    int a,b;
    std::cin>>a>>b;
    m.emplace_back(p{a,b});
    
    if(H[a]>H[b])
    {
      c[a]=c[a]==false?false:true;
      c[b]=false;
    }
    else if(H[a]<H[b])
    {
      c[a]=false;
      c[b]=c[b]==false?false:true;
    }
    else
    {
      c[a]=false;
      c[b]=false;
    }
  }
  
  int result=0;
  for(size_t i=1;i!=N+1;i++)
  {
    if(c[i])
      result++;
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

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

struct edge { 
	long long to;
	long long cap;
	long long rev;
};

vector<edge> G[110];
long long level[110];
long long iter[110];
long long INF = 1000000000000000;

void add_edge(long long from, long long to, long long cap) {
	G[from].push_back({ to, cap, (long long)G[to].size() });
	G[to].push_back({ from, 0, (long long)G[from].size() - 1 });
}

void BFS(long long S) {
	memset(level, -1, sizeof(level));
	queue<long long> Q;
	level[S] = 0;
	Q.push(S);
	while (!Q.empty()) {
		long long V = Q.front(); Q.pop();
		for (edge E : G[V]) {
			if (E.cap > 0 && level[E.to] < 0) {
				level[E.to] = level[V] + 1;
				Q.push(E.to);
			}
		}
	}
}

long long DFS(long long V, long long T, long long F) {
	if (V == T) return F;
	for (long long& i = iter[V]; i < G[V].size(); i++) {
		edge& E = G[V][i];
		if (E.cap > 0 && level[V] < level[E.to]) {
			long long D = DFS(E.to, T, min(F, E.cap));
			if (D > 0) {
				E.cap -= D;
				G[E.to][E.rev].cap += D;
				return D;
			}
		}
	}
	return 0;
}

long long max_flow(long long S, long long T) {
	long long flow = 0;
	while (1) {
		BFS(S);
		if (level[T] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		long long F;
		while ((F = DFS(S, T, INF)) > 0) {
			flow += F;
		}
	}
}

int main() {
	long long N, A[100], COUNT = 0;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) {
		if (A[i] < 0) {
			add_edge(100, i, -A[i]);
		}
		else {
			add_edge(i, 101, A[i]);
			COUNT += A[i];
		}
	}
	for (long long i = 1; i <= N; i++) {
		for (long long j = 2; i * j <= N; j++) {
			int From = i - 1;
			int To = i * j - 1;
			add_edge(From, To, INF);
		}
	}
	cout << COUNT - max_flow(100, 101) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1e18 : 1e9;
const int MOD = 1000000007;
const long double EPS = 1e-8;

int n;
string f[110];

int main() {
	while (cin >> n, n) {
		rep (i, n) cin >> f[i];
		int cnt = 0;
		bool left = false, right = false, up = false;
		rep (i, n) {
			if (f[i][0] == 'l') left = !left;
			if (f[i][0] == 'r') right = !right;
			if (left == right && !up == left) {
				cnt++;
				up = !up;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 1

int main()
{	
	ios_base::sync_with_stdio(0);
	int n,m;
	while(cin>>n>>m){
		vector<string> grid;
		string str;
		for(int i=0; i<n; i++){
			cin>>str;
			int dot=0;
			for(int j=0; j<m; j++) dot+=(str[j]=='.');
			if(dot!=m) grid.push_back(str);
		}
		vector<int> skip(m,0);
		for(int i=0; i<m; i++){
			int dot = 0;
			for(int j=0; j<grid.size(); j++){
				dot+=(grid[j][i]=='.');
			}
			if(dot==grid.size()) skip[i] = 1;
		}
		for(int i=0; i<grid.size(); i++){
			str = "";
			for(int j=0; j<m; j++){
				if(skip[j]==0) str+=grid[i][j];
			}
			if(!str.empty()) cout<<str<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
#define An setprecision(16) 
int main(){
    int A,B,K;
    cin >> A >> B >> K;
    for(int i=A;i<=B;i++){
        if((i<=A+K-1)||(i>=B-K+1))cout << i << endl;
    }
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <functional>
#include <string.h>
#include <queue>
using namespace std;

int x, y, z, k;
long long a[1000], b[1000], c[1000];
bool f[1000][1000][1000];

struct deli {
	long long dd;
	int di, dj, dk;

	bool operator > (const deli& rhs) const
	{
		return dd > rhs.dd;
	}

	bool operator < (const deli& rhs) const
	{
		return dd < rhs.dd;
	}
};

int main()
{
	cin >> x >> y >> z >> k;

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

	for (int i = 0; i < y; i++)
		cin >> b[i];

	for (int i = 0; i < z; i++)
		cin >> c[i];

	sort(a, a + x, greater<long long>());
	sort(b, b + y, greater<long long>());
	sort(c, c + z, greater<long long>());

	deli d1 = { a[0] + b[0] + c[0] , 0, 0, 0 };

	priority_queue <deli> que;
	int j = 0;

	que.push(d1);
	f[0][0][0] = 1;

	while (j < k) {
		deli dt = que.top();
		int p = dt.di, q = dt.dj, r = dt.dk;
		std::cout << dt.dd << endl;
		que.pop();

		if (!f[p + 1][q][r] && p + 1 < x) {
			deli dw = { a[p + 1] + b[q] + c[r] , p + 1 , q , r };
			que.push(dw);
			f[p + 1][q][r] = 1;
		}

		if (!f[p][q + 1][r] && q  + 1 < y) {
			deli dw = { a[p] + b[q + 1] + c[r] , p , q + 1 , r };
			que.push(dw);
			f[p][q + 1][r] = 1;
		}

		if (!f[p][q][r + 1] && r  + 1 < z) {
			deli dw = { a[p] + b[q] + c[r + 1] , p , q , r + 1 };
			que.push(dw);
			f[p][q][r + 1] = 1;
		}

		j++;
	}
	
	return 0;
}


Measured memory_bytes: 973312
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;

const ll MAX = 510000;
const ll MOD = 1000000007;
const int INF = 1<<30;
int main() {
  int N;  
  string S;
  int Q;
  cin>>N>>S>>Q;
  set<int>st[26];
  rep(i,N){
    st[S[i]-'a'].insert(i);
  }
  rep(i,26){st[i].insert(1000000);}
  rep(i,Q){
    int a;
    cin>>a;
    if(a==1){
      int b;
      char c;
      cin>>b>>c;b--;
      st[S[b]-'a'].erase(b);
      st[c-'a'].insert(b);
      S[b]=c;
    }
    if(a==2){
      int l,r;
      cin>>l>>r;
      l--;
      int ans=0;
      rep(j,26){
        int g=*st[j].lower_bound(l);
        int h=*st[j].lower_bound(r);
        if(g<h){ans++;}
      }
      cout<<ans<<endl;
    }
  }
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int x, a, b;
  cin>>x>>a>>b;
  if(a >= b) puts("delicious");
  else if(b-a > x) puts("dangerous");
  else puts("safe");
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl

int h,w;
vector<string> s;

void pl(int x,int y){
    if(x<0)return;
    if(y<0)return;
    if(x>=w)return;
    if(y>=h)return;
    if(s[y][x]=='#')return;
    s[y][x]++;
}

int main(){
    cin>>h>>w;
    string S;
    REP(i,h){
        cin>>S;
        replace(all(S),'.','0');
        s.pb(S);

    }
    REP(i,h){
        REP(j,w){
            if(s[i][j]=='#'){
                pl(j,i+1);
                pl(j+1,i+1);
                pl(j+1,i);
                pl(j+1,i-1);
                pl(j,i-1);
                pl(j-1,i-1);
                pl(j-1,i);
                pl(j-1,i+1);
            }
        }
    }
    REP(i,h){
        cout<<s[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

typedef long int ll;

ll Euclid(ll x, ll y);

int main()
{
  ll x,y;
  ll ans = 0;
  
  scanf("%ld%ld",&x,&y);

  ans = Euclid(x,y);

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

ll Euclid(ll x, ll y)
{
  ll temp = 0;
  ll r = 0;
  
  if(x < y){
    temp = x;
    x = y;
    y = temp;
  }
  
  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }
  
  return x;
}



Measured memory_bytes: 2128
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, K) = nextLongList()
    val z = (1..N).filter { it % K == 0L }.size.toLong()
    var ans = z * z * z
    if (K % 2 == 0L) {
        val zz = (1..N).filter { it % K == K / 2 }.size.toLong()
        ans += zz * zz * zz
    }
    println(ans)
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(m);
  for(int i=0;i<m;i++)
    cin >> a.at(i);
  sort(a.begin(),a.end());
  vector<int>d(m-1);
  for(int i=0;i<m-1;i++)
    d.at(i)=a.at(i+1)-a.at(i);
  int ans=0,mem=0,ka=0;
  sort(d.begin(),d.end(),greater());
  for(int i=0;i<n-1&&i<d.size();i++){
    ans+=d.at(i);
  }
  ans=a.at(m-1)-a.at(0)-ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3968
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;

bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i*i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}


template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	priority_queue<int> q;
	string s = {};
	string s1 = {};
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	ll x[300005] = {};
	ll y[300005] = {};
	ll z[302][302] = {};
	cin >> a;
	for (ll i = 1; i <= a; i++)
	{
		if (i < 10)
		{
			z[i][i]++;
		}
		else if (i < 100)
		{
			z[i / 10][i % 10]++;
		}
		else if (i < 1000)
		{
			z[i / 100][i % 10]++;
		}
		else if (i < 10000)
		{
			z[i / 1000][i % 10]++;

		}
		else if (i < 100000)
		{
			z[i / 10000][i % 10]++;

		}
		else
		{
			z[i / 100000][i % 10]++;
			//cout << i / 100000 << endl;
			//cout << i % 10 << endl;
			//cout << endl;
		}
	}
	//for (int i = 1; i < 10; i++)
	//{
	//	cout << z[i][i] * z[i][i] << endl;
	//	ans += z[i][i] * z[i][i];
	//}
	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j < 10; j++)
		{
			ans += z[i][j] * z[j][i];
			//cout << i << endl;
			//cout << j << endl;
			//cout << z[i][j] * z[j][i] << endl;

			//cout  << endl;
		}
		//if (i != 5)
		//{

		//	ans += z[i][10 - i] * z[i][10 - i];
		//}

	}


	cout << ans << endl;



	//return 0;

	/*cout << c << endl;
	cout << b << endl;*/
	//cout << fixed << setprecision(10) <<tmp << endl;
	//cout<<factorial<10><<endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


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

int main(){
    int x;
    cin>>x;
    x%=7;
    switch(x){
        case 0:
            cout<<"thu"<<endl;
            break;
        case 1:
            cout<<"fri"<<endl;
            break;
        case 2:
            cout<<"sat"<<endl;
            break;
        case 3:
            cout<<"sun"<<endl;
            break;
        case 4:
            cout<<"mon"<<endl;
            break;
        case 5:
            cout<<"tue"<<endl;
            break;
        case 6:
            cout<<"wed"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>

#define MAX_M 100
#define MAX_N 1000000
#define min(a,b) (a < b ? a : b)

void insertionSort(int*,int,int,int*);
void shellSort(int*,int);
void print(int*,int*,int,int,int);

int main(){
  int n,A[MAX_N],i;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  shellSort(A,n);
  return 0;
}

void insertionSort(int *A,int n,int g,int *cnt){
  int i,j,v;
  for(i = g ; i < n ; i++){
    v = A[i];
    j = i - g;
    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j = j - g;
      (*cnt)++;
    }
    A[j+g] = v;
  }
}

void shellSort(int *A,int n){
  int G[MAX_M],i,m = 1,cnt = 0;
  
  while(m*3+1 < n){ m = m*3+1; }
  for(i = 0 ; m > 0 ; m /= 3,i++){
    G[i] = m;
  }
  m = min(i,MAX_M);
  for(i = 0 ; i < m ; i++){
    insertionSort(A,n,G[i],&cnt);
  }
  print(A,G,n,m,cnt);
}

void print(int *A,int *G,int n,int m,int cnt){
  int i;
  printf("%d\n",m);
  for(i = 0 ; i < m ; i++){
    printf("%d%c",G[i],(i < m-1 ? ' ' : '\n'));
  }
  printf("%d\n",cnt);
  for(i = 0 ; i < n ; i++){
    printf("%d\n",A[i]);
  }
}

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

int n, k, v[104];

int main() {
	cin>>n>>k;
	for(int i = 1;i<=n;i++)	cin>>v[i];
	int ans = -1000000000;
	for(int l = 0; l<=n;l++){
		for(int r = l+1;r<=n+1;r++){
			vector<int> a;
			int tmp = l+n-r+1;
			int sum = 0;
			if(tmp>k)	continue;
			for(int i = 1;i<=l;i++)	{a.push_back(v[i]); sum += v[i];}
			for(int j = r;j<=n;j++)	{a.push_back(v[j]);	sum +=v[j];}
			sort(a.begin(),a.end());
			for(int i = 0;i<k-tmp && i<a.size();i++)
				if(a[i]<0)	sum -= a[i];
				else	break;
			ans = max(ans,sum);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    int N; cin >> N; 
    vector<int>A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    vector<long long>B(N);
    int ans = 0;
    long long count = 0;
    rep(i, N) {
        count += A[i];
        B[i] = count;
    }
    int a=-1;
    rep(i, N-1)if (B[i] * 2 < A[i + 1])a = i;
    cout << N - a - 1 << endl;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int a =0, b = 0;
  for(int i=0; i < s.size(); i++) {
    if(s[i] == '0') a++;
    else b++;
  }
  cout << 2*min(a, b) << endl;
}


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

int main(){
  string S;
  cin  >> S;
  
  if (S.at(0) == 'A' && S.at(1) ==  'A' && S.at(2) == 'A'){
    cout << "No" << endl;
  }
  
  else if (S.at(0) == 'B' && S.at(1) ==  'B' && S.at(2) == 'B'){
     cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}


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

int main(){
    int n, cnt;
    cnt = 0;
    cin >> n;
    int a[n], d[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        d[i] = i + 1;
    }
    for(int i = 0; i < n; i++){
        if(a[i] != d[i]) cnt++;
    }
    if(cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define a first
#define b second
#define all(x) x.begin(), x.end()

// AtCoder Library(https://img.atcoder.jp/practice2/ac-library.zip)
// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
// -> 一部改変(2020/09/08).
struct DSU{
public:
    DSU() : _n(0){}
    DSU(int n) : _n(n), parent_or_size(n, -1){}
    int merge(int a, int b){
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = root(a), y = root(b);
        if(x == y) return x;
        if(-parent_or_size[x] < -parent_or_size[y]) swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }
    
    bool same(int a, int b){
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return root(a) == root(b);
    }
    
    int root(int a){
        assert(0 <= a && a < _n);
        if(parent_or_size[a] < 0) return a;
        return parent_or_size[a] = root(parent_or_size[a]);
    }
    
    int size(int a){
        assert(0 <= a && a < _n);
        return -parent_or_size[root(a)];
    }
    
    vvi groups(){
        vi buf(_n), group_size(_n);
        rep(i, _n){
            buf[i] = root(i);
            group_size[buf[i]]++;
        }
        vvi result(_n);
        rep(i, _n) result[i].reserve(group_size[i]);
        rep(i, _n) result[buf[i]].pb(i);
        result.erase(
            remove_if(all(result), [&](const vi& v) { return v.empty(); }), result.end());
        return result;
    }
    
private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    vi parent_or_size;
};

int main(){
    
    // 1. 入力情報.
    int N, Q;
    scanf("%d %d", &N, &Q);
    
    // 2. クエリ回答.
    DSU uf(N);
    rep(i, Q){
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if(t) printf("%d\n", uf.same(u, v) ? 1 : 0);
        else  uf.merge(u, v);
    }
    return 0;
    
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,direction,cnt=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    for(int i=1;i<n;i++){
        if(v[i] > v[i-1])
            if(direction == 1)
                cnt++;
            else direction = 1;
        else
            if(direction == -1)
                cnt++;
            else direction = -1;
    }
    cout<<cnt<<endl;
    return 0;
}


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

using namespace std;

int main()
{
	int a;
	string b;
	cin >> a >> b;

	if (a < 3200)
	{
		cout << "red" << endl;
	}
	else
	{
		cout << b << endl;
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def calc(N, g):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                g[i][j] = min(g[i][j], g[i][k] + g[k][j])


def main():
    N, M, L = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        adj[A-1][B-1] = C
        adj[B-1][A-1] = C
    dst = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        dst[i][i] = 0
        for j in adj[i]:
            dst[i][j] = adj[i][j]
    calc(N, dst)
    ans = [[float("inf")] * N for _ in range(N)]
    for i in range(N):
        ans[i][i] = 0
        for j in range(i+1, N):
            if dst[i][j] <= L:
                ans[i][j] = 1
                ans[j][i] = 1
    calc(N, ans)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = ans[s-1][t-1]
        print(-1 if x == float("inf") else x-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 124764