akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<int> color(3);
  for(int i = 0; i < 3; i++){
    color[i] = -1;
  }

  vector<int> A(N);
  ll ans = 1;
  ll MOD = 1000000007;

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

  int cnt = 0;

  for(int i = 0; i < N; i++){
    cnt = 0;
    for(int j = 0; j < 3; j++){
      if(color[j] == (A[i]-1)){
        cnt++;
      }
    }

    bool nfind_1 = true;
    for(int j = 0; j < 3; j++){
      if(color[j] == (A[i]-1) && nfind_1){
        color[j] = A[i];
        nfind_1 = false;
      }
    }

    ans = (ans * cnt) % MOD;

  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
  int a,b;
  for(int i=0; i<=3; i++){
      cin>>a>>b;
      if(a==1){
          cout<<6000*b<<endl;
      }
     else if(a==2){
         cout<<4000*b<<endl;
     }
     else if(a==3){
         cout<<3000*b<<endl;
     }
     else if(a==4){
         cout<<2000*b<<endl;
     }
  }
        return 0;
  }



Measured memory_bytes: 3100
n = int(input())
a = list(map(int, input().split()))
a2 = [0] * (n + 1)
d = [1] * (n + 1)
ans = 1
a2[0] = sum(a)
for i in range(n):
    a2[i + 1] = a2[i] - a[i + 1]
for i in range(n):
    if d[i] - a[i] <= 0:
        ans = -1000000000000
    if (d[i] - a[i]) * 2 >= a2[i]:
        d[i + 1] = a2[i]
    else:
        d[i + 1] = (d[i] - a[i]) * 2

if ans < 0:
    ans = -1
elif d[n] != a[n]:
    ans = -1
else:
    ans = sum(d)
print(ans)


Measured memory_bytes: 649088
n,l = map(int,input().split())
c = [l+i-1 for i in range(1,n+1)]
k = sum(c) #n elements
z = []
for i in range(len(c)):
    z.append(k-c[i])  #n-1 elements
l = []
for i in range(len(z)):
    l.append(abs(k-z[i]))
print(z[l.index(min(l))])


Measured memory_bytes: 38448
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  int candies[2][n];
  for(int i=0;i<2;i++){
  	for(int j=0;j<n;j++){
  		cin>>candies[i][j];
  	}
  }
  vector<int>outcomes;
  int sum = 0,ans = 0;
  for(int i=0;i<n;i++){
  	sum+=candies[0][i];
  	int way = sum;
  	for(int j=i;j<n;j++){
  		way+=candies[1][j];
  	}
  	ans=max(ans,way);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	m := map[int]int{0: 1}
	sum := 0
	for i := 0; i < N; i++ {
		sum += ReadInt()
		m[sum]++
	}
	ans := 0
	for _, c := range m {
		if c >= 2 {
			ans += (c * (c - 1)) / 2
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 13872
def judge_equality(lhs:int, rhs:int) -> None:
    if lhs < -1000:
        raise ValueError('Parameter lhs is less than -1000.')
    if lhs > 1000:
        raise ValueError('Parameter lhs is larger than 1000.')
    if rhs < -1000:
        raise ValueError('Parameter rhs is less than -1000.')
    if rhs > 1000:
        raise ValueError('Parameter rhs is larger than 1000.')

    if lhs < rhs:
        print('a < b')
    elif lhs > rhs:
        print('a > b')
    else:
        print('a == b')

if __name__ == "__main__":
    in_str = input()
    in_str = in_str.split()
    a = int(in_str[0])
    b = int(in_str[1])
    judge_equality(a, b)



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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int L,R,d;
cin>>L>>R>>d;
int cnt=0;
reps(i,R+1,L){
    if(i%d==0)cnt++;
}
cout<<cnt<<endl;
return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>

using namespace std;

int main()
{
	
	int a[10];
	for (int i =0; i<6; i++) cin >> a[i];
	
	for (int i = 0; i<5; i++)
	{
		
		for (int j = i+1; j<5; j++)
		{
			if (a[j]-a[i] > a[5])
			{
				cout << ":(" <<endl;
				return 0;
			}
		}
	}
	
	cout << "Yay!" << endl;
	return 0;
	
		
	
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n+1);
    rep(i, n) cin >> a[i+1];

    vec b(n+1);
    int m = 0;

    for (int i = n; i >= 1; --i) {
        int cnt = 0;
        int j = i + i;
        while (j <= n) {
            cnt += b[j];
            j += i;
        }
        if (cnt % 2 != a[i] % 2) {
            b[i] = 1;
            m++;
        }
    }

    vec c;
    rep(i, n) if (b[i+1]) c.push_back(i+1);

    cout << m << endl;
    if (c.size() == 0) exit(0);
    rep(i, c.size()) {
        if (i != 0) cout << " ";
        cout << c[i];
    }
    cout << endl;
    return 0;
}

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

struct vertex {
  int d;
  int f;
  int k;
  int visited;
  int *vlist;
};

struct vertex *adj;
int t;

void dfs(int id);

int main(int argc, char *argv[])
{
  int n, i, j, id;

  t = 0;

  scanf("%d", &n);
  adj = (struct vertex *)malloc(sizeof(struct vertex) * (n + 1));

  for (i = 0; i < n; i++) {
    scanf("%d", &id);
    scanf("%d", &(adj[id].k));
    adj[id].vlist = (int *)malloc(sizeof(int) * adj[id].k);
    adj[id].visited = 0;
    adj[id].d = 0;
    adj[id].f = 0;
    for (j = 0; j < adj[id].k; j++) scanf("%d", &(adj[id].vlist[j]));
  }


  for (i = 1; i <= n; i++) {
    if (adj[i].d == 0) dfs(i);
  }

  for (i = 1; i <= n; i++) printf("%d %d %d\n", i, adj[i].d, adj[i].f);

  return 0;
}

void dfs(int id)
{
  int current = id;

  t++;
  if (adj[id].d == 0) adj[id].d = t;

  while (adj[id].visited != adj[id].k) {
    current = adj[id].vlist[adj[id].visited++];
    if (adj[current].d == 0) dfs(current);
  }

  t++;
  if (adj[id].f == 0) adj[id].f = t;
}

Measured memory_bytes: 600
c2,c3 = 0,0
def ret(a,b,c):
  global c2,c3
  if a == b:
    if c == 2:
      c2 += 1
    else:
      c3 += 1
    if b == "0":
      return "1"
    else:
      return "0"
  else:
    return b
S = input()
S2,S3 = list(S),list(S)
default = S2[0]
for j,k in enumerate(S2):
  if j == 0:
    continue
  S2[j] = ret(S2[j-1],k,2)
for j,k in enumerate(S3):
  if j == 0:
    S3[0] = ret(default,S3[0],3)
  S3[j] = ret(S3[j-1],k,3)
print(c2 if c2 <= c3 else c3)

Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll p=998244353ll;
const int N=200005;
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
multiset<int>S;
int main(){
	int n,i,a;multiset<int>::iterator it;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%d",&a);
		if((it=S.lower_bound(a))!=S.begin())S.erase(--it);
		S.insert(a);
	}
	printf("%d",S.size());
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int H = in.nextInt();
        int W = in.nextInt();

        while (H != 0 && W != 0) {
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();

            H = in.nextInt();
            W = in.nextInt();
        }
        System.exit(0);
    }
}



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

