akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int h1[3][10] = {}, h2[3][10] = {}, h3[3][10] = {}, h4[3][10] = {};
    int num_notice;
    cin >> num_notice;
    int house_num, floor_num, room_num, tenant_num;
    for(int i = 0; i < num_notice; i++) {
        cin >> house_num >> floor_num >> room_num >> tenant_num;
        if(house_num == 1) {
            h1[floor_num-1][room_num-1] += tenant_num;
        } else if(house_num == 2) {
            h2[floor_num-1][room_num-1] += tenant_num;
        } else if(house_num == 3) {
            h3[floor_num-1][room_num-1] += tenant_num;
        } else if(house_num == 4) {
            h4[floor_num-1][room_num-1] += tenant_num;
        }
    }
    
    for(int a = 0; a < 3; a++){
        cout << " ";
        for(int b = 0; b < 10; b++){
            cout << h1[a][b];
            if(b == 9) {
                cout << endl;
            } else {
                cout << " ";
            }
        }
    }
    
    cout << "####################" << endl;
    
    for(int a = 0; a < 3; a++){
        cout << " ";
        for(int b = 0; b < 10; b++){
            cout << h2[a][b];
            if(b == 9) {
                cout << endl;
            } else {
                cout << " ";
            }
        }
    }
    cout << "####################" << endl;
    
    for(int a = 0; a < 3; a++){
        cout << " ";
        for(int b = 0; b < 10; b++){
            cout << h3[a][b];
            if(b == 9) {
                cout << endl;
            } else {
                cout << " ";
            }
        }
    }
    cout << "####################" << endl;
    
    for(int a = 0; a < 3; a++){
        cout << " ";
        for(int b = 0; b < 10; b++){
            cout << h4[a][b];
            if(b == 9) {
                cout << endl;
            } else {
                cout << " ";
            }
        }
    }
    
    
}


Measured memory_bytes: 3108
import sys 
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass
# input = sys.stdin.readline
for tt in range(1):
	n = int(input())
	s = set()
	for i in range(n):
		s.add(input())
	print(len(s))
			

Measured memory_bytes: 31280
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		char[] s = sc.next().toCharArray();
		int max = 0;

		loop: for (int i = 0; i < s.length; i++) {
			if (s[i] == 'J') {
				int countJ = 0, countO = 0, countI = 0;
				for (int j = i; j < s.length; j++, i++) {
					if (s[i] == 'J') countJ++;
					else if (s[i] == 'O') break;
					else continue loop;
				}
				for (int j = i; j < s.length; j++, i++) {
					if (s[i] == 'O') countO++;
					else if (s[i] == 'I') break;
					else {
						i--;
						continue loop;
					}
				}
				for (int j = i; j < s.length; j++, i++) {
					if (s[i] == 'I') countI++;
					else {
						i--;
						break;
					}
				}
				if (countO <= countJ && countO <= countI) {
					max = max(max, countO);
				}
			}
		}

		out.println(max);
		out.flush();
	}

	static int min(int a, int b) {
		return a < b ? a : b;
	}

	static int max(int a, int b) {
		return a < b ? b : a;
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) { return false; }
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
}

Measured memory_bytes: 34140
import java.util.Scanner;

public class Main{
	private static Scanner scan;
	public static void main(String[] args) {
		scan = new Scanner(System.in);
		double a[] = new double[6];
		int n = Integer.parseInt(scan.next());
		for(int i = 0;i < n;i++){
			for(int j = 0;j < 6;j++)a[j] = Double.parseDouble(scan.next());
			double ab = Math.sqrt(Math.pow(a[3] - a[0], 2) + Math.pow(a[4] - a[1], 2));
			double ra = a[2];
			double rb = a[5];
			if(ra + rb < ab){
				System.out.println(0);
			}else if(Math.abs(ra - rb) > ab && ra > rb){
				System.out.println(2);
			}else if(Math.abs(ra - rb) > ab && ra < rb){
				System.out.println(-2);
			}else{
				System.out.println(1);
			}
		}
		System.exit(0);
	}

}

Measured memory_bytes: 11000
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
	Scanner scan = new Scanner(System.in);
	List<String> list = new ArrayList<String>();
	
	while (true) {
		String str = scan.next();
		if ("-".equals(str)) {
			break;
		}
		
		int m = scan.nextInt();
		int h[] = new int[m];

		for (int i = 0; i < m; i++) {
			h[i] = scan.nextInt();
			str = str.substring(h[i]) + str.substring(0, h[i]);						
		}
		list.add(str);
	}
	
	for (String str : list) {
		System.out.println(str); 
	}
}
}

Measured memory_bytes: 18296
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <iostream>

struct Node
{
    int key;
    Node *prev;
    Node *next;
};

