akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define f first
#define s second
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define pb push_back
 
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 1e9 + 7;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
} 

ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}

bool sortbysec(const pair<ll, ll>& a, 
               const pair<ll, ll>& b) 
{ 
    return (a.second < b.second); 
} 
  
// Function to find maximal disjoint set 
ll maxDisjointIntervals(vector<pair<ll, ll> > list) 
{ 
  
    // Sort the list of intervals 
    sort(list.begin(), list.end(), sortbysec); 
  
    // First Interval will always be 
    // included in set 
    // cout << "[" << list[0].first << ", "
    //      << list[0].second << "]" << endl; 
    ll count=1;
  
    // End point of first interval 
    ll r1 = list[0].second; 
  
    for (ll i = 1; i < list.size(); i++) { 
        ll l1 = list[i].first; 
        ll r2 = list[i].second; 
  
        // Check if given interval overlap with 
        // previously included interval, if not 
        // then include this interval and update 
        // the end point of last added interval 
        if (l1 >= r1) { 
            count++; 
            r1 = r2; 
        } 
    }
    
    return count;
} 

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    
    cin >> n;
    
    vp v1;
    rep(i,0,n)
    {
        ll x,l;
        cin >> x >>l;
        
        v1.pb({x-l,x+l});
    }
    
    cout << maxDisjointIntervals(v1);
}

Measured memory_bytes: 3568
#include<stdio.h>
const int maxn=207;
const int maxm=31622+100;

int sg(int n,int k){ 
        if(n<k) return 0;
        if(!(n%k)) return n/k;
        int d=(n/k)+1,p=1+(n-((n/k)*k)-1)/d;
        return sg(n-p*d,k);
}

int N,A;

