akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        int[][] card = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                card[i][j] = sc.nextInt();
            }
        }

        int n = sc.nextInt();

        Set<Integer> nums = new HashSet<>();
        for (int i = 0; i < n; i++) {
            nums.add(sc.nextInt());
        }

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (nums.contains(card[i][j])) {
                    card[i][j] = -1;
                }
            }
        }

        if (
            (card[0][0] == -1 && card[0][1] == -1 && card[0][2] == -1) ||
            (card[1][0] == -1 && card[1][1] == -1 && card[1][2] == -1) ||
            (card[2][0] == -1 && card[2][1] == -1 && card[2][2] == -1) ||
            (card[0][0] == -1 && card[1][0] == -1 && card[2][0] == -1) ||
            (card[0][1] == -1 && card[1][1] == -1 && card[2][1] == -1) ||
            (card[0][2] == -1 && card[1][2] == -1 && card[2][2] == -1) ||
            (card[0][0] == -1 && card[1][1] == -1 && card[2][2] == -1) ||
            (card[0][2] == -1 && card[1][1] == -1 && card[2][0] == -1)
        ) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, x;
    ll sum = 0;
    cin >> n >> m;
    for(int i=0; i<m; ++i){
        cin >> x;
        sum += x;
    }
    if(n - sum >= 0){
        cout << n - sum << "\n";
    }
    else
        cout << "-1\n";
}


Measured memory_bytes: 3648
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

ans = ['Sunny', '']
def main():
    s = input()
    if s == 'Sunny':
        print('Cloudy')
    elif s == 'Cloudy':
        print('Rainy')
    else:
        print('Sunny')



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;
using System.Text;

namespace ITP_3_C{
    public class Program{
        public static void Main(string[] args){
            StringBuilder buffer = new StringBuilder();

            while(true){
                string[] temp = Console.ReadLine().Split(' ');
                int a = int.Parse(temp[0]);
                int b = int.Parse(temp[1]);

                if(a==0 && b==0){
                    break;
                }
                if(a<b){
                    buffer.AppendLine(a+" "+b);
                }else{
                    buffer.AppendLine(b+" "+a);
                }
            }
            Console.Write(buffer.ToString());
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

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

ll dp[3005][3005][4];
ll rc[3005][3005];

void solve_abc_e() {
	ll r, c, k;
	ll l_ans = 0;

	cin >> r >> c >> k;

	rep(i, r)rep(j, c) {
		rep(a, 3) dp[i][j][a] = 0;
		rc[i][j] = 0;
	}

	ll tr, tc, tv;
	rep(i, k) {
		cin >> tr >> tc >> tv;
		rc[tr][tc] = tv;
	}

	ll add = 0;
	dp[1][1][0] = 0;
	dp[1][1][1] = rc[1][1];
	rep1(i, r)rep1(j, c) {
		if (i > 1) {
			// not get
			rep(a, 4) {
				chmax(dp[i][j][0], dp[i - 1][j][a]);
			}
			// get
			if (rc[i][j] > 0) {
				rep(a, 4) {
					chmax(dp[i][j][1], dp[i - 1][j][a] + rc[i][j]);
				}
			}
		}

		if (j > 1) {
			// not get
			rep(a, 4) {
				chmax(dp[i][j][a], dp[i][j - 1][a]);
			}
			// get
			if (rc[i][j] > 0) {
				chmax(dp[i][j][1], dp[i][j - 1][0] + rc[i][j]);
				chmax(dp[i][j][2], dp[i][j - 1][1] + rc[i][j]);
				chmax(dp[i][j][3], dp[i][j - 1][2] + rc[i][j]);
			}
		}
	}

	l_ans = 0;
	rep(i, 4) {
		chmax(l_ans, dp[r][c][i]);
	}

	cout << l_ans << "\n";

	return;
}

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

	solve_abc_e();

	return 0;
}

Measured memory_bytes: 355656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n){
        cin >> a.at(i);
    }
    rep(i, n){
        cin >> b.at(i);
    }
    for(int i=0; i<n-1; i++){
        cin >> c.at(i);
    }
    c.push_back(0);

    int sum=0;
    rep(i, n){
        int j = a[i];
        sum += b[j-1];
        if(a[i] == a[i-1]+1) sum += c[a[i-1]-1];
    }

    cout << sum << endl;

    

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}
 