ll lcm(ll x, ll y){
    if(x == 0 || y == 0)
        return 0;
    return (x * y / __gcd(x, y));
}

int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    
    ll ans = B - B/C - B/D + B/(lcm(C, D));
    ans -= (A - 1 - (A-1)/C - (A-1)/D + (A-1)/(lcm(C, D)));

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int x;
    cin >> x;
    if(x == 3 || x == 5 || x == 7) cout << "YES" ;
    else cout << "NO";
}

Measured memory_bytes: 256
import std.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.string;

long [] a;
long [] b;
long [] c;

struct Summand
{
	int u;
	int v;
	int w;

	@property auto value () const
	{
		return a[u] + b[v] + c[w];
	}

	@property auto id () const
	{
		return (u << 20) | (v << 10) | w;
	}

	int opCmp () (const auto ref Summand that) const
	{
		if (this.value != that.value)
		{
			return (this.value < that.value) -
			    (this.value > that.value);
		}
		return (this.id > that.id) - (this.id < that.id);
	}
}

void main ()
{
	int x, y, z, k;
	while (readf (" %s %s %s %s", &x, &y, &z, &k) > 0)
	{
		readln;
		a = readln.splitter.map !(to !(long)).array;
		b = readln.splitter.map !(to !(long)).array;
		c = readln.splitter.map !(to !(long)).array;
		sort !(q{a > b}) (a);
		sort !(q{a > b}) (b);
		sort !(q{a > b}) (c);

		auto t = redBlackTree !(Summand) ();
		t.insert (Summand (0, 0, 0));
		foreach (p; 0..k)
		{
			auto cur = t.front;
			writeln (cur.value);
			t.removeFront ();
			if (cur.u + 1 < x)
			{
				t.insert (Summand (cur.u + 1, cur.v, cur.w));
			}
			if (cur.v + 1 < y)
			{
				t.insert (Summand (cur.u, cur.v + 1, cur.w));
			}
			if (cur.w + 1 < z)
			{
				t.insert (Summand (cur.u, cur.v, cur.w + 1));
			}
		}
	}
}


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

long long r,l;

int main()
{
	cin >> r >> l;
	if(r <= 1 || l <= 1)
	{
		puts("1");
		return 0;
	}
	cout << (long long)r/2*l+r%2*((l+1)/2) << endl;
	return 0;
}

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

using namespace std;

