akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll k;
  cin>>k;
  string s="ACL";
  rep(i,k){
    cout<<s;
  }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    vi a(N);
    rep(i, N) cin >> a[i];
    GSORT(a);

    int Alice=0, Bob=0;
    rep(i, N) {
        if(i%2==0) Alice += a[i];
        else Bob += a[i];
    }

    cout << Alice - Bob << endl;

    return 0;
}

Measured memory_bytes: 256
import java.lang.Math;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        double r = Double.parseDouble(scanner.next());
        System.out.println(String.format("%.6f", r*r*Math.PI) + " " + String.format("%.6f", 2*r*Math.PI));
    }
}


Measured memory_bytes: 26408
#include<bits/stdc++.h>
#define N 400005
using namespace std;
int n,a[N],b[N*4][2],fst[N],to[N],nxt[N],l,cnt;
int cp(int x,int y)
{
	return a[x]<a[y]?x:y;
}
void up(int k)
{
	for (int i=0;i<=1;i++)
		b[k][i]=cp(b[k<<1][i],b[k<<1|1][i]);
}
void build(int k,int l,int r)
{
	if (l==r)
	{
		b[k][l&1]=l;
		return;
	}
	int mid=l+r>>1;
	build(k<<1,l,mid);build(k<<1|1,mid+1,r);
	up(k);
}
int qry(int k,int l,int r,int x,int y,int p)
{
	if (x<=l&&r<=y)
		return b[k][p];
	int mid=l+r>>1,ans=0;
	if (x<=mid) ans=cp(ans,qry(k<<1,l,mid,x,y,p));
	if (y>mid) ans=cp(ans,qry(k<<1|1,mid+1,r,x,y,p));
	return ans;
}
void link(int x,int y)
{
	to[++l]=y;nxt[l]=fst[x];fst[x]=l;
}
struct T
{
	int x,y;
}v[N];
bool operator<(T a,T b)
{
	return a.x>b.x;
}
void Get(int f,int l,int r)
{
	if (l>r) return;
	int t=l&1;
	int x=qry(1,1,n,l,r,t);
	int y=qry(1,1,n,x+1,r,t^1);
	int tmp=++cnt;
	v[tmp]=(T){a[x],a[y]};
	link(f,tmp);
	Get(tmp,l,x-1);
	Get(tmp,x+1,y-1);
	Get(tmp,y+1,r);
}

priority_queue<T>q;
int main()
{
	scanf("%d",&n);
	a[0]=10000000;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		//scanf("%d",&b[i]);
	}
	build(1,1,n);
	cnt=1;
	Get(1,1,n);
	
	for (int i=fst[1];i;i=nxt[i])
		q.push((T){v[to[i]].x,to[i]});
	while(q.size())
	{
		int t=q.top().y;
		q.pop();
		printf("%d %d ",v[t].x,v[t].y);
		for (int i=fst[t];i;i=nxt[i])
			q.push((T){v[to[i]].x,to[i]});
	}
	puts("");
}

Measured memory_bytes: 23040
#include<stdio.h>
#include<iostream>
#include"string"
#include"math.h"
using namespace std;


