akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N;
  cin >> N;
  N--;
  COUT(N * (N + 1) / 2);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int , int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 


int main () {
    int a, b, c;
    cin >> a >> b >> c ;
    if( c - (a - b) < 0 ){
        cout << 0 << endl ;
    }
    else {
        cout <<  c - (a - b)  << endl ;
    }
} 


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int GreatestCommonDivisor(int a, int b)
{
    while (1)
    {
        int t = b;
        b = a % b;
        if (b == 0)
        {
            a = t;
            break;
        }
        a = t;
    }
    return a;
}

int main(int argc, char *argv[])
{
    int a = 1, b = 1;
    cin >> a >> b;
    if (a >= b)
    {
        cout << GreatestCommonDivisor(a, b) << endl;
    }
    else
    {
        cout << GreatestCommonDivisor(b, a) << endl;
    }
    return 0;
}



Measured memory_bytes: 3108
//#pragma GCC optimize(\"Ofast,no-stack-protector\")
//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")
//#pragma GCC target(\"avx,tune=native\")
// Neil

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int MAXN=(int)(100000);
const ll MOD=(ll)(1e9+7);
int t;
int arr[10];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    t = 1;
    while(t--){
        int n, k;
        cin>>n>>k;
        for(int i=0;i<k;i++){
            int x;
            cin>>x;
            arr[x] = 1;
        }
        for(int i=n;i<MAXN;i++){
            int x = i;
            bool y = 1;
            while(x!=0){
                int z = x%10;
                if(arr[z]){
                    y = 0;
                    break;
                }
                x =x/10;
            }
            if(y == 1){
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  l=LI()

  sm=sum(l)
  a=sm/(4*m)

  l.sort(reverse=True)
  for x in l:
    if m<=0:
      return 'Yes'
    m-=1
    if x<a:
      return 'No'
  if m<=0:
    return 'Yes'
  return 'No'

# main()
print(main())


Measured memory_bytes: 5288
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,k;
    cin>>a>>b>>k;

    ll res1=max(ll(0),a-k);
    if(k>a)k-=a;
    else k=0;
    ll res2=max(ll(0),b-k);
    cout<<res1<<" "<<res2<<endl;
    return 0;

}


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

int H,W;
char S[400][400];
int reached[400][400];
long int b[160000],w[160000];
void init(int x,int y){
    for(int i = 0;i < x;i++){
        for(int j = 0;j < y;j++){
            reached[i][j] = 0;
        }
    }
    for(int i = 0;i < x*y;i++){
        b[i] = 0;
        w[i] = 0;
    }
}
void search(int x,int y,int k){ //深さ優先探索
    if(x < 0 || x >= H || y < 0 || y >= W || reached[x][y] == 1)return;

    reached[x][y] = 1;
    if(S[x][y] == '#')b[k]++;
    if(S[x][y] == '.')w[k]++;

    if(x<H){
        if(S[x][y] != S[x+1][y])search(x+1,y,k);
    }
    if(x>0){
        if(S[x][y] != S[x-1][y])search(x-1,y,k);
    }
    if(y<W){
        if(S[x][y] != S[x][y+1])search(x,y+1,k);
    }
    if(y>0){
        if(S[x][y] != S[x][y-1])search(x,y-1,k);
    }
}



int main(){
    scanf("%d%d",&H,&W);

    init(H,W);

    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            scanf("%c",&S[i][j]);
            if(S[i][j] == '\n')j = j - 1;
        }
    }

    long int count = 0;
    for(int k = 0;k < H*W;k++){
        search(k/W,k%W,k);
        count += b[k]*w[k];
    }

    printf("%ld\n",count);

    return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string s;
  cin>>s;
  int f, l;
  rep(i,s.size()) {
    if(s[i] == 'A') {
      f = i;
      break;
    }
  }
  
  for(int i = s.size() - 1; i >= 0; i--)
  {
    if(s[i] == 'Z') {
      l = i;
      break;
    }
  }
  // debug(f);debug(l);
  cout << l - f  + 1<< endl;

  return 0;
}


Measured memory_bytes: 720
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
n,m = map(int,input().split())
tmp = []
for i in make_divisors(m):
    if m % i == 0 and m // i >= n:
        tmp.append(i)
print(tmp[-1])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <fstream>
#include <numeric>
#include <cmath>
#include <set>
#include <functional>
#include <vector>
#include <queue>

using namespace std;

#define ll long long;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl;

int a[100010];
int b[100010];
int c[100010];