int main() {
     
     int col[8];
     memset(col, 0, sizeof(col));
     int ec = 0;
     int n;
     cin>>n;
     for(int i=0;i<n;i++)
     {   
          int a;
          cin>>a;
          if(a<400)
          {     col[0]=1;
//          cout<<i<<"\n"; 
          }
          else if(a<800)
          {     col[1]=1;
//          cout<<i<<"\n"; 
          }
          else if(a<1200)
          {     col[2]=1; 
//          cout<<i<<"\n"; 
          }
          else if(a<1600)
          {     col[3]=1; 
//          cout<<i<<"\n"; 
          }
          else if(a<2000)
          {     col[4]=1; 
//          cout<<i<<"\n"; 
          }
          else if(a<2400)
          {     col[5]=1; 
//          cout<<i<<"\n"; 
          }
          else if(a<2800)
          {     col[6]=1; 
//          cout<<i<<"\n"; 
          }
          else if(a<3200)
          {     col[7]=1; 
//          cout<<i<<"\n"; 
          }
          else if(a>=3200)
          {     ec++; 
//          cout<<"ec"<<"\n";   
          }
     }
     int ans_min=0;
     for(int i=0;i<8;i++)
     {
          if(col[i]!=0)
               ans_min++;
     }

     int ans_max=ans_min+ec;
     
     if (ec==n)
          ans_min=1;
     
     cout<<ans_min<<" "<<ans_max;
    
     return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll a,b;
    cin>>a>>b;
    if ((a*b)&1)
        cout<<"Odd\n";
    else
        cout<<"Even\n";
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n, k;
  cin >> n >> k;
  vector<bool> S(n);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      a--;
      S[a] = true;
    }
  }

  int res = 0;
  for (int i = 0; i < n; i++) {
    if (!S[i]) {
      res++;
    }
  }
  cout << res << "\n";
  return 0;
}

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

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

    int player = 0, point = -1;

    for (int i = 0; i < n; i++){
        int a, p;
        cin >> a >> p;
        if (player < a){
            player = a;
            point = p;
        }
    }
    player += point;
    cout << player << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
st=[list(map(int,input().split())) for i in range(M)]
way=[[] for i in range(N)]
for s,t in st:
    way[s-1].append(t-1)
dp=[0]*N
dp_reducable=[0]*N
pr=[0]*N
pr[0]=1
for i in range(N-1,-1,-1):
    l=len(way[i])
    if l>1:
        MAX=0
        x=0
        for j in way[i]:
            x+=dp[j]
            if dp[j]>MAX:
                MAX=dp[j]
        x_r=(x-MAX)/(l-1)+1
        x=x/l+1
        x_r=x-x_r
    elif l==0:
        continue
    else:
        x=dp[way[i][0]]+1
        x_r=0
    dp[i]=x
    dp_reducable[i]=x_r
    i=N-1-i-1
    l=len(way[i])
    for j in way[i]:
        pr[j]+=pr[i]/l
print(dp[0] - max(p * r for p, r in zip(pr, dp_reducable)))

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

int main()
{
     //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    char s[3];
    scanf("%s",&s);
    if(s[0]=='S' && s[1]=='S' && s[2]=='S')cout<<0<<endl;
    else if(s[0]=='R' && s[1]=='S' && s[2]=='R' || s[0]=='S' && s[1]=='R' && s[2]=='S' || s[0]=='S' && s[1]=='S' && s[2]=='R' || s[0]=='R' && s[1]=='S' && s[2]=='S')cout<<1<<endl;
    else if(s[0]=='R' && s[1]=='R' && s[2]=='S' || s[0]=='S' && s[1]=='R' && s[2]=='R')cout<<2<<endl;
    else if(s[0]=='R' && s[1]=='R' && s[2]=='R')cout<<3<<endl;
}


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

LL cao(LL h,LL w) {
  LL maxs,mins,s1,s2,s3,a,b,ans = h * w,c;
  if (w & 1) a = w / 2 + 1,b = w - a;
  else a = b = w / 2;
  for (LL i = 1; i < h; ++i) {
    s1 = a * i,s2 = b * i,s3 = h * w - s1 - s2;
    maxs = max({s1,s2,s3});
    mins = min({s1,s2,s3});
    ans = min(maxs - mins,ans);
    s1 = a * i,s2 = b * h,s3 = h * w - s1 - s2;
    maxs = max({s1,s2,s3});
    mins = min({s1,s2,s3});
    ans = min(maxs - mins,ans);
  }
  a = b = c = w / 3;
  ans = min(ans,h);
  return ans;
}
int main() {
  LL h,w,ans;
  scanf("%lld%lld",&h,&w);
  ans = h * w;
  if (h % 3 == 0 || w % 3 == 0) printf("0\n");
  else {
    ans = cao(h,w);
    ans = min(ans,cao(w,h));
    printf("%lld\n",ans);
  }
}
    


Measured memory_bytes: 256
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
import itertools
p = list(itertools.permutations(range(1,N+1),N))
a=0
b=0
for i in range(len(p)):
    if P==p[i]:
        a=i
    if Q==p[i]:
        b=i