string S,s;
int main(){
	cin >> S;
	cin >> s;

	for(int i=0;i<3;i++){
		if(S[i]!=s[2-i]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

ll n3r(ll n) {
    if (n < 3) return 0;
    return n*(n-1)*(n-2) / 6;
}

int main() {
    int n;
    string s;
    cin >> n;
    unordered_map<char, int> cnt;
    cnt['M'] = cnt['A'] = cnt['R'] = cnt['C'] = cnt['H'] = 0;
    ll acc = 0;
    for(int i = 0; i < n; i++) {
        cin >> s;
        if (cnt.count(s[0]) > 0) {
            cnt[s[0]] += 1;
            acc += 1;
        }
    }
    ll ans = 0;
    vector<string> cand = {"MAR", "MAC", "MAH", "MRC", "MRH", "MCH", "ARC",
        "ARH", "ACH", "RCH"};
    for (string s: cand) {
        ll tmp = 1;
        for(char c: s)
            tmp *= cnt[c];
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll  long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define main() int main()
#define ff1(i,n) for(int i=1;i<=n;++i)
#define ff0(i,n) for(int i=0;i<n;++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout<<x<<'\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d",a)
#define pab(a,b) printf("%d%d",a,b)
#define pii pair<int,int>
using namespace std;

#define maxn 100
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll powmod(ll a,ll b){
    ll ans = 1, pow = a%mod;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans%mod;
}
ll n,m,q,aa[maxn],b[maxn],c[maxn],d[maxn],a[maxn];
ll ans;
void sousuo(ll x,ll y) {
    if(x-1==n){
    	ll tmp=0;
    	for(int i=1;i<=q;i++){
    		if(a[b[i]]-a[aa[i]]==c[i])tmp+=d[i];
		}
		ans=max(ans,tmp);
        return;
    }
    for(int i=y;i<=m;i++){
    	a[x]=i;
    	sousuo(x+1,i);
	}
}
main(){
	IO;
	cin>>n;
	
	for(int i=-120;i<=120;i++) 
	{
		for(int j=-120;j<=120;j++) 
		{
			if(pow(i,5)-pow(j,5)==n) 
			{
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}	
} 

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    char a[n][n],b[m][m];
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
        {
            cin >> a[i][j];
        }
    }
    for(int i = 0;i < m;i++)
    {
        for(int j = 0;j < m;j++)
        {
            cin >> b[i][j];
        }
    }
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
        {
            bool flag = true;
            for(int k = 0;k < m && flag;k++)
            {
                for(int l = 0;l < m;l++)
                {
                    if(a[i + k][j + l] != b[k][l])
                    {
                        flag = false;
                        break;
                    }
                }
            }
            if(flag)
            {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    puts(s*t >= d ? "Yes" : "No");
    return 0;
}

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

int main() {
	int h,w,n;cin>>h>>w>>n;
	int a[n];
	int c[h][w];
	int count=0;
	int l[h*w];
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<a[i];j++){
			l[count+j]=i+1;
		}
		count+=a[i];
	}
//	for(int i=0;i<h*w;i++){
//		cout<<l[i]<<' ';
//	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i%2){
			c[i][j]=l[i*w+j];
			}else{
				c[i][j]=l[(i+1)*w-j-1];
			}
			if(j)cout<<' ';
			cout<<c[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class a
{
    static void Main(string[] args)
    {
        var ABT = Console.ReadLine().Split();
        var A = int.Parse(ABT[0]);
        var B = int.Parse(ABT[1]);
        var T = int.Parse(ABT[2]);
        Console.WriteLine(T / A * B); 
    }
}


Measured memory_bytes: 11220
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

int vs[110];

int main(void) {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> vs[i];
  }

  int res = 0;
  for(;;) {
    bool exist = false;
    REP(i, n) {
      if(vs[i] > 0) {
        exist = true;
        ++res;
        for(int i1 = i; i1 < n && vs[i1] > 0; ++i1) {
          --vs[i1];
        }
        break;
      }
    }
    if(!exist) {
      break;
    }
  }
  cout << res << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,  n) for (int i  =  0; i < (int)(n); ++i)
#define REPR(i,  n) for (int i  =  n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------

struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

signed main() {
  int N, M; cin >> N >> M;
  UnionFindTree tree(N + 1);
  REP(i, M) {
    int A, B; cin >> A >> B;
    tree.Unite(A-1, B-1);
  }
  int ans = 0;
  REP(i, N) {
    ans = max(ans, tree.Size(i));
  }
  cout << ans  << endl;
  return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define LOG 19
#define off 2

#define mod 1000000007LL

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less< i64 >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 100005

int main()
{
    int n ;

    vector < pair<int,int> > vp ;

    scanf("%d",&n) ;

    for(int i=1 ; i<=n ; i++)
    {
        int x ;
        scanf("%d",&x) ;
        vp.pb(mp(x,0)) ;
    }

    for(int i=1 ; i<=n ; i++)
    {
        int x ;
        scanf("%d",&x) ;
        vp.pb(mp(x,1)) ;
    }

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

    int a[2] ;

    a[0] = a[1] = 0 ;

    int ans = 1 ;

    for(int i=0 ; i<2*n ; i++)
    {
        if( a[ (vp[i].yy^1) ] != 0 )
        {
            ans = (1LL*ans*a[ (vp[i].yy^1) ])%mod ;
            a[ (vp[i].yy^1) ]-- ;
        }
        else{
            a[ vp[i].yy ]++ ;
        }
    }

    printf("%d\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 2420
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
	while(true) {
		int x;
		int y;
		cin >> x >> y;
		if ( x == 0 ) break;
		int a[15][15] = {0};
		for ( int i = 0; i < y ; i++ ) {
			for ( int j = 0; j < x ; j++ ) {
				cin >> a[j][i];
			}
		}
		int b[15][15] = {0};
		for ( int j = 0; j < x ; j++ ) {
			if ( a[j][y-1] != 1) b[j][y-1] = 1;
		}
		if ( y > 1 ) {
			for ( int j = 0; j < x ; j++ ) {
				if ( a[j][y-2] == 2) b[j][y-2] = 1;
			}
		}
		for ( int i = y - 1; i > 0; i-- ) {
			for ( int j = 0; j < x ; j++ ) {
				if ( a[j][i] == 0 ) {
					for ( int k = j - 1; k < j + 2; k++ ) {
						if ( k < 0 || k >= x ) continue;
						if ( a[k][i-1] == 0 ) {
							b[k][i-1] += b[j][i];
						}
					}
					if ( i > 1 ) {
						if ( a[j][i-2] == 2 ) b[j][i-2] += b[j][i];
					}
				}else if ( a[j][i] == 2 ) {
					if ( a[j][i-1] == 0 ) b[j][i-1] += b[j][i];
					if ( i > 1 ) {
						if ( a[j][i-2] == 2 ) b[j][i-2] += b[j][i];
					}
				}
			}
		}
		int s = 0;
		for ( int j = 0; j < x ; j++ ) {
			s += b[j][0];
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] a = new int[n];
		int[] h = new int[n];
		for(int i=0;i<n;i++) {
			h[i] = in.nextInt();
		}
		for(int i=0;i<n;i++) {
			a[i] = Integer.MAX_VALUE;
		}
		a[0] = 0;
		for(int i=0;i<n;i++) {
			for(int j=1;j<=k&&i+j<n;j++) {
				a[i+j] = Math.min(a[i+j], a[i]+Math.abs(h[i]-h[i+j]));
			}
		}
		System.out.println(a[n-1]);
	}
}


Measured memory_bytes: 61956
#include <bits/stdc++.h>
using namespace std;
const int MXN = 100005;

int main()
{
    int n, k, q;
    int a[MXN] = {};
    cin >> n >> k >> q;
    for(int i = 0, x; i < q; ++i)
    {
        cin >> x;
        ++a[x];
    }
    for(int i = 1; i <= n; ++i)
    {
        cout << (k - (q - a[i]) > 0 ? "Yes\n" : "No\n");
    }
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL(x) memset(x,0,sizeof(x))


using namespace std;

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

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 main()
{

  cout << setprecision(8);


  double L;
  cin >> L;

  cout << pow(L/3.0, 3)  <<endl;


  

  return 0;
}



//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int> b(n);
    for(int i=0;i<n;i++){
        b[i]=(a[i]-(i+1));
    }
    sort(b.begin(),b.end());
    long long sum1=0,sum2=0;
    for(int i=0;i<n;i++){
        sum1+=abs(a[i]-(b[n/2]+i+1));
        sum2+=abs(a[i]-(b[n/2+1]+i+1));
    }
    cout<<min(sum1,sum2)<<endl;
    return 0;
}


Measured memory_bytes: 1792
// B - Christmas Eve Eve
// https://atcoder.jp/contests/abc115/tasks/abc115_b

use std::io::*;
use std::str::*;

fn main() {
    let nk: Vec<usize> = read_split_number();
    let n: usize = nk[0];
    let k: usize = nk[1];

    let mut hs: Vec<usize> = Vec::new();
    for _i in 0..n {
        hs.push(read_number());
    }

    let ans = solve(k, hs);
    println!("{}", ans);
}

fn read_split_number() -> Vec<usize> {
    let mut in_str = String::new();
    stdin().read_line(&mut in_str).ok();
    let ns: Vec<usize> = in_str.trim_right().split(' ')
        .map(|a|usize::from_str(a).expect("error parsing input"))
        .collect();

    ns
}

fn read_number() -> usize {
    let mut in_str = String::new();
    stdin().read_line(&mut in_str).ok();
    let num = usize::from_str(&in_str.trim_right()).expect("error parsing input");

    num
}

fn solve(k: usize, mut ps: Vec<usize>) -> usize {
    ps.sort();
    let ps_len: usize = ps.len();
    let mut smallest_diff = usize::max_value();
    for i in 0..(ps_len-k+1) {
        let diff = ps[i+k-1] - ps[i];
        if diff < smallest_diff {
            smallest_diff = diff;
        }
    }

    smallest_diff
}

#[test]
fn test_solve() {
    let v1 = vec![10, 15, 11, 14, 12];
    assert_eq!(solve(3, v1), 2);

    let v2 = vec![5, 7, 5, 7, 7];
    assert_eq!(solve(3, v2), 0);
}


Measured memory_bytes: 4352
def ball_sum(balls, index)
  sum = 0
  m = 2
  while balls.size >= (index+1)*m
    sum += balls[(index+1)*m-1]
    m += 1
  end
  sum % 2
end
def a
  n = gets.to_i
  as = gets.split.map(&:to_i)

  result = []
  balls = Array.new(n, 0)
  (0..n-1).to_a.reverse.each do |i|
    res = ball_sum(balls, i)
    if res != as[i]
      result << (i+1)
      balls[i] = 1
      # balls[i] = (balls[i] + 1) % 2
    end
  end
  p result.size
  puts result.reverse.map(&:to_s).join(' ')
end

p -1 if a



Measured memory_bytes: 25860
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



def main2():
    a, b, c, d = list(map(int, input().split()))

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    di = lcm(c,d)
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()

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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N,K;
    cin >> N >> K;
    int A[N];
    rep(i,N) {
        int a;
        cin >> a;
        A[i] = a;
    }
    int ans = 1;

    while(1) {
        int tmp = (K-1)*ans+1;
        if (tmp>=N) break;
        else ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N, W;
    cin >> N >> W;
    int w[N], v[N];
    for(int i=0; i<N; i++){
        cin >> w[i] >> v[i];
    }

    ll val[N+1][W+1];
    for(int i=0; i<N+1; i++){
        for(int j=0; j<W+1; j++){
            val[i][j] = 0;
        }
    }

    ll ans = 0;
    for(int i=1; i<N+1; i++){
        for(int j=1; j<W+1; j++){
            if(j - w[i-1] >= 0){
                chmax(val[i][j], val[i-1][j-w[i-1]] + v[i-1]);
            }
            chmax(val[i][j], val[i-1][j]);
            if(val[i][j] > ans){
                ans = val[i][j];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 79104
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll dp[2005][2005];
int main(){
  ll N,M;cin>>N>>M;
  ll S[N+1],T[M+1];
  ll i,j,k,l;
  repn(i,N) cin>>S[i];
  repn(i,M) cin>>T[i];
  rep(i,N+1) dp[i][0]=1;
  rep(i,M+1) dp[0][i]=1;
  repn(i,N){
    repn(j,M){
      if(S[i]==T[j]){
        dp[i][j]+=dp[i-1][j-1];
        dp[i][j]%=mod;
      }
      dp[i][j]+=dp[i-1][j]+dp[i][j-1];
      dp[i][j]%=mod;
      dp[i][j]-=dp[i-1][j-1];
      dp[i][j]%=mod;
      if(dp[i][j]<0) dp[i][j]+=mod;
    }
  }
  //rep(i,N) rep(j,M) cout<<dp[i][j]<<endl;
  cout<<dp[N][M]<<endl;
}


Measured memory_bytes: 31616
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


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

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (i == A[A[i]]) cnt++;
  }
  cout << cnt / 2 << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<=(int)(n-1);i++)

int main() {
	int N;
	cin>>N;
	char S[N];
	rep(i,N) cin>>S[i];
	int count = 0;
	rep(i,N){
		if(S[i]=='Y'){
			count++;
		}
	}
	if(count==0) cout<<"Three"<<endl;
	else cout<<"Four"<<endl;
	

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX=200005;
ll n,p[MAX],fin,u[MAX];
int main(){
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&p[i]);
    if(p[1]!=0){
        printf("-1\n");
        return 0;
    }
    for(ll i=1;i<n;i++){
        if(p[i+1]-p[i]>=2) {
            printf("-1\n");
            return 0;
        }
        if(p[i+1]-p[i]==1) u[i]=1;
    }
    for(int i=n-1;i>=1;i--){
        ll t;
        for(t=i;t>=1&&u[t];t--);
        fin+=p[i+1];
        i=t;
    }
    printf("%lld\n",fin);
}


Measured memory_bytes: 3328
n,k=map(int,input().split())
a=[int(j) for j in input().split()]
ma=0.0
for i in range(0,k):
    temp=(1+a[i])
    temp=temp*a[i]
    temp=temp//2
    ma+=(temp/a[i])

sum=ma
#print(sum)

for i in range(k,n):
    temp=(1+a[i])
    temp=temp*a[i]
    temp=temp//2
    temp=temp/a[i]

    temp1=(1+a[i-k])
    temp1=temp1*a[i-k]
    temp1=temp1//2
    temp1=temp1/a[i-k]

    sum=(sum+temp)-temp1
    if(sum>ma):
        ma=sum

print(ma)


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

using namespace std;

#define MAXN 102

#define MXN 3001

double dp[MXN][MXN];

double a[MAXN];

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

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

	dp[1][1]=a[1];

	dp[1][0]=1.00-a[1];

	double sum=0.00;

	if(n==1) sum+=dp[1][1];

	for(int i=2;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0]*(1-a[i]);

		for(int j=1;j<=i;j++)
		{
			dp[i][j]=(dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*(a[i]));
		
			if(i==n&&(j>(n-j))) sum+=dp[n][j]; 
		}
	}

	printf("%.10lf",sum);

	return 0;
}

Measured memory_bytes: 68992
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a[3];
	a[0] = "Sunny";
	a[1] = "Cloudy";
	a[2] = "Rainy";
	string s; 
	cin>>s;
	if(s=="Sunny")
		cout<<"Cloudy"<<endl;
	if(s=="Cloudy")
		cout<<"Rainy"<<endl;
	if(s=="Rainy")
		cout<<"Sunny"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,c=0;
	cin>>n;
	long long a[n];
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
		for (long long j=0;j<10000000000;j++)
		if (a[i]%2==0)
		{
			a[i]=a[i]/2;
		}
		else 
		{
			c=c+j;
			break;
		}
	}
	cout<<c<<endl;
	return 0;
} 

Measured memory_bytes: 384
//#include<bits/stdc++.h>
#include<iostream>
#include<climits>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<list>
#include<string>
#include <unordered_map>
#include <unordered_set> 
#include<iomanip>
#include<iterator>
#include<cmath>
#include<fstream>
using namespace std;
#define F0(i,n) for(int i=0;i<int(n);++i)
#define F1(i,n) for(int i=1;i<=int(n);++i)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << ((c+b-1)/b <= (a+d-1)/d? "Yes":"No");
}


Measured memory_bytes: 3132
# AC 回避した https://atcoder.jp/contests/abc137/submissions/6845103 の再提出

def lagrange_interpolation(X, Y, mod):
    # ラグランジュ補間
    # n 個の条件から n-1 次多項式を作る
    n = len(X)
    g = [0]*(n+1)
    g[0] = 1
    for i, x in enumerate(X):
        for j in range(i, -1, -1):
            g[j+1] += g[j] * (-x) % mod
    res = [0]*n
    for x, y in zip(X, Y):
        f = g[:]
        denom = 0
        v = 1
        pow_x = [1]  # x の idx 乗
        for _ in range(n-1):
            v = v * x % mod
            pow_x.append(v)
        pow_x.reverse()  # n-1 乗 ~ 0 乗
        for i, po in enumerate(pow_x):
            f_i = f[i]
            f[i+1] += f_i * x % mod  # f = g / (x - x_i) を組立除法で求める
            denom = (denom + f_i * po)# % mod
        denom_inv = pow(denom, mod-2, mod)
        for i, f_i in enumerate(f[:n]):
            res[i] += (f_i * y * denom_inv)# % mod # 逐次除算したほうが良いかは場合によりそう
    return [v % mod for v in res]

p = int(input())
A = list(map(int, input().split()))
ans = lagrange_interpolation(list(range(p)), A, p)
print(" ".join(map(str, ans[::-1])))


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

int main(){
  char s;
  cin >> s;
  if (s == 'A'){
    cout << 'T' << endl;
  }
  else if (s == 'T'){
    cout << 'A' << endl;
  }
  else if (s == 'C'){
    cout << 'G' << endl;
  }
  else{
    cout << 'C' << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int n;
int c = 0;
int i;
char s[51];
scanf("%d",&n);
scanf("%s",s);
for (i = 0;i < n-2;i++){
if(s [i] == 'A'
	&& s[i+1] == 'B'
		&& s[i+2] == 'C')
c++;}
printf("%d",c);
return 0;
}


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

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

bool comp (pi a, pi b) {return a.second < b.second;}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	pi seg[m];
	FOR (i, 0, m - 1)
		cin >> seg[i].first >> seg[i].second;
	sort(seg, seg + m, comp);
	
	int cur = 0, cnt = 0;
	FOR (i, 0, m - 1)
	{
		int x = seg[i].first;
		if (x > cur) {cur = seg[i].second - 1; cnt++;}
	}
	cout << cnt;
}

Measured memory_bytes: 1792
#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>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;

int main() {
	while (cin >> n&&n) {
		map<char, int> MAX, MIN;
		string s;
		rep(i, n) {
			char c;
			cin >> c;
			s.push_back(c);
		}
		rep(i, 26) {
			MAX[(char)('A' + i)] = n;
		}
		bool f = 1;
		rep(i, n) {
			rep(j, 26) {
				if (s[i] == (char)('A' + j))MIN[(char)('A' + j)]++;
				else MAX[(char)('A' + j)]--;
				/*cout << (char)('A' + j) << " " << MAX[(char)('A' + j)] << " "
					<< MIN[(char)('A' + j)] << endl;*/
			}
			rep(j, 26) {
				bool g = 1;
				rep(k, 26) {
					if (j != k) {
						if (MIN[(char)('A' + j)] <= MAX[(char)('A' + k)])g = 0;
					}
				}
				if (g) {
					f = 0;
					cout << (char)('A' + j) << " " << i + 1 << endl;
				}
				if (!f)break;
			}
			if (!f)break;
		}
		if (f)cout << "TIE" << endl;
	}
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

int main(){
    
    int n;cin>>n;
    int a[n];int sum=0;rep(i,0,n-1){cin>>a[i];sum+=a[i];}
    int d=1<<20,pos=-1;
    rep(i,0,n-1){
        int dis=abs(sum-n*a[i]);
        if(d>dis){
            d=dis;
            pos=i;
        }
    }
    
    cout<<pos<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <math.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
// typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
vector<int>G[10010];
vector<int>c(10010,0);
int num[10010];
bool used[10010];
int now_c=0;
int dfs(int s){
    if(used[s]){
        return 0;
    }else{
        used[s]=true;
    }

    num[s]=c[now_c];
    now_c++;

    for(int i=0; i<G[s].size(); i++){
        dfs(G[s][i]);
    }
    return 0;
}

bool ball[200001];

int main() {
    int N; cin >> N;
    vector<int>a(N);

    rep(i,N){
        cin >> a[i];
    }

    for(int i=N; i>0; i--){
        int x=i;
        int sum=0;
        for(int j=2; x*j<=N; j++){
            if(ball[x*j-1])
                sum++;
        }
        if(sum%2!=a[x-1]){
            ball[x-1]= true;
        }
    }

    int ans=0;
    for(int i=0; i<N; i++){
        if(ball[i])
            ans++;
    }
    cout << ans << endl;

    for(int i=0; i<N; i++){
        if(ball[i])
            cout << i+1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <set>
#include <unordered_map>

long long N, M;

int main() {
  std::cin >> N >> M;
  std::set<int> AC;
  std::unordered_map<int, int> WA;
  
  int p;
  std::string result;
  int ac = 0, wa = 0;
  while (std::cin >> p >> result) {
    if (result == "AC" && AC.count(p) == 0) {
      ++ac; wa += WA[p]; AC.insert(p);
    } else if (result == "WA") {
      ++WA[p];
    }
  }
  std::cout << ac << " " << wa << "\n";
}

Measured memory_bytes: 8996
class Node(object):
    def __init__(self, num, prev = None, nxt = None):
        self.num = num;
        self.prev = prev;
        self.nxt = nxt;

class Double_Linked_List(object):
    def __init__(self):
        self.first = self.last = None;

    def insert(self, num):
        node = Node(num);
        if self.first is not None:
            self.first.prev = node;
            node.nxt = self.first;
            self.first = node;
        else:
            self.first = node;
            self.last = node;

    def delete(self, num):
        current = self.first;
        while current is not None:
            if current.num == num:
                prev = current.prev;
                nxt = current.nxt;
                if prev is not None:
                    current.prev = None;
                    prev.nxt = nxt;
                if nxt is not None:
                    current.nxt = None;
                    nxt.prev = prev;
                if nxt is None:
                    self.last = prev;
                if prev is None:
                    self.first = nxt;
                break;
            else:
                current = current.nxt;

    def delete_first(self):
        if self.first is not None:
            nxt = self.first.nxt;
            if nxt is not None:
                self.first.nxt = None;
                nxt.prev = None;
                self.first = nxt;
            else:
                self.first = None;
                self.last = None;

    def delete_last(self):
        if self.last is not None:
            prev = self.last.prev;
            if prev is not None:
                self.last.prev = None;
                prev.nxt = None;
                self.last = prev;
            else:
                self.first = None;
                self.last = None;

    def get_content(self):
        ret = [];
        append = ret.append;
        current = self.first;
        while current is not None:
            append(current.num);
            current = current.nxt;
        return " ".join(ret);

def main():
    from sys import stdin
    double_linked_list = Double_Linked_List();
    count = int(input());
    delete_first = double_linked_list.delete_first;
    delete_last = double_linked_list.delete_last;
    delete = double_linked_list.delete;
    insert = double_linked_list.insert;
    for i in range(count):
        command = stdin.readline().strip().split();
        if command[0] == "insert":
            insert(command[1]);
        if command[0] == "delete":
            delete(command[1]);
        elif command[0] == "deleteFirst":
            delete_first();
        elif command[0] == "deleteLast":
            delete_last();
    print(double_linked_list.get_content());

main();









Measured memory_bytes: 227588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  string s;
  int k;
  cin >> s >> k;
  char now = s[0];
  bool flag = true;
  REP(i, s.size()) if (s[i] != now) flag = false;
  if (flag) {
    cout << (ll)(s.size() * k / 2) << endl;
    return;
  }
  ll count = 0, j = 1;
  FOR(i, 1, s.size() - 1) {
    if (s[i] == now) {
      j++;
    } else {
      count += j / 2;
      j = 1;
    }
    now = s[i];
  }
  count += j / 2;
  ll ans;
  if (s[0] == s[s.size() - 1]) {
    ll a = 1, b = 1;
    FOR(i, 1, s.size() - 1) {
      if (s[i] == s[i - 1]) a++;
      else
        break;
    }
    RFOR(i, s.size() - 2, 0) {
      if (s[i] == s[i + 1]) b++;
      else
        break;
    }
    ans = (ll)(count) * k - (a / 2 + b / 2 - (a + b) / 2) * (k - 1);
  } else {
    ans = (ll)(count) * k;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int gcd = 0;
			for (int i = 0; i < n; i++) {
				int x = scanner.nextInt();
				if (x != k) {
					if (0 == gcd) {
						gcd = Math.abs(x - k);
					} else {
						gcd = gcd(gcd, Math.abs(x - k));
					}
				}
			}
			System.out.println(gcd);
		}
	}

	/**
	 * mとnの最大公約数を返す
	 * 
	 * @param m
	 * @param n
	 * @return mとnの最大公約数
	 */
	private static int gcd(int m, int n) {
		if (0 == n) {
			return m;
		}
		return gcd(n, m % n);
	}
}


Measured memory_bytes: 58916
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 2000005;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[SIZE], finv[SIZE], inv[SIZE];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

double len(int a, int b, int c, int d) {
	return (double)sqrt((a - c) * (a - c) + (b - d) * (b - d));
}

ll a, b, dp[105][100005], ans;
vector<pair<ll, ll>>v;

int main() {
	cin >> a >> b;
	v.resize(a);

	for (int i = 0; i < a; ++i) {
		cin >> v[i].first >> v[i].second;
	}

	for (int i = a - 1; i >= 0; --i) {
		for (int j = 0; j <= b; ++j) {
			if (j < v[i].first) { dp[i][j] = dp[i + 1][j]; }
			else { dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - v[i].first] + v[i].second); }
		}
	}

	cout << dp[0][b] << endl;
}

Measured memory_bytes: 82176
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int n;
    cin >> n;
    cout << 800 * n - 200 * (n / 15) << endl;
    return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> y[i];
    }
    sort(all(x));
    sort(all(y));
    for(int z = X + 1; z <= Y; z++) {
        if (x.back() >= z) continue;
        if (y[0] < z) continue;
        cout << "No War" << endl;
        return;
    }
    cout << "War" << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	
	vector<pair<int,int>> r,b;
	rep(i,0,n){
		int y,x; cin >> x >> y; r.push_back(make_pair(y,x));
	}

	rep(i,0,n){
		int y,x; cin >> x >> y; b.push_back(make_pair(y,x));
	}

	vsort(r); vsort(b);

	/*
	rep(i,0,n) cout << "<" << r[i].fir << "," << r[i].sec << ">";
	cout << endl;
	rep(i,0,n) cout << "<" << b[i].fir << "," << b[i].sec << ">";
	cout << endl;
	*/


	int cnt = 0;
	rep(i,0,n){
		int idx = lb(r , b[i] ) - r.begin();
		if( idx == 0 ) continue;

		int m = -1 , m_idx = -1;

		rep(j,0,idx){
			if( r[j].sec < b[i].sec && m < r[j].sec ){
				m = r[j].sec;
				m_idx = j;
			}
		}

		if( m_idx >= 0 ){
			r.erase( r.begin() + m_idx );
			cnt++;
		}
	}

	cout << cnt << endl;
	
	ret 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = scanner.nextInt();
        int N = scanner.nextInt();
        int arr[] = new int[size];
        for (int i = 0; i < size; i++) {
            arr[i] = scanner.nextInt();

        }
        System.out.println((DP(arr, N) == 0 ? "Second" : "First"));

    }

    public static int DP(int arr[], int N) {
        int ans[] = new int[N + 1];
        ans[0] = 0;
        Arrays.sort(arr);
        int index = 0;
        for (int i = 1; i < ans.length; i++) {
            while (index < arr.length && arr[index] <= i) {
                int oppo = ans[i - arr[index]];
                if (oppo == 0) {
                    ans[i] = 1;
                }
                index++;

            }
            index = 0;

        }
        return ans[N];

    }

    public static int getWinner(int arr[], int N) {
        Arrays.sort(arr);
        int index = 0;
        int ans[][] = new int[N + 1][2];
        for (int i = 0; i < ans.length; i++) {
            if (i == 0) {
                ans[0][0] = 1;
                ans[1][0] = 0;
                continue;
            }
            if (index < arr.length && i == arr[index]) {
                ans[i][0] = 0;

                ans[i][1] = 1;
                index++;
                continue;

            }

            for (int j = 0; j < 2; j++) {

                ans[i][j] = -1;

            }
        }
        // for (int i = 0; i < ans.length; i++) {
        // for (int j = 0; j < 2; j++) {
        // System.out.print(ans[i][j] + " ");
        // }
        // // System.out.println(" break");
        // }

        for (int i = 0; i < ans.length; i++) {

            for (int j = 0; j < 2; j++) {
                index = 0;
                int tempAns = -1;
                int o = j == 1 ? 0 : 1;
                ans[i][j] = o;
                while (index < arr.length && i - arr[index] >= 0) {
                    tempAns = ans[i - arr[index]][o];
                    if (tempAns == j) {
                        ans[i][j] = j;
                        break;
                    }
                    index++;
                }

            }
        }

        // for (int i = 0; i < ans.length; i++) {
        // for (int j = 0; j < 2; j++) {
        // System.out.print(ans[i][j] + " ");
        // }
        // System.out.println();
        // }

        return ans[ans.length - 1][0];

    }

}


Measured memory_bytes: 36592
#![allow(unused)]

use std::collections::HashMap;
use proconio::{input, fastout};
use proconio::marker::{Chars, Usize1};

#[fastout]
fn main() {
    input! {
        n: usize,
        xs: [i64; n],
        q: usize,
        ops: [(i64, i64); q],
    }

    let mut s: i64 = xs.iter().sum();

    let mut h = HashMap::new();
    for &x in &xs {
        *h.entry(x).or_insert(0) += 1;
    }

    for &(b, c) in &ops {
        let k = h.remove(&b).unwrap_or(0);
        s += (c - b) * k;
        *h.entry(c).or_insert(0) += k;
        println!("{}", s);
    }
}


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

bool isprime(int p) {
    if (p == 2) {
        return true;
    }
    else if (p < 2 || p % 2 == 0) {
        return false;
    }
    else {
        int i = 3;
        while (i <= sqrt(p)) {
            if (p % i == 0) {
                return false;
            }
            i += 2;
        }
        return true;
    }
}
int main(){
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if (isprime(p)) {
            ans++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;


int main(){
    int N; cin >> N;
    vector<int> V(N);
    for(int i = 0; i < N; i++) cin >> V[i];
    sort(V.begin(), V.end());
    ll ans = 1e18;
    for(int i = 1; i <= 100; i++){
        ll cnt = 0;
        for(int j = 0; j < N; j++){
            cnt += pow(V[j] - i, 2);
        }
        ans = min(cnt, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256