int main() {
    int N;
    cin >> N;
    rep(i, N)cin >> a[i];
    rep(i, N)cin >> b[i];
    rep(i, N)cin >> c[i];

    sort(a, a + N);
    sort(c, c + N);

    long long sum = 0;
    rep(i, N) {
        long long suma = lower_bound(a, a + N, b[i]) - a;
        long long sumc = N - (upper_bound(c, c + N, b[i]) - c);
        sum += suma*sumc;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct Node{
    int key;
    struct Node *prev;
    struct Node *next;
};
typedef struct Node Node;
Node *nil;
void init(void){
    nil = (Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}
void insert(int key){
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}
Node* listSearch(int key){
    Node *cur=nil->next;
    while (cur!=nil&&cur->key!=key) {
        cur = cur->next;
    }
    return cur;
}
void deleteNode(Node *t){
    if (t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}
void deleteFirst(void){
    deleteNode(nil->next);
}
void deleteLast(void){
    deleteNode(nil->prev);
}
void deleteKey(int key){
    deleteNode(listSearch(key));
}
void printList(void){
    Node *cur=nil->next;
    while (cur!=nil) {
        printf("%d",cur->key);
        if (cur->next!=nil) {
            printf(" ");
        }
        cur = cur->next;
    }
    printf("\n");
}
int main(){
    int n, i, x;
    char a[20];
    init();
    scanf("%d",&n);
    for (i=0;i<n;i++) {
        scanf("%s",a);
        if (a[0]=='i') {
            scanf("%d",&x);
            insert(x);
        } else if (a[0]=='d') {
            if (strlen(a)>6) {
                if (a[6]=='F') {
                    deleteFirst();
                } else if (a[6]=='L') {
                    deleteLast();
                }
            } else {
                scanf("%d",&x);
                deleteKey(x);
            }
        }
    }
    printList();
    return 0;
}



Measured memory_bytes: 33108
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) (i%(ll)(1e9 + 7))

ll n,m;
int d[100005] = {};

int main(){
    cin >> n >> m;
    
    rep(i,0,m){
        int a,b;
        cin >> a >> b;
        d[a-1]++;
        d[b-1]++;
    }

    rep(i,0,n){
        if(d[i] %2 == 1){
            cout << "NO" << endl;
            return 0;
        }
    }

   cout << "YES" << endl;
    
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r = sc.nextInt();
    
    if(n < 10){
      System.out.println(100*(10-n)+r);
    }
    
    if(n >= 10){
      System.out.println(r);
    }
    
  }
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
#define maxn 200009
using namespace std;
int a[maxn];
int main(){
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
    scanf("%d",a+i);
  if(a[1]!=0) puts("-1"),exit(0);
  long long ans=0;
  for(int i=2;i<=n;i++){
    if(a[i]>a[i-1]+1) puts("-1"),exit(0);
    if(a[i]==a[i-1]+1) ans++;
    else ans+=a[i];
  }
  printf("%lld",ans);
  return 0;
}


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

int main(){
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);

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

	int ans = 0;
	rep(i, n-1){
		if(a.at(i) <= x){
			x -= a.at(i);
			ans++;
		}
	}
	if(x == a.at(n-1))
		ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i=0; i<s.length(); i++) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}


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

using namespace std;

char A[1010], B[1010];
int n, m;

int main() {
	scanf("%s%s", A, B);
	n = strlen(A); m = strlen(B);
	int ans = m;
	for(int i = 0;i <= n - m; ++i) {
		int tmp = 0;
		for(int j = 0;j < m; ++j)
			tmp += (A[i + j] != B[j]);
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3760
/*
ID: leezhen
TASK: practice
LANG: C++11                
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <bitset>
#include <list>

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef long long ll;
const int inf = 1e9;
const int mod = 1e9+7;

int main() {
	int n;
	scanf("%d", &n);
	int t = -1, p;
	int ans = 0;
	for(int i=0; i<n; i++) {
		scanf("%d", &p);
		ans += p;
		t = max(t, p);
	}
	ans -= t/2;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=2e5+5;
struct node{
	int x,v;
	inline bool operator <(const node &b)const{return x<b.x;}
}a[N];
int id[N],l[N],r[N],f[N],n;
inline bool cmp(const int &x,const int &y){return a[x].v<a[y].v;}
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d%d",&a[i].x,&a[i].v),id[i]=i;
	sort(a+1,a+1+n),sort(id+1,id+1+n,cmp);
	fp(i,1,n)l[id[i]]=r[id[i]]=i;
	fp(i,2,n)cmax(r[i],r[i-1]);
	fd(i,n-1,1)cmin(l[i],l[i+1]);
	f[0]=1;
	for(R int i=1,j=0,sum=1;i<=n;++i){
		while(j<l[i]-1)sum=dec(sum,f[j++]);
		upd(f[r[i]],sum),upd(sum,sum);
	}
	printf("%d\n",f[n]);
	return 0;
}

Measured memory_bytes: 4992
import math

n, a, b = map(int, input().split())
mod = 10**9+7

c_all = pow(2,n,mod) - 1

c_a_x = 1
c_a_y = 1
for i in range(a):
    c_a_x = c_a_x * (n-i) % mod
    c_a_y = c_a_y * (i+1) % mod

c_a = c_a_x * pow(c_a_y,mod-2,mod) % mod

c_b_x = 1
c_b_y = 1
for i in range(b):
    c_b_x = c_b_x * (n-i) % mod
    c_b_y = c_b_y * (i+1) % mod

c_b = c_b_x * pow(c_b_y,mod-2,mod) % mod

print((c_all - c_a - c_b) % mod)

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> pow_time(19,0);
    for(int i=1; i<=n; i++){
        int time=0;
        int calc=i;
        while(calc <k){
            calc *= 2;
            time++;
        }
        pow_time.at(time)++;
    }
    ll ans=0;
    ll down = pow(2,18);
    ll two_pow=1;
    for(int i=18; i>=0; i--){
        ans += pow_time.at(i) * two_pow;
        two_pow *= 2;
    }
    ll div = down*n;
    cout << fixed << setprecision(10) << (double) ans/div << endl;
}


Measured memory_bytes: 3796
package main

import (
	"fmt"
	"os"
	"strings"
)

func main() {

	var s string
	var i int = 0
	var result string = ""

	fmt.Scan(&s)

	if len(s) > 100000 {
		fmt.Println("overflow")
		os.Exit(0)
	}

	string_array := strings.Split(s, "")

	for ; i < len(s); i++ {
		count := i + 1
		// odd
		if count%2 == 1 {

			result += string_array[i]

		}
	}
	fmt.Println(result)

}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
int main(){
  long K,M=9;
  long long ans[100000]={1,2,3,4,5,6,7,8,9};
  cin >> K;
  long long *adr=ans;
  while(M<K){
    for(int i=-1;i<=1;i++){
      if(*adr%10+i>9||*adr%10+i<0)
        continue;
      ans[M++]=*adr*10+*adr%10+i;
    }
    adr++;
  }
  endend:
  cout << ans[K-1] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int N;
	char S[2*10*10*10*10*10];
	int i;
	int B[2*10*10*10*10*10]={0};
	int W[2*10*10*10*10*10]={0};
	int ans=2*10*10*10*10*10;
	int myself=0;
	scanf("%d %s",&N,S);
	
	
	
	for(i=N-2;i>=0;i--){
		if(S[i+1]=='#'){
			B[i]=B[i+1]+1;
			W[i]=W[i+1];
		}else {
			W[i]=W[i+1]+1;
			B[i]=B[i+1];
		}
	}
	if(B[0]==0){
		if(S[0]=='.'){
			printf("0");
			return 0;
		}
	}

	for(i=0;i<N;i++){
		if(S[i]=='#'){
			if(ans>W[i]+myself){
				ans=W[i]+myself;
			}
			myself++;
		}
	
	}
	if(ans>myself){
		ans=myself;
	}
	
	printf("%d",ans);
	
	
	
	
	
	return 0;
}


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

long long int N, M, x, y, z, d[5] = {-1, 1, 1, 1, 1}, A;
vector<long long int> v[8];

int main(){
    scanf("%lld%lld", &N, &M);
    for(int i = 0; i < N; ++i){
        scanf("%lld%lld%lld", &x, &y, &z);
        for(int j = 0; j < 8; ++j)
            v[j].push_back(d[j & 1] * x + d[j & 2] * y + d[j & 4] * z);
    }
    for(int j = 0; j < 8; ++j){
        sort(v[j].rbegin(), v[j].rend());
        partial_sum(v[j].begin(), v[j].end(), v[j].begin());
        A = max(A, v[j][M - 1]);
    }
    cout << (M ? A : M) << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
//--GLOBAL------------------------------------


//--MAIN------------------------------------
void Main(){
    int N; cin>>N;

    reps(i,1,10){
        reps(j,1,10){
            if(i*j==N) {
                cout<< "Yes" <<"\n";
                return;
            }
        }
    }

    cout<< "No" <<"\n";
}

//--START---------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------


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

#define int long long int
#define endl "\n"

int32_t main(){
	int n, w;
	cin >> n >> w;

	vector<int> val(n), wt(n);

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

	vector<vector<int> > dp(n+1, vector<int>(w+1,0));

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= w; j++){
			if(wt[i-1] <= j)
				dp[i][j] = max(val[i-1] + dp[i-1][j - wt[i-1]], dp[i-1][j]);

			else
				dp[i][j] = dp[i-1][j];
		}
	}

	cout << dp[n][w] << endl;

}

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

int main(void)
{
    int n,m,ans = 0,student[55][2],cp[55][2];
    long min = 99999999999;
    cin >> n >> m;
    for(int i = 0;i < n;i++){cin >> student[i][0] >> student[i][1];}
    for(int i = 0;i < m;i++){cin >> cp[i][0] >> cp[i][1];}
    for(int i = 0;i < n;i++)
    {
        for(int j = m - 1;0 <= j;j--)
        {
            if(abs(student[i][0] - cp[j][0]) + abs(student[i][1] - cp[j][1]) <= min)
            {
                ans = j + 1;
                min = abs(student[i][0] - cp[j][0]) + abs(student[i][1] - cp[j][1]);
            }
        }
        cout << ans << endl;
        min = 99999999999;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


char isused[100010];


int main(){
  int N,K;
  map<char,int> mp;
  string s;
  cin >> N >> K;
  cin >> mp['s'] >> mp['p'] >> mp['r'];
  cin >> s;
  


  int ans = 0;
  rep(i,N){
    if(i>=K && s[i] == isused[i-K]) continue;
    ans+=mp[s[i]];
    isused[i] = s[i];
    // cout<<i<<":"<<s[i]<<": "<< ans << endl;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 512
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
lcm%=mod
ans=0
for x in a:
  ans+=pow(x,mod-2,mod)
  ans%=mod
print(ans*lcm%mod)

Measured memory_bytes: 6076
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  var k = n - 1
  val out = Array.fill(n)("0")
  val buff = StdIn.readLine().split(' ').foreach{ e =>
    out(k) = e
    k -= 1
  }
  println(out.mkString(" "))
  
}


Measured memory_bytes: 43876
fun main() {
    val (n, k) = next2Int()
    val s = hashSetOf<Int>()
    repeat(k) {
        val d = nextInt()
        repeat(d) {
            s += nextInt()
        }
    }
    println(n - s.size)
}

val sc = java.util.Scanner(System.`in`)
fun next(): String = sc.next()
fun nextInt() = sc.nextInt()
fun next2Int() = Pair(nextInt(), nextInt())
fun next3Int() = Triple(nextInt(), nextInt(), nextInt())
fun nextIntArray(size: Int) = IntArray(size) { nextInt() }
fun nextLong() = sc.nextLong()
fun nextLine(): String = sc.nextLine()
fun nextList() = nextLine().split(" ")
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")
fun printString(action: StringBuilder.() -> Unit) = println(buildString(action))


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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

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

  int N;
  cin >> N;
  auto cdiv = [&](auto a, auto b) {
    return (a + b - 1) / b;
  };
  int tmp = cdiv(N, 1000);
  tmp *= 1000;
  cout << tmp - N << "\n";
}

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

int main(){
	
	int N;
	cin >> N;
	if ( N == 19 || N == 29 || N == 39 || N == 49 || N == 59 || N == 69 || N == 79 || N == 89 ||N == 91 || N == 99 ){
		cout << " Yes " << endl;
	} else {
		cout << " No " << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N, A, B;
	scanf("%d %d %d", &N, &A, &B);
	int sum = 0;
	//i == 123
	//123 % 10 == 3; 123/10 == 12
	//12 % 10 == 2; 12/10 == 1
	//1 % 10 == 1; 1/10 == 0
	//3+2+1 = 6;
	
	for(int i = 1; i <= N; i++){
		int digitSum = 0;
		int temp = i;
		while(temp != 0) {
			digitSum = digitSum + temp % 10;
			temp /= 10;
		}
		//temp = 0;
		if(digitSum >= A && digitSum <= B){
			sum += i;
		}
	}
	printf ("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 1724
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String t = sc.next();
		
		for(int i = 0; i < t.length(); i++) {
			if(t.charAt(i) == '?') {
				System.out.print('D');
			} else {
				System.out.print(t.charAt(i));
			}
		}
		System.out.println("");
		
	}
}

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


int main() 
{


    int N,M;

    cin >>N >> M;

    vector<int> S(M);
    vector<char> C(M);
    for(int i=0;i<M;i++){
        cin >> S.at(i) >> C.at(i);
    }

    int loop_start;
    int loop_end;
    if(N==1){
        loop_start=0;
        loop_end=10;
    }else if(N==2){
        loop_start=10;
        loop_end=100;
    }else if(N==3){
        loop_start=100;
        loop_end=1000;
    }

    bool flag=false;
    int result=1000;
    for(int i=loop_start;i<loop_end;i++){
        string strwk = to_string(i);
        for(int j=0;j<M;j++){
            if(strwk.at(S.at(j)-1)==C.at(j)){
                if(j==M-1){
                    flag=true;
                    result = min(result,i);
                }
            }
            else
                break;
        }
    }

    if(M==0){
        if(N==1)
            cout<<0<<endl;
        else if(N==2)
            cout<<10<<endl;
        else if(N==3)
            cout<<100<<endl;
    }
    else if(flag)
        cout<<result<<endl;
    else
        cout<<-1<<endl;
    

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  cin >> str;
  bool ans = false;
  
  for(int i=0;i<3;i++){
    if(str.at(i) == '7'){
      ans = true;
    }
  }
  
  if(ans==true) 
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3560
read a b
if [ $a -lt 0 ]; then
	if [ $b -lt 0 ]; then
		if [ $(( $b - $a + 1 & 1 )) -eq 1 ]; then
			echo 'Negative'
			exit
		fi
	else
		echo 'Zero'
		exit
	fi
fi
echo 'Positive'


Measured memory_bytes: 1400
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
 
#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
 
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;
 
int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}
 
const int N=200000+19;
 
int S[N],A[N],l[N],r[N];
int n,top;
ll res;
 
int main(){
	n=IN();
	For(i,1,n+1) A[i]=IN();
	S[top=1]=0;
	for (int i=1;i<=n;i++){
		while (A[i]<A[S[top]]) top--;
		l[i]=S[top];
		S[++top]=i;
	}
	S[top=1]=n+1;
	for (int i=n;i>=1;i--){
		while (A[i]<A[S[top]]) top--;
		r[i]=S[top];
		S[++top]=i;
	}
	For(i,1,n+1){
		res+=1ll*A[i]*(i-l[i])*(r[i]-i);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int n;
	queue<int> q;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		q.push(a);
	}

	int target = 1;
	int cnt = 0;
	while (q.size() != 0) {
		if (q.front() != target) {
			cnt++;
		} else {
			target++;
		}
		q.pop();
	}
	if (cnt == n) {
		cnt = -1;
	}

	cout << cnt << endl;
}


Measured memory_bytes: 1024
input = raw_input

n, m = map(int, input().split(" "))
pairs = set( [tuple(map(int, input().split(" "))) for _ in range(m)] )
#pairs = sorted(tmp , key=lambda x: x[0])

values = [None] * (n+1)

flag = True
for s, c in pairs:
    if s == 1 and c == 0 and n != 1:
        flag = False
        break

    if values[s] is not None:
        flag = False
        break

    values[s] = c

if flag:
    out = 0
    for i in range(1, n+1):
        value = values[i]
        if value is None:
            if i == 1 and n != 1:
                value = 1
            else:
                value = 0

        j = n - i + 1
        out += value * (10 ** (j-1)) 

else:
    out = -1

print(out)

Measured memory_bytes: 28396
#include<iostream>
#include<cmath>

int main(){

    size_t h;
    std::cin >> h;

    size_t bit = 0;
    while(h != 0){
        h /= 2;
        bit++;
    }

    std::cout << (1ul << bit) - 1 << std::endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()
    
    n, c = map(int, input().split())
    d = [list(map(int, input().split())) for _ in range(c)]

    '''
    # if I can change the color of the same square many times
    # Warshall-Floyd algorithm
    for k in range(c):
        for i in range(c):
            for j in range(c):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
    '''

    color = [list(map(int, input().split())) for _ in range(n)]

    counters = [[0] * c for _ in range(3)]
    for i in range(n):
        for j in range(n):
            counters[(i+j) % 3][color[i][j] - 1] += 1
    
    # full search
    cost = []
    for group in counters:
        l = []
        # from j to i
        for i in range(c):
            num = 0
            for j in range(c):
                num += d[j][i] * group[j]
            l.append((num, i))
        l.sort()
        cost.append(l[:3])

    ans = 10 ** 9
    for i in range(3):
        for j in range(3):
            for k in range(3):
                if cost[0][i][1] != cost[1][j][1] and cost[1][j][1] != cost[2][k][1] and cost[2][k][1] != cost[0][i][1]:
                    if ans > cost[0][i][0] + cost[1][j][0] + cost[2][k][0]:
                        ans = cost[0][i][0] + cost[1][j][0] + cost[2][k][0]
    
    print(ans)

main()

Measured memory_bytes: 11556
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    cout<<char(s1[0]-32)<<char(s2[0]-32)<<char(s3[0]-32)<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma GCC optimize("unroll-loops")
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    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 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 n,x,d;
    map<ll,vector<pair<ll,ll>>>M;
     
    int main(){
    	cin >> n >> x >> d;
    	if(d == 0){
    	    if(x != 0) cout<<n+1<<endl; else cout<<1<<endl; return 0;
    	}
    	int j = 0;
    	for(ll i=-n;i<=n;i+=2){
    		ll val = x*i;
    		ll K =  (val%d+d)%d;
    		val -= (val%d+d)%d;
    		ll beg = 1LL*(j-1)*(j)/2; beg = -1LL*n*(n-1)/2+beg*2;
    		ll en = 1LL*(n-j-1)*(n-j)/2; en = 1LL*n*(n-1)/2-en*2;
            assert(beg <= en);
    		ll L = val/d+beg;
    		ll R = val/d+en;
    		assert( (L+R)%2 == 0 );
    		K = K*2+(L%2+2)%2;
    		L -= (L%2+2)%2; L /= 2;
    		R -= (R%2+2)%2; R /= 2;
    		j++;
    		M[K].pb(mp(L,R));
    		assert(L <= R);
    	}
    	unsigned long long ans = 0;
    	for(auto a:M){
    		vector<pair<ll,ll>>vec = a.sc;
    		vector<ll>za;
    		vector<ll>rui;
    		rep(i,vec.size()) {za.pb(vec[i].fi); za.pb(vec[i].sc+1);}
    		SORT(za); ERASE(za);
    		rui.resize(za.size()+2,0);
    		rep(i,vec.size()){
    			int a = POSL(za,vec[i].fi);
    			int b = POSL(za,vec[i].sc+1);
    			rui[a]++;
    			rui[b]--;
    		}
    		for(int i=1;i<rui.size();i++){
    			rui[i]+=rui[i-1];
    		}
    		rep(i,rui.size()-1){
    			if(rui[i]) ans += za[i+1]-za[i];
    		}
    	}
    	cout << ans << endl;
    }

Measured memory_bytes: 22144
#include<stdio.h>
int main()
{
  int N,L;
  int n[200];
  int abs1,abs2,i,min;
  
  scanf("%d %d",&N,&L);
  
  for(i=1;i<=N;i++){
    n[i]=L+i-1;
    abs1+=n[i];
    abs2+=n[i];
    if(n[i]>=0&&n[i]<=n[i-1]){
      min=n[i];
    }
    else if(n[i]<=0&&n[i]>=n[i-1]){
      min=n[i];
    }
  }
  
  printf("%d",abs2-min);
  
  return 0;
}

Measured memory_bytes: 128
import itertools

def split(xs, t):
    total = 0
    tmp = []
    for i, x in enumerate(xs):
        if i in t:
            total += int(''.join(tmp))
            tmp = [x]
        else:
            tmp.append(x)
    if tmp:
        total += int(''.join(tmp))
    return total


def main():
    nums = list(input())
    length = len(nums)
    total = 0
    for i in range(length):
        for t in itertools.combinations(range(1, length), i):
            total += split(nums, t)
    print(total)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll x=n/2;
  if(n%2==0) x--;
  pr(x);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

vector<int> adj[300001];
int vis[300001],sub[300001];
void dfs(int node)
{
    vis[node]=1;
    int cnt=0;
    for(int i=0;i<adj[node].size();i++)
    {
        if(!vis[adj[node][i]])
            dfs(adj[node][i]);
    }
    sub[node]=cnt;
}
void go()
{
    int n;
    cin>>n;
    vector<int> a(n),dp(n+1,INT_MAX);
    for(int i=0;i<n;i++)
        cin>>a[i];
    dp[1]=0;
    for(int i=1;i<=n;i++)
    {
        if(i>2)
            dp[i]=min(dp[i],dp[i-2]+abs(a[i-3]-a[i-1]));
        if(i>1)
            dp[i]=min(dp[i],dp[i-1]+abs(a[i-2]-a[i-1]));
    }
    cout<<dp[n];
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}


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

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

  if(N>=2 && M>=2) {
    cout << N*(N-1)/2 + M*(M-1)/2 << endl;
  }
  else if(N>=2 && M<2) {
    cout << N*(N-1)/2 << endl;
  }
  else if(N<2 && M>=2) {
    cout << M*(M-1)/2 << endl;
  }
  else cout << 0 << endl;
  
}

Measured memory_bytes: 3604
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

typedef long long ll;
int K, N;
const int MAX_N = 1e5 + 1;
int t[MAX_N];
int d[MAX_N];
bool used[MAX_N];

int main() {
   cin >> N >> K;
   
   pair<int, int> d[N];

   for (int i = 0; i < N; i++) cin >> d[i].second >> d[i].first;
   sort(d, d + N);
   reverse(d, d + N);

   priority_queue<int, vector<int>, greater<int> > que;
   ll var = 0, sum = 0;

   memset(used, false, sizeof(used));
   for (int i = 0; i < K; i++) {
      sum += d[i].first;
      if (!used[d[i].second]) {
         var++;
         used[d[i].second] = true;
      } else que.push(d[i].first);
   }
   ll ans = sum + var * var;
   
   for (int i = K; i < N; i++) {
      if (var >= K) break;
      if (used[d[i].second]) continue;
      var++;
      used[d[i].second] = true;
      int rm = que.top();
      que.pop();
      sum -= rm;
      sum += d[i].first;
      ans = max(ans, sum + var * var);
   }

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


Measured memory_bytes: 1536
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        a = 10 * a + b;
        if(a % 4 == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 35712
#include <stdio.h>

int main(){
  char c[1201];
  int i;
  int ans[26];
  int b=1;
  for(i=0; i<26; i++)ans[i]=0;
  i=0;
  while(scanf("%c",&c[i])!=EOF){
      if(c[i]>='a'&&c[i]<='z')ans[c[i]-'a']++;
      if(c[i]>='A'&&c[i]<='Z')ans[c[i]-'A']++;
      i+=1;
  }
  for(i=0; i<26; i++)printf("%c : %d\n",'a'+i,ans[i]);
  return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#ifdef XLor
  #define dbg(args...) do {cout << #args << " -> "; err(args);} while (0)
#else
  #define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int maxn = 100000 + 5;

ll a, b;

ll cal(ll a) {
    if (a <= 0) return 0;
    ll ans = 0;
    for (int i = 1; i <= 50; i++) {
        ll tot = 1ll << i;
        ll cnt = a / tot * (tot / 2) + max(0ll, a % tot - (tot / 2) + 1);
        if (cnt % 2ll == 1ll) ans ^= 1ll << (i - 1);
    }
    return ans;
}

int main() {
    cin >> a >> b;
    // cal(a - 1);
    // cal(b);
    cout << (cal(a - 1) ^ cal(b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535;

int dp[101][10001];

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

    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define ll long long
using namespace std;

int main(){
    int a[4] = {1, 7, 9, 4};
    for(int i=0;i<4;i++){
        int n, f=0;
        cin >> n;
        for(int j=0;j<4;j++){
            if (a[j] == n) {
                f=1;
                a[j] = 100;
                break;
            }
        }
        if(f == 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

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

  long long tmp[200010];
  tmp[0] = 0;
  for(int i = 0;i < n;i++){
    tmp[i+1] = tmp[i]+a[i];
  }
  n++;
  sort(tmp,tmp+n);

  long long ans = 0;
  long long tmpnum = tmp[0];
  long long tmpsum = 0;
  for(int i = 1;i < n;i++){
    if(tmp[i] == tmpnum){
      tmpsum++;
    }else{
      long long atmp = tmpsum*(tmpsum+1)/2;
      ans += atmp;
      tmpnum = tmp[i];
      tmpsum = 0;
    }
  }

  long long atmp = tmpsum*(tmpsum+1)/2;
  ans += atmp;

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

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

char derv(char c1, char c2)
{
	string res("rgb");
	
	res.erase(res.begin() + res.find(c1));
	res.erase(res.begin() + res.find(c2));
	
	return res[0];
}

string conv(string str, int p, char c)
{
	str[p + 0] = c;
	str[p + 1] = c;
	return str;
}

string answer[16][4];

void init()
{
	rep(i, 16)
	{
		answer[i][0] = string().append(i, 'r');
		answer[i][1] = string().append(i, 'g');
		answer[i][2] = string().append(i, 'b');
	}
}

inline bool check(const string& str)
{
	bool res = false;
	
	rep(i, 3) res |= str == answer[str.size()][i];
	
	return 	res;
}

template<class T>
string toString(T sig)
{
	stringstream ss;
	
	ss << sig;
	
	return ss.str();
}

int main()
{
	init();
	
    for(string worm; cin >> worm && worm != "0";)
	{
		int n = worm.size();
		string ans("NA");
		queue<pair<int, string> > que;
		map<string, int> table;
		
		
		for(que.push(mp(0, worm)); !que.empty(); que.pop())
		{
			string sub(que.front().second);
			int times = que.front().first;
			
			if(table[sub] != 0) continue;
			else table[sub] = 1;
			
			if(check(sub))
			{
				ans = toString(times);
				break;
			}
			
			rep(i, sub.size() - 1) if(sub[i] != sub[i + 1])
			{
				char d = derv(sub[i], sub[i + 1]);
				
				que.push(mp(times + 1, conv(sub, i, d)));
			}
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 2208
program sample
    implicit none
    character(100)::s1,s2,s3
    character(3)::ans
    integer(8) :: i,j,m,n
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) s1,s2,s3
    
    ans(1:1)=char(ichar(s1(1:1))-32)
    ans(2:2)=char(ichar(s2(1:1))-32)
    ans(3:3)=char(ichar(s3(1:1))-32)
    
  
    write(*,'(a)') ans
  
    stop
end program sample
  



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

int main() {
  int H,W;
  cin >> H >> W;
  string A;
  
  for (int i = 0; i < W+2; i++) {
    cout << "#";
  }
  cout << endl;
  for (int i = 0; i < H; i++) {
    cin >> A;
    cout << "#" + A + "#" << endl;
  }  
  for (int i = 0; i < W+2; i++) {
    cout << "#";
  }
}

Measured memory_bytes: 3600
/**
*    author:  Dooloper
*    created: 16.09.2020 23:48:27
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
   long long x;
public:
   mint(long long x=0) : x((x%mod+mod)%mod) {}
   mint operator-() const {
     return mint(-x);
   }
   mint& operator+=(const mint& a) {
       if ((x += a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator-=(const mint& a) {
       if ((x += mod-a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator*=(const  mint& a) {
       (x *= a.x) %= mod;
       return *this;
   }
   mint operator+(const mint& a) const {
       mint res(*this);
       return res+=a;
   }
   mint operator-(const mint& a) const {
       mint res(*this);
       return res-=a;
   }
   mint operator*(const mint& a) const {
       mint res(*this);
       return res*=a;
   }
   mint pow(ll t) const {
       if (!t) return 1;
       mint a = pow(t>>1);
       a *= a;
       return a;
   }
   // for prime mod
   mint inv() const {
       return pow(mod-2);
   }
   mint& operator/=(const mint& a) {
       return (*this) *= a.inv();
   }
   mint operator/(const mint& a) const {
       mint res(*this);
       return res/=a;
   }

   friend ostream& operator<<(ostream& os, const mint& m){
       os << m.x;
       return os;
   }
};
#pragma endregion

int h, w;
char maze[1005][1005];

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> h >> w;
  int sh,sw,gh,gw;
  cin >> sh >> sw >> gh >> gw;
  sh--;sw--;gh--;gw--;
  rep(i,h)rep(j,w) cin >> maze[i][j];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[sh][sw] = 0;
  q.emplace_back(sh,sw);
  while(!q.empty()){
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    if(dist[i][j] != d) continue;
    rep(v,4){
      int ni = i+di[v], nj = j+dj[v];
      if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if(maze[ni][nj] == '#') continue;
      if(dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for(int ei = -2; ei <= 2; ei++){
      for(int ej = -2; ej <= 2; ej++){
        int ni = i+ei, nj = j+ej;
        if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if(maze[ni][nj] == '#') continue;
        if(dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = (dist[gh][gw]==INF)?-1:dist[gh][gw];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8584
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

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

	bool flg = true;
	if(N%2==1){
		//Nが奇数
		for (int i = 0; i < N; i++) {
			if(i==0){
				if(A[i]!=1){
					flg = false;
				}
			}else if(i%2==0){
				if(A[i]!=2){
					flg = false;
				}
			}else{
				if(A[i]>0){
					flg = false;
				}
			}
		}
	}else{
		//Nが偶数
		for (int i = 0; i < N; i++) {
			if(i%2==1){
				if(A[i]!=2){
					flg = false;
				}
			}else{
				if(A[i]>0){
					flg = false;
				}
			}
		}
	}

	int ans = 1;
	for (int i = 0; i < N/2; i++) {
		ans *= 2;
		ans %= MOD;
	}

	if(flg){
		cout << ans << endl;
	}else{
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin>>S;
    int quesID=0;
    vector<string> res;
    for(int i = 0; i < 12; i++)
        if(S[i]=='?')
            quesID=i;
    for(int t = '0'; t <= '9'; t++){
        string test=S;
        test[quesID]=t;
        int p0=test.back()-'0';
        int pq=0;
        for(int i = 0; i < 11; i++){
            int m=11-i;
            if(7<=m&&m<=11)pq+=(m-5)*(test[i]-'0');
                else pq+=(m+1)*(test[i]-'0');
        }

    pq%=11;if(pq<=1)pq=0;else pq=11-pq;
    if(p0==pq)res.push_back(test);
    }
    if(res.size()>1)cout<<"MULTIPLE"<<endl;
    else cout<<res[0][quesID]<<endl;
    return 0;
}

Measured memory_bytes: 3196