int main(){
        for(scanf("%d",&N);N;--N){
                int a,k;scanf("%d%d",&a,&k);
                A^=sg(a,k);
        }   
        printf("%s\n",A?"Takahashi":"Aoki");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n;
  cin >> n;
  ll ans=10000000000000+1;
  for(ll i=1;i*i<=n;++i){
    if(n%i==0){
      ll j=n/i;
      ans=min(i+j-2,ans);
    }else{
      continue;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using F = bool;
struct S{
  ll nb0,nb1,cnt;
};
S op(S a, S b){
  return S{a.nb0+b.nb0, a.nb1+b.nb1, a.cnt+b.cnt+a.nb1*b.nb0};
}
S e(){
  return S{0, 0, 0};
}
S mapping(F f, S x){
  if(f) return S{x.nb1, x.nb0, x.nb0*x.nb1-x.cnt};
  return x;
}
F composition(F f2, F f1){
  return (f1 != f2);
}
F id(){
  return false;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,q,x,type,l,r;
  cin >> n >> q;
  vector<S> a(n);
  for(int i = 0; i < n; ++i){
    cin >> x;
    a[i] = S{1-x,x,0};
  }
  lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
  while(q--){
    cin >> type >> l >> r;
    if(type == 1){
      seg.apply(l-1,r,true);
    }
    else{
      cout << seg.prod(l-1,r).cnt << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 20400
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
coins = [10, 50, 100, 500]

is_beginning = True
while True:
  P = int(raw_input())
  if P==0: break
  else:
    if is_beginning == False:
      print ""
    is_beginning = False
  c = map(int, raw_input().split())
  rest = -P
  for i in xrange(len(coins)):
    rest += coins[i] * c[i]
  k = [0]*len(coins)
  for i in xrange(len(coins)):
    idx = len(coins)-1-i
    k[idx] = c[idx] - (rest / coins[idx])
    rest -= coins[idx] * (c[idx] - k[idx])
  for i in xrange(len(coins)):
    if k[i] > 0:
      print "%d %d" % (coins[i], k[i])

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    
    int max = a;
    if(b > max) max = b;
    if(c > max) max = c;
    cout << a + b + c - max << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    int n,ans=mod;
    string s;
    cin>>n>>s;
    ll w=0;
    ll l[300009];
    l[0]=0;
    rep(i,n){
        if(s[i]=='W') w++;
        l[i+1]=w;
    }
    rep(i,n){
        int kk=l[i]+((n-i-1)-(l[n]-l[i+1]));
        ans=min(kk,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2948
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int n, m,k;
	scanf("%lld", &n);

	if (n % 2 == 0) { printf("%lld", n); }
	else { printf("%lld", 2 * n); }
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    char s[100000];
    scanf("%s", s);

    int i, cnt[26] = {0};
    for (i = 0; s[i] != '\0'; i++) {
       cnt[s[i] - 'a'] = 1;
    }

    for (i = 0; i < 26; i++) {
        if (cnt[i] == 0) {
            printf("%c\n", 'a' + i);
            return 0;
        }
    }
    puts("None");
    return 0;
}

Measured memory_bytes: 256
def dfs(i, f):
    if i == n-1:
        return sum(list(map(int, f.split('+'))))

    return dfs(i+1, f+s[i+1]) + \
        dfs(i+1, f+"+"+s[i+1])

s = input()
n = len(s)

print(dfs(0, s[0]))

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
B - Shiritori
https://atcoder.jp/contests/abc109/tasks/abc109_b

"""
import sys


def solve(words):
    seen = set()
    prev = words[0][0]
    for w in words:
        if w in seen or w[0] != prev[-1]:
            return 'No'
        prev = w
        seen.add(w)
    return 'Yes'


def main(args):
    N = int(input())
    words = [input() for _ in range(N)]
    ans = solve(words)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	int n, m;

	std::cin >> n >> m;

	if (n + m >= 10) {
		std::cout << "error" << std::endl;
	}
	else {
		std::cout << n + m << std::endl;
	}
	return 0;

}


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

using namespace std;

void A_AC_or_WA(void) {

	int N, M;
	cin >> N >> M;
	cout << ((N == M) ? "Yes" : "No") << flush;
}

void B_Comparing_Strings(void) {

	int a, b;
	cin >> a >> b;

	for (int loop = 0; loop < max(a, b); loop++) cout << min(a, b);
	cout << flush;
	return;
}

void C_Low_Elements(void) {

	int N;
	cin >> N;

	vector<int> P(N);
	for (int& it : P) cin >> it;

	int PMin = 0;
	int counter = 0;
	for (int loop = 0; loop < N; loop++) {
		if (loop == 0 || P[loop] <= PMin) {
			counter++;
			PMin = P[loop];
		}
	}
	cout << counter << flush;
	return;
}

int main(void) {

	//A_AC_or_WA();
	//B_Comparing_Strings();
	C_Low_Elements();
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
    int n, m, i, j, a[100][100], b[100], c[100],goukei;

    scanf("%d %d", &n, &m);

    for (i = 0;i < n;i++)
    {
        for (j = 0;j < m;j++)
        {
            scanf("%d", &a[i][j]);
        }
    }

    for (j = 0;j < m;j++)
    {
        scanf("%d", &b[j]);
    }

    for (i = 0;i < n;i++)
    {
        goukei = 0;

        for (j = 0;j < m;j++)
        {
            goukei = goukei + a[i][j] * b[j];
        }
        c[i] = goukei;
    }

    for (i = 0;i < n;i++)
    {
        printf("%d\n", c[i]);
    }
    return 0;
}


Measured memory_bytes: 2112
A,B = map(int,input().split())
S = list(input())
flag = True
num = ['0','1','2','3','4','5','6','7','8','9']

for i in range(A+B+1):
    if i != A:
        if S[i] not in num:
            flag = False
            break
    else:
        if S[i] != '-':
            flag = False
            break

if flag:
    print('Yes')
else:
    print('No')

          

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#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 all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
int main()
{
	int n;
	cin >> n;
	vector<P> x(n);
	rep(i, n)
	{
		cin >> x[i].second >> x[i].first;
	}
	sort(all(x));
	int now_time = 0;
	bool is_ok = true;
	rep(i, n)
	{
		now_time += x[i].second;
		if (now_time > x[i].first)
			is_ok = false;
	}
	cout << (is_ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 4844
from sys import stdin

n, *a = map(int, stdin.read().split())    
a.sort(reverse=1)

l_count = {}
for l in a:
    l_count.update({l: l_count.get(l, 0) + 1})
  
long_side, short_side = 0, 0
for l, c in sorted(l_count.items(), reverse=1):
    if c != 1:
        if not long_side:
            if c >= 4:
                print(l ** 2)
                exit()
            else:
                long_side = l
        else:
            short_side = l
            break

print(long_side * short_side)

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

signed main(){
  Int n;
  cin>>n;

  Int da=-1,ta=-1,db=-1,tb=-1;

  Int pt=-1,pa=-1,pf=0;
  double px,py;
  for(Int i=0;i<n;i++){
    Int f,a,t,x,y;
    cin>>f>>a>>t>>x>>y;
    if(pt!=t||pa==a){
      pt=t;
      pa=a;
      pf=f;
      px=x;
      py=y;
      continue;
    }
    
    Int dd=(px-x)*(px-x)+(py-y)*(py-y);
    Int df=f-pf;

    if(t==0){
      if((da<dd)||(da==dd&&ta>df)) da=dd,ta=df;      
    }
    if(t==1){
      if((db<dd)||(db==dd&&tb>df)) db=dd,tb=df;            
    }
    
    pt=t;
    pa=a;
    pf=f;
    px=x;
    py=y;
  }
  
  
  cout<<fixed<<setprecision(12);
  if(da<0) cout<<-1<<" "<<-1<<endl;
  else cout<<sqrt((double)da)<<" "<<ta/60.0<<endl;
  if(db<0) cout<<-1<<" "<<-1<<endl;
  else cout<<sqrt((double)db)<<" "<<tb/60.0<<endl;
  return 0;
}



Measured memory_bytes: 3288
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int H, W, P[450][450], bl, wh;
vector<string> S;
bool check(int i, int j, int h, int w){
    if(P[i+h][j+w]==0 && S[i][j]!=S[i+h][j+w]){
        P[i+h][j+w]=1;
        if(S[i][j]=='.') ++bl;
        else ++wh;
        return true;
    }
    else return false;
}

void search(int i, int j){
    if(i>0) if(check(i, j, -1, 0)) search(i-1, j);
    if(j>0) if(check(i, j, 0, -1)) search(i, j-1);
    if(i+1<H) if(check(i, j, 1, 0)) search(i+1, j);
    if(j+1<W) if(check(i, j, 0, 1)) search(i, j+1);
}

int main() {
	cin >> H >> W;
	string str;
	for(int i=0; i<H; ++i){
	    cin >> str;
	    S.push_back(str);
	}
	for(int i=0; i<H; ++i) for(int j=0; j<W; ++j) P[i][j]=0;
	long ans=0;
	for(int i=0; i<H; ++i){
	    for(int j=0; j<W; ++j){
	        if(P[i][j]==0){
	            P[i][j]=1;
	            bl=0; wh=0;
	            if(S[i][j]=='.') ++wh;
	            else ++bl;
	            search(i, j);
	            ans += (long) bl*wh;
	        }
	    }
	}
	cout << ans << endl;
	return 0;
}


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

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

// operator<< definitions for some classes

template <typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N, M; cin >> N >> M;
  string S; cin >> S;

  stack<int> st;
  int x = N;

  auto f = [&]() -> int {
    for (int y = max(0, x - M) ; y < x; y++) {
      if (S.at(y) == '0') return y;
    }
    cout << "-1\n";
    exit(0);
  };

  while (x > 0) {
    int y = f();
    DLOG("y", y);
    st.push(x - y);
    x = y;
  }
  bool fst = true;
  while (!st.empty()) {
    if (fst) fst = false;
    else cout << " ";
    cout << st.top();
    st.pop();
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 924
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
string S;

int main() {
  cin >> S;
  int ans = 0;
  for (auto c : S) {
    if (c == '+') {
      ++ans;
    } else {
      --ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >>n;
  vector<int>a(n);
  int count=0;
  long long sum=0;
  int shou=INT_MAX;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    shou=min(shou,abs(x));
    sum+=abs(x);
    if(x<0)count++;
  }
  if(count%2==0){
    cout<<sum<<endl;
  }else{
    sum-=shou*2;
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,m,sum=0;
    cin>>n>>m;
    for(ll i=0;i<n;i++)sum+=i;
    for(ll i=0;i<m;i++)sum+=i;
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
function Main(input){ 
var inputs =input.split(" ");
var W = parseInt(inputs[0],10);
var H = parseInt(inputs[1],10);
var x = parseInt(inputs[2],10);
var y = parseInt(inputs[3],10);
var cenX = W/2;
var cenY = H/2;
var Max = (W*H/2).toFixed(6);
if(cenX==x&&cenY==y){
  console.log(Max+" "+"1");
}else{
  console.log(Max+" "+"0");
}
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7496
#
import sys
import math
import numpy as np
import itertools

# ひとつ入力
n = int(input())
# 文字列をリストに
s = list(input())
count_r = 0
count_b = 0
for i in range(n):
    if s[i] == 'R':
        count_r += 1
    else:
        count_b += 1

if count_r > count_b:
    print("Yes")
else:
    print("No")





Measured memory_bytes: 12456
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools
import logging

logging.basicConfig(level=logging.DEBUG, format="DBG: %(message)s")

def dbg(msg, *args, **kwargs):
    logging.debug(msg, *args, **kwargs)

Mat = collections.namedtuple("Mat", "r c")

def mat_mul(ms):
    return Mat(ms[0].r, ms[-1].c)

def cost(m1, m2):
    return m1.r * m1.c * m2.c

def solve(n, ms):
    if n == 1: return 0

    dp = {}
    for i in range(n):
        dp[(i,i)] = 0

    for l in range(2, n+1):
        for i in range(n-l+1):
            #cost_min = math.inf
            cost_min = float("inf")
            for j in range(l-1):
                #dbg("l, i, j: %d %d %d", l, i, j)
                m_lhs = mat_mul(ms[i:i+j+1])
                m_rhs = mat_mul(ms[i+j+1:i+l])
                #dbg("m_lhs, m_rhs: %r %r", m_lhs, m_rhs)
                cost_lhs = dp[(i,i+j)]
                cost_rhs = dp[(i+j+1,i+l-1)]
                #dbg("cost_lhs, cost_rhs: %d %d", cost_lhs, cost_rhs)
                cost_mul = cost(m_lhs, m_rhs)
                #dbg("cost_mul: %d", cost_mul)
                cost_now = cost_mul + cost_lhs + cost_rhs
                #dbg("cost_now: %d", cost_now)
                if cost_min > cost_now:
                    cost_min = cost_now
            dp[(i,i+l-1)] = cost_min

    #dbg(dp)
    return dp[(0,n-1)]

def main():
    n = int(input())

    ms = []
    for _ in range(n):
        r,c = map(int, input().split())
        ms.append(Mat(r,c))

    print(solve(n, ms))

if __name__ == "__main__": main()

Measured memory_bytes: 9680
/* ex 7_1
   unomi */

#include <stdio.h>

// 頂点を表す構造体 point
typedef struct point{
int x_elem;
int y_elem;
}point;

point shift_point(point pnt, int dist_x, int dist_y){
    point new_pnt={0,0};
    new_pnt.x_elem = pnt.x_elem + dist_y;
    new_pnt.y_elem = pnt.y_elem - dist_x;
    return new_pnt;
}

int main(void){
    int dist_x, dist_y;
    point pnt_1={0,0}, pnt_2={0,0}, pnt_3={0,0}, pnt_4={0,0};
    // 頂点の取得
    scanf("%d %d %d %d", &pnt_1.x_elem, &pnt_1.y_elem, &pnt_2.x_elem, &pnt_2.y_elem);

    // pnt_1,2のx軸方向での距離：pnt_1.x_elem - pnt_2.x_elem
    //          y軸方向での距離：pnt_1.y_elem - pnt_2.y_elem
    dist_x = pnt_1.x_elem - pnt_2.x_elem;
    dist_y = pnt_1.y_elem - pnt_2.y_elem;

    // 関数shift_point で移動した他の頂点を求める
    pnt_3 = shift_point(pnt_2, dist_x, dist_y);
    pnt_4 = shift_point(pnt_1, dist_x, dist_y);

    printf("%d %d %d %d\n", pnt_3.x_elem, pnt_3.y_elem, pnt_4.x_elem, pnt_4.y_elem);

    return 0;
}

Measured memory_bytes: 1732
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, a, b] <- getIntList
  let up = a + (n-1) * b
      lw = (n-1) * a + b
      ans = if up >= lw then up - lw + 1 else 0
  print ans

Measured memory_bytes: 380
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	string A;
	cin >> A;

	lint al[26]={};
	lint ans=1;

	for(int i=0;i<A.size();i++)
	{
		ans+=i-al[A[i]-'a'];
		al[A[i]-'a']++;
	}

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



Measured memory_bytes: 640
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

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

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int f(i64 n) {
    int cnt = 0;
    while (n > 0 && n % 100 == 0) n /= 100, ++cnt;
    return cnt;
}

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

    var(i64, D, N);

    int cnt = 0;
    rep(i, 1, 10000000) {
        if (f(i) == D) ++cnt;
        if (cnt == N) {
            print(i);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> v;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    v.push_back({a,b});
  }
  reverse(ALLOF(v));

  map<int,ll> cnt;
  REP(i,1,N+1){
    cnt[i] = 1;
  }

  ll sum = N*(ll)(N-1)/2;
  vector<ll> ret;
  UnionFind uf(N+1);
  rep(i,M){
    ret.push_back(sum);
    int a = v[i][0];
    int b = v[i][1];
    int ra = uf.find_root(a);
    int rb = uf.find_root(b);
    if(ra!=rb){
      ll ca = cnt[ra];
      ll cb = cnt[rb];
      sum -= ca*cb;
      uf.link(a,b);
      int r = uf.find_root(a);
      cnt[ra] = 0;
      cnt[rb] = 0;
      cnt[r] = ca+cb;
    }    
  }

  reverse(ALLOF(ret));

  rep(i,ret.size()){
    cout << ret[i] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 17072
#include<bits/stdc++.h>
#define  ll long long int
using namespace std;
int main()
{
   int n,m,s[10000],i,c=0;
   double sum=0.0,p;
   cin>>n>>m;
   for(i=0;i<n;i++)
   {
       cin>>s[i];
       sum+=s[i];
   }
   p=sum/(4*m);
   for(i=0;i<n;i++)
   {
       if(s[i]>=p)
       {
           c++;
       }
   }
   if(c<m)
   {
       cout<<"No"<<endl;
   }
   else
   {
       cout<<"Yes"<<endl;
   }

}




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

int main(){
int cnt = 0;
int A,B,A_buf,B_buf;
int K;
int ans;

cin >> A>> B >> K;
for(int i = 100;i>=1;i--){
  if(A%i==0 && B%i ==0){
  cnt ++;
  if(cnt == K){
  ans = i;
   break;
   }
  }
}

cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <ctime>
#define fi first
#define se second
#define pii pair<int,int>
//#define ivorysi
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 300005
using namespace std;
typedef long long int64;
typedef double db;
typedef unsigned int u32;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9' ) {
		res = res * 10 - '0' + c;
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N,A,B;
int cnt[MAXN];
void Solve() {
	read(N);read(A);read(B);
	int d = (N - 1) / A + 1,u = N - A + 1;
	if(B > u || B < d) {puts("-1");return;}
	cnt[1] = A;
	int t = N - A;
	for(int i = 2 ; i <= B ; ++i) {
		cnt[i] = t - A >= B - i ? A : t - (B - i);
		t -= cnt[i];
	}
	t = N;
	for(int i = B ; i >= 1 ; --i) {
		for(int j = t - cnt[i] + 1 ; j <= t ; ++j) {
			out(j);space;
		}
		t -= cnt[i];
	}
	enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
	return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>


using namespace std;

int main(void)
{
	int n, k, y, x;
	cin >> n >> k >> x>>y;
	int ans;
	
	if (n > k)
	{
		ans = k * x;
		ans = ans + (n - k)*y;
	}
	else
	{
		ans = n * x;
	}

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


Measured memory_bytes: 256
def check() -> int:
    n = int(input())
    n_l = list(map(int, input().split()))

    VORDER = 10 ** 18
    ans = 1

    if 0 in n_l:
        ans = 0
    else:
        for i in n_l:
            ans = i * ans
            if ans > VORDER:
                ans = -1
                break
    return ans


if __name__ == '__main__':
    print(check())

Measured memory_bytes: 21396
#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>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int n;cin>>n;
    int ans=1;
    while(1){
        if(n>=ans){ans*=2;}
        else{break;}
    }
    
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 256
/*input
20
>>>><>>><>><>>><<>>
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ld,ld>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=1e6+1;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a);
        if(res>1e10) return 1e11;
        a=(a*a);
        b>>=1;
    }
    return res;
}
const ll maxn=3005;
const ll maxlg=__lg(maxn)+2;
ll dp[maxn][maxn];
int main(){
    int n;
    string cmp;
    cin>>n>>cmp;
    dp[1][1]=1;
    for(int i=2;i<=n;i++){
        vector<ll> pref(i);
        REP1(j,i-1){
            pref[j]=(pref[j-1]+dp[i-1][j])%MOD;
        }
        REP1(j,i){
            int l=0,r=0;
            if(cmp[i-2]=='<') l=j,r=i-1;
            else l=1,r=j-1;
            if(l<=r) dp[i][j]=(dp[i][j]+pref[r]-pref[l-1]+MOD)%MOD;
        }
    }
    ll sum=0;
    REP1(i,n) sum=(sum+dp[n][i])%MOD;
    cout<<sum;
}

Measured memory_bytes: 69120
import sys
sys.setrecursionlimit(10**6)

cnt = 0
def dfs(graph, v, seen):
    if not False in seen:
        global cnt
        cnt += 1
        return

    for i in graph[v]:
        if seen[i]:
            continue
        seen[i] = True
        dfs(graph, i, seen)
        seen[i] = False
    return cnt

n, m = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    seen = [False for _ in range(n)]
    seen[0] = True



print(dfs(graph, 0, seen))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
int main() {
	int A;
	int B;
	int C;

	cin >> A >> B >> C;

	int cntEatC=0;
	int cntEatB=0;
	//C食べる
	while (C > 0)
	{
		cntEatC++;
		C--;
		if (B > 0)
		{
			B--;
			cntEatB++;
		}
		else if (A > 0)
		{
			A--;

		}
		else
		{
			//解毒入りクッキーなし
			break;
		}
	}
	//残りの美味食べる。
	cout << cntEatC + cntEatB + B << endl;
	return 0;
}

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

int main(){
  int N, K;
  string S;
  cin >> N >> K >> S;
  S='E' + S + 'E';
  int ans=0;
  for(int i=1; i<N+1; i++){
    if(S.at(i)=='L' && S.at(i-1)=='L') ans++;
    if(S.at(i)=='R' && S.at(i+1)=='R') ans++;
  }
  ans=min(N-1,ans+2*K);
  cout << ans << endl;
}

Measured memory_bytes: 512
#先人の方々の知恵を借りて、workの評価式と<(x-x_r)^2>のテーブルを使ってみる
#clst、xlst、tableをタプル化してパフォーマンスを向上
#比較的重いtb1へのアクセスをsetにする


def main():
    inf=float("inf")

    while 1 :
        n,m=map(int,input().split())
        if (n,m)==(0,0) : break
        clst=tuple(int(input()) for _ in range(m))
        xlst=tuple(int(input()) for _ in range(n))

        #tb1=tuple(tuple(255 if i+work>255 else 0 if i+work<0 else i+work for work in clst) for i in range(256))
        tb1=set((max(0,min(255,i+work)),i) for work in clst for i in range(256))
        #ij成分が(i-j)^2に対応する行列
        tb2=tuple(tuple((i-j)**2 for j in range(256)) for i in range(256))

        dp_new=[inf]*256
        dp_new[128]=0
        for val in xlst:
            dp_old=dp_new[:]
            dp_new=[inf]*256
            xlst_tb=tb2[val]
            for j,i in tb1:
                error=dp_old[i]+xlst_tb[j]
                if error<dp_new[j] :
                    dp_new[j]=error
        
        print(min(dp_new))

main()


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

int isACGT(char c)
{
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
        return 1;
    }

    return 0;
}

int main(int argc, char *argv[])
{
    char c[20];
    char *p = c;
    int ans;
    int len;

    scanf("%s", &c);

    len = 0;
    ans = 0;
    while (*p != '\0') {
        if (isACGT(*p)) {
            len++;
        } else {
            if (len > ans) {ans = len;}
            len = 0;
        }
        p++;
    }
    if (len > ans) {ans = len;}

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

    return 0;
}

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

const int maxn=1e8+10;
int n,w;
char s[maxn];

int main(){
	cin>>s>>w;
	n=strlen(s);
	for(int i=0;i<n;i+=w)
		putchar(s[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  int cnt_dup = 0;
  int cnt_kind = 0;
  map<int,bool> dict;
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    if(dict[a] == false){
      dict[a] = true;
      cnt_kind++;
    }
    else cnt_dup++;
  }

  if(cnt_dup % 2 == 0)cout << cnt_kind << endl;
  else cout << cnt_kind - 1 << endl;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int N, vector<int> B) {
  sort(B.begin(), B.end());
  int x = B[(N + 1) / 2 - 1];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += abs(B[i] - x);
  }
  printf("%lld\n", ans);
}

int main() {
  int N;
  cin >> N;
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    B[i] = a - (i + 1);
  }
  solve(N, B);
  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	double a, b, C;
	
	scanf("%lf %lf %lf", &a, &b, &C);
	
	printf("%.7f\n", a * b * sin((M_PI * C / 180)) / 2);
	printf("%.7f\n", a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos((M_PI * C / 180))));
	printf("%.7f\n", b * sin((M_PI * C / 180)));

	return 0;
}



Measured memory_bytes: 3060
#include <stdio.h>

int selectionSort(int A[100],int N);

void show(int A[100],int N);

int selectionSort(int A[100],int N){

  int i=0,j=0,k,c=0,temp,min;
    for (i = 0; i < N - 1; i++) {
                    /* i 番目の要素を暫定的に最小値とし */
        k = i;                        /* 添字を保存 */
        for (j = i + 1; j < N; j++) {
            if (A[j] < A[k]) {       /* より小さい値が現れたら */
                        /* 最小値の入れ替え */
                k = j;                /* 添字を保存 */
                
            }
        }  /* このループを抜けるとk に最小値の添字が入っている */
    if(i!=k){
        c++;
        temp = A[i];                /* i 番目の要素と最小値の交換 */
        A[i] = A[k];
        A[k] = temp;
    }
        
    }
    return c;
}

void show(int A[100],int N){

 int i;

 for(i=0;i<N;i++){
     printf("%d",A[i]);
     if(i+1!=N){
         printf(" ");
     }
 }
 printf("\n");

}

int main(){

    int n,i;
    int a[100];

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }

   int x;
   x = selectionSort(a,n);

    show(a,n);

    printf("%d\n",x);
   
return 0;

}


Measured memory_bytes: 2144
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] tosimiti = ReadLine().Split(' ');
        int tosi = 1+int.Parse(tosimiti[0]);
        int miti = int.Parse(tosimiti[1]);
        int[] honsu = new int[tosi];
        for(int i=0;i<miti;i++){
            string[] temp = ReadLine().Split(' ');
            int a = int.Parse(temp[0]);
            int b =int.Parse(temp[1]);
            honsu[a]++;
            honsu[b]++;
        }
        for(int i=1;i<tosi;i++){
            WriteLine(honsu[i]);
        }
    }
}


Measured memory_bytes: 13140
from collections import deque


def bfs(N):
    coord = ["3", "5", "7"]
    q = deque(coord)
    ans = 0
    while q:
        s = q.pop()

        for c in coord:
            ns = s + c
            if int(ns) <= N:
                if "3" in ns and "5" in ns and "7" in ns:
                    ans += 1
                q.append(ns)
            else:
                continue

    return ans


N = int(input())
print(bfs(N))


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int n, p[20];
    cin >> n;
    REP(i, n) cin >> p[i];
    int ans = 0;
    REP(i, n - 2) {
        int max_n = max(p[i], max(p[i + 1], p[i + 2]));
        int min_n = min(p[i], min(p[i + 1], p[i + 2]));
        if (p[i + 1] != max_n && p[i + 1] != min_n) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d[3005][3005],mod = 998244353;
int A,B,C,D;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> A >> B >> C >> D;
    d[A][B] = 1;
    for(int i = A;i <= C;i++) {
        for(int j = B;j <= D;j++) {
            if(i == A&&j == B) continue;
            d[i][j] = ((d[i-1][j]*j+d[i][j-1]*i-d[i-1][j-1]*(i-1)*(j-1))%mod+mod)%mod;
        }
    }
    cout << d[C][D];
}

Measured memory_bytes: 74044
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_lim=(n); i<i##_lim; ++i)
#define FOR(i, a, b) for (int i=(a), i##_lim=(b); i<i##_lim; ++i)
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;

string solve(int n1, int n2)
{
    bool n1m = 1 <= n1 && n1 <= 12;
    bool n1y = 0 <= n1 && n1 <= 99;
    bool n2m = 1 <= n2 && n2 <= 12;
    bool n2y = 0 <= n2 && n2 <= 99;

    if (n1m && n2y && n2m && n1y) return "AMBIGUOUS";
    if (n1y && n2m) return "YYMM";
    if (n1m && n2y) return "MMYY";
    return "NA";
}

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

    int n1 = (S[0]-'0')*10 + (S[1]-'0');
    int n2 = (S[2]-'0')*10 + (S[3]-'0');

    cout << (solve(n1, n2)) << endl;
    return 0;
}

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

int main() {
	int N, Q;
	cin >> N >> Q;
	fenwick_tree<long long> fw(N);
	for (int i = 0; i < N; i++) {
		long long a;
		cin >> a;
		fw.add(i, a);
	}
	for (int q = 0; q < Q; q++) {
		int s;
		long long a, b;
		cin >> s >> a >> b;
		if (s == 0) fw.add(a, b);
		else cout << fw.sum((int)a, (int)b) << endl;
	}
}


Measured memory_bytes: 8212
n = int(input())
a = 0
c = 0
while 7*a <=n:
    b = 0
    while (4*b) <= n-(7*a):
        if (7*a)+(4*b) == n:
            c += 1
            break
        else:
            b += 1
    a += 1
    if c == 0:
        pass
    else:
        break
if c == 1 or n == 4:
    print('Yes')
else:
    print('No')

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int n,m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;

  

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,i,a[101];
	long long s1=0,s2=0,s=0,t=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    	scanf("%d",&a[i]);
    	t+=(a[i]*a[i]);
    	s+=a[i];
	}
	s1=t+n*(s/n)*(s/n)-2*s*(s/n);
	s2=t+n*(s/n+1)*(s/n+1)-2*s*(s/n+1);
	if(s1>s2)
	printf("%I64d",s2);
	else
	printf("%I64d",s1);	
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define INF LONG_LONG_MAX
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string st;
    cin>>st;
    int ans=0,c=0;
    for (int i=0;i<st.length();i++)
    {
        if (st[i]=='R') c++;
        else 
        {
        ans=max(ans,c);
        c=0;
        }
    }
    cout<<max(ans,c);
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int A[100010];
multiset<int> st;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        auto it = st.lower_bound(A);
        if(it != st.begin()){
            it--;
            st.erase(it);
        }
        st.insert(A);    
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n,m;cin>>n>>m;
    vector<P>B(m);
    int f,t;
    rep(i,m){
        cin>>f>>t;f--;t--;
        B[i]=make_pair(t,f);
    }
    sort(all(B));
//    rep(i,m){
  //      cout<<B[i].F<<':'<<B[i].S<<endl;
    //}
    t=-1;int count=0;
    rep(i,m){
        if(t<=B[i].S){
            count++;
            t=B[i].F;
        }
    }
    cout<<count<<endl;
    
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, a[maxn];
map<int,int> mp;

struct op {
  int t,i,j;
};

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

  int n,a,b;
  cin>>n>>a>>b;
  int ans=0;
  for (int i=1; i<=n; i++) {
    int x=i;
    int d=0;
	while (x) {
      d += (x%10);
      x/=10;
    }
    if(d>=a &&d<=b) ans+=i;
  }
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
F = sys.stdin

N = int(F.readline().rstrip())
S = F.readline().rstrip()
count = 0

for i in range(N - 2):
    if S[i] == 'A':
        if S[i+1] == 'B' and S[i+2] == 'C':
            count += 1


print(count)


Measured memory_bytes: 5764
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long power(long long x, long long y) 
{ 
    long long res = 1;    
    x=x%mod;
    while(y>0) 
    { 
        if(y & 1) 
        res=(res*x)%mod; 
        y=y/2; 
        x=(x*x)%mod;   
    } 
    return res; 
}
int main() {
	
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
   
      long long n,i,j,k,sum=0,count=0,ans=0,x=0,y=0,l,r,m;
      cin>>n;
     long long a[n],b[n];
     count=100000000000000;
     y=count;
     x=-1000000000000000;
     for(i=0;i<n;i++)
     {
         cin>>a[i]>>b[i];
         if((a[i]+b[i])>sum)
         sum=a[i]+b[i];
         if((a[i]-b[i])>x)
         x=a[i]-b[i];
         if((a[i]+b[i])<count)
         count=a[i]+b[i];
         if((a[i]-b[i])<y)
         y=a[i]-b[i];
     }
     
     cout<<max(sum-count,x-y);
      
      
	return 0;
}

Measured memory_bytes: 6716
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

int a[12][12];

void solve()
{
    int n, m, x;
    scanf("%d%d%d", &n, &m, &x);
    vector<int> c(n);
    int i, j;
    for (i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        for (j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    ll ans = LINF;
    for (i = 0; i < (1 << n); i++) {
        ll sum = 0;
        vector<ll> aa(m);
        for (j = 0; j < n; j++) {
            if (i & (1 << j)) {
                sum += c[j];
                int k;
                for (k = 0; k < m; k++) {
                    aa[k] += a[j][k];
                }
            }
        }
        int bad = 0;
        int k;
        for (k = 0; k < m; k++) {
            if (aa[k] < x) {
                bad = 1;
            }
        }
        if (bad == 0) {
            ans = MIN(ans, sum);
        }
    }

    if (ans == LINF) {
        printf("-1\n");
    }
    else {
        printf("%lld\n", ans);
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 3212