Node *nil;

void Initialize()
{
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void Delete(Node *node)
{
    if (node == nil)
        return;
    node->prev->next = node->next;
    node->next->prev = node->prev;
    free(node);
}

void DeleteFirst()
{
    Delete(nil->next);
}

void DeleteLast()
{
    Delete(nil->prev);
}

Node *SearchNode(int key)
{
    Node *node = nil->next;
    while (node != nil)
    {
        if (node->key == key)
        {
            return node;
        }
        node = node->next;
    }
    return nullptr;
}

void DeleteByKey(int key)
{
    Node *targetNode = SearchNode(key);
    if (targetNode == nullptr)
    {
        return;
    }
    Delete(targetNode);
}

void Insert(int key)
{
    Node *node = (Node *)malloc(sizeof(Node));
    node->key = key;
    node->next = nil->next;
    node->prev = nil;
    nil->next->prev = node;
    nil->next = node;
}

void PrintKey()
{
    Node *node = nil->next;
    int counter = 0;
    while (node != nil)
    {
        if (counter > 0)
        {
            std::cout << " ";
        }
        std::cout << node->key;
        node = node->next;
        counter++;
    }
    std::cout << std::endl;
}

int main()
{
    int num;
    scanf("%d", &num);
    Initialize();
    char command[20];
    int key;
    for (int i = 0; i < num; i++)
    {
        scanf("%s%d", command, &key);
        if (command[0] == 'i')
        {
            Insert(key);
        }
        else if (command[0] == 'd')
        {
            if (strlen(command) > 6)
            {
                if (command[6] == 'F')
                {
                    DeleteFirst();
                }
                else if (command[6] == 'L')
                {
                    DeleteLast();
                }
            }
            else
            {
                DeleteByKey(key);
            }
        }
    }
    PrintKey();
}


Measured memory_bytes: 34500
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>

using namespace std;


int main(int argc, const char * argv[]) {
    
    int n;
    
    cin >> n;
    
    int a[n];
    
    
    
    string ans = "YES";
    
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        
    }
    
    std::sort(a, a+n);
    
    for(int i=0; i<n; i++)
    {
        if(a[i] == a[i+1])
        {
            ans = "NO";
            break;
        }
    }
        

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    ll ans = 0;
    ans += X / 500 * 1000;
    X -= X / 500 * 500;
    cout << ans + X / 5 * 5 << endl;
}

Measured memory_bytes: 256
package main

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

var n int