int32_t main()
{
	fast;

	int h;
	cin>>h;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		h-=x;
	}
	if(h>0)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    int n,m;
    int[][] cost, time;
    int INF = 100000000;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            m = sc.nextInt();
            if(n==0 && m==0) break;

            cost = new int[m][m];
            time = new int[m][m];
            for(int i=0; i<m; i++){
                Arrays.fill(cost[i], INF);
                Arrays.fill(time[i], INF);
            }
            for(int i=0; i<n; i++){
                int a = sc.nextInt()-1, b = sc.nextInt()-1;
                int c = sc.nextInt(), t = sc.nextInt();
                cost[a][b] = c; cost[b][a] = c;
                time[a][b] = t; time[b][a] = t;
            }

            warshall_floyd();

            int k = sc.nextInt();
            for(int i=0; i<k; i++){
                int p = sc.nextInt()-1, q = sc.nextInt()-1;
                int r = sc.nextInt();
                if(r==0) System.out.println(cost[p][q]);
                if(r==1) System.out.println(time[p][q]);
            }
        }
    }

    void warshall_floyd(){
        for(int k=0; k<m; k++){
            for(int i=0; i<m; i++){
                for(int j=0; j<m; j++){
                    cost[i][j] = Math.min(cost[i][j], cost[i][k]+cost[k][j]);
                    time[i][j] = Math.min(time[i][j], time[i][k]+time[k][j]);
                }
            }
        }
    }

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

Measured memory_bytes: 14000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int n; cin >> n;
    int dis = 0b0000000;
    while(n!=-1){
        vector<int> seg = {0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,
                           0b1101101,0b1111101,0b0100111,0b1111111,0b1101111};
        for(int i=0;i<n;i++){
            int d; cin >> d;
            int next;
            next = seg[d];
            int ans;
            ans = dis^next;
            dis = next;
            cout << bitset<7>(ans) << endl;
        }
        dis = 0b0000000;
        cin >> n;
    }
}



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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define ZERO(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define eb emplace_back
#define mp make_pair

int n,k;

int main() {
    cin>>n>>k;


    ll ans = k;
    k--;
    rep(i,n-1)
        ans *= k;

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		boolean[] own = new boolean[n];
		for(int i = 0; i < k; i++) {
			int d = sc.nextInt();
			for(int j = 0; j < d; j++) {
				int a = sc.nextInt();
				if(own[a-1]==false) {
					own[a-1]=true;
				}
			}
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			if(own[i]==false) {
				count++;
			}
		}
		System.out.println(count);
	 }
}

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

class UnionFind{
private:
    std::vector<int> parent;
    std::vector<int> size;
    
public:
    UnionFind(int N){
        parent.resize(N);
        size.resize(N);
        for(int i = 0; i < N; i++){
            parent[i] = i;
            size[i] = 1;
        }
    }

    int root(int x){
        if (parent[x] == x) return x;
        int rx = root(parent[x]);
        parent[x] = rx;
        return rx;
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        parent[rx] = ry;
        size[ry] += size[rx];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size[root(x)];
    }
};

int main(){
    int N, M, K;
    std::cin >> N >> M >> K;
    UnionFind tree(N);
    std::vector< int > friend_num(N, 0);
    int a, b;
    for(int i=0; i<M; i++){
        std::cin >> a >> b;
        tree.unite(a-1, b-1);
        friend_num[a-1]++;
        friend_num[b-1]++;
    }
    
    std::vector< int > block_num(N, 0);
    for(int i=0; i<K; i++){
        std::cin >> a >> b;
        if(tree.same(a-1, b-1)){
            block_num[a-1]++;
            block_num[b-1]++;
        }
    }
    bool first = true;
    for(int i=0; i<N; i++){
        int ans = tree.get_size(i) - friend_num[i] - block_num[i] - 1;
        if(first){
            std::cout << ans;
            first = false;
        }else{
            std::cout << " " << ans;
        }
    }
    std::cout << std::endl;
}


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

const long long INIT = (1ll << 55);

class segment_tree {
private:
  int n;
  vector<long long> dat;

  static inline long long func(long long a, long long b) {
    return min(a, b);
  }

  long long query(int a, int b, int k, int l, int r) const {
    if(r <= a || b <= l) return INIT;
    if(a <= l && r <= b) return dat[k];

    const auto vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    const auto vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return func(vl, vr);
  }

public:
  segment_tree(int n_):n(1) {
    while(n < n_) n <<= 1;
    dat.resize(2 * n - 1, INIT);
  }

  void update(int k, long long a) {
    k += n - 1;
    dat[k] = a;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  long long query(int a, int b) const {
    return query(a, b, 0, 0, n);
  }
};

segment_tree make_segment_tree(const vector<int> &a, int sign) {
  const int n = a.size();
  segment_tree res(n);

  for(int i = 0; i < n; ++i) {
    res.update(i, a[i] * sign);
  }

  return res;
}

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

  int n;
  cin >> n;

  vector<int> a(n);
  for(auto &e : a) cin >> e;

  auto plus = make_segment_tree(a, 1);
  auto minus = make_segment_tree(a, -1);

