akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    int m, n;
    char nn[55][55];
    char mm[55][55];
    cin>>n>>m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin>>nn[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
            cin>>mm[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < n-m; i++){
        if(ans == 1)break;
        for(int j = 0; j < n-m; j++){
            if(nn[i][j] == mm[0][0]){
                int flag = 1;
                for(int k = 0; k < m; k++){
                    if(flag == 0)break;
                    for(int l = 0; l < m; l++){
                        if(nn[i+k][j+l] != mm[k][l]){
                            flag = 0;
                            break;
                        }
                    }
                }
                if(flag == 0)continue;
                else ans = 1;
                break;
            }
            else continue;
        }
    }
    if(n == m){
        int flag = 1;
        for(int i = 0; i < n; i++){
            if(flag == 0)break;
            for(int j = 0; j < m; j++){
                if(nn[i][j] != mm[i][j]){
                    flag = 0;
                    break;
                }
            }
        }
        if(flag == 1)ans = 1;
        else ans = 0;
    }
    if(ans == 1)cout<<"Yes";
    else cout<<"No";


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define MOD 1000000007
typedef long long ll;

int main(){
	int l[] = {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 k;
	scanf("%d", &k);
	k -= 1;
	printf("%d", l[k]);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;

int N,M,Q;

int rec(const auto &v, auto a){
  if(a[N-1]!=0){
    int ans=0;
    for(int i=0;i<Q;i++){
      if(a[v[i][1]-1]-a[v[i][0]-1]==v[i][2]) ans+=v[i][3];
    }
    return ans;
  }else{
    for(int i=0;i<N;i++){
      if(a[i]==0){
        int ans=0;
        for(int j=a[i-1]; j<=M; j++){
          a[i]=j;
          ans=max(ans,rec(v,a));
        }
        return ans;
      }
    }
  }
}

int main(){

  cin >> N >> M >> Q;
  vector<vector<int>> v(Q,vector<int>(4));
  for(int i=0;i<Q;i++){
    cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
  }

  int ans=0;
  vector<int> a(N);
  for(int i=1;i<=M;i++){
    a[0]=i;
    ans=max(ans,rec(v,a));
  }

  cout << ans << endl;


  return 0;
}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

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

const double PI = acos(-1);

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
}


Measured memory_bytes: 3620
#include <cstdio>

using namespace std;

int n, r;
// greater is upper
int D[51];
int X[51];

int main() {
    for (;;) {
        scanf("%d%d", &n, &r);
        if (!n && !r) { break; }

        for (int i = 1; i <= 50; i++) {
            D[i] = i;
        }

        for (int i = 0; i < r; i++) {
            int p, c;
            scanf("%d%d", &p, &c);
            for (int j = 0; j < c; j++) {
                X[j] = D[n - (p - 1) - c + 1 + j];
            }
            for (int j = 0; j < p - 1; j++) {
                D[n - (p - 1) - c + 1 + j] = D[n - (p - 1) - c + 1 + j + c];
            }
            for (int j = 0; j < c; j++) {
                D[n - c + 1 + j] = X[j];
            }
        }

        printf("%d\n", D[n]);
    }
    return 0;
}

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

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

int N, M;
vector<bool> used;
vector<vector<int> > G;

void dfs(int v) {
  if ( used[v] ) return;
  used[v] = true;

  for ( int &u: G[v] ) {
    if ( !used[u] ) dfs(u);
  }
}

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

  cin >> N >> M;
  used.resize(N, false);
  G.resize(N);
  for ( int i = 0; i < M; i++ ) {
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( !used[i] ) {
      ans++;
      dfs(i);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11796
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
signed main(){
    int h,w;
    cin>>h>>w;
    if(h==1||w==1)cout<<1<<endl;
    else if((h*w)%2==0)cout<<(h*w)/2<<endl;
    else cout<<(h*w+1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    double a,b;
    cin>>a>>b;
    if(a>=13)
    {
        cout<<b<<endl;
    }
    else if(a<=12&&a>=6)
    {
        cout<<b/2<<endl;
    }
    else 
    {
        cout<<"0"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
a,b,c=map(float,input().split())
sinc=math.sin(math.radians(c))
cosc=math.cos(math.radians(c))
cc=math.sqrt(a**2+b**2-cosc*2*a*b)
h=sinc*(b/1)
print('{:.8f}'.format(a*h*(1/2)))
print('{:.8f}'.format(a+b+cc))
print('{:.8f}'.format(h))



Measured memory_bytes: 5696
N = int(input())
W = list(map(int, input().split()))
 
S1 = 0
S2 = 0
ans = []
 
for i in range(N-1):
  S1 = sum(W[:i+1])
  S2 = sum(W[i+1:])
  ans.append(abs(S1-S2))
print(min(ans))

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
static const int MAXN = 1e5 + 4;

int n;
int a[MAXN];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

    std::sort(a, a + n);
    int s1 = 0, s2 = 0;
    for (int i = 0; i < n - 1; ++i) if (a[i] == a[i + 1]) {
        s2 = s1; s1 = a[i];
        ++i;
    }

    printf("%lld\n", (long long)s1 * s2);
    return 0;
}


Measured memory_bytes: 512
N, K = map(int, input().split())
sunuke = [0]*(N+1)

for i in range(1, K+1):
    d = int(input())
    A = list(map(int, input().split()))
    for a in A:
#        print(a)
        sunuke[a] = 1
print(N - sunuke.count(1))

Measured memory_bytes: 67588
// Try M-SOLUTIONS プロコンオープン
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    
    let ans = 180 * n - 360;
    
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

typedef struct{
	int original_order;
	int instant_order;
} alphabet_t;

inline void interchangeAlphabet(alphabet_t *a, alphabet_t *b){
	alphabet_t temp = *a;
	*a = *b;
	*b = temp;
}

int main(){
	const long long MOD = 1000000007;
	int N, R, sr, tr;
	alphabet_t *alphabet = new alphabet_t[100000];
	long long *ans = new long long[100];
	long long *factorial = new long long[100000];
	int set_number;

	//0から10万-1の階乗を10億7で割った余りを計算
	factorial[0] = 1;
	for(int n=1; n<100000; n++){
		factorial[n] = n * factorial[n-1] % MOD;
	}

	//各デ−タセットの入力および答えを計算
	for(set_number=0; set_number<100; set_number++){
		//答えを初期化
		ans[set_number] = 0;

		//文字の数を入力
		cin >> N;
		if(N == 0) break;

		//単語を初期化
		for(int i=1; i<=N; i++){
			int index = i-1;
			alphabet[index].original_order = i;
			alphabet[index].instant_order = 0;
		}

		//文字の入れ替え回数を入力
		cin >> R;
		
		for(int r=0; r<R; r++){
			//入れ替える文字の位置を入力
			cin >> sr >> tr;

			//文字の位置を入れ替える
			for(int i=sr; i<tr; i++){
				int index = i-1;
				if(alphabet[index].original_order < alphabet[index+1].original_order) alphabet[index+1].instant_order++;
				else alphabet[index].instant_order--;

				interchangeAlphabet(&alphabet[index], &alphabet[index+1]);
			}

			for(int i=tr-1; i>sr; i--){
				int index = i-1;
				if(alphabet[index].original_order < alphabet[index-1].original_order) alphabet[index-1].instant_order--;
				else alphabet[index].instant_order++;

				interchangeAlphabet(&alphabet[index], &alphabet[index-1]);
			}
		}

		for(int i=1; i<=N; i++){
			int index = i-1;
			ans[set_number] += factorial[N-i] * alphabet[index].instant_order;
			ans[set_number] %= MOD;
		}
	}

	for(int s=0; s<set_number; s++) cout << ans[s] << endl;

	delete[] ans;
	delete[] alphabet;
	delete[] factorial;

	return 0;
}

Measured memory_bytes: 2592
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define mp make_pair
#define pb push_pack
#define LL long long
#define inf 2e9
#define zeros x^(x-1)&x
using namespace std;

int x,s,nr;
int main()
{
    cin>>x;

    int i = 1;
    while (s<x)
    {
        s+=i;
        nr++;
        i++;
    }
    cout<<nr<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n)
{
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p)
  {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0)
    {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}
int main()
{
  int n, m, q;
  cin >> n >> m >> q;
  int a[50], b[50], c[50], d[50];
  rep(i, q)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  int ans = 0;
  for (int i1 = 1; i1 < m + 1; i1++)
  {
    for (int i2 = i1; i2 < m + 1; i2++)
    {
      for (int i3 = i2; i3 < m + 1; i3++)
      {
        for (int i4 = i3; i4 < m + 1; i4++)
        {
          for (int i5 = i4; i5 < m + 1; i5++)
          {
            for (int i6 = i5; i6 < m + 1; i6++)
            {
              for (int i7 = i6; i7 < m + 1; i7++)
              {
                for (int i8 = i7; i8 < m + 1; i8++)
                {
                  for (int i9 = i8; i9 < m + 1; i9++)
                  {
                    for (int i10 = i9; i10 < m + 1; i10++)
                    {
                      int tmp = 0;
                      int A[] = {0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10};
                      for (int j = 0; j < q; j++)
                      {
                        if (A[b[j]] - A[a[j]] == c[j])
                        {
                          tmp += d[j];
                        }
                      }
                      ans = max(ans, tmp);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
int gcd(int x,int y){
	int r;
	if(x%y==0){
		return y;
	}else{
		r=x%y;
		gcd(y,r);
	}
}
int main(){
	int ans,N,hp[100000];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>hp[i];
	}
	ans=hp[0];
	for(int i=1;i<N;i++){
		ans=gcd(ans,hp[i]);	
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for(char c = 'a'; c <= 'z'; c++) {
        vector<int> a(s.size());
        for(int i = 0; i < s.size(); i++) {
            a[i] = s[i] == c ? 1 : -1;
        }
        int max_sum = 0, max_len = 0;
        int max_running_sum = 0, start = 0;
        for(int i = 0; i < a.size(); i++) {
            max_running_sum += a[i];
            if(max_running_sum < a[i]) {
                max_running_sum = a[i];
                start = i;
            }
            if(max_running_sum > max_sum or (max_running_sum == max_sum and i - start + 1 > max_len)) {
                max_sum = max_running_sum;
                max_len = i - start + 1;
            }
            if(max_sum >= 1 and max_len >= 2) {
                cout << start + 1 << " " << i + 1 << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
int main(){

  int d;
  cin>>d;
  for(int cnt=0;cnt<d;cnt++){
    int n,m,ld=0,a[200][200]={};

    if(cnt) cout<<endl;

    cin>>n;
    m=n;

    for(;n>0;){

      for(int i=ld;i<n+ld;i++){
	a[ld][i]=1;
	a[ld+n-1][i]=1;
	a[i][ld]=1;
	a[i][ld+n-1]=1;
      }

      a[ld][ld+1]=0;
      if(n>4) a[ld+1][ld+2]=1;
      n-=4;
      ld+=2;

    }

    for(int i=m-1;i!=-1;i--){
      for(int j=0;j<m;j++) cout<<(a[i][j]?"#":" ");
      cout<<endl;
    }
  }
  return 0;

}



Measured memory_bytes: 3244
// abc062_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll H, W;
    cin >> H >> W;

    ll ans = 1e20;
    REPN(i, 1, H+1){
        ll h = H-i;
        ll a = i * W;
        if (h % 2 == 0 || W % 2 == 0){
            ll b = h * W / 2;
            ans = min(ans, abs(a - b));
        } else {
            ll b = (h * W + min(h, W)) / 2;
            ll c = (h * W - min(h, W)) / 2;
            ans = min(ans, abs(max(a, b) - min(a, c)));
        }
    }

    REPN(i, 1, W+1){
        ll w = W-i;
        ll a = i * H;
        if (w % 2 == 0 || H % 2 == 0){
            ll b = w * H / 2;
            ans = min(ans, abs(a - b));
        } else {
            ll b = (w * H + min(w, H)) / 2;
            ll c = (w * H - min(w, H)) / 2;
            ans = min(ans, abs(max(a, b) - min(a, c)));
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin>>str;
  for(int i=0;i<str.size();i++){
    if(str[i]=='7'){
      cout<<"Yes"<<endl;
      return(0);
    }
  }
  cout<<"No"<<endl;
  return(0);
}

Measured memory_bytes: 3624
from sys import stdin

while True:
    (h, w) = [int(i) for i in stdin.readline().split(' ')]
    if h == 0 and w == 0:
        break

    for i in range(h):
        for j in range(w):
            if (i + j) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')

        print()

    print()

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

int main()
{
    int n;
    int i, j = 0, k = 0;
    
    cin >> n;
    
    int a[n];
    int a1[(n+1)/2], a2[(n+1)/2];
    int b[n];
    
    for(i = 0; i < n; i++) {
        cin >> a[i];
        
        if((i % 2) == 0) {
            a1[j] = a[i];
            j++;
        } else {
            a2[k] = a[i];
            k++;
        }
    }
    
    if((n % 2) == 0) {
        
        for(i = 0; i < n/2; i++) {
            b[i] = a2[(n/2)-1-i];
        }
        for(i = n/2; i < n; i++) {
            b[i] = a1[i-(n/2)];
        }
    } else {
        
        for(j = 0; j < (n+1)/2; j++) {
            b[j] = a1[((n+1)/2)-1-j];
        }
        for(j = (n+1)/2; j < n; j++) {
            b[j] = a2[j-(n+1)/2];
        }
    }
    
    for(k = 0; k < n-1; k++) {
        cout << b[k] << " ";
    }
    
    cout << b[n-1] << "\n";
    
    return 0;
}

Measured memory_bytes: 4480
import collections,sys
def s():
 d=collections.deque()
 input()
 for e in sys.stdin:
  if'i'==e[0]:d.appendleft(e[7:-1])
  else:
   if' '==e[6]:
    m=e[7:-1]
    if m in d:d.remove(m)
   elif len(e)%2:d.pop()
   else:d.popleft()
 print(*d)
s()


Measured memory_bytes: 69736
#include<stdio.h>
#define MAX 1000002
#define MOD 1000000007

long long fac[MAX], finv[MAX], inv[MAX];

void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long f(int n1, int n2){
    return fac[n1+n2] * (finv[n1] * finv[n2] % MOD) % MOD;
}

int main()
{
  int x, y, a=0, b=0;
  scanf("%d %d", &x, &y);
  init();

  for(int i=0; i<=MAX; i++){
    int j = x - 2*i;
    if(y == i+2*j){
      a = i;
      b = j;
    }
  }

  if(a==0 && b==0 || a<0 || b<0){
    printf("0");
    return 0;
  }
  long long ans;
  ans = f(a, b);
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 23552
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	int h, w, n; cin >> h >> w >> n;
	int sr, sc; cin >> sr >> sc;
	string s, t; cin >> s >> t;

	int lpos = 0;
	int rpos = w + 1;
	int upos = 0;
	int dpos = h + 1;
	//cout << lpos << " " << rpos << " " << upos << " " << dpos << endl;

	FOR_DW(i, n - 1, 0) {
		if (i != n - 1) {
			switch (t[i]) {
			case 'U':
				if (dpos <= h) dpos++;
				break;
			case 'D':
				if (1 < upos) upos--;
				break;
			case 'L':
				if (rpos <= w) rpos++;
				break;
			case 'R':
				if (1 < lpos) lpos--;
				break;
			}
		}
		switch (s[i]) {
		case 'U': upos++; break;
		case 'D': dpos--; break;
		case 'L': lpos++; break;
		case 'R': rpos--; break;
		}

		//cout << lpos << " " << rpos << " " << upos << " " << dpos << endl;

		if (rpos <= 1 || w <= lpos || dpos <= 1 || h <= upos) {
			cout << "NO" << endl;
			return 0;
		}
		if (rpos <= lpos || dpos <= upos) {
			cout << "NO" << endl;
			return 0;
		}
	}

	if (sr <= upos || dpos <= sr || sc <= lpos || rpos <= sc) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>

typedef long long LL;

const long long INF = 1LL << 60;

using namespace std;

int main()
{
    int H1, M1, H2, M2, K;

    cin >> H1 >> M1 >> H2 >> M2 >> K;

    M1 += 60 * H1;
    M2 += 60 * H2;

    cout << M2 - M1 - K << endl;

    return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll a,b;
  cin >> a >> b;
  if(a+b>=10) cout << "error" << endl;
  else cout << a+b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, ans, k;
string s, t, a;

void solve(char c){
	if (c >= '2'&&c <= '9'){
		k = c - '0';
	}
	else{
		if (c == 'm'){
			k *= 1000;
		}
		else if (c == 'c'){
			k *= 100;
		}
		else if (c == 'x'){
			k *= 10;
		}
		ans += k;
		k = 1;
	}
}

string changes(int num){
	string res;
	stringstream ss;
	ss << num;
	ss >> res;
	return res;
}

int main(){
	cin >> n;
	REP(i, n){
		cin >> s >> t;
		ans = 0;
		k = 1;
		REP(i, s.size()){
			solve(s[i]);
		}
		REP(i, t.size()){
			solve(t[i]);
		}
		string f[4] = { "", "", "", "" };
		a = changes(ans);
		REP(i, a.size()){
			char c = a[a.size() - 1 - i];
			if (c != '0'){
				if (c != '1')f[i] += c;
				if (i == 0)f[i] += 'i';
				if (i == 1)f[i] += 'x';
				if (i == 2)f[i] += 'c';
				if (i == 3)f[i] += 'm';
			}
		}
		string q = f[3] + f[2] + f[1] + f[0];
		cout << q << endl;
	}
}

Measured memory_bytes: 1236
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string a,b,c;
    int a1,b1,sum=0;
    cin>>a>>b;
    for(int j=0;j<a.size();j++){
      if(a[j]=='m'||a[j]=='c'||a[j]=='x'||a[j]=='i'){
	a[j]=='m'&&(sum+=1000);
	a[j]=='c'&&(sum+=100);
	a[j]=='x'&&(sum+=10);
	a[j]=='i'&&(sum+=1);
      }
      else {
	a[j+1]=='m'&&(sum+=(a[j]-'0')*1000);
	a[j+1]=='c'&&(sum+=(a[j]-'0')*100);
	a[j+1]=='x'&&(sum+=(a[j]-'0')*10);
	a[j+1]=='i'&&(sum+=(a[j]-'0'));
	j++;
      }
    }
    for(int j=0;j<b.size();j++){
      if(b[j]=='m'||b[j]=='c'||b[j]=='x'||b[j]=='i'){
	b[j]=='m'&&(sum+=1000);
	b[j]=='c'&&(sum+=100);
	b[j]=='x'&&(sum+=10);
	b[j]=='i'&&(sum+=1);
      }
      else {
	b[j+1]=='m'&&(sum+=(b[j]-'0')*1000);
	b[j+1]=='c'&&(sum+=(b[j]-'0')*100);
	b[j+1]=='x'&&(sum+=(b[j]-'0')*10);
	b[j+1]=='i'&&(sum+=(b[j]-'0'));
	j++;
      }
    }
    if(sum>=1000){
      if(sum>=2000)cout<<sum/1000;
      cout<<'m';
      sum%=1000;
    }
    if(sum>=100){
      if(sum>=200)cout<<sum/100;
      cout<<'c';
      sum%=100;
    }
    if(sum>=10){
      if(sum>=20)cout<<sum/10;
      cout<<'x';
      sum%=10;
    }
    if(sum>=1){
      if(sum>=2)cout<<sum;
      cout<<'i';
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vl v(n);
	for (ll i = 0; i < n; i++)
		cin >> v[i];
	vl pre(n);
	pre[0] = v[0];
	for (ll i = 1; i < n; i++)
		pre[i] = pre[i - 1] + v[i];
	vector <vl> dp(n, vl (n, 1e15));
	for (ll l = n - 1; l >= 0; l--) {
		for (ll r = l; r < n; r++) {
			if (r == l) {
				dp[l][r] = 0;
				continue;
			}
			for (ll k = l; k < r; k++)
				dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r] + pre[r] - (l > 0 ? pre[l - 1] : 0));
		}
	}
	cout << dp[0][n - 1];
}


Measured memory_bytes: 4468
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  int m;cin>>m;
  int ans = 0;
  while(n){
    n /= m;
    ans++;
  }
  print(ans);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> p;
typedef pair<double, double> dop;
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    std::string s;
    cin >> s;
    int l = s.length();
    int fi = -2;
    int se = -2;
    for (int i = 0; i < 26; i++) {
        int other = 0;
        int target = 0;
        int flag = 0;
        int start = 0;
        for (int j = 0; j < l; j++) {
            if (s[j] == (char)('a' + i)) {
                target++;
                if (target == 1) {
                    start = j;
                }
            } else {
                other++;
            }
            if (other > target) {
                target = 0;
                other = 0;
            }
            if (target > other && target > 1) {
                fi = start;
                se = start + target + other - 1;
                flag = 1;
                break;
            }
        }
        if (flag) {
            break;
        }
    }
    cout << fi + 1 << " " << se + 1 << endl;
    return 0;
}

Measured memory_bytes: 512
n = int(input())
A = list(map(int,input().split()))
color = []
cnt = 0

for i in range(n):
    c = A[i]//400
    if c<=7:
        color.append(c)
    else:
        cnt += 1

diff = set(color)
minimum = max(len(diff),1)
maximum = len(diff)+cnt

print(minimum, maximum)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf (ll)(1e18)
#define mod 1000000007


int main()
{
    int t=1;
    //cin>>t;
    while( t-- )
    {
        int n;
        cin>>n;
        ll a[n];

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

        sort( a,a+n );
        ll ans=0;
        for( int i=0 ; i<n-2 ; i++ )
        {
            for( int j=i+1 ; j<n-1 ; j++ )
            {
                if( a[j]>a[i] )
                {
                    for( int k=j+1 ; k<n ; k++ )
                    {
                        if( a[k]>a[j] && a[i]+a[j]>a[k] )
                        {
                            ans++ ;
                        }
                    }
                }
            }
        }

        cout<<ans;
    }

    return 0;
}












Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define maxn 100010
using namespace std;
char s[maxn], t[maxn];
map<ll, int> need;
int flag = 1;
void check(ll x, int y)
{
	if (need.find(x) != need.end())
	{
		if (need[x] != y) flag = 0;
		return;
	}
	need[x] = y;
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	ll res = n;
	while (res % m) res += n;
	for (int i = 1; i <= n; i++)
		check(res / n * (i - 1), s[i]);
	for (int i = 1; i <= m; i++)
		check(res / m * (i - 1), t[i]);
	if (flag == 0) puts("-1");
	else printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long



signed main() {
   long double x, y;
   cin >> x >> y;

   cout << floor(log2(y)-log2(x))+1 << endl;

  return 0;
}


Measured memory_bytes: 3880
#include <stdio.h> 
int main(void)
{ 
    int a, b, d, r; 
    double f; 
    scanf("%d %d", &a, &b); 
    d=a/b; 
    r=a%b; 
    f=(double)a/(double)b; 
    printf("%d %d %f\n", d, r, f); 
    return 0; 
} 



Measured memory_bytes: 2048
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

struct Vec{
	int ind;
	int val;
};

bool valDesc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val> right.val: left.val > right.val;
}

bool valAsc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val <  right.val: left.val < right.val;
}
int main(void){
	int w;
	
	string S,T,tmp;
	vector<int> stable;
	cin >> S;
	cin >> T;
	for(int i=0;i<S.size();i++){
		S = S.substr(S.size()-1) + S.substr(0,S.size()-1);
		if(S == T){
			printf("Yes\n");
			fflush(stdout);
			return 0;
		}
	}
	printf("No\n");
	fflush(stdout);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7;
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
int main(){
  string S;
  cin>>S;
  ll K;
  cin>>K;
  
  vector<string>date;
  
  for(ll i=1;i<=min(K,S.size());i++){//iは範囲の大きさ
    for(ll j=0;j<S.size();j++){//範囲の初項
      if(j+i-1<S.size()){
     
    date.push_back(S.substr(j,i));
      }
    }
  }
  sort(date.begin(),date.end());
unique(date.begin(),date.end());
  
  cout<<date[K-1]<<endl;
}


Measured memory_bytes: 1660
#include<stdio.h>
int main(){
  int n,m,i,i1,i2,i3,i4,i5,i6,i7,e,a[7],b[7];
  while(scanf("%d",&n),n){
    int d[7]={0};
    int c[1001]={0};
    for(i=0;i<n;i++)scanf("%d %d",&a[i],&b[i]);
    for(i1=0;i1<=b[0];i1++){
      for(i2=0;i2<=b[1];i2++){
	for(i3=0;i3<=b[2];i3++){
	  for(i4=0;i4<=b[3];i4++){
	    for(i5=0;i5<=b[4];i5++){
	      for(i6=0;i6<=b[5];i6++){
		for(i7=0;i7<=b[6];i7++){
		  e=i1*a[0]+i2*a[1]+i3*a[2]+i4*a[3]+i5*a[4]+i6*a[5]+i7*a[6];
		  if(e<1001)c[e]++;
		  if(n<7)break;
		}
		if(n<6)break;
	      }
	      if(n<5)break;
	    }
	    if(n<4)break;
	  }
	  if(n<3)break;
	}
	if(n<2)break;
      }
    }
    scanf("%d",&n);
    while(n--){
      scanf("%d",&m);
      printf("%d\n",c[m]);
    }
  }
  return 0;
}

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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int dfs(int last, int depth, vector<int>nowa);

int n, m, q;
vector<int> a, b, c, d;

int main(){
    cin >> n >> m >> q;
    rep(i, q){
        int A, B, C, D;
        cin >> A >> B >> C >> D;
        a.push_back(A);
        b.push_back(B);
        c.push_back(C);
        d.push_back(D);
    }

    int maxim=0;
    rep(i, n){
        vector<int> nowa;
        nowa.push_back(i+1);
        int score = dfs(i+1, 0, nowa);
        maxim = max(maxim, score);
    }
    // vector<int> nowa;
    // nowa.push_back()
    // int maxim = dfs(1, 1, nowa);
    cout << maxim << endl;
    return 0;
}

int dfs(int last, int depth, vector<int>nowa){
    int maxim=0, score=0;
    if(depth==n){
        rep(i, q){
            if(nowa[b[i]-1]-nowa[a[i]-1]==c[i]){
                score += d[i];
            }
        }
        //cout << nowa.size() << endl;
        return score;
    }else{
        rep2(i, last, m+1){
            nowa.push_back(i);
            score = dfs(i, depth+1, nowa);
            nowa.pop_back();
            maxim = max(maxim, score);
        }
        return maxim;
    }
}

Measured memory_bytes: 3608
n = gets.to_i
as = gets.split.map(&:to_i)

count_h = Hash.new(0)
as.each do |a|
  count_h[a] += 1
end

all_count = count_h.map { |k, v| v * (v - 1) / 2 }.inject(:+)

as.each do |a|
  puts all_count - (count_h[a] - 1)
end


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

using ld = long double;

using point = complex<ld>;

constexpr ld pi = acos(-1.0);

point rot(point p, ld theta) {
    ld x = real(p), y = imag(p);
    return point(x*cos(theta)-y*sin(theta), x*sin(theta)+y*cos(theta));
}

int main() {
    int N;
    ld D;
    while(cin >> N >> D, N) {
        point now(0, 0);
        ld ang = 0;
        for(int i=0; i<N; ++i) {
            ld l, r, t;
            cin >> l >> r >> t;
            l = 2*pi * l / 360, r = 2*pi * r/360;
            ld ang2 = (l-r) / (2*D) * t;
            if(l == r) {
                now += rot(point(0, t*l), ang);
            } else {
                point v((l+r)/(l-r) * D * (1 - cos(ang2)), (l+r)/(l-r) * D * sin(ang2));
                v = rot(v, ang);
                now += v;
                ang -= ang2;
            }
        }
        cout << fixed << setprecision(10) << real(now) << '\n' << imag(now) << endl;
    }
}


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

int main()
{
    ll n, ans = 0, cnt = 0;
    cin >> n;
    ll h[n];
    rep(i, n) cin >> h[i];
    rep(i, n - 1)
    {
        if (h[i] >= h[i + 1])
            cnt++;
        if (h[i] < h[i + 1] || i == n - 2)
        {
            // cout << h[i] << h[i + 1] << endl;
            if (cnt > ans)
                ans = cnt;

            cnt = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4408
#include <limits.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <functional>
#include <algorithm>

using namespace std;


typedef long	DWORD;
typedef unsigned long U_DWORD;
typedef long long QWORD;
typedef unsigned long long U_QWORD;
typedef short WORD;
typedef unsigned short U_WORD;
typedef bool	BOOL;
typedef pair<U_DWORD, U_DWORD> PAIR;

#define N_MAX		(1<<20)

DWORD N;
DWORD A[N_MAX];
int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif

	DWORD res = 0;
	DWORD left = 0, right = 0;
	DWORD sum = 0;
	cin >> N;

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

	while (left < N) {
		while (right < N && ((sum ^ A[right]) == (sum + A[right]))) {
				sum += A[right];
				right ++;
				res += right - left;
		}
		
		if (left == right) {
			right ++;
			left ++;
		}	else {
			sum -= A[left];
			left ++;
		}
	}

	cout << res << endl;	

	return 0;

}

Measured memory_bytes: 1792
n,k = [int(i) for i in input().split()]
s = input()

if s[0] == "1":
    retu = "whiteblack"
else:
    retu = "blackwhite"


count = 0
pre_person = s[0]
groups = []
for i in range(n):
    person = s[i]

    if person != pre_person:
        groups.append(count)
        count = 0
        pre_person = person
    count += 1
groups.append(count)


maxscore1 = 0
if retu == "whiteblack":
    score1 = 0
    blackgroups = len(groups)//2
    if k < blackgroups:
        start_index = 1
        score1 = groups[start_index-1]
        for j in range(k):
            score1 += groups[start_index+2*j]
            if start_index + 2*j+1 < len(groups):
                score1 += groups[start_index+2*j+1]
        maxscore1 = max(score1, maxscore1)
        for i in range(blackgroups - k):
            score1 -= groups[start_index + 2*i - 1]
            score1 -= groups[start_index + 2*i]
            score1 += groups[start_index + 2*k +2*i]
            if start_index+2*k+1+2*i < len(groups):
                score1 += groups[start_index + 2 * k +1 + 2 * i]
            maxscore1 = max(score1, maxscore1)
    else:
        maxscore1 = n

else:
    score1 = 0
    blackgroups = len(groups) - len(groups)//2
    if k < blackgroups:
        start_index = 0
        score1 = 0
        for j in range(k):
            score1 += groups[start_index+2*j]
            if start_index + 2*j+1 < len(groups):
                score1 += groups[start_index+2*j+1]

        maxscore1 = max(score1, maxscore1)
        for i in range(blackgroups - k):
            if i >=1:
                score1 -= groups[start_index + 2*i - 1]
            score1 -= groups[start_index + 2*i]
            score1 += groups[start_index + 2*k +2*i]
            if start_index+2*k+1+2*i < len(groups):
                score1 += groups[start_index + 2 * k + 1 + 2 * i]

            maxscore1 = max(score1, maxscore1)
    else:
        maxscore1 = n

print(maxscore1)

Measured memory_bytes: 4212
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1000000007;

ll rec(ll n, vvll& dist, vvll& dp, ll s, ll v) {
  if (dp[s][v] != -1) return dp[s][v];

  if (s == (1 << v)) {
    return dp[s][v] = INF;
  }

  ll ans = INF;
  ll prevs = s & ~(1 << v);
  rep(i, n) {
    bool conda = (prevs & (1 << i)) > 0;
    bool condb = (dist[i][v] != INF);
    bool cond = conda && condb;
    if (!cond) continue;
    ll tmp = min(INF, rec(n, dist, dp, prevs, i) + dist[i][v]);
    chmin(ans, tmp);
  }  // i

  return (dp[s][v] = ans);
}

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

  vvll dist(n, vll(n, INF));
  vvll dp(1 << n, vll(n, -1));

  rep(i, m) {
    ll s, t, d;
    cin >> s >> t >> d;
    dist[s][t] = d;
  }

  ll ans = INF;
  dp[1][0] = 0;
  rep(i, n) {
    if (i == 0) continue;
    ll tmp = rec(n, dist, dp, ((1 << n) - 1), i) + dist[i][0];
    chmin(ans, tmp);
  }

  if (ans == INF) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}



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

int main() {
  int n,m;
  while (cin >> n >> m, n) {
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int ans = -1;
    REP(i,n) rep(j,i+1,n) {
      int tmp = a[i]+a[j];
      if (tmp > m) continue;
      ans = max(ans,tmp);
    }
    if (ans < 0) cout << "NONE" << endl;
    else cout << ans << endl;
  }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  cin>>k;
  string s;
  cin>>s;
  int n=s.length();
  if(n<=k)
    cout<<s<<endl;
  else
    cout<<s.substr(0,k)+"..."<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;



signed main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a + 3);
    if (a[0] + a[1] == a[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int S1 = A * B;
  int S2 = C * D;
  if (S1 > S2) {
    cout << S1 << endl;
  } else {
    cout << S2 << endl;
  }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    println!("{}", match &*s {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        _ => 1
    });
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin>>n;
  int t[n+1],x[n+1],y[n+1]; t[0]=0,x[0]=0,y[0]=0;
  for(int i=1;i<n+1;i++) cin>>t[i]>>x[i]>>y[i];
  for(int i=0;i<n;i++){
    int d=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    int u=t[i+1]-t[i];
    if(d>u||(d<u&&(u-d)%2)){cout<<"No"; return 0;}
  }
  cout<<"Yes";
}

Measured memory_bytes: 4720
n = int(input())
ws = list(map(int, input().split()))
a = [w for w in ws]

for i in range(1, n):
    a[i] = ws[i] + a[i - 1]
print(min([abs(a[i] - (a[-1] - a[i])) for i in range(1, n)]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ((A == B && B != C) || (A != B && B == C) || (A == C && B != C)){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

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

const int N = 100;

long long a[N], p[N], n, x, y;

int main() {
	cin >> x >> y;
	for (long long i = 2; i * i <= y; i++) {
		if (y % i == 0) {
			n++;
			p[n] = i;
			while (y % i == 0)
				a[n]++, y /= i;
		}
	}
	if (y > 1) {
		n++;
		a[n] = 1;
		p[n] = y;
	}
	long long res = 1;
	for (long long i = 1; i <= n; i++) {
		long long tmp = a[i] / x;
		for (int j = 1; j <= tmp; j++)
			res *= p[i];
	}
	cout << res;
	return 0;
}


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

signed main() {
  int N;
  cin >> N;
  vector<int> a(N + 1, 0), ans(N + 1, 0), A;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  for (int i = N; i >= 1; i--) {
    int sum = 0;
    for (int j = 2 * i; j <= N; j += i) {
      sum += ans[j];
    }
    if (sum % 2 != a[i]) {
      ans[i] = 1;
      A.push_back(i);
    }
  }

  cout << A.size() << endl;
  for (int i = 0; i < A.size(); i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << A[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 5108
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by DELL on 2017/7/15.
 */
public class Main {
    public static void main(String[] args) {

        Scanner in=new Scanner(System.in);
        long sum=0,j=0;
        List<Long> list=new ArrayList();
        BigInteger min;
        int N=in.nextInt();
        for (int i = 0; i < N; i++) {
            list.add(in.nextLong());
        }
        long summ=list.parallelStream().mapToLong(x->x).sum();
        sum+=list.get(0);
        if(N>2){
            min=BigInteger.valueOf(Math.abs(2*sum-summ));
        for (int i = 1 ; i <N-1 ; i++) {
            sum+=list.get(i);
            if(BigInteger.valueOf(Math.abs(2*sum-summ)).compareTo(min)==-1){
                min=BigInteger.valueOf(Math.abs(2*sum-summ));
            }
        }
            System.out.println(min);
        }
        else System.out.println(Math.abs(list.get(0)-list.get(1)));



    }

}


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

int main() {
  long long N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  
  cout << (N+min({A,B,C,D,E})-1)/min({A,B,C,D,E}) + 4LL << endl;

  return 0;
}


Measured memory_bytes: 256