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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int h = sc.nextInt();
		int w = sc.nextInt();
		for (; h != 0 || w != 0;) {
			StringBuffer line = new StringBuffer();
			StringBuffer inline = new StringBuffer();
			for (int i = 0; i < w; i++) {
				line.append('#');
				if (i == 0 || i == w -1) {
					inline.append('#');
				} else {
					inline.append('.');
				}
			}
			for (int i = 0; i < h; i++) {
				if (i == 0 || i == h -1) {
					System.out.println(line);
				} else {
					System.out.println(inline);
				}
			}
			System.out.println("");
			
			h = sc.nextInt();
			w = sc.nextInt();
		}
		
		sc.close();
	}
}

Measured memory_bytes: 19172
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n;
    cin >> n;
    vec a(n);
    rep(i,n){
        cin >> a[i];
    }
    string ans="second";
    rep(i,n){
        if(a[i]%2==1){
            ans="first";
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4056
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if (a < b && b < c){
            System.out.println("Yes");
        }
        else System.out.println("No");
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> xy(n);
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    xy[i].resize(a);
    for(int j = 0; j < a; j++){
      cin >> xy[i][j].first >> xy[i][j].second;
      xy[i][j].first--; 
    }
  }
  int ans = 0;
  for(int bit = 0; bit < (1<<n); bit++){
    bool flg = true;
    for(int i = 0; i < n; i++){
      if(!(bit & (1<<i))) continue;
      for(pair<int,int> v: xy[i]){
        int x = v.first;
        int y = v.second;
        if(bit & (1<<x) && y == 0) flg = false;
        if(!(bit & (1<<x)) && y == 1) flg = false;
      }
    }
    if(flg){
      int cnt = 0;
      for(int i = 0; i < n; i++){
        if(bit & (1<<i)) cnt++;
      }
      ans = max(ans,cnt);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int qq[100000+100];
int len=0;
int main()
{
	LL n;
	scanf("%lld",&n);
	LL oo=1;
	LL fh=1; 
	LL hh=n;
	while(n!=0)
	{
	//	printf("%d\n",n);
		if(abs(n%2)==1)
		{
			qq[len++]=1;
			n-=1*fh;	
		}
		else
			qq[len++]=0;
		fh=-fh;
		n/=2;
	}
	for(int i=len-1;i>=0;i--)
		printf("%d",qq[i]);
	if(len==0)
		printf("0");
	return 0;
 } 

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

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

    if (x <= k * 500)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def remove_monster(a_rest, a, b_rest, b):
    if a_rest <= b_rest:
        removed = a_rest
        a_rest = 0
    else:
        removed = b_rest
        a_rest -= b_rest

    if a_rest <= b:
        removed += a_rest
        b_rest = b - a_rest
    else:
        removed += b
        b_rest = 0

    if a <= b_rest:
        removed += a
        b_rest -= a
        a_rest = 0
    else:
        removed += b_rest
        a_rest = a - b_rest
        b_rest = 0

    return removed, a_rest, b_rest

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
    
a_rest = A[0]
b_rest = 0
all_removed = 0
for n in range(N):
    removed, a_rest, b_rest = \
        remove_monster(a_rest, A[n + 1], b_rest, B[n])
    # print(f'({n}):', removed, a_rest, b_rest)
    all_removed += removed

print(all_removed)


Measured memory_bytes: 19648
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var s = (Console.ReadLine().Split()).Select(x => long.Parse(x)).ToArray();
        long n = s[0];
        long k = s[1];
        long ans = 0;

        for(var i = 0; i < n; i++)
        {
            if (i == 0) ans = k;
            else ans *= (k - 1);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 2776
#include<stdio.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define swap(a,b) (a+=b,b=a-b,a-=b)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=(c==45),c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?~x+1:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
struct REV{int val;}rev[524288];
const int mod=998244353,MOD=200003;
int A[524288]={0},B[200004],len=1;
static inline int ModPow(int a,int b){return b?1l*ModPow(1l*a*a%mod,b>>1)*(b&1?a:1)%mod:1;}
static inline int ModAdd(int a,int b){return (a+=b)>=mod?a-mod:a;}
static inline void NTT(int *a,int lim,int inv)
{
  rep(i,len)if(i<rev[i].val)swap(a[i],a[rev[i].val]);
  for(int l=2;l<=len;l<<=1)
  {
    int m=l>>1,g=ModPow(3,(mod-1)/l),d;
    if(inv)g=ModPow(g,mod-2);
    for(int i=0;i<len;i+=l)
      for(int j=i,w=1;j<i+m;++j,w=1l*w*g%mod)
        d=1l*a[j+m]*w%mod,a[j+m]=ModAdd(a[j],mod-d),a[j]=ModAdd(a[j],d);
  }
  if(inv){inv=ModPow(len,mod-2);rep(i,len){a[i]=1l*a[i]*inv%mod;}}
  return;
}
int main(void)
{
  int N=IN(),bit=1,lim=0,to[200003];long total=0;
  rep(i,MOD-2){bit=2*bit%MOD;to[bit]=i+1;}
  rep(i,N){int x=IN();total-=1l*x*x%MOD;while(1<<lim<=(to[x]+10)<<1){lim++;}if(x){B[x]++,A[to[x]]++;}}
  rep(i,MOD){if(B[i+1]>4800){rep(j,MOD){total+=1l*(i+1)*(j+1)%MOD*B[i+1]*B[j+1]*(1+(i!=j));}B[i+1]=A[to[i+1]]=0;}}
  len=1<<lim;rep(i,len){rev[i].val=(rev[i>>1].val>>1)|((i&1)<<lim>>1);}
  NTT(A,lim,0);rep(i,len){A[i]=1l*A[i]*A[i]%mod;}NTT(A,lim,1);
  bit=1;rep(i,400004){total+=1l*A[i]*bit;bit=2*bit%MOD;}
  return OUT(total/2),0;
}

Measured memory_bytes: 7160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000; // 十分大きな値

int main(){
    int a,b;
    cin >> a >> b;
    if(8 >= a && 8 >= b) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    
}
    



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();

    long a = Math.min(x, y);
    long b = Math.max(x, y);
    for (long i = 1; i <= 100000; i++) {
      if (a * i % b == 0) {
        System.out.println(a * i);
        break;
      }
    }
  }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;

//queue push pair<int,int> practice
int main(){
    int n; cin >> n;
    if(n%2==0){
      cout << n*(n-1)/2-n/2 << endl;
        for(int i=1;i<n;i++){
            for(int j=i+1;j<=n;j++){
                if(j!=n+1-i) cout << i << " " << j << endl;
            }
        }
    }
    else{
        cout << n*(n-1)/2-(n-1)/2 << endl;
        for(int i=1;i<n;i++){
            for(int j=i+1;j<=n;j++){
                if(j!=n-i) cout << i << " " << j << endl;
            }
        }
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	for (int i = 0; i < 365; i++) {
		cout << rand() % 26 + 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;

double calcoo(double r1,double r2){
  //cout << "cal:"<< r1 << " " << r2 <<"->" << sqrt(exp2(r1+r2)-exp2(r1-r2)) <<endl;
  
  if(r1==r2)return 2*r1;
  return sqrt((r1+r2)*(r1+r2)-(r1-r2)*(r1-r2));
}

int main()
{
  int n;

  cin >> n;

  double r[n];
  

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

  vector<double> x;
  vector<double> r_len;
  
  double len=0;
 
  x.push_back(r[0]);
  r_len.push_back(r[0]);
  
  for(int i=1;i<n;i++){
    //???????????§??\????????????????????????
    double max_x=r[i];
    int selected = -1;
    for(int j=0;j<x.size();j++){
      //cout << "x[j]:" << x[j] << endl;
      double tmp = x[j]+calcoo(r[i],r_len[j]); 
      if(max_x< tmp){
	max_x=tmp;
	selected=j;
      }
    }
    //?????°?????????????????????
    //x.erase(v.begin()+selected);
    //r_len.erace(r_len.begin()+selected);
    //cout << max_x << endl;
    x.push_back(max_x);
    r_len.push_back(r[i]);   
  }
  
  double ans=-1.0;
  for(int i=0;i<x.size();i++){
    if(ans<x[i]+r_len[i])ans=x[i]+r_len[i];
  }
  
  printf("%.10f",ans);
  
}

Measured memory_bytes: 1280
while True :
	H, W = map(int, input().split())
	if(H == 0 & W == 0) :
		break
	else :
		for i in range(H) :
			for j in range(W) :
				if(i == 0 or i == H - 1 or
				j == 0 or j == W - 1) :
					print("#", end = "")
				else :
					print(".", end = "")
			print()
		print()


Measured memory_bytes: 7004
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;

int main(){
    int n=0;
    int A[1500];
    int flag =0;
    int out =0;

    cin >> n;
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    for(int i=0;i<n;i++){
        if(A[i] % 2 == 0){
            if((A[i] %3 != 0 )&& (A[i] % 5 != 0)){
                flag = 1;
            }
        }
    }
    if(flag == 0) printf("APPROVED\n");
    else printf("DENIED\n");
    return 0;
}




Measured memory_bytes: 256
x = [0] * 3
y = [0] * 3
z = [0] * 3
x[0], y[0], z[0] = map(int, input().split())
x[1], y[1], z[1] = map(int, input().split())
x[2], y[2], z[2] = map(int, input().split())
N=int(input())

b = []
for i in range(N):
    b.append(int(input()))

for i in range(N):
    for j in range(3):
        if x[j]==b[i]:
            x[j]=0
        if y[j]==b[i]:
            y[j]=0
        if z[j]==b[i]:
            z[j]=0

ans=0

for i in range(3):
    if x[i]==0 and y[i]==0 and z[i]==0:
        ans=1
        break

if x[0]==0 and x[1]==0 and x[2]==0:
    ans=1
if y[0]==0 and y[1]==0 and y[2]==0:
    ans=1
if z[0]==0 and z[1]==0 and z[2]==0:
    ans=1
if x[0]==0 and y[1]==0 and z[2]==0:
    ans=1
if z[0]==0 and y[1]==0 and x[2]==0:
    ans=1

if ans==1:
    print('Yes')
else:
    print('No')


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

int main()
{
    long long int n, m,a,s=0,i;
    scanf("%lld %lld",&n,&m);
    for(i=0;i<m; i++){
        scanf("%lld",&a);
        s=s+a;
    }
    if(s>n){
        printf("-1\n");
    }
    else {
        printf("%lld\n",n-s);
    }
    return 0;
}


Measured memory_bytes: 3720
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        q: usize,
        s: chars,
        lr: [(usize, usize); q],
    }
    let mut v = vec![0; n];
    for i in 1..n {
        if s[i - 1] == 'A' && s[i] == 'C' {
            v[i] += v[i - 1] + 1;
        } else {
            v[i] = v[i - 1];
        }
    }
    let ans = lr
        .iter()
        .map(|&(l, r)| (v[r - 1] - v[l - 1]).to_string())
        .collect::<Vec<_>>()
        .join("\n");
    println!("{}", ans);
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    cin >> n;
    vector<Int> a;
    rep(i,n) {
        Int x;
        cin >> x;
        a.push_back(x);
        a.push_back(x);
    }
    sort(a.begin(), a.end(), greater<Int>());
    Int ans = 0;
    for (int i = 1; i < n; i++) {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 7452
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Abc166D
    {
        public static void Main()
        {
            var x = long.Parse(Console.ReadLine());

            for (long a = 0; (long)Math.Pow(a, 4) <= x; a++)
                for (long b = 0; b < a; b++)
                    if ((long)(Math.Pow(a, 5) - Math.Pow(b, 5)) == x)
                    {
                        Console.WriteLine($"{a} {b}");
                        return;
                    }

            for (long i = 0; (long)Math.Pow(i, 5) <= x; i++)
                for (long j = 0; j <= i; j++)
                    if ((long)(Math.Pow(i, 5) + Math.Pow(j, 5)) == x)
                    {
                        Console.WriteLine($"{i} {-j}");
                        return;
                    }
        }
    }
}


Measured memory_bytes: 27780
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  string s;
  cin >> s;
  int n = s.size(), ans = 0;
  REP(i, n / 2) {
    if (s[i] != s[n - i - 1]) {
      ans++;
    }
  }
  cout << ans << endl;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


int main(){

	int n, m;

	while(1){
		cin >> n;
		cin >> m;

		if(n==0 && m==0) break;

		int taro[n];
		int taro_s=0;
		int hana[m];
		int hana_s=0;

		for(int i=0 ; i<n ; i++){
			cin >> taro[i];
			taro_s += taro[i];
		}
		for(int i=0 ; i<m ; i++){
			cin >> hana[i];
			hana_s += hana[i];
		}

		sort(taro, taro+n);
		sort(hana, hana+m);
		int flag = 0;

		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<m ; j++){
				if((taro_s-taro[i]+hana[j]) == (hana_s-hana[j]+taro[i])){
					cout << taro[i] << ' ' << hana[j] << endl;
					flag = 1;
					break;
				}
			}
			if(flag==1) break;
		}

		if(flag==0) cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <algorithm>
#include <string>

#define ll long long

using namespace std;

ll n;
ll a[100000],b[100000];
ll dff[100000];
ll sum;
ll negasum;

int main(){
 cin>>n;
 for(int i=0;i<n;++i) cin>>a[i];
 for(int i=0;i<n;++i) {
     cin>>b[i];
     dff[i]=a[i]-b[i];
     sum+=dff[i];
 }
 
 if(sum<0){ cout<<-1<<endl; return 0; }

 sort(dff,dff+n);
 
 int ans=0;
 for(int i=0;i<n;++i){
     if(dff[i]<0) { negasum+=dff[i]; ans++;}
     else break;
 }

 if(ans==0){ cout<<0<<endl; return 0;}

 for(int i=n-1;i>=0;--i){
    if(negasum<0){
        ans++;
        negasum+=dff[i];
    }
 }

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


Measured memory_bytes: 2560
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, M, K = in.nextInt
  val As = List.fill(N)(in.nextLong)
  val Bs = List.fill(M)(in.nextLong)

  def takeRead(unread: List[Long], time: Long, cnt: Int, read: List[Long]): (List[Long], List[Long], Long, Int) = unread match {
    case Nil => (unread, read, time, cnt)
    case x :: xs =>
      if (time + x > K) (unread, read, time, cnt)
      else takeRead(xs, time + x, cnt + 1, x :: read)
  }

  def readBs(readAs: List[Long], unreadBs: List[Long], time: Long, cnt: Int, cntMax: Int): Int = readAs match {
    case Nil => cntMax
    case x :: xs =>
      val (newUnreadBs, _, newTime, newCnt) = takeRead(unreadBs, time - x, cnt - 1, Nil)
      readBs(xs, newUnreadBs, newTime, newCnt, cntMax max newCnt)
  }

  val (_, as, time, cnt) = takeRead(As, 0L, 0, Nil)
  println(readBs(0L :: as, Bs, time, cnt + 1, cnt))
}

Measured memory_bytes: 103200
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int memo[3005][3005];
char n[3005],m[3005];
int dp(int i,int j){
    if (!n[i]||!m[j]) return 0;
    if (memo[i][j]!=-1) return memo[i][j];
    if (n[i]==m[j]) return memo[i][j]=dp(i+1,j+1)+1;
    else return memo[i][j]=max(dp(i,j+1),dp(i+1,j));
}
int main(){
    memset(memo,-1,sizeof(memo));
    scanf("%s%s",&n,&m);
    dp(0,0);
    int i=0,j=0;
    while (n[i]&&m[j]){
        if (n[i]==m[j]){
            printf("%c",n[i]);
            i++;
            j++;
        }
        else if (memo[i][j+1]>memo[i+1][j]) j++;
        else i++;
    }
}


Measured memory_bytes: 35712
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int tb[8];

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

	int kanmuri = 0;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;

		if (x >=3200) {
			kanmuri++;
		}
		else {
			tb[x / 400]++;
		}
		
	}

	int bonzin = 0;
	for (int i = 0; i < 8; i++) {
		if (tb[i] != 0) {
			bonzin++;
		}
	}

	if (bonzin > 0) {
		cout << bonzin << " " << bonzin + kanmuri << endl;
	}
	else {
		cout << 1 << " " <<kanmuri<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
D,G=map(int,input().split())
p=[]
c=[]
for i in range(D):
  p1,c1=map(int,input().split())
  p.append(p1)
  c.append(c1)
ans=sum(p)
for i in range(2**D):
  num=0
  point=0
  flag=[0]*D
  for j in range(D):
    if(i>>j&1):
      num+=p[j]
      flag[j]=1
      point+=(j+1)*100*p[j]+c[j]
  if(point<G):
    sitt=flag[::-1]
    loc=D-1-sitt.index(0)
    k=0
    while(point<G):
      num+=1
      k+=1
      point+=(loc+1)*100
    if(k<p[loc]):
      ans=min(ans,num)
  else:
    ans=min(ans,num)
  #print(loc)
print(ans)

Measured memory_bytes: 3064
while True :
    n = int(input())
    if(n == 0) :
        break
    else :
        T = list()
        for i in range(n) :
            T.append(int(input()))
        
        T.sort()
        W = [0 for i in range(n)]
        
        for i in range(1, n) :
            W[i] = sum(T[0 : i])
     
        print(sum(W))
        
    



Measured memory_bytes: 6156
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

const ll MAX = 5000001;//10^7が限界
const ll MOD = Mod;
//const ll MOD = INT64_MAX;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll n;
Vi a;


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    a.resize(n+1);
    map<ll,ll> st;
    ll fro,bac;
    rep(i,n+1){
        cin>>a[i];
        if(st.count(a[i])){
            fro = st[a[i]];
            bac = i;
        }
        st[a[i]] = i;
    }
    COMinit();
    rep(i,n+1){
        ll tmp = 0;
        if(fro+n+1-bac>=i+1){
            tmp = COM(fro+n-bac,i);
        }
        ll ans = Mod + COM(n+1,i+1) - tmp;
        print(ans%Mod);
    }
    return 0;
}

Measured memory_bytes: 125440
#include<stdio.h>
 
int main()
{
  int a,b,c,count=0,i;
  scanf("%d %d %d",&a,&b,&c);

  for(i=1;i<=a;i++){
    if(i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10>=b&&i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10<=c){
      count= count+i;
    }
  }
  printf("%d",count);
  
  return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        List<String> list = new ArrayList<>(Arrays.asList("A", "B", "C", "D", "E", "F", "G", "H","I", "J", "K", "L", "M", "N", "O", "P", "Q","R", "S", "T", "U", "V", "W", "X", "Y", "Z"));
        StringBuilder sb = new StringBuilder();

        String num_s = br.readLine();
        int num = Integer.parseInt(num_s);
        String str = br.readLine();
       
        for(int i=0; i < str.length(); i++){
          int index = list.indexOf(String.valueOf(str.charAt(i)));
          int tmp = index + num;
          if(tmp > list.size() - 1){
            tmp = tmp - (list.size() - 1) - 1;
          }
          sb.append(list.get(tmp));
        }

        System.out.println(sb);
      }
    }
}

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

using namespace std;

char c[100005];
int main()
{
    cin>>c;
    int len=strlen(c);
    if(c[0]==c[len-1])
        len++;
    if(len%2==0)
        cout<<"Second"<<endl;
    else
    cout << "First" << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <queue>
#include <unordered_set>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair

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

struct S {
    int x, y, d;
    S() {}
    S(int x, int y, int d) : x(x), y(y), d(d) {}
};

inline int sig(const S& s) {
    return (s.x<<8) | (s.y<<2) | s.d;
}

inline int sig(const S& p, const S& q) {
    return (sig(p) << 16) | sig(q);
}

bool operator<(const S& l, const S& r) {
    if (l.x != r.x) return l.x < r.x;
    if (l.y != r.y) return l.y < r.y;
    return l.d < r.d;
}

int H, W;
char f[16][64];
int sx, sy, sd, tx, ty, td;
unordered_set<int> reach_h, acc_h;

S forward(int x, int y, int d) {
    for (;;) {
        const int nx = x + dx[d], ny = y + dy[d];
        if (f[nx][ny] == '#') return S(x, y, d);
        x = nx, y = ny;
    }
}

bool reach_r(const S& cur) {
    if (cur.x == tx && cur.y == ty) return true;
    const int si = sig(cur);
    if (reach_h.count(si)) return false;
    reach_h.insert(si);
    int dd = 1;
    rep (_, 2) {
        if (reach_r(forward(cur.x, cur.y, (cur.d+dd)%4))) return true;
        dd += 2;
    }
    return false;
}

bool reach() {
    reach_h.clear();
    return reach_r(forward(sx, sy, sd));
}

bool acc_r(const S& cur, const S& rev);

bool move(const S& l, int x, int y, int d) {
    const int rd = (d+2) % 4;
    if (f[x+dx[d]][y+dy[d]] != '#') return false;
    for (;;) {
        const int si = sig(l, S(x, y, d));
        if (acc_h.count(si) == 0) {
            acc_h.insert(si);
            if (acc_r(l, S(x, y, d))) return true;
        }
        const int nx = x + dx[rd], ny = y + dy[rd];
        if (f[nx][ny] == '#') break;
        x = nx, y = ny;
    }
    return false;
}

bool acc_r(const S& cur, const S& rev) {
    if (cur.x == tx && cur.y == ty
            && rev.x == tx && rev.y == ty && rev.d == td) {
        return true;
    }
    int dd = 1;
    rep (_, 2) {
        if (move(forward(cur.x, cur.y, (cur.d+dd)%4),
                rev.x, rev.y, (rev.d+dd)%4)) return true;
        dd += 2;
    }
    return false;
}

bool accomplish() {
    acc_h.clear();
    const S st = forward(sx, sy, sd);
    rep (d, 4) if (move(st, sx, sy, d)) return true;
    return false;
}

void solve() {
    rep (i, H) rep (j, W) if (f[i][j] == 'K') {
        f[i][j] = '.';
        sx = i, sy = j;
        rep (d, 4) if (f[i+dx[d]][j+dy[d]] != '#') sd = d;
    }
    rep (i, H) rep (j, W) if (f[i][j] == 'M') {
        f[i][j] = '.';
        tx = i, ty = j;
        rep (d, 4) if (f[i+dx[d]][j+dy[d]] != '#') td = d;
    }
    if (!reach()) puts("He cannot bring tea to his master.");
    else if (!accomplish()) puts("He cannot return to the kitchen.");
    else puts("He can accomplish his mission.");
}

int main() {
    for (;;) {
        scanf("%d%d", &W, &H);
        if (H == 0) return 0;
        rep (i, H) rep (j, W) scanf(" %c", f[i]+j);
        solve();
    }
}

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

int main() {
 int N,X,Y;
  cin>>N>>X>>Y;
  
  vector<int> count(N+1);
                       
    for(int i=1;i<=N;i++){
      for(int j=i;j<=N;j++){
        int A,B,C,D;
        A=j-i;
        B=1;
        if(j>Y){C=j-Y;}
        else{C=Y-j;}
        if(i>X){D=i-X;}
        else{D=X-i;}
        int distance;
        distance=min(A,B+C+D);
         count.at(distance)++;
        }
      }
for(int i=1;i<N;i++){
  cout<<count.at(i)<<endl;}
    
                
}
    

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

int main()
{
    int x, result = 0;
    cin >> x;
    while (x > 4){
        if (x >= 500){
            x -= 500;
            result += 1000;
        } else {
            x -= 5;
            result += 5;
        }
    }
    cout << result;
    return 0;
}

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

int main(){
    map<long long,int> dict;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(dict.count(a)){
            cout << "NO" << endl;
            return 0;
        }else{
            dict[a] = 1;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 16080
#include <bits/stdc++.h>
using namespace std;
void roll(vector<int> &saikoro,char houkou){
    //上が１、下が６、手前が２、奥が５、右が３、左が４
    int x,y;
    x = saikoro.at(6);
    y = saikoro.at(1);
    if(houkou == 'N') {
        saikoro.at(6) = saikoro.at(5);
        saikoro.at(1) = saikoro.at(2);
        saikoro.at(2) = x;
        saikoro.at(5) = y;
    }
    else if(houkou == 'S') {
        saikoro.at(6) = saikoro.at(2);
        saikoro.at(1) = saikoro.at(5);
        saikoro.at(5) = x;
        saikoro.at(2) = y;
    }
    else if(houkou == 'E') {
        saikoro.at(6) = saikoro.at(3);
        saikoro.at(1) = saikoro.at(4);
        saikoro.at(4) = x;
        saikoro.at(3) = y;
    }
    else if(houkou == 'W') {
        saikoro.at(6) = saikoro.at(4);
        saikoro.at(1) = saikoro.at(3);
        saikoro.at(3) = x;
        saikoro.at(4) = y;
    }
    else if(houkou == 'T') {
        int u = saikoro.at(2);
        saikoro.at(2) = saikoro.at(3);
        saikoro.at(3) = saikoro.at(5);
        saikoro.at(5) = saikoro.at(4);
        saikoro.at(4) = u;
    }
    else if(houkou == 'R') {
        swap(saikoro.at(1),saikoro.at(6));
        swap(saikoro.at(2),saikoro.at(5));
    }
}

int main() {
    bool b = false;
    bool bl = true;
    vector<int> A1(7);
    for(int i = 1; i <= 6; i++) {
        cin >> A1.at(i);
    }
    vector<int> B1(7);
    for(int i = 1; i <= 6; i++) {
        cin >> B1.at(i);
    }
        queue<char> q;
        
        if(A1.at(1) == B1.at(1)) q.push('A');
        if(A1.at(1) == B1.at(2)) q.push('N');
        if(A1.at(1) == B1.at(3)) q.push('W');
        if(A1.at(1) == B1.at(4)) q.push('E');
        if(A1.at(1) == B1.at(5)) q.push('S');
        if(A1.at(1) == B1.at(6)) q.push('R');
        
        
        while(q.empty() != true && b == false) {
            vector<int> B2(7);
            
            for(int i = 1; i <= 6; i++) {
                B2.at(i) = B1.at(i);
            }
            roll(B2,q.front());
            for(int i = 0; i < 4; i++) {
                roll(B2,'T');
                if(A1 == B2) {
                    b = true;
                    break;
                }
            }
            q.pop();
        }
        if(b == true) cout << "Yes" << endl;
        if(b == false) cout << "No" << endl;
}



Measured memory_bytes: 3112
#include<stdio.h>
int main()
{
	int n,i,a=0,b=0,c=0,d=0;
	char s;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf(" %c ",&s);
		if(s=='P')
			a=1;
		else if(s=='W')
			b=1;
		else if(s=='G')
			c=1;
		else
			d=1;
	}
	printf("%s",(a+b+c+d==4)?"Four":"Three");
	return 0;
}

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

int main() {
	// your code goes here
	double r;
	cin>>r;
	double c;
	c=2*3.141592653589793238*r;
	cout<<fixed<<setprecision(18)<<c<<endl;
	return 0;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define rep(n) for(int i=0;i<(n);i++)
#define rep1(n) for(int i=1;i<=(n);i++)
#define all(n) n.begin(),n.end()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
using namespace std;
using ll=long long;
using pii=pair<ll,ll>;
#define pb push_back
ll n,c;
deque<pii> dq;
ll h[200005];
ll dp[200005];
ll val(pii li,ll x){
   return li.fi * x + li.se;
}
double xv(pii a, pii b){
  return (b.se - a.se)*1.0/(a.fi-b.fi);
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>c;
    for(int i=1;i<=n;i++){
      cin>>h[i];
    }
    dp[1]=0;
    dq.push_back({-2*h[1],h[1]*h[1]});

    for(int i=2;i<=n;i++){
      while(dq.size()>=2 && val(dq[1],h[i]) < val(dq[0],h[i])) dq.pop_front();
      dp[i] = val(dq[0],h[i]) + h[i]*h[i] + c;
      pii tmp = {-2*h[i],h[i]*h[i]+dp[i]};
      while(dq.size()>=2 && xv(tmp,dq[dq.size()-2]) <= xv(dq[dq.size()-1],dq[dq.size()-2])) dq.pop_back();
      dq.push_back(tmp);
      //cout<<"%"<<i<<"\n";

      //cout<<dp[i]<<'\n';
    }
    cout<<dp[n]<<'\n';




}


Measured memory_bytes: 5632
#include <stdio.h>

int main(void) {
	int n, sum, x;
	scanf("%d %d", &n, &sum);
	for (int i = 0; i <= n; i++)
	{
		x = n - i;
		for (int j = 0; j <= n - i; j++)
		{
			if (i * 10000 + j * 5000 + x * 1000 == sum)
			{
				printf("%d %d %d", i, j, x);
				return 0;
			}
			x--;
		}
	}
	printf("-1 -1 -1");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256

int main(void) {

	int A, B, K;
	scanf("%d%d%d", &A, &B, &K);

	int count = 0;
	int X[100];
	for (int i = 1;i<=100; i++) {
		if (A%i == 0 && B%i == 0) {
			X[count] = i;
			count++;
		}
	}

	printf("%d\n", X[count - K]);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int other_sum = 0;
  for(int i = 1; i < n; i++){
    other_sum += vec.at(i);
  }
  if(vec[0]<other_sum){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 256
// Shinchan Loves Coding :)))
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<stack>
using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define double long double
#define en "\n"
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define toUpper(x) transform(x.begin(), x.end(), x.begin(),::toupper);
#define toLower(x) transform(x.begin(), x.end(), x.begin(),::tolower);
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;
bool secdes(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi>b.fi;}else{return a.se>b.se;}}//second descending !
bool sir(const pair<int,int>&a , const pair<int,int>&b){if(a.fi==b.fi){return a.se>b.se;}else{return a.first>b.first;}}//first descending !
bool bysec(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi<b.fi;} else{return a.se<b.se;}}//second ascending !

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

const int no=3e6+5;
const int modulo=1e9+7;
const int inf=1e18+9;
const int N=1001;
int a[no]={},b[no]={},cc[no]={},suma[no]={},mat[N][N]={{0}};
stack<int> S;
stack<int> ma;

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

int poww(int x, int y, int modulo) {x %= modulo;int res=1;while (y > 0) {if (y & 1){res = res * x % modulo;}x = x * x % modulo;y >>= 1;}return res;}

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

vi adj[no];
int used[no]={};

void solve(){
    int n,m;
    cin>>n;
    for(int i=0 ; i<n ; i++) cin>>a[i];
    int ans=0;
    for(int i=0 ; i<(n-2) ; i++){
        for(int j=i+1 ; j<(n-1) ; j++){
            for(int k=j+1 ; k<n ; k++){
                if(((a[i]+a[j])>a[k] && (a[i]+a[k])>a[j] && (a[j]+a[k])>a[i]) && a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]) ans++;
            }
        }
    }
    cout<<ans<<en;
}

void runn(){
        #ifndef ONLINE JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
    }

signed main()
{
    night_rider
    //runn();
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 73932
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int mo = 1e9 + 7;
const int ma = 1000;
#define int long long
struct mint
{
    int x;
    mint():x(0){}
    mint( int x ) : x ( (x % mo + mo) % mo ){} 
    mint & fix() { x = (x % mo + mo) % mo; return *this;}
    mint operator-() const { return mint(0) - *this;}
    mint & operator+=( const mint & a ){ if( (x+=a.x ) >= mo) x -= mo; return *this;}
    mint & operator-=( const mint & a ){ if( (x+=mo - a.x) >= mo) x -= mo; return *this;}
    mint & operator*=( const mint & a ){ ( x *= a.x) %= mo; return *this;}
    mint operator+( const mint & a ) const {return mint(*this) += a;}
    mint operator-( const mint & a ) const {return mint(*this) -= a;}
    mint operator*( const mint & a ) const {return mint(*this) *= a;}
    bool operator<( const mint & a ) const {return x < a.x;}
    bool operator==( const mint & a ) const {return x == a.x;}
};
istream & operator>>(istream & i, mint & a ){ i >> a.x; return i;}
ostream & operator<<(ostream & o, const mint & a ) { o << a.x; return o;}
mint dp[ma][ma];
main()
{
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for( int i = 0; i < h; i++ )cin >> s[i];
    dp[0][0] = 1;
    for( int i = 0; i < h; i++ )
    {
        for( int j = 0; j < w; j++ )
        {
            if( i ) dp[i][j] += dp[i - 1][j];
            if( j ) dp[i][j] += dp[i][j - 1];
            if( s[i][j] == '#' ) dp[i][j] = 0;
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int N;

	cin >> N;

	int A;

	cin >> A;


	cout << N*N-A << endl;

	return 0;
}

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

using namespace std;

int main(){
    string s, s_r;
    cin >> s;
    for (unsigned int i=0; i<s.length(); i++){
            s_r.push_back(s[s.length()-i-1]);
        }
    while(!s_r.empty()){
        if (s_r.substr(0,5) == "maerd"){
            s_r = s_r.erase(0,5);
        }
        else if(s_r.substr(0,7) == "remaerd"){
            s_r = s_r.erase(0,7);
        }
        else if (s_r.substr(0,5) == "esare"){
            s_r = s_r.erase(0,5);
        }
        else if (s_r.substr(0,6) == "resare"){
            s_r = s_r.erase(0,6);
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

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

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<double> p(n);
    rep(i,n){
        p[i] = (double(a[i]) + 1.0) / 2.0;
    }
    // print(p);
    double ans = 0, temp = 0;
    ll cnt = 0;
    rep(i,n){
        temp += p[i];
        cnt++;
        if(cnt > k){
            temp -= p[i - k];
            cnt--;
        }
        // debug(i);debug(temp);
        chmax(ans, temp);
    }

    cout << fixed << setprecision(15);
    cout << ans << endl;
}

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

# xorの性質を使う
# すべての値のxorを求める
x_sum = 0
for i in range(len(a)):
    x_sum ^= a[i]
# すべての値のxorと自分以外のxorから自分を求める
ans = []
for i in a:
    ans.append(x_sum ^ i)

for i in ans:
    print(i)

Measured memory_bytes: 31604
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

bool is_prime(int n) {
    for(int i = 2; i * i <= n; i++) {
        if(n % i == 0) return false;
    }
    return n != 1;
}

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

  int m[50500];
  m[0] = 0;
  rep(i, 50500) {
    m[i + 1] = m[i] + (is_prime(i + 1) && is_prime(2 * i + 1) ? 1 : 0);
  }
  int Q; cin >> Q;
  rep(i, Q) {
      int l, r; cin >> l >> r;
      l = (l + 1) / 2; r = (r + 1) / 2;
      cout << m[r] - m[l - 1] << "\n"; 
  }
  return 0;
}

Measured memory_bytes: 896
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vll a(n);
    ll sum = 0;
    REP(i,n){
        cin >> a[i];
        if(i%2==0){
            sum+=a[i];
        }else{
            sum-=a[i];
        }
    }
    vll ans(n);
    ans[0]=sum;
    for(int i=1;i<n;i++){
        ans[i]=(a[i-1]-(ans[i-1]/2))*2;
    }
    REP(i,n){
        cout << ans[i] << (i==n-1?"\n":" ");
    }

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> T(N);
  for(int i=0;i<N;i++){
    cin>>T[i];
  }
  
  int M;
  cin>>M;
  
  vector<vector<int>> vec(M,vector<int>(2));
  for(int i=0;i<M;i++){
    cin>>vec[i][0]>>vec[i][1];
  }
 
  
  for(int i=0;i<M;i++){
    int sum=0;
    for(int i=0;i<N;i++){
      sum+=T[i];
    }
    sum=sum-T[vec[i][0]-1]+vec[i][1];
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 3576