func dfs(s []byte, x, kind int) {
	if x == n {
		putf("%s\n", string(s))
		return
	}
	for i := 0; i < kind; i++ {
		s[x] = byte('a' + i)
		if i < kind-1 {
			dfs(s, x+1, kind)
		} else {
			dfs(s, x+1, kind+1)
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n = nextInt()

	dfs(make([]byte, n), 0, 1)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 5632
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// https://atcoder.jp/contests/abc168/tasks/abc168_d
string ans[2] = {"No", "Yes"};
bool isVisited[200001] ={0,};
vector<ll> v[200001];
vector<ll> r(200001);
ll cnt = 0;
void BFS(ll start){
	queue<ll> q;
	q.push(start);
	isVisited[start] = true;
	while(!q.empty()){
		ll e = q.front();
		q.pop();
		for(int i = 0;i<v[e].size();i++){
			if(!isVisited[v[e][i]]){
				isVisited[v[e][i]] = true;
				q.push(v[e][i]);
				r[v[e][i]] = e;
			}
		}
	}
} 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

	ll n,m;
	cin >> n >> m;
	for(int i = 0;i<m;i++){
		ll s,e;
		cin >> s >> e;
		v[s].push_back(e);
		v[e].push_back(s);
	}
	BFS(1);
	cout<<"Yes\n";
	for(int j = 2; j <= n; j++) 
		cout<<r[j]<<'\n';
    return 0;
}

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

#define ll long long
#define endl "\n"

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans1 = a * c;
  ll ans2 = a * d;
  ll ans3 = b * c;
  ll ans4 = b * d;
  cout << max(max(ans1, ans2), max(ans3, ans4)) << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll imosa[1000*1000+10];
ll imosb[1000*1000+10];
int ita[1000*1000+10];
int itb[1000*1000+10];

int main(){
  ll n,m;
  cin>>n>>m;
  ll a[n+1]={};
  ll b[n+1]={};
  //ll imosa[n*m+10]={};
  //ll imosb[n*m+10]={};

  for(int i=1;i<=n;i++){
    cin>>a[i];
    imosa[a[i]]++;
    if(ita[a[i]]==0) ita[a[i]]=i;
    else{
      cout<<0<<endl;
      return 0;
    }
  }
  for(int i=1;i<=m;i++){
    cin>>b[i];
    imosb[b[i]]++;
    if(itb[b[i]]==0) itb[b[i]]=i;
    else{
      cout<<0<<endl;
      return 0;
    }
  }

  for(int i=n*m;i>=0;i--){
    imosa[i]=imosa[i]+imosa[i+1];
    imosb[i]=imosb[i]+imosb[i+1];
  }

  ll ans=1,count=0;
  for(int i=n*m;i>0;i--){
    //cout<<i<<" "<<ans<<endl;
    if(ita[i]>0&&itb[i]>0){
      count++;
    }else if(ita[i]>0){
      ans=ans*(imosb[i])%MOD;
      count++;
    }else if(itb[i]>0){
      ans=ans*(imosa[i])%MOD;
      count++;
    }else{
      ll z=(imosa[i]*imosb[i]-count);
      if(z>0) ans=ans*z%MOD;
      else{
        cout<<0<<endl;
        return 0;
      }
      count++;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 19584
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
I suck at CP T_T
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;

int t=1,n,m,k;
vi_t a,b;

int gcd(int a,int b){
	if(a==0){
		return b;
	}
	return gcd(b%a,a);
}
int main(){
	//scanf("%d",&t);
	while(t--){
		cin>>n;
		a.resize(n);
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		int pregcd[n],sufgcd[n];
		pregcd[0]=a[0];
		sufgcd[n-1]=a[n-1];
		for(int i=1;i<n;i++){
			pregcd[i]=gcd(pregcd[i-1],a[i]);
		}
		for(int i=n-2;i>=0;i--){
			sufgcd[i]=gcd(sufgcd[i+1],a[i]);
		}
		int ma=sufgcd[1];
		for(int i=1;i<n-1;i++){
			ma=max(ma,gcd(pregcd[i-1],sufgcd[i+1]));
		}
		ma=max(ma,pregcd[n-2]);
		cout<<ma<<endl;
	}
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

bool is_palindrome(string s)
{
  int n = s.size();
  for (int i = 0; i < n / 2; ++i) {
    if (s[i] != s[n - 1 - i]) { return false; }
  }
  return true;
}


int main()
{
  int A, B; scanf("%d %d", &A, &B);
  int ans = 0;
  for (int i = A; i <= B; ++i) {
    if (is_palindrome(to_string(i))) { ++ans; }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

multiset<lint> decomp(lint N){
    multiset<lint> res;
    lint num=N;
    for(lint i=2;i*i<=num;i++){
        while(N%i==0) N/=i,res.insert(i);
        if(N==1) break;
    }
    if(N!=1) res.insert(N);
    return res; 
}

int main(void){
    int N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    lint ans=0;
    rep(i,60){
        lint zero=0,one=0;
        rep(j,N){
            if(A[j]&(1LL<<i)) one++;
            else zero++;
        }
        lint mul=(zero*one)%MOD;
        lint mul2=(1LL<<i)%MOD;
        ans=(ans+mul*mul2)%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5960
#include<stdio.h>
int w,n,i;
int main(void){
        scanf("%d",&w);
        scanf("%d",&n);
        int data[w];
        for(i=0;i<w;i++) data[i] = i+1;
        for(i=0;i<n;i++){
                int data1,data2;
                scanf("%d,%d",&data1,&data2);
                int temp = data[data1-1];
                data[data1-1] = data[data2-1];
                data[data2-1] = temp;
        }
        for(i=0;i<w;i++) printf("%d\n",data[i]);
        return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int main() {
	int N; cin >> N;
	vector<int> nos(N),args(N),ans(N);
	for (int i = 0; i < N; i++) cin >> nos[i];
	for (int i = 0; i < N; i++) args[i] = i;
	sort(args.begin(), args.end(), [&nos](int lhs, int rhs) {return nos[lhs] < nos[rhs]; });
	for (int i = 0; i < N / 2; i++) ans[args[i]] = nos[args[N / 2]];
	for (int i = N / 2; i < N; i++) ans[args[i]] = nos[args[N / 2 - 1]];
	for (auto x : ans) cout << x << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//----------------------------------------------------------------------

#define MAX 10000

int main(void) {
  ll c[4][4];
  ll b1, b2, b3;
  ll mn;

  FOR(i, 0, 3) {
	FOR(j, 0, 3) {
	  cin >> temp;
	  c[i][j] = temp;
	}
  }

  FOR(i, 0, 101) {
	FOR(j, 0,101) {
	  FOR(k, 0, 101) {
		b1 = c[0][0] - i;
		b2 = c[1][0] - i;
		b3 = c[2][0] - i;

		if (j + b1 == c[0][1] && j + b2 == c[1][1] && j + b3 == c[2][1] && k + b1 == c[0][2] && k + b2 == c[1][2] && k + b3 == c[2][2]) {
		  cout << "Yes" << endl;
		  return 0;
		}
	  }
	}
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
const int maxn=300+7;
int n,K,MOD;
int now[maxn];
int C[maxn][maxn];
int f[maxn][maxn];
int g[maxn][maxn];
int main(){
	scanf("%d%d%d",&n,&K,&MOD);
	for(int i=0;i<=K;++i)
		for(int j=C[i][0]=1;j<=i;++j)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
	for(int i=0;i<n;++i){
		for(int k=1;k<=i+1;++k)now[k]=k;
		for(int j=1,sum=0;j<=n-i;++j,sum=0){
			for(int k=1;k<=i+1;++k)
				sum=(sum+now[k])%MOD,now[k]=sum*1ll*k%MOD;
			g[i][j]=sum;
		}
	}
	f[0][0]=1;
	for(int i=0;i<n;++i)
		for(int j=0;j<K;++j){
			if(!f[i][j])continue;
			const int F=f[i][j];
			for(int k=1;k<=n-i;++k)
				f[i+k][j+1]=(f[i+k][j+1]+F*1ll*g[i][k])%MOD;
		}
	int ans=0;
	for(int i=1;i<=K;++i)
		ans=(ans+f[n][i]*1ll*C[K][i])%MOD;
	printf("%d\n",ans);
	return 0;
}

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

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

    int sum_a=0, sum_b = 0;
    rep(i, n) {
        string a, b;
        cin >> a >> b;
        if (a > b) {
            sum_a += 3;
        }
        else if(a < b) {
            sum_b += 3;
        }
        else {
            sum_a++; sum_b++;
        }
    }
    cout << sum_a << " " << sum_b << endl;
}



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

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

    dp[0] = 1000000;
    dp[1] = 0;
    
    for(int i=2;i<=n;i++){
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
 
#define REP(i,x,n) for (int i = x; i < n; i++)
int N,Y;
int main(){
    cin >> N >> Y;
    REP(i,0,N+1) {
        REP(j,0,N+1-i){
            if (i + j > N) continue;
            int k = N - i - j;
            if (10000*i + 5000*j + 1000*k == Y){
                printf("%d %d %d",i,j,k);
                return 0;
            }
        }
    }
    
    printf("%d %d %d",-1,-1,-1);
            
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int x;
	cin >> x;
	cout << 360 / gcd(360, x) << endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define mp make_pair
#define P pair
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))
#define modp(x, y) (((y) + (x) % (y)) % (y))
#define divd(x, y) (static_cast<double>(x) / static_cast<double>(y))

ll N;
string NS;

int main()
{
    //
    cin >> N;
    stringstream ss;
    ss << N;
    ss >> NS;

    ll s = 0;
    rep(i, 0, NS.size()) { s += NS[i] - '0'; }
    cout << (N % s == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 1e5 + 10;
int a[MAXN] , b[MAXN];
int la = 0 , lb = 0;
int n;
int main(){
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 1 ; i <= n ; ++ i){
		int x;
		cin >> x;
		if(i & 1) a[++ la] = x;
		else b[++ lb] = x;
	}
	sort(a + 1 , a + la + 1);
	sort(b + 1 , b + lb + 1);
	int ans = 0 , now = 0 , sa = 1 , sb = 1;
	while(sa <= la && sb <= lb){
		++ now;
		if(a[sa] < b[sb]){
			if(!(now & 1)) ans ++;
			sa ++;
		}
		else
			sb ++;
	}
	while(sa <= la){
		++ now;
		if(!(now & 1)) ans ++;
		sa ++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std; 

bool
is_good_distance(int64_t l, vector<int64_t> & a, vector<int64_t> & b)
{
    int64_t sum = 0;
    for (int64_t i = 0; i < l; ++i) {
	// cerr << "a[" << i<< "] is " << a[i] << ", b[" << i<< "] is " << b[i] << endl;
	sum = sum + (a[i] - b[i]) * (a[i] - b[i]);
    }
    double d = sqrt((double)sum);
    // cerr << "sum is " << sum << ", d is " << d << endl;
    if (((int64_t) d) * ((int64_t) d) == sum) {
	return true;
    }
    return false;
}


int
main(int argc, char const *argv[])
{
    int64_t n;
    cin >> n;
    vector<int64_t> v(n);
    vector<int64_t> a(n);

    for (int64_t i = 0; i < n; ++i) {
	cin >> v[i];
    }

    a[0] = v[0];
    for (int64_t i = 1; i < n; i = i + 2) {
	a[0] = a[0] - v[i] + v[i+1];
    }
    for (int64_t i = 1; i < n - 1; ++i) {
	a[i] = v[i-1] * 2 - a[i-1];
	// cerr << "v[i-1] * 2 - a[i-1] is " << v[i-1] << " * 2 - " << a[i-1] << endl;
    }
    a[n-1] = v[n-1] * 2 - a[0];

    for (int64_t i = 0; i < n; ++i) {
	cout << a[i];
	if (i != n -1) {
	    cout << " ";
	}
    }
    cout << endl;
    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll MAXN = 150000;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);
uniform_int_distribution<> DD(0, 1000000000);

ll random(ll r){
    return (ll(DD(eng))*1000000000 + ll(DD(eng)))%r;
}

vl A;

vl ANS;

vl B;

bool get(){
    B.clear();
    bool yes = 0;
    for(int c1 = sz(A)-1; c1 >= 0; c1--){
        if(A[c1]-1 == c1 && !yes){
            ANS.push_back(A[c1]);
            yes = 1;
        }
        else{
            B.push_back(A[c1]);
        }
    }
    reverse(all(B));
    A.clear();
    for(int c1 = 0; c1 < sz(B); c1++){
        A.push_back(B[c1]);
    }
    return yes;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n;
    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
    }


    for(int c1 = 0; c1 < n; c1++){
        if(!get()){
            cout << "-1\n";
            return 0;
        }
    }
    reverse(all(ANS));
    for(int c1 = 0; c1 < n; c1++){
        cout << ANS[c1] << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;

int main(){
  ll a,b,c=0,d=0,e,f,g,h,n,m;
  cin>>n>>m;
  co(n*(n-1)/2+m*(m-1)/2);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n, m;
    cin >> n >> m;
    int *x;
    x = new int[MAX];
    priority_queue<int, vector<int>, greater<int> > q;
    rep(i, m){
        cin >> x[i];
    }
    sort(x, x+m);
    rep(i, m){
        if(i){
            q.push(abs(x[i-1]-x[i]));
        }
    }
    
    ll res = 0;
    
    rep(i, m-n){
        res += q.top(); q.pop();
    }
    
    cout << res << endl;
    
    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N;
    while (cin >> N, N) {
        vector<PII> B;
        rep(i, N) {
            int W, M;
            cin >> W >> M;
            B.emplace_back(M, W);
        }
        sort(ALL(B));

        ll sum = 0;
        bool ans = true;
        for (auto b : B) {
            sum += b.second;
            ans &= (sum <= b.first);
        }
        cout << (ans ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 3040
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  int n = s.length();
  
  int begin = 0;
  int end = 0;
  
  for(int i=0;i<n;i++){
    if(s[i] == 'A'){
      begin = i;
      break;
    }
  }
  
  for(int i=n-1;i>=0;i--){
    if(s[i] == 'Z'){
      end = i;
      break;
    }
  }
  
  if(end > begin){
    cout << end - begin + 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int h = sc.nextInt();
      	int w = sc.nextInt();
      	String[] a = new String[h];
      	for(int i = 0; i < h; i++){
        	a[i] = sc.next();
        }
      
      	for(int i = 0; i < w+2; i++){
          System.out.print("#");
          if(i==w+1) System.out.println("");
      	}
      	
      	for(int i = 0; i < h; i++){
        	System.out.println("#" + a[i] + "#");
        }
      
      	for(int i = 0; i < w+2; i++){
          System.out.print("#");
          if(i==w+1) System.out.println("");
      	}
    }
}

Measured memory_bytes: 39132
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N;
string c;

int cnt[202020];

void solve() {
    for (int i = N - 1; i >= 0; i--) {
        cnt[i] = cnt[i + 1] + c[i];
    }

    int ans = 0;
    int tmp = cnt[0];
    for (int i = 0; i < N; i++) {
        if (i < tmp && !c[i])
            ans++;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> c;
    for (auto& s : c) {
        if (s == 'R')
            s = 1;
        else
            s = 0;
    }


    solve();
    return 0;
}


Measured memory_bytes: 5340
#include<stdio.h>

int main(){
	int N;
	int A,B,C;
	for(scanf("%d",&N);N>=1;N--){
		scanf("%d %d %d",&A,&B,&C);
		if(A*A==B*B+C*C||B*B==A*A+C*C||C*C==A*A+B*B)
			printf("YES\n");
		else	
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

    int N,K;
    cin>>N>>K;

    int temp=(N+2-1)/2;

    if(temp>=K){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <limits.h>

#define ll long long

using namespace std;



int main(){

    int h,w;
    cin >> h >> w;
    vector<string> s;
    vector<vector<int>> snh;
    vector<vector<int>> snw;

    for(int i = 0; i < h; i++){
        string tmp;
        cin >> tmp;

        s.push_back(tmp);

        vector<int> tmpv;
        int tmpcount = 0;
        for(int j = 0; j < w; j++){
            if(tmp[j] == '.'){
                tmpcount++;
                tmpv.push_back(tmpcount);
            }else{
                tmpcount = 0;
                tmpv.push_back(tmpcount);
            }
        }

        tmpcount = 0;

        for(int j = w - 1; j > -1; j--){
            if(tmpv[j] == 0){
                tmpcount = 0;
            }else{
                tmpcount = max(tmpcount,tmpv[j]);
                tmpv[j] = tmpcount;
            }
        }

        snh.push_back(tmpv);
    }

    for(int i = 0; i < w; i++){
        vector<int> tmpv;
        int tmpcount = 0;
        for(int j = 0; j < h; j++){
            if(s[j][i] == '.'){
                tmpcount++;
                tmpv.push_back(tmpcount);

            }else{
                tmpcount = 0;
                tmpv.push_back(tmpcount);
            }
        }

        tmpcount = 0;

        for(int j = h - 1; j > -1; j--){
            if(tmpv[j] == 0){
                tmpcount = 0;
            }else{
                tmpcount = max(tmpcount,tmpv[j]);
                tmpv[j] = tmpcount;
            }
        }

        snw.push_back(tmpv);
    }

    int ans = 0;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            
            ans = max(ans, snh[i][j] + snw[j][i]);
        }
    }

    cout << ans - 1 << endl;

    return 0;
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e12;
vector<ll> A;
vector<ll> F;
ll N, K;

bool check(ll x) {
  // K回以下の修行でx以下の成績に出来るならtrueを返す
  ll cnt = 0;
  rep(i, N) {
    ll need = x / F[i];
    ll y = A[i] - need;
    cnt += ((y < 0) ? 0 : y);
  }
  return (cnt <= K);
}

int main() {
  // sort、二分探索
  cin >> N >> K;
  A.resize(N);
  F.resize(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> F[i];
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());

  ll ok = INF; ll ng = -1;
  while (abs(ng-ok) > 1) {
    ll mid = (ok+ng) / 2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  cout << ok << '\n';
  return 0;
}

Measured memory_bytes: 6320
#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 mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int a,b; cin >> a >> b;
	cout << (a+b-1)/b << endl;
}

Measured memory_bytes: 256
data = Array.new()
i = 0
x = Array.new()
y = Array.new()
while true
	data[i] = gets
	break if data[i] == nil
	data[i] = data[i].split(" ")
	a = data[i][0].to_f
	b = data[i][1].to_f
	c = data[i][2].to_f
	d = data[i][3].to_f
	e = data[i][4].to_f
	f = data[i][5].to_f
	y[i] = (((c * (d / a)) - f) / (((d / a) * b) - e)).round(3)
	x[i] = ((c - b * y[i]) / a).round(3)
	i += 1
end
(x.size).times do |i|
	puts "#{sprintf("%.3f",x[i])} #{sprintf("%.3f",y[i])}"
end

Measured memory_bytes: 8760
N, A, B, K = map(int, input().split())
mod = 998244353

fac = [1]
inv = [1]
for i in range(1, N + 1) :
    fac.append(fac[-1] * i % mod)
    inv.append(pow(fac[-1], mod - 2, mod))

ret = 0
for na in range(N + 1) :
    if (K - na * A) % B != 0 :
        continue
        
    nb = (K - na * A) // B
    if 0 <= na <= N and 0 <= nb <= N :
        ret += fac[N] * inv[N-na] * inv[na] * fac[N] * inv[N-nb] * inv[nb]
        ret %= mod
        
print(ret)


Measured memory_bytes: 79472
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
//const int inf=100000;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	ll n;
	cin>>n;
	pair<int,int> p[n];
	int ave=1;
	for(int i=0;i<n;++i)
	{
		int x,y;
		cin>>x>>y;
		p[i].first=x;
		p[i].second=y;
		ave*=i+1;
	}
	vector<vector<double>> dist(n,vector<double>(n));
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			double x_dis=pow((p[i].first-p[j].first),2);
			double y_dis=pow((p[i].second-p[j].second),2);
			double dis=x_dis+y_dis;
			dist[i][j]=sqrt(dis);
		}
	}
	vector<int> order(n);
	for(int i=0;i<n;++i)
	{
		order[i]=i;
	}
	double ans=0;
	do
	{
		double temp_dis=0;
		for(int i=1;i<n;++i)
		{
			temp_dis+=dist[order[i-1]][order[i]];
		}
		ans+=temp_dis;
	}while(next_permutation(order.begin(),order.end()));
	ans=ans/ave;
	printf("%10lf",ans);
	return 0;
}


Measured memory_bytes: 3776
program answer
  implicit none
  integer :: i, n, ans
  integer, allocatable :: p(:)
  read(*,*) n
  allocate(p(n))
  read(*,*) p

  ans=0

  do i = 2, n-1
     if(max(p(i-1),p(i),p(i+1))/=p(i).and.min(p(i-1),p(i),p(i+1))/=p(i)) then
        ans=ans+1
     end if
  end do

  write(*,*) ans
  stop
 end program answer
  

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

int main() {
  int n, temp, result=1;
  vector<int> diameters;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> temp;
    diameters.push_back(temp);
  }
  sort(diameters.begin(),diameters.end());
  
  if (n==1) result==1;
  else {
    for (int i=1; i<n; i++) {
      if (diameters[i]!=diameters[i-1]) result++;
    }
  }
  cout << result;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define SHEET_MAX 101
#define LOOP_RESET 0
#define NULL 0

int main(){
	unsigned short usW_D_row;            	/* 行数格納用変数 */
	unsigned short usW_D_col;            	/* 列数格納用変数 */
	unsigned long ulW_D_sheet[SHEET_MAX][SHEET_MAX];	/* 表格納用配列 */
	unsigned short usW_D_i,usW_D_j;            	/* ループ変数 */
	
	/* 配列の初期化 */
	for(usW_D_i = LOOP_RESET;usW_D_i < SHEET_MAX;usW_D_i++){
		for(usW_D_j = LOOP_RESET;usW_D_j < SHEET_MAX;usW_D_j++){
			ulW_D_sheet[usW_D_i][usW_D_j] = NULL;
		}
	}
	
	/* 行数、列数の入力 */
	scanf("%d %d", &usW_D_row, &usW_D_col);
	
	/* 表の要素の入力 */
	for(usW_D_i =LOOP_RESET;usW_D_i < usW_D_row;usW_D_i++){
		for(usW_D_j = LOOP_RESET;usW_D_j < usW_D_col;usW_D_j++){
			/* usW_D_i行usW_D_j列の要素の入力 */
			scanf("%ld", &ulW_D_sheet[usW_D_i][usW_D_j]);
		}
	}
	
	/* 各行の要素の合計の計算 */
	for(usW_D_i =LOOP_RESET;usW_D_i < usW_D_row;usW_D_i++){
		for(usW_D_j = LOOP_RESET;usW_D_j < usW_D_col;usW_D_j++){
			/* usW_D_i行usW_D_j列の要素をusW_D_i行末端に加算 */
			ulW_D_sheet[usW_D_i][usW_D_col] += ulW_D_sheet[usW_D_i][usW_D_j];
		}
	}
	
	/* 各列の要素の合計の計算 */
	for(usW_D_i =LOOP_RESET;usW_D_i < usW_D_row;usW_D_i++){
		for(usW_D_j = LOOP_RESET;usW_D_j < usW_D_col;usW_D_j++){
			/* usW_D_i行usW_D_j列の要素をusW_D_j列末端に加算 */
			ulW_D_sheet[usW_D_row][usW_D_j] += ulW_D_sheet[usW_D_i][usW_D_j];
		}
	}
	
	/* 全要素の合計の計算 */
	for(usW_D_i = LOOP_RESET;usW_D_i < usW_D_row;usW_D_i++){
		/* 各行の合計を表の末端に加算 */
		ulW_D_sheet[usW_D_row][usW_D_col] += ulW_D_sheet[usW_D_i][usW_D_col];
	}
	
	/* 表を出力 */
	for(usW_D_i =LOOP_RESET;usW_D_i <= usW_D_row;usW_D_i++){
		for(usW_D_j = LOOP_RESET;usW_D_j < usW_D_col;usW_D_j++){
			/* usW_D_i行usW_D_j列の要素の出力 */
			printf("%ld ", ulW_D_sheet[usW_D_i][usW_D_j]);
		}
		/* 末列の出力 */
		printf("%ld\n", ulW_D_sheet[usW_D_i][usW_D_col]);
	}
	return LOOP_RESET;
}


Measured memory_bytes: 2040
n, k = map(int, input().split())
a = list(map(int, input().split()))
stand_bit = [set() for i in range(42)]
acc = [0 for i in range(n+1)]
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        tmp = acc[j+1] - acc[i]
        set_ans.add(tmp)
        s = tmp
        index = 41
        while s:
            if s & 1:
                stand_bit[index].add(tmp)
            s = s >> 1
            index -= 1
for i in range(42):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)


Measured memory_bytes: 625212
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
#define mx 998244353
lli arr[3001][3001];
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  arr[a][b]=1;
  reps(i,a,c+1) reps(j,b,d+1){
      if(i==a && j==b) arr[i][j]=1;
      else if(i==a) arr[i][j]=arr[i][j-1]*i%mx;
      else if(j==b)arr[i][j]=arr[i-1][j]*j%mx;
      else arr[i][j]=(arr[i-1][j]*j%mx+arr[i][j-1]*i%mx-arr[i-1][j-1]*(i-1)%mx*(j-1)%mx +mx)%mx;//+arr[i-1][j-1]*(i+j) ;
      //cout<<arr[i][j]<<" ";
  }
 // int l=c-a+d-b;
  //cout<<c*d-a*b<<" "<<l<<endl;
  cout<<arr[c][d];
  return 0;
}


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

#define MAX 100002

int n;
int h;

#define MAXX 202
int lef[MAXX];
int rig[MAXX];

int deg[MAXX*2];

vector<int> v[MAXX*2];

int belong[MAXX * 2];
inline int root(int b){
	if (belong[b] == -1){
		return b;

	}
	belong[b] = root(belong[b]);
	return belong[b];
}
void merge(int a, int b){
	a = root(a);
	b = root(b);
	if (a == b){
		return;
	}
	belong[a] = b;
}
map<int, vector<int> > mp;

bool ava[MAXX*2];
bool flag[MAXX * 2];

bool check(vector<int> vv){
	bool ng = false;
	int restr = 0;
	int restl = 0;
	int id = -1;
	int id2 = -1;
	bool ok = false;
	for (int ii = 0; ii < vv.size(); ii++){
		ok |= flag[vv[ii]];
	}
	if (ok == false){
		return true;
	}
	for (int ii = 0; ii <vv.size();ii++){
		int ix = vv[ii];
		if (ix & 1){
			int i = ix / 2;
			if (deg[rig[i]] >= 0){
				restr += deg[rig[i]];
				if (deg[rig[i]]){
					id = rig[i];
				}
			}
			else{
				ng = true;
			}
		}
		else{
			int i = ix / 2;
			if ( deg[lef[i]] <= 0){
				restl += -deg[lef[i]];
				if (deg[lef[i]] < 0){
					id2 = lef[i];
				}
			}
			else{
				ng = true;
			}
		}
	}
	if (restr == 0 || restl == 0){
		return false;
	}
	if (ng){
		return false;
	}
	if (restr == 1 && restl == 1 && v[id].size() == 1 && v[id2].size() == 1 && v[id][0] == v[id2][0]){
		return false;
	}
	return true;
}
int main(){
	memset(belong, -1, sizeof(belong));
	for (int i = 0; i < MAXX; i++){
		lef[i] = 2 * i;
		rig[i] = lef[i] + 1;
	}
	cin >> n >> h;
	for (int i = 0; i < n; i++){
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int k;
		if (c){
			deg[lef[c]]++;
			k = lef[c];
			ava[lef[c]] = true;
			flag[lef[c]] = true;
		}
		else{
			deg[rig[a]]++;
			v[rig[a]].push_back(i);
			k = rig[a];
			ava[rig[a]] = true;
		}
		if (d){
			deg[rig[d]]--;
			flag[rig[d]] = true;
			merge(k, rig[d]);
			ava[rig[d]] = true;
		}
		else{
			deg[lef[b]]--;
			v[lef[b]].push_back(i);
			merge(k, lef[b]);
			ava[lef[b]] = true;
		}
	}
	for (int i = 0; i < 2*MAXX; i++){
		if(ava[i])mp[root(i)].push_back(i);
	}
	for (auto it = mp.begin(); it != mp.end(); it++){
		if (check((*it).second) == false){
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+int(b[i])<=0:
    counter_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print(min(counter_1,counter_2,counter_3))

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

int main(){
    string s;
    cin >>s;
    int c=0;
    int f=0;
    int i=0;
    while((i<s.size())&&(c==0)){
        if(s.at(i)=='C'){
            c++;

        }
        i++;
    }
    while((i<s.size())&&(f==0)){
        if(s.at(i)=='F'){
            f++;

        }
        i++;
    }
    if((c==1)&&(f==1)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/

const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int N,D;

int main(void) {
  cin >> N >> D;
  
  int count=0;
  
  while(N>0){
    N=N-(2*D+1);
    count++;
  }
  
  cout << count << endl;
  return 0;
}


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int n;
	cin >> n;
	vector<ll> a(n);
	loop(n) cin >> a[i];
	ll ans = 0;
	sort(riter(a));
	priority_queue<tuple<ll, ll, ll>> pos;
	pos.emplace(a[0], a[0], a[0]);
	for (int i = 1;i < n;i++) {
		auto [v, l, r] = pos.top();
		pos.pop();
		ans += v;
		pos.emplace(a[i], l, a[i]);
		pos.emplace(a[i], a[i], r);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 11092