  vector<pair<int, int>> order;
  order.reserve(n);
  for(int i = 0; i < n; ++i) {
    order.emplace_back(a[i], i);
  }

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

  int q;
  cin >> q;

  vector<tuple<int, int, int, int>> query;
  query.reserve(q);

  for(int i = 0; i < q; ++i) {
    int l, r, d;
    cin >> l >> r >> d;
    query.emplace_back(d, l, r, i);
  }

  sort(query.begin(), query.end());
  vector<long long> res(q, INIT);

  int i = 0;
  for(const auto &qu : query) {
    int d, l, r, idx;
    tie(d, l, r, idx) = qu;

    while(i < n && order[i].first < d) {
      const int id = order[i].second;
      plus.update(id, INIT);
      ++i;
    }

    res[idx] = plus.query(l, r + 1) - d;
  }

  reverse(query.begin(), query.end());
  reverse(order.begin(), order.end());
  i = 0;

  for(const auto &qu : query) {
    int d, l, r, idx;
    tie(d, l, r, idx) = qu;

    while(i < n && order[i].first > d) {
      const int id = order[i].second;
      minus.update(id, INIT);
      ++i;
    }

    res[idx] = min(res[idx], minus.query(l, r + 1) + d);
  }

  for(const auto &e : res) {
    cout << e << endl;
  }

  return 0;
}


Measured memory_bytes: 8652
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int t = sc.nextInt();
    int a = sc.nextInt();
    int ans = 0;
    double mingap = Double.MAX_VALUE;

    for (int i = 0; i < n; i++) {
      int h = sc.nextInt();
      double gap = Math.abs(t - (h * 0.006) - a);
      if (gap < mingap) {
        mingap = gap;
        ans = i + 1;
      }
    }

    System.out.println(ans);

  }
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

