akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int intceil(int a, int b) {
    return (a + (b - 1)) / b;
}

signed main() {
    cin >> X >> A >> B;
    A = abs(X - A);
    B = abs(X - B);
    if (A < B)
        cout << 'A' << endl;
    else
        cout << 'B' << endl;
}

Measured memory_bytes: 3516
import sys
input = sys.stdin.readline

n, q = [int(x) for x in input().split()]
g = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(x) for x in input().split()]
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
cnt = [0]*n
for _ in range(q):
    p, x = [int(x) for x in input().split()]
    cnt[p - 1] += x
def dfs(x):
    stack = [x]
    used = [0]*n
    used[x] = 1
    while stack:
        u = stack.pop()
        for v in g[u]:
            if not used[v]:
                cnt[v] += cnt[u]
                stack.append(v)
                used[v] = 1
dfs(0)
print(*cnt)

Measured memory_bytes: 54292
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   int s; cin>>s;
   set<int> st;
   int x=s;
   while(st.count(x)==0){
      st.insert(x);
      if(x%2==0) x/=2;
      else x=x*3+1;
   }
   cout<<(st.size()+1)<<endl;
   return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    l = []
    a = []
    b = []
    for _ in range(N):
        A, B = map(int, input().split())
        l.append((A, B))
        a.append(A)
        b.append(B)
    a.sort()
    b.sort()
    if N % 2 == 1:
        return b[N//2] - a[N//2] + 1
    return b[N//2] + b[(N//2)-1] - a[N//2] - a[(N//2)-1] + 1
print(main())


Measured memory_bytes: 39672
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);
const int MAXN = 1e5+5;
int fa[MAXN];
void init()
{
    for(int i = 0; i < MAXN; i++)
    {
        fa[i] = i;
    }
}
int find_root(int x)
{
    return x == fa[x] ? x : fa[x] = find_root(fa[x]);
}
void merge(int x, int y)
{
    int fx = find_root(x), fy = find_root(y);
    if(fx != fy) fa[fy] = fx;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    init();
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int x, y, w;
        cin >> x >> y >> w;
        merge(x, y);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(fa[i] == i)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

pair<ll,int> norm(int c[4]){
	ll x[4]={};
	REP(i,4)
		REP(j,4){
			x[i]*=1000;
			x[i]+=c[(i+j)%4];
		}
	ll a=*min_element(x,x+4);
	int b=0;
	REP(i,4)if(x[i]==a)
		b++;
	return MP(a,b);
}

int main(){
	int n=read();
	vector<pair<ll,int>> fs(n);
	vector<int[4]> raw(n);
	map<ll,int> k;
	REP(i,n){
		REP(j,4)
			raw[i][j]=read();
		fs[i]=norm(raw[i]);
		k[fs[i].first]+=fs[i].second;
	}
	ll ans=0;
	REP(top,n){
		k[fs[top].first]-=fs[top].second;
		FOR(bot,top+1,n){
			k[fs[bot].first]-=fs[bot].second;
			REP(d,4){
				ll w=1;
				pair<ll,int> x[4];
				REP(i,4){
					int tmp[4]={raw[top][(d+1+i)%4],raw[top][(d+0+i)%4],raw[bot][(3-i+4)%4],raw[bot][(2-i+4)%4]};
					x[i]=norm(tmp);
				}
				REP(i,4){
					w*=k[x[i].first];
					k[x[i].first]-=x[i].second;
				}
				ans+=w;
				REP(i,4)
					k[x[i].first]+=x[i].second;
			}
			k[fs[bot].first]+=fs[bot].second;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 80128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int d = a / b;
		int r = a % b;
		double f = 1.0 * a / b;
		System.out.println(d + " " + r + " " + String.format("%.5f", f));
	}
}


Measured memory_bytes: 26424
list1 = [int(a) for a in input().split()]
list1_0 = list1[0] #A
list1_1 = list1[1] #B

plus = list1_0 + list1_1
minus = list1_0 - list1_1
mul = list1_0 * list1_1

max_ans = max(plus, minus, mul)

print(max_ans)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    uint64_t n;
    cin >> n;
    uint64_t i= sqrt(n);
    bool res = false;
    while(i!=1){
        if(n%i == 0){
            cout << n/i + i -2 << endl;
            res = true;
            break;
        }
        i--;
    }
    if(!res){
        cout << n - 1 << endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
 
using namespace std;
 
typedef long long ll;
 
const int N = 200005;
 
int n;
vector<pair<int,int> > adj[N];

ll dst[N];

void dfs(int x,int p){
	for(auto t:adj[x]){
		int y = t.first,v = t.second;
		if(y == p)continue;
		dst[y] = dst[x] + v;
		dfs(y,x);
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y,z;
		cin>>x>>y>>z;
		adj[x].push_back({y,z});
		adj[y].push_back({x,z});
	}
	
	dst[1] = 0;
	
	dfs(1,1);
	
	for(int i=1;i<=n;i++){
		cout<<(dst[i]%2)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 14924
int main(void){
  char a[3],d[7][3] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  
  scanf("%s",a);
  
  int i=6;
  
  while(1){
    if(a[0] == d[i][0] && a[1] == d[i][1]) {
      printf("%d",7-i);
      break;
    }
    
    i --;
  }
    
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
int N,a[200000],b[200000];
int main() {
  cin >> N;
  int minv = 0;
  for(int i = 0;i < N;++i)
    cin >> a[i];
  int j = 1, ans = 0, tmpans = 0;
  bool flg = false;
  for(int i = 0;i < N;++i){
    if(a[i] == j){
      j++;
      flg = true;
    }else{
      ans += 1;
    }
  }
  if(flg)
    cout << ans;
  else
    cout << -1;
}
//0 0 0 0 1 5 2 0 3
//0 -1 -2 -3


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

#define  _   int v, int tl, int tr, int l, int r
#define tm  (tl+tr >> 1)
#define sol v+v,tl,tm,l,r
#define sag v+v+1,tm+1,tr,l,r

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair< int , int > pp;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

map < int , int > M;
map < int , int > :: iterator it;
pp T[N];
int t,n,k,i,x,ans;

signed main(){
    cin >> n >> k;
    for(i=1;i<=n;i++){
        scanf("%d",&x);
        if(M[x]++ == 0) k--;
    }
    if(k >= 0){
        cout << 0; return 0;
    }
    
    for(it=M.begin(); it!=M.end(); it++)
        T[++t] = mp(it->nd,it->st);
    sort(T+1 , T+t+1);
    for(i=1; k++ ;i++){
        ans += T[i].st;
    }
    
    cout << ans;
    return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
bool used[1005][1005];

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

    int h,w;
    cin >> h >> w;
    string a[1005];
    
    queue<ii> q;


    for(int i=0; i<h; i++){
            cin >> a[i];
        for(int j=0; j<w; j++)
            if(a[i][j]=='#'){
                q.emplace(i, j);
                used[i][j]=true;
            }
    }
    int sol=0;
    while(!q.empty()){
        bool added=0;
        int l=q.size();
        for(int i=0; i<l; i++){
            ii frt = q.front();
            q.pop();
            for(int k=0; k<4; k++){
                int nx=frt.first+dx[k], ny=frt.second+dy[k];
                if(nx < 0 || ny < 0 || nx >= h || ny >= w || used[nx][ny])
                    continue;
                used[nx][ny]=1;
                q.emplace(nx, ny);
                added=1;
            }
        }
        sol+=added;
    }
    cout << sol;
}

Measured memory_bytes: 10512
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] != 'R' and S[i] != 'U' and S[i] != 'D':
                print('No')
                return
        if i % 2 == 1:
            if S[i] != 'L' and S[i] != 'U' and S[i] != 'D':
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define N 8
using namespace std;

struct point{
  double x,y;
};

void koch(int d, point p1, point p2){
  point s,u,t;
  if (d==0) return;

  s.x=(2.0*p1.x+p2.x)/3;
  s.y=(2.0*p1.y+p2.y)/3;
  t.x=(p1.x+2.0*p2.x)/3;
  t.y=(p1.y+2.0*p2.y)/3;
  u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
  u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;
  
  koch(d-1, p1, s);
  cout << fixed << setprecision(N) << s.x << " " << s.y << endl;
  koch(d-1, s, u);
  cout << fixed << setprecision(N) << u.x << " " << u.y << endl;
  koch(d-1, u, t);
  cout << fixed << setprecision(N) << t.x << " " << t.y << endl;
  koch(d-1, t, p2);
}

int main(){
  int n;
  cin >> n;
  point p1,p2;
  p1.x=p1.y=0;
  p2.x=100.0;
  p2.y=0;
  cout << fixed <<setprecision(N) << p1.x << " " << p1.y << endl;
  koch(n,p1,p2);
  cout << fixed <<setprecision(N) << p2.x << " " << p2.y << endl;
  return 0;
}



Measured memory_bytes: 3244
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
vector<int> h;
int dp[100001];
int solve(int n, int k){
    dp[1] = 0;
    dp[2] = abs(h[1]-h[0]);
    for(int i=3; i<=n; i++){
        dp[i] = abs(h[i-1]-h[i-2])+dp[i-1];
        for(int j=2; j<=k; j++){
            if(i-j >= 1) dp[i] = min(dp[i], abs(h[i-1]-h[i-j-1]) + dp[i-j]);
        }
    }
    return dp[n];
}
inline void test_case(){
    memset(dp, 0, sizeof dp);
    int n,k;
    cin>>n>>k;
    h.resize(n);
    for(int& i : h) cin>>i;
    cout<<solve(n, k)<<"\n";
}
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    test_case();
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int n,i,j,c,s;
  while(scanf("%d",&n),n){
    for(i=c=1;i<n;i++){
      for(j=s=0;s<n;j++)s+=i+j;
      if(s==n)c++;
    }
    printf("%d\n",c-1);
  }
  return 0;
}
	      

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

using namespace std;

#define fread freopen("in.txt", "r", stdin)
#define fwrite freopen("out.txt", "w", stdout)
#define ll long long

int main ()
{
    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);
    int cnt = 0;
    for (int i = a; i <= b; i++) {
        if (i % c == 0) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}

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

using namespace std ;

int n ; 

const int MAXN = 510 ;

char mp[MAXN][MAXN] ;

bool br[MAXN], bc[MAXN], wr[MAXN] ,wc[MAXN] ; 

bool tvis = 0;  
int main() { 
#ifdef YJQ_LOCAL
		freopen(".in", "r", stdin) ; 
#endif
		scanf("%d", &n) ; 
		for (int i = 1; i <= n; i ++) {
				scanf("%s", mp[i] + 1) ; 
				for (int j = 1; j <= n; j ++) { 
						if (mp[i][j] == '#') { 
								br[i] = 1, bc[j] = 1, tvis = 1; 
						}
						else {
								wr[i] = 1, wc[j] = 1 ; 
						}
				}
		}
		
		if (!tvis) {
				puts("-1"); 
				return 0 ;
		}
		int ans = -1 ; 
		for (int i = 1; i <= n; i ++) {
						int tmp = 0 ;
						if (!bc[i]) tmp = 1 ; 
								for (int j = 1; j <= n; j ++) { 
										if (mp[i][j] == '.') tmp ++ ; 
								}
								for (int j = 1; j <= n; j ++) {
										if (wc[j]) tmp ++ ; 
								}
								if (tmp < ans || ans == -1) ans = tmp ; 
		}
		printf("%d\n", ans) ; 
}



Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  string t;
  cin >> t;

  int n = t.size();
  ll ans = 0;

  int i = n-1;
  while (i >= 0) {
    if (t[i] == '?') { // scan.
      // if (i+1 < n && t[i+1] == 'D') {
      //   t[i] = 'P';
      // } else { // not D
      //   t[i] = 'D';
      // }
      t[i] = 'D';
    }
    --i;
  }
  cout << t << endl;
}


Measured memory_bytes: 3720
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, count = 0;
  char a, b;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    if (a != b) {
      b = a;
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <algorithm>
#define N 301000
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
inline void MIN(int &a, int b) {
	if (b < a)	a = b;
}
int n;
int h[N], sum[N];
namespace jzp1 {
	inline void sol() {
		for (int i = 1; i <= n; ++i)	read(h[i]);
		int tmp1 = 0, tmp2 = 0;
		for (int i = 1; i <= n; i += 2) {
			tmp1 += h[i], tmp2 += h[i + 1];
		}
		printf("%d %d\n", max(tmp1, tmp2), min(tmp1, tmp2));
	}
}

inline bool che(int k) {
	int tmp = 0;
	for (int i = 1; i <= n; ++i) if (i & 1) {
		if (sum[i] - tmp >= k) {
			MIN(tmp, sum[i + 1]);
		} else if (i == n)	return false;
	}
	return true;
}

int main() {
	read(n);
	if (n % 2 == 0) {
		jzp1::sol();
		return 0;
	}
	int r = 0, tot = 0, totsum = 0;
	for (int i= 1; i <= n; ++i) read(h[i]), r += h[i], totsum += h[i];
	for (int i = 1; i <= n; ++i) {
		if (i & 1)	sum[i] = sum[i - 1] + h[i];
		else	sum[i] = sum[i - 1] - h[i], tot += h[i];
	}
	int l = -r, res = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (che(mid))	res = mid, l = mid + 1;
		else	r = mid - 1;
	}
	printf("%d %d\n", res + tot, totsum - (res + tot));
	return 0;
}

/*
5
20 100 10 1 10
//120 21

6
4 5 1 1 4 5
//11 9

5
1 10 100 10 1
//102 20
*/

Measured memory_bytes: 5556
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n;cin>>n;
    vector<long long> a(n);
    for(long long i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    long long ans=1;
    long long b=0,f=b+1;
    long long renzoku=1;
    while(b<n){
        if(abs(a[b]-a[f])<=2){
            f++;
            renzoku++;
            ans=max(ans,renzoku);
        }
        else{
            b++;
            f=b+1;
            ans=max(ans,renzoku);
            renzoku=1;
        }
        if(f==n){
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
def D_Axis_Parallel_Rectangle(N, K, P):
    x = [0 for _ in range(N)]  # 点のx座標
    y = [0 for _ in range(N)]  # y座標
    x_array = [0 for _ in range(N)]
    y_array = [0 for _ in range(N)]
    for i in range(N):
        x[i] = P[i][0]
        y[i] = P[i][1]
        x_array[i] = x[i]
        y_array[i] = y[i]

    x_array = sorted(x_array)
    y_array = sorted(y_array)

    # すべての点を内部に含む、最大の面積を持つ矩形が初期値
    ans = (x_array[N - 1] - x_array[0]) * (y_array[N - 1] - y_array[0])

    # 全探索
    for xi in range(0, N, 1):
        for xj in range(xi + 1, N, 1):
            for yi in range(0, N, 1):
                for yj in range(yi + 1, N, 1):
                    num = 0
                    left = x_array[xi]
                    right = x_array[xj]
                    bottom = y_array[yi]
                    upper = y_array[yj]

                    for i in range(N):
                        if(left <= x[i] and x[i] <= right and bottom <= y[i] and y[i] <= upper):
                            num += 1
                    if num >= K:
                        ans = min(ans, (right - left) * (upper - bottom))
    return ans

N,K = [int(i) for i in input().split()]
P = [[int(i) for i in input().split()] for j in range(N)]
print(D_Axis_Parallel_Rectangle(N, K, P))


Measured memory_bytes: 47580
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,p,y,g,w;
	char a;
	p=y=w=g=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		getchar();
		scanf("%c",&a);
		if(a=='G')
			g=1;
		if(a=='Y')
			y=1;
		if(a=='W')
			w=1;
		if(a=='P')
			p=1; 
	}
	if(w+g+y+p==4)
		printf("Four");
	else
		printf("Three");
	return 0;
}

Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


n = int(input())
cnt = [0]*1001
div = []
for i in range(2, n+1):
    div += prime_factorize(i)

for x in div:
    cnt[x] += 1

m = 1
for i in range(len(cnt)):
    if cnt[i] > 0:
        m *= (cnt[i]+1)
print(m % (10**9+7))

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

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

    if (n >= 30)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

int main(void)
{
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<int> l(q), r(q);
    rep(i, 0, q) cin >> l[i] >> r[i];
    vector<int> cusum(n + 1);
    cusum[0] = 0;
    rep(i, 0, n)
    {
        if (s[max(i - 1, ll(0))] == 'A' && s[i] == 'C')
            cusum[i + 1] = cusum[i] + 1;
        else
            cusum[i + 1] = cusum[i];
    }
    rep(i, 0, q) cout << cusum[r[i]] - cusum[l[i]] << endl;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>

#define MAX (int)1e5

using namespace std;

int num[MAX];
int main(void){
  string S;
  cin >> S;
  vector<int> locateRL;
  char form = 'R';
  num[0] = 0;
  for(int i=1;i<S.size();i++){
    if(form == 'R' && S[i] == 'L')
      locateRL.push_back(i-1);
    form = S[i];
    num[i] = 0;
  }
  // locateRL にはRLとなっている場所のRの位置が入っている
  for(int i=0;i<locateRL.size();i++){
    int R = locateRL[i];
    // 左からやる
    for(int n=0;;n++){
      //範囲外かLになったらおわり
      if(R-n < 0 || S[R-n] == 'L')
	break;
      if(n%2 == 0){
	num[R]++;
      }else{
	num[R+1]++;
      }
    }
    //右のversion
    for(int n=0;;n++){
      //範囲外かLになったらおわり
      if(R+1+n >= S.size() || S[R+1+n] == 'R')
	break;
      if(n%2 == 0){
	num[R+1]++;
      }else{
	num[R]++;
      }
    }
  }
  for(int i=0;i<S.size();i++){
    cout << num[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <array>
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll k,a,b,ans;

int main(int argc,char const* argv[])
{
  cin >> k >> a >> b;
  if(b-a<=2)
    {
      cout << k+1 << endl;
      return 0;
    }
  else
    {
      k-=(a-1);
      ans=a;
      ans+=(k/2)*(b-a);
      if(k%2!=0)
	{
	  ans+=1;
	}
      cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n;
	string w0 = "AC", w1 = "WA", w2 = "TLE", w3 = "RE";
	int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
	cin >> n;
	string w[n];
	
	for(int i = 0 ; i < n ; i++){
		cin >> w[i];
		if(w[i] == w0){
			c0++;
		}else if(w[i] == w1){
			c1++;
		}else if(w[i] == w2){
			c2++;
		}else if(w[i] == w3){
			c3++;
		}
	}
	cout << w0 << " x " << c0 << endl;
	cout << w1 << " x " << c1 << endl;
	cout << w2 << " x " << c2 << endl;
	cout << w3 << " x " << c3 << endl;
}

Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int f[3][3];

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

	int a[3][3];
	rep(i, 3) rep(j, 3) cin >> a[i][j];
	int n;
	cin >> n;
	int b[n];
	rep(i, n) cin >> b[i];

	rep(i, 3) {
		rep(j, 3) {
			rep(k, n) {
				if(a[i][j] == b[k]) f[i][j] = 1;
			}
		}
	}

	int ans = 0;
	rep(i, 3) {
		if(f[i][0] && f[i][1] && f[i][2]) ans = 1;
		if(f[0][i] && f[1][i] && f[2][i]) ans = 1;
	}
	if(f[0][0] && f[1][1] && f[2][2]) ans = 1;
	if(f[2][0] && f[1][1] && f[0][2]) ans = 1;
	yorn(ans);
	// rep(i, 3) {
	// 	rep(j, 3) cout << f[i][j] << " ";
	// 	cout << endl;
	// }
	return 0;
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;

    if(n>=k)
    n=n%k;

    cout<<min(n,abs(k-n))<<endl;

    return 0;
}

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

int main()
{
	int K, T;
	cin >> K >> T;
	priority_queue<int> pq;
	for (int i = 0, a; i < T; i++) {
		cin >> a;
		pq.push(a);
	}
	cout << (K >= pq.top() * 2 ? 0 : (pq.top() * 2 - K - 1)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int sum=0,x=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='R'){
      x++;
      if(x==4){
        sum++;
        x=0;
      }
    }
    else{
      x--;
      if(x==-4)x=0;
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void chmin(int &a, int b) { if (a > b) a = b; }
const int INF = 1<<29; // 十分大きな値

int main() {
    // 入力
    string S, T;
    cin >> S >> T;
    
    // DP テーブル定義
    vector<vector<int> > dp(S.size()+1, vector<int>(T.size()+1, INF));

    // DP 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i <= S.size(); ++i) {
        for (int j = 0; j <= T.size(); ++j) {
            // 変更操作
            if (i > 0 && j > 0) {
                if (S[i-1] == T[j-1]) chmin(dp[i][j], dp[i-1][j-1]);
                else chmin(dp[i][j], dp[i-1][j-1] + 1);
            }
            
            // 削除操作
            if (i > 0) chmin(dp[i][j], dp[i-1][j] + 1);

            // 挿入操作
            if (j > 0) chmin(dp[i][j], dp[i][j-1] + 1);
        }
    }
    
    // 答えの出力
    cout << dp[S.size()][T.size()] << endl;
}



Measured memory_bytes: 6764
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  while (true) {
    double x, h;
    cin >> x >> h;
    if (x == 0 && h == 0)
      return 0;
    double ans = x * x;
    ans += x * sqrt(x * x / 4 + h * h) * 2;
    printf("%.9lf\n", ans);
  }

  return 0;
}



Measured memory_bytes: 3176
#include <iostream>

using namespace std;

int main() {
  char a = 0;
  int ans = 700;
  cin >> a;
  if (a == 'o') ans += 100;
  cin >> a;
  if (a == 'o') ans += 100;
  cin >> a;
  if (a == 'o') ans += 100;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a, b;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> a >> b;
	if(a+b-1 <= n && n <= a*b){
		rrep(j, b, 1){
			cout << j << " ";
		}
		ll cnt = b;
		ll acnt = 1;
		rep(i, 2, a){
			if(n-cnt > a-acnt){
				ll can = min(n-acnt*b-(a-acnt)+1, b);
				rrep(j, cnt+can, cnt+1){
					cout << j << " ";
				}
				cnt += can;
				acnt++;
			}
			else{
				cout << cnt+1 << " ";
				cnt++;
				acnt++;
			}
		}
		cout << endl;
	}
	else{
		print(-1)
	}
	return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<int> a(n), fre(4e5, 0), pre(4e5, 0), suf(4e5, 0);

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

  for (int i = 1; i < 4e5; ++i) {
    if (!fre[i])  continue;
    suf[fre[i]]++;
    pre[fre[i]]++;
  }

  for (int i = 3e5; i >= 0; --i)
    suf[i] += suf[i+1];
  for (int i = 1; i < 4e5; ++i)
    pre[i] = pre[i] * i + pre[i-1];

  auto sum = [&](int x) {
    int ret = suf[x] * x; 
    ret += pre[x-1];
    return ret;
  };

  int cur = n;
  for (int k = 1; k <= n; ++k) {
    while (sum(cur) < cur * k) cur--;
    cout << cur << '\n';
  } 
}

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

#define pf printf
#define sc scanf
#define rep0(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repU(i,bottom,ceiling) for(int (i)=(bottom);(i)<=(ceiling);(i)++)
#define repD(i,ceiling,bottom) for(int (i)=(ceiling);(i)>=(bottom);(i)--)
#define V vector
#define vi V<int>
#define pub(v,el) v.push_back(el)
#define pob(v) v.pop_back
#define ci(a) cin>>a
#define lco(a) cout<<a<<endl
#define co(a) cout<<a
#define vco(v) rep0(i,v.size()){ co(v[i]<<' '); } co('\n')
#define P pair
#define pii P<int,int>
#define mp(a,b) make_P(a,b)
#define fir first
#define sec second

typedef long long ll;
typedef double db;

const int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
const int Inf=2e9+1e8;

template <typename T,typename U>                                                   
pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir+r.fir,l.sec+r.sec};                                    
} 

template <typename T,typename U> 
pair<T,U> operator-(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir-r.fir,l.sec-r.sec};                                    
} 
             
/*The main code follows*/

int main(){
	int s=0,n; 
	ci(n);
	vi a(2000);
	bitset<4000000> b;
	b[0]=1;
	rep0(i,n){ ci(a[i]); s+=a[i];  b|=b<<a[i]; }
	int cnt=(s+1)/2;
	while(!b[cnt]) cnt++;
	lco(cnt);
    return 0;
}







Measured memory_bytes: 1792
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

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

int main() {
	#ifdef KAPPA
	fstream in("../input.txt");
	cin.rdbuf(in.rdbuf());
	#else
	ios::sync_with_stdio(false);
	cin.tie(cout.tie(nullptr));
	#endif

	int n;
	cin >> n;
	vector<int> v(n), dp(n);
	for (auto& i : v) cin >> i;
	dp[0] = 0;
	dp[1] = abs(v[1] - v[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 2] + abs(v[i] - v[i - 2]), dp[i - 1] + abs(v[i] - v[i - 1]));
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

N, M = map(int, input().split())


class Dijkstra(object):
    """ ある特定の点からそのほかの頂点への最小距離を求める
    最短区間を実現するルートについては、prevに格納していく
    """
    def __init__(self, n:int):
        self.adjacency_dict = {}
        self.n = n
        for i in range(n):
            self.add_vertex(i)

    def add_vertex(self, v: int):
        """ ノードを追加する """
        self.adjacency_dict[v] = {}

    def add_edge(self, v1: int, v2: int, w: float, undirected=False):
        self.adjacency_dict[v1][v2] = w
        if undirected:
            self.adjacency_dict[v2][v1] = w

    def run(self, start: int) -> (list, list):
        """ startから初めてそれ以外のノードへの最短距離をダイクストラ法で求める """
        # sからの距離とその前のノードを管理する
        dist = [float('inf')] * self.n
        prev = [None] * self.n
        heap_q = []

        dist[start] = 0

        # プライオリティキューでstartから各ノードの(最短距離, ノードindex)を管理する
        heappush(heap_q, (0, start))

        while len(heap_q) > 0:
            # 未確定な中から最小のノードを取得し、確定する
            d, l = heappop(heap_q)

            # 最小のノードから直接リンクしているノードについて、距離が縮まるようであれば更新する
            for node in self.adjacency_dict[l].keys():
                new_dist = dist[l] + self.adjacency_dict[l][node]
                if dist[node] > new_dist:
                    dist[node] = new_dist
                    heappush(heap_q, (new_dist, node))
                    prev[node] = l

        return dist, prev


g = Dijkstra(N)
for _ in range(M):
    v1, v2 = map(int, input().split())
    g.add_edge(v1 - 1, v2 - 1, 1, undirected=True)

# print(g.adjacency_dict)

dist, prev = g.run(start=0)
# print(dist)

print('Yes')
for p in prev[1:]:
    print(p+1)


Measured memory_bytes: 128228
import numpy as np

mod = 10**9+7
N = int(input())
A = np.array([int(i) for i in input().split()])

sum = A.sum() % mod

#B = np.square(A)
#sum2 = B.sum() % mod

sum2 = 0

for x in A:
  sum2 += x**2
  sum2 %= mod

ans = (sum**2 - sum2) % mod

if ans%2==1 : ans += mod
ans //= 2
ans %= mod
print(int(ans))


Measured memory_bytes: 49788
N = int(input())
S = [input() for _ in range(N)]

ans = 0
for B in range(N):
    flag = True
    for i in range(N):
        for j in range(i+1, N):
            if S[i][(j-B)%N] != S[j][(i-B)%N]:
                flag = False
                break
    if flag:
        ans += N-B

for A in range(1, N):
    flag = True
    for i in range(N):
        for j in range(i+1, N):
            if S[(i-A)%N][j] != S[(j-A)%N][i]:
                flag = False
                break
    if flag:
        ans += N-A
print(ans)

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

using namespace std;

const int N = 1e5 + 1;
const int INF = 1e9;

int n, k;
int a[N], cache[N];

int dp(int i) {
    if (cache[i] != -1) return cache[i];
    if (i < 1) return 0;

    int ans = INF;
    for (int j = 1; j <= k; j++) {
        if (i - j > 0) {
            ans = min(ans, abs(a[i] - a[i - j]) + dp(i - j));
        }
    }

    if (ans == INF) ans = 0;
    return cache[i] = ans;
}

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

    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    
    fill(cache, cache + N, -1);

    cout << dp(n);

    return 0;
}



Measured memory_bytes: 10644
from math import gcd
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
cnt_a = [0] * (max_a + 1)
for ai in a:
  cnt_a[ai] += 1
ans = 'pairwise'
for i in range(2, max_a + 1):
  cnt = 0
  for j in range(i, max_a + 1, i):
    cnt += cnt_a[j]
  if cnt > 1:
    ans = 'setwise'
g = 0
for ai in a:
  g = gcd(g, ai)

if ans == 'pairwise':
  print(ans, 'coprime')
elif ans == 'setwise' and g == 1:
  print(ans, 'coprime')
else:
  print('not coprime')


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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 1e5+20;
const double EPS= 1e-10;

int h[MAXN];
int dp[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(2)<< fixed;
    int n;
    cin>> n;
    forn(i,n){
        cin>> h[i];
    }
    dp[0]=0;
    dp[1]= abs(h[0]-h[1]);
    fore(i,2,n-1){
        dp[i]= min(dp[i-1]+ abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]) );
    }
    cout<< dp[n-1]<<el;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
int main(){
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> count(n);
  count[0] = 0;
  for(int i = 1;i < n;i++){
    if(s[i] == 'C' && s[i - 1] == 'A')count[i] = count[i - 1] + 1;
    else count[i] = count[i - 1];
    //cout << count[i] << " ";
  }
  //cout << endl;
  for(int i = 0;i < q;i++){
    int l,r;
    cin >> l >> r;
    l--,r--;
    cout << count[r] - count[l] << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
s = list(input())

for i in range(4):
    s[i] = int(s[i])

ans = "NA"

if 1 <= s[0] * 10 + s[1] <= 12 and 1 <= s[2] * 10 + s[3] <= 12:
    ans = "AMBIGUOUS"
elif 1 <= s[0] * 10 + s[1] <= 12:
    ans = "MMYY"
elif 1 <= s[2] * 10 + s[3] <= 12:
    ans = "YYMM"

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
int N, M, A[1111], B[1111], V[1111], i, j;main(){scanf("%d%d",&N,&M);for(i=1;i<=N;i++){scanf("%d",&A[i]);}for(i=1;i<=M;i++){scanf("%d",&B[i]);}for(i=1;i<=M;i++){for(j=1;j<=N;j++){if(A[j]<=B[i]){V[j]++;break;}}}printf("%d\n",std::distance(V, std::max_element(V, V + N)));}

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

using namespace std;

int main(){
    int n,m,x;
    cin >> n >> m >> x;

    vector<int> c(n,0);
    vector<vector<int>> a(n,vector<int>(m,0));
    

    for(int i=0; i<n; i++){
        cin >> c[i];
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }

    int min = -1;

    for(int bit = 0; bit < (1<<n); bit++){
        vector<int> u(m,0);
        int sum=0;
        bool flg=true;
        for(int i=0; i<n; i++){
            if(bit & (1<<i)){
                sum += c[i];
                for(int j=0; j<m; j++){
                    u[j] += a[i][j];
                }
            }
        }

        for(int j=0; j<m; j++){
            if(u[j] < x){
                flg = false;
            }
        }
        if(flg){
            if(sum < min || min == -1){
                min = sum;
            }
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
	int a[10000];
	long n,i,saishou=1000001,saidai=-1000001,goukei=0;
	scanf("%ld",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		if(a[i]<saishou){
			saishou=a[i];
		}
		if(a[i]>saidai){
			saidai=a[i];
		}
		goukei+=a[i];
	}
	printf("%ld %ld %ld\n",saishou,saidai,goukei);
	return 0;
}

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

int main()
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    vector<int> w;
    rep(i, F)
    {
        rep(j, F)
        {
            int x = i * 100 * A + j * 100 * B;
            if (x <= F)
                w.push_back(x);
        }
    }

    vector<int> s;
    rep(i, F)
    {
        rep(j, F)
        {
            int y = i * C + j * D;
            if (y <= F)
                s.push_back(y);
        }
    }

    double n = 0;
    int sw_a = 100 * A;
    int s_a = 0;
    rep(i, w.size())
    {
        rep(j, s.size())
        {
            int sum = w[i] + s[j];
            if (sum > F || sum == 0)
                continue;
            if ((w[i] * E) / 100 >= s[j] && n < (100.0F * s[j] / sum))
            {
                n = 100.0F * s[j] / sum;
                sw_a = sum;
                s_a = s[j];
            }
        }
    }
    cout << sw_a << " " << s_a << endl;
    return 0;
}

Measured memory_bytes: 4068
n = gets.to_i
points = readlines.map{|line| line.split.map(&:to_i)}
p1 = []
p2 = []
p3 = []
p4 = []
points.each do |i|
  x =  i[0]+i[1]
  y =  i[0]-i[1]
  p1 << x
  p2 << -x
  p3 << y
  p4 << -y
end
p1.sort!
p2.sort!
p3.sort!
p4.sort!
puts [p1[-1]+p2[-1],p3[-1]+p4[-1]].max

Measured memory_bytes: 51820
#include <iostream>
#include <vector>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  int n, m;
  cin >> n >> m;
  vector<int> v(n, 0);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    v[a]++;
    v[b]++;
  }
  rep(i, n){
    cout << v[i] << endl;
  }
  return 0;
}


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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;
int a[maxn];

int main()
{
  ios::sync_with_stdio(false);
  int k,n;
  cin >> k >> n;

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

  // sort(a, a + n);

  int ans = INT_MAX;
  for(int i = 0; i < n ; i++)
  {
    int cost = k - (k + a[(i+1) % n] - a[i]) % k;
    ans = min(ans, cost);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


r, d, x = nm()
for i in range(10):
    x = r * x - d
    print(x)


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

namespace ABC_D
{
    class D054
    {
        public static void Main(string[] args)
        {
            int[] h = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = h[0], Ma = h[1], Mb = h[2];

            List<int[]> list = new List<int[]>();
            int sumA = 0, sumB = 0;
            for(int i = 0; i < N; i++)
            {
                int[] p = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                list.Add(p);
                int a = p[0], b = p[1], c = p[2];
                sumA += a;sumB += b;
            }

            int[,] price = new int[sumA + 1, sumB + 1];

            for(int i = 0; i <= sumA; i++)
            {
                for(int j = 0; j <= sumB; j++)
                {
                    price[i, j] = int.MaxValue;
                }
            }
            price[0, 0] = 0;

            foreach (int[] p in list)
            {
                int a = p[0], b = p[1], c = p[2];
                for (int i = sumA; i >= a; i--)
                {
                    for (int j = sumB; j >= b; j--)
                    {
                        if (price[i - a, j - b] != int.MaxValue)
                            price[i, j] = Math.Min(price[i, j], price[i - a, j - b] + c);
                    }
                }
            }

            int min = int.MaxValue;
            for(int i = 1; i <= sumA; i++)
            {
                for(int j = 1; j <= sumB; j++)
                {
                    if (i * Mb == j * Ma)
                    {
                        if (price[i, j] < min) min = price[i, j];
                    }
                }
            }
            if (min == int.MaxValue) min = -1;
            Console.WriteLine(min);
        }

    }
}


Measured memory_bytes: 13468
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <utility>

#define MAX_MN (200000L)
#define MAX_FACT (MAX_MN)
#define NUM_MOD (1000000007L)

using namespace std;

long fs[MAX_FACT + 1], finvs[MAX_FACT + 1], invs[MAX_FACT + 1];

void combination_init() {
  fs[0] = fs[1] = 1;
  finvs[0] = finvs[1] = 1;
  invs[1] = 1;
  for (long i = 2; i <= MAX_FACT; i++) {
    fs[i] = fs[i - 1] * i % NUM_MOD;
    invs[i] = NUM_MOD - invs[NUM_MOD % i] * (NUM_MOD / i) % NUM_MOD;
    finvs[i] = finvs[i - 1] * invs[i] % NUM_MOD;
  }
}

long combination(long n, long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fs[n] * (finvs[k] * finvs[n - k] % NUM_MOD) % NUM_MOD;
}

long mod(long n, long k) { return n % k >= 0 ? n % k : n % k + k; }

int main(int argc, char *argv[]) {
  // read inputs
  long N, M, K;
  scanf("%ld %ld %ld", &N, &M, &K);

  // combination init
  combination_init();

  // solve dp
  //   dp1ss[i][j] : sum of (|x1 - x2| + |y1 - y2|) for all pairs of
  //                 cells in a ixj grid
  //   dp2ss[i][j] : sum of (|x1 - x2| + |y1 - y2|) for all pairs of
  //                 cells where one cell is from area A and the other cell
  //                 is from area B in the diagram below.
  //                 Area A is a ixj grid.
  //                   |-------|-|
  //                   |-------|-|
  //                   |---A---|B|
  //                   |-------|-|
  //                   |-------|-|
  map<pair<long, long>, long> dp1ss, dp2ss;
  long s;
  // calculate dp2ss[N][0]
  dp2ss[make_pair(N, 0)] = 0;  // for convenience
  // calculate dp2ss[N][j]
  for (long j = 1; j < M; j++) {
    s = mod(N * (2 * j + N - 1) / 2, NUM_MOD);
    dp2ss[make_pair(N, j)] = mod(dp2ss[make_pair(N, j - 1)] + s, NUM_MOD);
    for (long k = 1; k < N; k++) {
      s = mod(s + k - (N - k), NUM_MOD);
      dp2ss[make_pair(N, j)] = mod(dp2ss[make_pair(N, j)] + s, NUM_MOD);
    }
  }
  // calculate dp1ss[N][0]
  dp1ss[make_pair(N, 1)] = 0;
  for (long d = 1; d < N; d++) {
    dp1ss[make_pair(N, 1)] = mod(dp1ss[make_pair(N, 1)] + d * (N - d), NUM_MOD);
  }
  // calculate dp1ss[N][j]
  for (long j = 2; j <= M; j++) {
    dp1ss[make_pair(N, j)] =
        mod(dp1ss[make_pair(N, j - 1)] + dp1ss[make_pair(N, 1)] +
                dp2ss[make_pair(N, j - 1)],
            NUM_MOD);
  }
  // printf("dp1ss[N][1] = %ld, dp2ss[N][1] = %ld\n", dp1ss[make_pair(N, 1)],
  //        dp2ss[make_pair(N, 1)]);
  // printf("dp1ss[N][M] = %ld, comb(NM-2, K-2) = %ld\n", dp1ss[make_pair(N, M)],
  //        combination(N * M - 2, K - 2));
  printf("%ld\n",
         mod(dp1ss[make_pair(N, M)] * combination(N * M - 2, K - 2), NUM_MOD));

  return 0;
}


Measured memory_bytes: 29952