print(abs(a-b))

Measured memory_bytes: 45168
import java.util.*;
public class Main{
static int A= 0;
static int B= 0;
static int C= 0;
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		A=sc.nextInt();
		B=sc.nextInt();
		C=sc.nextInt();
		int t=A-B;
		int ans =C-t;
		if(ans<0) {
			System.out.println("0");
		}else {
		System.out.println(ans);
		}

}
}


Measured memory_bytes: 22740
//
//  main.cpp
//  ALDS1_8_A

#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
struct Node{
    int key;
    Node *right,*left,*parent;
};
Node *root,*NIL;
void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z=(Node *)malloc(sizeof(Node));
    z->key =k;
    z->left = NIL;
    z->right = NIL;
    
    while(x!=NIL){
        y=x;
        if(z->key < x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NIL){
        root=z;
    }else{
        if(z->key < y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}
void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
int main(int argc, const char * argv[]) {
    int n,x;
    string com;
    scanf("%d",&n);
    rep(i,n){
        cin>>com;
        if(com=="insert"){
            scanf("%d",&x);
            insert(x);
        }else if(com=="print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 26656
#include<stdio.h>

int main(){

  int a,b,c,k;
  scanf("%d%d%d%d",&a,&b,&c,&k);

  if(k<=a){
    printf("%d",k);
  }else if(k>a && k<=a+b){
    printf("%d",a);
  }else{
    printf("%d",a+(k-a-b)*(-1));
  }


  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include <string.h>
#include <numeric>

using namespace std;

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

int main(){
    ll n,m,x,y;cin>>n>>m>>x>>y;
    ll aaaa;
    vi vx,vy;
    rep(i,n){
        cin>>aaaa;
        vx.pb(aaaa);
    }
    rep(i,m){
        cin>>aaaa;
        vy.pb(aaaa);
    }
    sort(all(vx));
    sort(all(vy));
    if(vx[vx.size()-1]<vy[0] && y>=vy[0] && x<=vx[vx.size()-1]){
        cout<<"No War"<<endl;
    }else{
        cout<<"War"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
n=int(input())
a=list(map(int,input().split()))
money=1000
kabu=0
flg=0
first=True
if a[1]-a[0]>=0:
    flg="+"
else:
    flg="-"
x=a[1]

if len(a)==2:
    if a[1]>a[0]:
        kabu+=money//a[0]
        money-=a[0]*(money//a[0])
        money+=kabu*a[1]
    print(money)
    sys.exit()

for i , y in enumerate(a[2:],2):
    if flg=="+"  and y-x>=0:
        x=y
    elif flg=="-" and y-x<=0:
        x=y
    elif flg=="+" and y-x<0:
        x=y
        if first:
            kabu+=money//a[0]
            money-=a[0]*(money//a[0])
            first=False
        flg="-"
        money+=kabu*a[i-1]
        kabu=0
    elif flg=="-" and y-x>0:
        x=y
        if first:
            first=False
        flg="+"
        kabu+=money//a[i-1]
        money-=a[i-1]*(money//a[i-1])
    # print(flg,money,kabu)

if kabu!=0:
    if flg=="+":
        money+=kabu*a[-1]
    elif flg=="-":
        X=a[-1]
        for Y in a.reverse()[1:]:
            if X<=Y:
                X=Y
            else:
                money+=kabu*Y
                break

if first:
    if a[-1]>a[0]:
        kabu+=money//a[0]
        money-=a[0]*(money//a[0])
        money+=kabu*a[-1]

print(money)

Measured memory_bytes: 9332
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int len = sz(s);
  vi m3(len+1,0);
  int k=1;
  drep(i,len) {
    int x = (s[i]-'0')*k%3;
    m3[i] = (m3[i+1]+x) % 3;
    k *= 10;
    k %= 3;
  }
  vi m673(len+1,0);
  k=1;
  drep(i,len) {
    int x = (s[i]-'0')*k%673;
    m673[i] = (m673[i+1]+x) % 673;
    k *= 10;
    k %= 673;
  }
  vvi mm673(673);
  rep(i,len+1) {
    mm673[m673[i]].push_back(i);
  }
  ll ans = 0;
  rep(k,673) {
    if(sz(mm673[k])==0) continue;
    vi cnt(3,0);
    for(int i: mm673[k]) {
      ans += cnt[m3[i]];
      cnt[m3[i]]++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

const int N = 5e5+15;
const int mod = 1e9+7;
const int M = (1<<22);
int A[N];

int add(int x,int y) {
    return (x+y)%mod;
}
int mul(int x,int y) {
    return (ll)x*y%mod;
}

int dp[M];
int sum[M],X[M];

void solve() {
    int n;
    scanf("%d",&n);
    int g = 0;
    for(int i=0;i<n;++i) {
        scanf("%d",&A[i]);
        g^= A[i];
    }
    int c = 0;
    int ret = 0;
    ++dp[0];
    if(g>0) {
        for(int i=0;i<n-1;++i) {
            c^= A[i];
            if(c==0) {
                ret = add(ret,dp[g]);
                int u = dp[g];
                dp[0] = add(dp[0],u);
            } else if(c==g) {
                int u = dp[0];
                dp[g] = add(dp[g],u);
            }
        }
        ret = add(ret,1);
    } else {
        int k = 0;
        for(int i=0;i<n-1;++i) {
            c^= A[i];
            if(c==0) {
                ret= add(ret,dp[0]);
                dp[0] = add(dp[0],dp[0]);
                ++k;
            } else {
                int x = k - sum[c];
                sum[c] = k;
                int v = mul(x,X[c]);
                dp[c] = add(dp[c],v);
                X[c] = add(1,add(X[c],dp[c]));
                ret = add(1,add(ret,dp[c]));
            }
        }
        ret = add(ret,1);
    }
    printf("%d\n", ret);
}

int main(){
    //freopen("input.txt","r",stdin);
    solve();
}


Measured memory_bytes: 20608
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<iomanip>
#include<cstdio>
#include<stack>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 300005;
struct person
{
	int x, y;
};
person a[100005];
int cmp(person k1, person k2)
{
	return k1.y < k2.y;
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].y;
		a[i].x = i;
	}
	sort(a, a + n,cmp);
	for (int i = 0; i < n; i++) cout << a[i].x + 1 << " ";
	system("pause");
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int dp[n][3];
    int a, b, c;
    cin >> a >> b >> c;
    dp[0][0] = a;
    dp[0][1] = b;
    dp[0][2] = c;

    for (int i = 1; i < n; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c + max(dp[i - 1][0], dp[i - 1][1]);
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}

Measured memory_bytes: 4700
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
#define ld long double

int main(void)
{
    ll n, sum = 0;
    cin >> n;
    vector<ll>  a(n);
    for(ll i = 0; i < n; i++){
        cin >> a.at(i);
    }

    for(ll i = 1; i < n; i++) {
        if(a.at(i) < a.at(i - 1)) {
            sum += (a.at(i - 1) - a.at(i));
            a.at(i) = a.at(i - 1);
        }
    }

    cout << sum;
}

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int cur=0;
    int ans=0;
    if(a+cur<=k){
        ans += a;
        cur += a;
    }else{
        ans += k;
        cur = k;
    }
    if(b+cur<=k){
        cur += b;
    }else{
        cur=k;
    }
    if(cur<k){
        ans -= k-cur;
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

int INF = 1'000'000'000;
int ans;

int mizuyari(vector<int> v){

    if( v.empty() ) return ans;

    int minNum = INF, minIndex=0;
    for(int i=0;i<v.size();i++) {
        if( v[i] < minNum ){
            minNum = v[i];
            minIndex = i;
        }
    }
    
    for(int i=0;i<v.size();i++){
        v[i] -= minNum;
    }
    ans += minNum;
    vector<int> v1;
    v1.assign(v.begin(), v.begin()+minIndex);
    mizuyari(v1);
    v1.assign(v.begin()+minIndex+1, v.end());
    mizuyari(v1);
}

int main() {
    int N;
    cin >> N;

    vector<int> H(N);
    for(int i=0;i<N;i++)    cin >> H[i];

    ans=0;
    mizuyari(H);

    cout << ans << endl;

}

Measured memory_bytes: 256
import static java.util.Arrays.deepToString;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			int n = sc.nextInt();
			if (n == 0) break;
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = sc.nextInt();
			
			int st = 32;
			for (int time = 0; st > 0; time++) {
				st -= (st - 1) % 5;
				System.out.println(st);
				int g = a[time%a.length];
				st -= g;
				if (st < 0) {
					st = 0;
				}
				System.out.println(st);
			}
		}
	}
}

Measured memory_bytes: 20812
macro_rules! input {
    ($x:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        $x = buf.trim().parse().unwrap();
    };

    ($x:expr, $($y:expr), +) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        input_iter!(buf.split_whitespace(), $x, $($y), +);
    };

    ($v:expr; $size:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        for v in buf.split_whitespace() {
            $v.push(v.parse().unwrap());
        }
    };

    ($v:expr; $h_size:expr, $w_size:expr) => {
        for _ in 0..$h_size {
            let mut part_vec = Vec::new();
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).ok();
            for v in buf.split_whitespace() {
                part_vec.push(v.parse().unwrap());
            }
            $v.push(part_vec);
        }
    };
}

#[allow(unused_macros)]
macro_rules! input_iter {
    ($iter:expr, $x:expr) => {
        $x = $iter.next().unwrap().parse().unwrap();
    };

    ($iter:expr, $x:expr, $($y:expr), +) => {
        let mut iter = $iter;
        $x = iter.next().unwrap().parse().unwrap();
        input_iter!(iter, $($y), *);
    };
}

fn main() {
    let _n: i32;
    input!(_n);
    let mut v: Vec<i32> = Vec::new();
    let mut c: Vec<i32> = Vec::new();
    let mut val: Vec<i32> = Vec::new();
    input!(v; _n);
    input!(c; _n);
    for i in 0..(_n as usize) {
        val.push(v[i] - c[i]);
    }
    val.sort();
    val.reverse();
    let mut ans = 0;
    for v in val {
        if v < 0 {
            break;
        }
        ans += v;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 100100
#define MOD 1000000007
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,X,a[MAX],ans,f[2][MAX];
int main()
{
	n=read();X=read();
	for(int i=1;i<=n;++i)a[i]=read();
	sort(&a[1],&a[n+1]);reverse(&a[1],&a[n+1]);
	f[0][X]=1;
	for(int i=1,nw=1,pw=0;i<=n;++i,pw^=1,nw^=1)
	{
		memset(f[nw],0,sizeof(f[nw]));
		if(i!=n)for(int j=0;j<=X;++j)add(f[nw][j],1ll*(n-i)*f[pw][j]%MOD);
		for(int j=0;j<=X;++j)add(f[nw][j%a[i]],f[pw][j]);
	}
	for(int i=0;i<=X;++i)add(ans,1ll*i*f[n&1][i]%MOD);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int p[201], ans, t;
    int m, n_min, n_max;

    while (cin >> m >> n_min >> n_max) {
        if (m == 0 && n_min == 0 && n_max == 0) { break; }

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

        ans = 0; t = 0;

        for (int i = n_min; i <= n_max; i++) {
            if (t <= p[i-1] - p[i]) {
                ans = i;
                t = p[i-1] - p[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> E[101010];
ll dp[101010][2];
ll mo=1000000007;

void dfs(int cur,int pre) {
	dp[cur][0]=dp[cur][1]=1;
	
	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur);
		(dp[cur][0]*=(dp[e][0]+dp[e][1]))%=mo;
		(dp[cur][1]*=(dp[e][0]))%=mo;
	}
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	dfs(0,-1);
	cout<<(dp[0][0]+dp[0][1])%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}


int main(){
	float d,t,s;
    cin>>d>>t>>s;
    if ((d/s)>t){
        cout<<"No";
    }

    else{
        cout<<"Yes";
    }
    }

Measured memory_bytes: 3628
N = int(input())
P = [int(_) for _ in input().split()]
Q = P.copy()
count = 0
for i in range(N - 1):
    if P[i] == i + 1:
        count += 1
        P[i], P[i + 1] = P[i + 1], P[i]
if P[N - 1] == N:
    count += 1
print(count)


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

int main()
{
	int n;

	while (cin >> n){
		if (n % 39 == 0){
			cout << "3C" << "39" << endl;
		}
		else if (n % 39 < 10){
			cout << "3C0" << n % 39 << endl;
		}
		else {
			cout << "3C" << n % 39 << endl;
		}
	}

	return (0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
    int n,l; cin >> n >> l;
    string s[110];
    rep(i,n) cin >> s[i];

    sort(s, s + n);
    
    string ans;
    rep(i,n) ans += s[i];
    print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<class T>
vector<T> get_divisor(T n) {
    vector<T> res;
    for (long long i = 1; (i * i) <= n; i++) {
        if (n % i != 0) continue;
        res.push_back(i);
        if ((i * i) != n) res.push_back(n / i);
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = a[0];
    reps(i, 1, n) ans = __gcd(ans, a[i]);
    auto div = get_divisor(accumulate(all(a), 0LL));
    for(auto &x : div) {
        vector<ll> d(n);
        rep(i, n) d[i] = a[i] % x;
        sort(all(d));
        vector<ll> dp(n + 1, 0);
        rep(i, n) dp[i + 1] += dp[i] + d[i];
        bool f = false;
        reps(i, 1, n) {
            ll left = dp[i];
            ll right = (n - i) * x - (dp[n] - dp[i]);
            if ((left == right) && (k >= left)) {
                f = true;
                break;
            }
        }
        if (f) ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}


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




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

    int h[n+5];

    rep(i,n){
        cin >> h[i];
    } 

    int p=-1;

    rep(i,n){
        if(p<=h[i]-1){
            p=h[i]-1;
        }

        else if(p<=h[i]){
            p=h[i];
        }

        else{
            cout << "No" <<endl;

            return 0;
        }
    }

    cout << "Yes" <<endl;


    return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) throws IOException {
        int n = 3;

        int s[] = new int[n];
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        Scanner scan = new Scanner(System.in);

        for (int i=0; i < n; i++) {
                 s[i] = scan.nextInt();
        }
        int cnt5 = 0;
        int cnt7 = 0;

        //5・7・5かどうか判定
        for (int i=0; i < n; i++) {
            if (s[i] == 5) {
                cnt5++;
            } else if (s[i] == 7) {
                cnt7++;
            }
        }

        if (cnt5 == 2 && cnt7 == 1) {
            out.println("YES");
        }else{
            out.println("NO");
        }
        out.flush();
    }

    }


Measured memory_bytes: 9552
import java.util.Scanner;

public class Main {

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

	void solve() {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		sc.close();

		int coin = 0;
		for(int i=0;i<2;i++) {
			if(a>b) { coin +=a ;a--;}
			else {coin += b;b--; }
		}
		System.out.println(coin);

	}

}

Measured memory_bytes: 25300
a=gets.chomp.to_i
b=0
c=gets.chomp.split.map(&:to_i)
d=[]
c.each do |z|
  if z%2==0
    d.push(z)
  end
end
e=d.length
if e>0
  d.each do |x|
    if x%3==0||x%5==0
      b+=1
    end
  end
end
if e==b
  puts "APPROVED"
else puts "DENIED"
end

    
  
  

Measured memory_bytes: 1788
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => {
        let _ = writeln!(&mut std::io::stderr(), $($args),*);
    };
}
macro_rules! trace {
    ($var:expr) => { ewriteln!(">>> {} = {:?}", stringify!($var), $var); };
    ($($args:expr),*) => { trace!(($($args),*)) }
}
macro_rules! put {
    ($var:expr) => { println!("{}", $var); };
    ($var:expr, $($args:expr),*) => { println!("{} ", $var); put!($($args),*); };
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let k: usize = sc.cin();
    trace!(n,k);
    let xs: Vec<usize> = (0..n).map(|_|sc.cin()).collect();
    let mut dp: Vec<Vec<i64>> = vec![vec![0; 100000+10]; 102];
    dp[0][0] = 1;
    for i in 0..n {
        for j in 0..100002 {
            dp[i+1][j] += dp[i][j];
            if j+xs[i]+1 < dp[0].len(){
                dp[i+1][j+xs[i]+1] -= dp[i][j];
            }
        }
        let mut ac = 0;
        for j in 0..100002 {
            ac += dp[i+1][j];
            ac = (ac + M) % M;
            dp[i+1][j] = ac;
        }
    }
    put!(dp[n][k]);
}

use std::io::{ self, Write };
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 108796
import java.util.Scanner;


public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int count=0;
		for(;;){
			count++;
			int W = sc.nextInt();
			if(W==0) break;
			int N = sc.nextInt();
			int[] value = new int[N];
			int[] weight = new int[N];
			int[][] dp= new int[N+1][W+2];
			String read;
			String[] read2;
			for(int i=0;i<N;i++){
				read = sc.next();
				read2 = read.split(",");
				value[i] = Integer.parseInt(read2[0]);
				weight[i] = Integer.parseInt(read2[1]);
			}
			for(int i=0;i<N;i++){
				for(int j=0;j<=W;j++){
					if(j<weight[i]){
						dp[i+1][j] = dp[i][j];
					}else{
						dp[i+1][j]=Math.max(dp[i][j], dp[i][j-weight[i]]+value[i]);
					}
				}
			}
			int max = dp[N][W];
			int sumWeight=0;
			for(int j=0;j<=W;j++){
				if(dp[N][j]>=max){
					sumWeight = j;
					break;
				}
			}
			System.out.println("Case "+count+":\n"+max);
			System.out.println(sumWeight);
		}
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
bool R(){return true;}
template<typename T, typename ... Args>
bool R(T & x, Args & ... args){return cin >> x && R(args...);}
void init_io(){ios::sync_with_stdio(false);cin.tie(0);}

#define PB push_back
#define MP make_pair
#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define SV(vec) do{int __sv;R(__sv);vec.PB(__sv);}while(0)
#define ALL(vec) (vec).begin(), (vec).end()
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF   1000000007
#define INFLL 4000000000000000007LL

int a, b, h, m;

void solve ()
{
  R(a, b, h, m);
  double hang = ((h + m / 60.0) / 12.0) * 2.0 * M_PI;
  double mang = (m / 60.0) * 2.0 * M_PI;
  double ang = min(abs(max(hang, mang) - min(hang, mang)), abs(min(hang, mang) + 2 * M_PI - max(hang, mang)));
  printf("%.12lf\n", sqrt(a * a + b * b - 2.0 * a * b * cos(ang)));
}

int main ()
{
  init_io();
  int t = 1;
  //R(t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 4108
#include <iostream>

using namespace std;

int main()
{
    int a[3];
    int f=0,s=0;
    for(int i=0;i<3;i++){
        cin>>a[i];
        if(a[i]==5)
            f++;
        else if(a[i]==7)
            s++;
    }
    if(f==2 && s==1)
        cout<<"YES";
    else
        cout<<"NO";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
 
  string input;
  getline( cin, input );
  string ans = input;
 
  string apple = "apple";
  string peach = "peach";
 
  while(true) {
 
    int x = input.find( apple, 0 );
    if ( x == string::npos ) break;
    for ( int i = 0; i < 5; i++ ) {
      ans[x+i] = peach[i];
      input[x+i] = '-';
    }
 
  }
 
  while(true) {
 
    int x = input.find( peach, 0 );
    if ( x == string::npos ) break;
    for ( int i = 0; i < 5; i++ ) {
      ans[x+i] = apple[i];
      input[x+i] = '-';
    }
 
  }
 
  cout << ans << endl;
 
  return 0;
 
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#define MAX 1000000000
#define ll long long

using namespace std;


int main() {
    ll n,i,j,k,ans=0,maxim=0;

    cin>>n;

    vector<ll> a(n);
    for(i=0;i<n;i++){
        cin>>a[i];
        if(maxim<a[i])maxim=a[i];
    }
    map<ll,ll> b;
    for(i=0;i<n;i++){
        b[a[i]]++;
    }
    for(auto p:b){
        int x1 = p.first;
        int x2 = p.second;
        if (x2 < x1) ans += x2;
        else ans += x2 - x1;
    }


    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
 
int main() {
boost
int a;
int b;
cin>>a>>b;
int p,q,r;
p=a+b;
q=a-b;
r=a*b;
int max=-100;
if(p>max)
	max=p;
if(q>max)
	max=q;
if (r>max)
	max=r;
cout<<max;	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map> 
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn=2e5+6;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,m;
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
signed main(){
	n=read(),m=read();
	cout<<n*m<<endl;
	return 0; 
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

map<int, int> prime;

void prime_factorization(int x){
    for(int i = 2; i * i <= x; ++i){
        while(x % i == 0){
            ++prime[i];
            x /= i;
        }
    }
    if(x != 1)  ++prime[x];
    return;
}

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

    int n;
    cin >> n;
    for(int i = 2; i <= n; ++i){
        prime_factorization(i);
    }
    vector<int> cnt(5, 0);
    for(auto it : prime){
        if(it.second >= 74) ++cnt[4];
        else if(it.second >= 24)    ++cnt[3];
        else if(it.second >= 14)    ++cnt[2];
        else if(it.second >= 4)     ++cnt[1];
        else if(it.second >= 2)     ++cnt[0];
    }
    vector<int> sum(5, 0);
    sum[0] = cnt[0];
    for(int i = 0; i < 4; ++i)  sum[i + 1] = sum[i] + cnt[i + 1];
    int res = 0;
    // 75 = 1 * 75
    res += cnt[4];
    // 75 = 3 * 25
    res += (sum[4] - sum[2]) * (sum[4] - 1);
    // 75 = 5 * 15
    res += (sum[4] - sum[1]) * (sum[4] - sum[0] - 1);
    // 75 = 3 * 5 * 5
    res += (sum[4] - sum[0]) * (sum[4] - sum[0] - 1) / 2 * (sum[4] - 2);

    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main() {
	string S, T;
	int count = 0;
	cin >> S >> T;
	for (int i = 0; i < 3; i++) {
		if (T[i] == S[i]) {
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	while(true)
	{
		int ans=0,chains=0;
		int n,m;
		string s;
		cin>>n;
		if(n==0)break;
		cin>>m>>s;
		for(int i=1;i<m-1;++i){
			if(s[i]=='O'){
				if(s[i-1]!='O'&&s[i+1]!='O'){
					++chains;
					++i;
					continue;
				}
			}
			if(chains >= n)
				ans += chains - n + 1;
			chains=0;
		}
		if(chains >= n)
			ans += chains - n + 1;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1892
#include <stdio.h>
 
using namespace std;
 
struct Node{
    Node(){
        left_child = right_child = parent = -1;
    };
    int left_child,right_child,parent;
};
 
void preORDER(Node order[],int id){
    printf(" %d",id);
    if(order[id].left_child != -1) preORDER(order,order[id].left_child );
    if(order[id].right_child != -1) preORDER(order,order[id].right_child );
}
 
void inORDER(Node order[],int id){
    if(order[id].left_child != -1) inORDER(order,order[id].left_child );
    printf(" %d",id);
    if(order[id].right_child != -1) inORDER(order,order[id].right_child );
}
 
void postORDER(Node order[],int id){
    if(order[id].left_child != -1) postORDER(order,order[id].left_child );
    if(order[id].right_child != -1) postORDER(order,order[id].right_child );
    printf(" %d",id);
}
 
int main(){
    int n,id,left,right,root_id;
    scanf("%d",&n);
    Node order[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&id,&left,&right);
        if(left != -1){
            order[id].left_child = left;
            order[left].parent = id;
        }
        if(right != -1){
            order[id].right_child = right;
            order[right].parent = id;
        }
    }
 
    for(root_id = 0; root_id < n; root_id++){
        if(order[root_id].parent == -1) break;
    }
 
    printf("Preorder\n");
    preORDER(order,root_id);
    printf("\n");
 
    printf("Inorder\n");
    inORDER(order,root_id);
    printf("\n");
 
    printf("Postorder\n");
    postORDER(order,root_id);
    printf("\n");
}



Measured memory_bytes: 2736