string S, T;
signed main() {
    cin >> S >> T;
    cout << T << S << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;

  i64 answer = 0;
  const i64 max_i = static_cast<i64>(std::sqrt(N + 1)) - 1;
  for (i64 i = 1; i <= max_i; ++i) {
    if (N % i == 0) {
      answer += N / i - 1;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

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

using namespace std;

int main()
{
    long long int n,k;
    cin>>n>>k;
    int t=0;
    if(k==1)
    {
        cout<<0<<endl;
        return 0;
    }
    n=n%k;
    while(t==0)
    {
        if(n>abs(n-k))
        {
          n=abs(n-k);
        }else
        {
            break;
        }
    }
    cout<<n<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mkp make_pair
#define mod 1000000007
#define F first
#define S second
#define ld long double
#define f(i,l,f,n) for(i=(l); i<(n) && !(f); i++)
#define endl "\n"

int countt[100000+1], arr[100000+1];

int jump(int pos)
{
    if(pos<=0)
    return 0;
    else if(countt[pos]!=-1)
    return countt[pos];
    else
    {
        int p1 = abs(arr[pos]-arr[pos-1]);
        int p2;
        if(pos>1)
        p2 = abs(arr[pos]-arr[pos-2]);
        else
        p2 = INT_MAX;
        countt[pos]=min(p1+jump(pos-1), p2+jump(pos-2));
    }
    return countt[pos];
}

void solve()
{
    int i, j, k, n;
    cin>>n;
    f(i,0,0,n)
    cin>>arr[i];
    memset(countt, -1, sizeof(countt));
    cout<<jump(n-1);
}


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

    int t=1, i=0;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<i++<<": "<<solve()<<endl;
        solve();
    }
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>

using namespace std;

typedef pair<long long, long long> pll;

long long n, m, s, t;
vector<vector<pair<long long, long long> > > ag, bg;
vector<long long> acost, bcost;
vector<pair<long long, long long> > comb;

void dijkstra(long long s, vector<vector<pair<long long, long long> > > &g, vector<long long> &cost)
{
    fill(cost.begin(), cost.end(), 1e16);
    priority_queue<pll, vector<pll>, greater<pll> > pq;
    cost[s] = 0;
    pq.push(make_pair(0, s));
    while(!pq.empty())
    {
        long long xc = pq.top().first;
        long long x = pq.top().second;
        pq.pop();
        if(xc > cost[x])
        {
            continue;
        }
        for (int i = 0; i < g[x].size(); i++)
        {
            long long y = g[x][i].first;
            long long yc = g[x][i].second;
            if(xc + yc < cost[y])
            {
                cost[y] = xc + yc;
                pq.push(make_pair(xc + yc, y));
            }
        }
    }
}

int main()
{
    cin >> n >> m >> s >> t;
    s--;
    t--;
    acost.resize(n);
    bcost.resize(n);
    ag.resize(n);
    bg.resize(n);
    for (long long i = 0;i < m;i++)
    {
        long long u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        ag[u].push_back(make_pair(v, a));
        bg[u].push_back(make_pair(v, b));
        ag[v].push_back(make_pair(u, a));
        bg[v].push_back(make_pair(u, b));
    }

    dijkstra(s, ag, acost);
    dijkstra(t, bg, bcost);

    for (long long i = 0; i < n; i++)
    {
        comb.push_back(make_pair(acost[i] + bcost[i], i));
    }
    sort(comb.begin(), comb.end());
    long long ansi = comb[0].second;
    long long ansp = 0;
    long long init = 1e15;
    for (long long i = 0; i < n;i++)
    {
        while(i > ansi)
        {
            ansi = comb[++ansp].second;
        }
        cout << init - comb[ansp].first << endl;
    }

    return 0;
}

Measured memory_bytes: 19952
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include<string.h>
#include<limits.h>

int main(){
	char stage[101][101]={'\0'};
	int same_x[10000]={0},same_y[10000]={0};
	int x,y,i,j,k=0,flag=0,m=0;
	
	while((scanf("%d %d",&y,&x))!=EOF){
		if(y==0 && x==0)break;
	for(i=0;i<y;i++)scanf("%s",stage[i]);

	i=0;
	j=0;
	while(stage[i][j]!='.'){
		switch(stage[i][j]){
			case '>':
			same_x[k]=j;
			same_y[k]=i;
			k++;
			j++;
			break;
			
			case '<':
			same_x[k]=j;
			same_y[k]=i;
			k++;
			j--;
			break;
		
			case '^':
			same_x[k]=j;
			same_y[k]=i;
			k++;
			i--;
			break;
		
			case 'v':
			same_x[k]=j;
			same_y[k]=i;
			k++;
			i++;
			break;
		}
		for(m=0;m<k;m++)if(same_x[m]==j && same_y[m]==i){
			flag=1;
		}
		if(flag==1)break;
	}
	if(flag==0)printf("%d %d\n",j,i);
	else printf("LOOP\n");
		flag=0;
		k=0;
	}
	
return 0;
}

Measured memory_bytes: 708
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (ll i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

vector<long long> PrimeFactorization(long long n) {
    vector<long long> res;
    long long t = n;
    for (long long i = 2; i * i <= t; ){
        if (n % i == 0) res.push_back(i), n /= i;
        else i++;
    }
    if(n != 1) res.push_back(n);
    return res;
}

ll pow_t (ll n, ll k) {
    ll ret = 1LL;
    REP(i,k) ret *= n;
    return ret;
}

int main ()
{
    ll N,P; cin >> N >> P;
    vector < ll > prime = PrimeFactorization(P);
    map < ll,ll > cnt;
    REP(i,prime.size()) {
        cnt[prime[i]]++;
    }

    ll ans = 1LL;
    for (auto itr = cnt.begin(); itr != cnt.end(); itr++) {
        ll num = itr->first;
        ll sum = itr->second;
        if (sum / N > 0) {
            ans *= pow_t(num, (sum / N));
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
long long a,b;
scanf("%lld%lld",&a,&b);
if (a<=0 && b>=0){
    printf("Zero");
    return 0;
}
if (b<0 && (b-a+1)%2==1){
    printf("Negative");
}
else printf("Positive");
}


Measured memory_bytes: 256
from operator import itemgetter
n = int(input())
A = []
for i in range(1, n+1):
    tmp = input().split()
    tmp[1] = -int(tmp[1])
    tmp.append(i)
    A.append(tmp)
A = sorted(A, key=itemgetter(0,1))
for i in range(n):
    print(A[i][-1])

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	pair<int, int> X[501];
	int kotae[250001] = {};
	rep1(i, N) {
		cin >> X[i].first;
		X[i].second = i;
		kotae[X[i].first] = i;
	}

	sort(X + 1, X + N + 1);

	queue<pair<int, int>> que;
	rep1(i, N) {
		rep(j, X[i].second - 1) que.push(mp(X[i].second, X[i].first));
	}

	int OK = 1;
	rep1(i, N* N) {
		if (kotae[i] == 0) {
			if (que.size() == 0) {
				OK = 0;
				break;
			}
			auto q = que.front();
			que.pop();
			if (q.second < i) {
				OK = 0;
				break;
			}
			kotae[i] = q.first;
		}
		else {
			rep(j, N - kotae[i]) que.push(mp(kotae[i], 300000));
		}
	}

	if (OK) {
		co("Yes");
		rep1(i, N * N) co(kotae[i]);
	}
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	string s, t;
	cin >> s >> t;
	int l = s.size();
	int cnt = 0;
	rep(i, l) {
		if (s[i] != t[i]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main(){
    int a,b,h; cin >> a >> b >> h;

    int ans = a*h + (b-a)*h/2;
    cout << ans << endl;    
    return 0;
}


Measured memory_bytes: 256
N,A,B = list(map(int,input().split()))
if (B-A)%2 == 0:
    print((B-A)//2)
    exit()
A1 = A
B1 = B
A2 = A
B2 = B
count1 = N-B1
ans1 = 0
A1 += (N-B1)
B1 = N
if (B1-A1)%2 == 0:
    ans1 = count1+(B1-A1)//2
else:
    ans1 = count1+1+(B1-A1)//2

count2 = A2-1
ans2 = 0
B2 -= (A2-1)
A2 = 1
if (B2-A2)%2 == 0:
    ans2 = count2+(B2-A2)//2
else:
    ans2 = count2+1+(B2-A2)//2
print(min(ans1,ans2))

Measured memory_bytes: 3064
import java.util.Scanner

/**
  * Created by 80011714 on 2018/2/5.
  */
object Main {

  def solve(sc: Scanner): Unit = {
    val x, y = sc.nextLong()
    println(if (x % y == 0) (-1) else {
      var i = 1
      while (i * x % y == 0) (i += 1)
      i * x
    })
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 27448
#include <stdio.h>
 
int main()
{
    int N=0;
  	int A[9999999]={0};
  	int x[9999999]={0};
  	scanf("%d",&N);
 	for(int i=0;i<N;i++){
	scanf("%d",&A[i]);
    }
  for(int i=0;i<1;i++){
    int count=0;
    int hoge;
    for(int j=i;j<i+N;j++){
      
      if(j<N){
			hoge=j;      
      }else{
      		hoge=j-N;
      }
      
      if((count%2)==1){
      x[i]=-A[hoge]+x[i];
      }else{
      	x[i]=A[hoge]+x[i];
      }
    	
      count++;
    }
  printf("%d ",x[i]);
  }
  for(int i=1;i<N;i++){
  	x[i]=2*A[i-1]-x[i-1];
    printf("%d ",x[i]);
  }
  return 0;
}

Measured memory_bytes: 79360
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int n;cin>>n;
    V<int> v(n);
    rep(i,n) cin>>v[i];
    int s,t;
    s=t=n/2;
    set<int> ss,tt;
    map<int,int> mp1,mp2;
    for(int i=0;i<n;i++){
        if(i%2!=0){
            ss.insert(v[i]);
            mp1[v[i]]++;
        }else{
            tt.insert(v[i]);
            mp2[v[i]]++;
        }
    }
    int fir=ss.size();
    int sec=tt.size();
    V<pair<int,int>> p(fir),q(sec);
    int b=0;
    for(auto a:ss){
        p[b]=make_pair(s-mp1[a],a);
        b++;
    }
    b=0;
    for(auto a:tt){
        q[b]=make_pair(t-mp2[a],a);
        b++;
    }
    sort(all(p));
    sort(all(q));
    int ans;
    if(p[0].sc!=q[0].sc) ans=p[0].ft+q[0].ft;
    else{
        if(fir==1&&sec==1) ans=n/2;
        else if(fir==1){
            ans=q[1].ft;
        }else if(sec==1){
            ans=p[1].ft;
        }else{
            ans=min(p[0].ft+q[1].ft,p[1].ft+q[0].ft);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10752
$,=$";$k=($K=-<>)&3;print$n=3-$K>>2<<1,~$K?map{map{($t=($'+$_)%$n)+1-($'%2?$k-$n:$t<$n-$k?0:$K+$n)}//..$n}1..$n:(1)x4

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

using namespace std;

using int64 = long long;

int64 Solve() {
  int64 n, a, b;
  cin >> n >> a >> b;

  if (a > b) return 0;

  if (n == 1) {
    if (a == b) return 1;
    else return 0;
  }

  return (b - a) * (n - 2) + 1;

}

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

  cout << Solve() << endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

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

    if((a*b%2) != 0) cout << "Odd" << endl;
    else cout << "Even" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		double max = Double.MIN_VALUE, min = Double.MAX_VALUE;
		String line = "";
		while ((line = br.readLine()) != null) {
			double data = Double.parseDouble(line);
			max = Math.max(max, data);
			min = Math.min(min, data);
		}
		System.out.println(max - min);

	}

}

Measured memory_bytes: 16916
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

vector<string> s;
string SS = "ABC";
vector<int> v;
map<vector<int>, int> mem[(int) 1e5 + 9];
int solve(int idx);
int Try(int idx, int i, int j) {
	v[i]++;
	v[j]--;
	int rt = solve(idx + 1);
	v[i]--;
	v[j]++;
	return rt;
}

int solve(int idx) {
	if (v[0] < 0 || v[1] < 0 || v[2] < 0)
		return false;
	if (idx == sz(s))
		return true;
	auto it = mem[idx].find(v);
	if (it != mem[idx].end())
		return it->second;
	int i = SS.find(s[idx][0]);
	int j = SS.find(s[idx][1]);
	if (Try(idx, i, j))
		return mem[idx][v] = true;
	if (Try(idx, j, i))
		return mem[idx][v] = true;
	return mem[idx][v] = false;
}

void build(int idx) {
	if (idx == sz(s))
		return;
	int i = SS.find(s[idx][0]);
	int j = SS.find(s[idx][1]);
	if (Try(idx, i, j)) {
		cout << s[idx][0] << endl;
		v[i]++;
		v[j]--;
		build(idx + 1);
		return;
	}
	if (Try(idx, j, i)) {
		cout << s[idx][1] << endl;
		v[i]--;
		v[j]++;
		build(idx + 1);
		return;
	}
}

int main() {
	run();
	int n;
	cin >> n;
	v = vector<int>(3);
	for (auto &it : v)
		cin >> it;
	s = vector<string>(n);
	for (auto &it : s)
		cin >> it;
	if (solve(0)) {
		cout << "Yes\n";
		build(0);
	} else
		cout << "No\n";
}


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

int main()
{
    long int n, m;
    cin>> n >>m;

    long int input1,input2;

    map<long int,int>mp;
    bool x = false;
    vector<long int>check;
    for(long int i = 1; i <= m; i++)
    {
        cin>> input1 >> input2;
        if(!x)
        {

        if((input1 == 1)&&(input2 == n))
            x = true;

        else
        {
            if(input1 == 1)
                mp.insert(make_pair(input2,1));

            if(input2 == n)
                check.push_back(input1);

        }
        }
    }

    for(long int i = 0; i < check.size(); i++)
    {
        if(mp.find(check[i]) != mp.end())
        {
            x = true;
            break;
        }
    }

    if(x)
        cout<< "POSSIBLE";
    else
        cout<< "IMPOSSIBLE";

        return 0;
}


Measured memory_bytes: 10336
#include <iostream>

int main() {
  int n = 0, x = 0, tmp = 0;
  
  std::cin >> n;
  
  tmp = n;
  
  for (int i = 0; i < 9; i++) {
    if (i == 0) {
      x += n % 10;
      continue;
    }
    n /= 10;
    x += n % 10;
    if (!n) break;
  }
  
  if(tmp % x) {
    std::cout << "No\n";
    return 0;
  }
  
  std::cout << "Yes\n";
  
  return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

a_max = max(a)
cnt = [0] * (max(a) + 1)
ans = 0

for ai in a:
    for multi in range(ai, a_max + 1, ai):
        cnt[multi] += 1

for ai in a:
    if cnt[ai] == 1:
        ans += 1

print(ans)

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

int main() {
long long ans = 0;
int N,K;
cin >> N >> K;
vector<long long> H(N);
for (int i = 0; i < N; i++)
{
    cin >> H.at(i);
}


sort(H.begin(),H.end());
reverse(H.begin(),H.end());
for (int i = K; i < N; i++)
{
    ans += H.at(i);
}

cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w,a,b;cin >> w >> a >> b;
	if(a+w<b) cout << b-w-a << endl;
	else if(b+w<a) cout << a-w-b << endl;
	else cout << 0 << endl;
}

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

int main()
{
    ll n, m, k;
    string s;
    cin>>s;
    ll ln = s.size();
    if(s[ln - 1] == 's') cout<<s<<"es"<<"\n";
    else cout<<s<<"s"<<"\n";
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
	string s,p;
	string ss;
	cin >> s;
	cin >> p;
	ss = s + s;
	if(ss.find(p) == std::string::npos){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}



Measured memory_bytes: 3216
package main

import (
	"bytes"
	"fmt"
)

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

func main() {
	var str string
	fmt.Scan(&str)

	var q int
	fmt.Scan(&q)
	rev := 0
	var first bytes.Buffer
	var last bytes.Buffer
	for i := 0; i < q; i++ {
		var t int
		fmt.Scan(&t)
		if t == 1 {
			rev++
		}
		if t == 2 {
			var f int
			var c string
			fmt.Scan(&f, &c)

			if (f == 1 && rev%2 == 0) || (f == 2 && rev%2 == 1) {
				first.WriteString(c)
			} else if (f == 2 && rev%2 == 0) || (f == 1 && rev%2 == 1) {
				last.WriteString(c)
			}
		}
	}
	if rev%2 == 1 {
		fmt.Println(reverse(last.String()) + reverse(str) + first.String())
	} else {
		fmt.Println(reverse(first.String()) + str + last.String())
	}
}


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

int main(){
  int a[3], b[2] = {0};
  for(int i=0;i<3;i++){
    cin>>a[i];
  }

  for(int i=0;i<3;i++){
    if(a[i] == 5)b[0]++;
    if(a[i] == 7)b[1]++;
  }

  if(b[0] == 2 && b[1] == 1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int arr[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int input;
	cin >> input;
	cout << arr[input - 1];
	return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc135/tasks/abc135_a
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a;
	cin>>a;
	ll b;
	cin>>b;
	ll k;
	k=(a+b)/2;
	ll chk;
	chk=a+b;
	if(a==b)
	{
		cout<<0<<"\n";
	}
	else
	{
		if(chk%2==0)
		{
			cout<<k<<"\n";
		}
		else
		{
			cout<<"IMPOSSIBLE"<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3616
import heapq
const = 0
left = []
right = []

q = int(input())
cnt = 0
left_sum = 0
right_sum = 0
for _ in range(q):
    t = list(map(int, input().split()))
    if t[0] == 1:
        # update
        a, b = t[1:]
        const += b
        if cnt % 2 == 0:
            if not right:
                heapq.heappush(left, -a)
                left_sum += a
                cnt += 1
                #print(left_sum, right_sum, cnt)
                continue

            c = heapq.heappop(right)
            right_sum -= c
            if a <= c:
                heapq.heappush(left, -a)
                heapq.heappush(right, c)
                left_sum += a
                right_sum += c
            else:
                heapq.heappush(left, -c)
                heapq.heappush(right, a)
                left_sum += c
                right_sum += a
        else:
            c = heapq.heappop(left)
            left_sum += c
            if a <= -c:
                heapq.heappush(left, -a)
                heapq.heappush(right, -c)
                left_sum += a
                right_sum -= c
            else:
                heapq.heappush(left, c)
                heapq.heappush(right, a)
                left_sum -= c
                right_sum += a
        cnt += 1
        #print(left_sum, right_sum, cnt)
    else:
        tmp = -left[0]
        print(tmp, const - left_sum + right_sum + tmp * (cnt % 2))



Measured memory_bytes: 16924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;
// Union find : O(α(V))
// verified : 
class UnionFind {
	typedef size_t U;
	// v[i] : i番目の頂点が根 ? i番目の頂点の属する木のサイズ * -1
	//                       : i番目の頂点の親のindex
	vector<int32_t> v;
public:
	UnionFind(U n) : v(n, -1) {}
	U find(U x) { return v[x] < 0 ? x : (v[x] = find((U)v[x])); }
	bool same(U x, U y) { return find(x) == find(y); }
	U size(U x) { return (U)-v[find(x)]; }
	void unite(U x, U y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}
};

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n, m; cin >> n >> m;
	vl x(n); REP(i, n) cin >> x[i];

	vl y(TEN(5) + 1, 0); REP(i, n) y[x[i]]++;
	vl y_mod(m, 0); REP(i, TEN(5) + 1) y_mod[i % m] += y[i];
	vl y_mod_use(m, 0);
	ll cnt = y_mod[0] / 2;
	FOR(i, 1, m / 2 + m % 2) {
		y_mod_use[i] = y_mod_use[m - i] = min(y_mod[i], y_mod[m - i]);
		cnt += y_mod_use[i];
	}
	if (m % 2 == 0) cnt += y_mod[m / 2] / 2;
	FOR(i, 1, m) if (i * 2 != m) if (y_mod[i] - y_mod_use[i] > 0){

		ll yobun = 0;
		for (ll j = i; j < TEN(5) + 1; j += m) {
			if (y[j] % 2 == 1) yobun++;
		}


		y_mod[i] -= yobun;
		if (yobun < y_mod_use[i]) {
			y_mod[i] -= y_mod_use[i] - yobun;
		}
		cnt += y_mod[i] / 2;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h> 
using namespace std;
char a[100007];
int main()
{
  scanf("%s",a);
  int l=strlen(a),x=0,i;
  for(i=0;i<l;i++)
    if(a[i]=='g')
	  x++;
  printf("%d\n",min(l/2,x)-min(l-l/2,l-x));
  return 0;
}

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

#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define reset(x, y) memset(x, y, sizeof(x))
#define BUG(x) cerr << #x << " = " << (x) << endl
#define BUGP(x) cout << #x << " = " << (x)._1 << ", " << (x)._2 << endl
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
// Head

int a, b, c, n;

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

    cin >> a >> b >> c >> n;

    int ans = 0;
    ans += min(a, n);
    n -= min(a, n);

    n -= min(b, n);

    ans -= min(c, n);

    cout << ans << '\n';
    return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
  return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/12  Problem: 081_arc_c / Link: https://arc081.contest.atcoder.jp/tasks/arc081_c?lang=en  ----- */
/* ------問題------

文字列 S に対して，その文字列を構成する文字を 0 文字以上取り除き，残った文字を元の順番で並べて得られる文字列を S の部分列と呼びます． たとえば，arc や artistic や (空文字列) は artistic の部分列ですが，abc や ci は artistic の部分列ではありません．
英小文字からなる文字列 A が与えられます． このとき，英小文字からなる文字列で，A の部分列ではないようなもののうち，最も短いものを求めてください． ただし，そのようなものが複数ある場合には，辞書順で最小のものを求めてください．

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	string s;
	cin >> s;
	// 長さが最小
	VI alinfo(26, 0);
	VI premin(SZ(s) + 1, 0);
	ans = 1;
	FORR(i, SZ(s) - 1, 0 - 1) {

		LL ret = 0;
		alinfo[s[i] - 'a'] = 1;
		premin[i] = premin[i+1];
		FOR(al, 0, 26) {
			if (alinfo[al])ret++;
			else break;
		}
		if (ret == 26) {
			FOR(al, 0, 26) {
				alinfo[al] = 0;
			}
			ans++;
		}
		premin[i] = ret % 26;

	}
	//FOR(i, 0, 26) {
	//	cout << alinfo[i] << " ";
	//}cout << endl;	
	//debug(ans);
	FOR(i, 0, SZ(s)) {
		char c = 'a' + premin[i];
		cout << c;
		while (i < SZ(s) && s[i] != (c))i++;
	}
	cout << "\n";

	return 0;
}


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

using namespace std;

int main()
{
	string str = "";
	cin >> str;
	string a = str.substr(0, 4);
	string b = str.substr(4);
	cout << a << " " << b << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<cassert>
#include<map>
#include<set>

typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 5000000000000;
//typedef std::pair<int, int> P;
struct edge { int to;double cost; };
#define VMAX 1010

     ll N,K;
     ll A[300000],B,C;
     ll P[11];
     ll ans;

int main() {
    cin>>N;
    EREP(i,N-1){
        ll a;
        cin>>a;
        A[a]++;
    }
    EREP(i,N){
        cout<<A[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5128
#include <iostream>
#include <fstream>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    ll t, a, b, c, d;
    cin >> t;
    for (ll i = 0; i < t; i++) {
        cin >> a >> b >> c >> d;
        ll g = gcd(b, d);
        ll l = (((a - b) % g) + b) - g;
        if (a < b || d < b || c < l) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}


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

signed main() {
    int x;
    cin >> x;
    int ans = 0;
    for (int i=0; i != x+1; i++) {
        if (i % 15 != 0 && i % 5 != 0 && i % 3 != 0) {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, M;
    cin >> N >> M;
    
    if (M == 100) M++;
    switch(N) {
        case 0:
            cout << M << endl;
            break;
        case 1:
            cout << M * 100 << endl;
            break;
        case 2:
            cout << M * 10000 << endl;
            break;
        default:
            break;
    }
}

Measured memory_bytes: 256
n, m, q = gets.chomp.split(" ").map(&:to_i)
abcd = q.times.map { gets.chomp.split(" ").map(&:to_i) }
ans = 0
[*1..m].repeated_combination(n) do |arr|
  score = 0
  abcd.each do |e|
    a, b, c, d = [e[0] - 1, e[1] - 1, e[2], e[3]]
    score += d if arr[b] - arr[a] == c
  end
  ans = [score, ans].max
end
puts ans

Measured memory_bytes: 14804
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
#define MAX_N 18
#define INF 1000000000000
ll dp[1ll<<MAX_N];
ll n;
ll t[MAX_N][MAX_N];
ll f(ll s){
  if(dp[s]!=INF) return dp[s];
  if(s==0){
    return dp[s] = 0;
  }
  ll res = INF;
  for(ll i=0;i<n;i++){
    if(s&(1ll<<i)){
      ll ts = s^(1ll<<i);
      ll tmp = f(ts);
      ll cost = t[i][0];
      for(ll j=0;j<n;j++){
        if(ts&(1ll<<j)){
          cost = min(cost,t[i][j+1]);
        }
      }
      tmp += cost;
      res = min(res,tmp);
    }
  }
  return dp[s] = res;
}
void solve(){
  cin >> n;
  if(n==0) return;
  fill(dp,dp+(1ll<<MAX_N),INF);
  for(int i=0;i<n;i++){
    for(int j=0;j<=n;j++){
      cin >> t[i][j];
    }
  }
  f((1ll<<n)-1);
  cout << dp[(1ll<<n)-1]<<endl;
  solve();
}
signed main(){
  init_io();
  solve();
}



Measured memory_bytes: 5156