akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 10000000000007
 
#define ARRAY_MAX 100005
 
int main(){
 
    ll n,k;
    cin >> n >> k;
    vector<ll> a(ARRAY_MAX);
    REP(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.begin()+n);
    
    ll mini = INF;
    for(int i = 0;i < n-k+1;i++){
        mini = min(mini,a[i+k-1]-a[i]);
    }
    cout << mini << endl;
 
 
 
 
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
const int MAX=1e9;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(m,0);
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        for(int j = 0; j < b[i]; j++) {
            int tc;
            cin >> tc;
            c[i]|= (1<<(tc-1));
        }
    }

    int dp[(1<<n)];
    for(int i = 0; i < (1<<n); i++) {
        dp[i]=MAX;
    }
    dp[0]=0;

    for(int j = 0; j < m; j++) {
        for(int i = 0; i < (1<<n); i++) {
            int ni = (i|c[j]);
            dp[ni] = min(dp[i]+a[j],dp[ni]);
        }
    }

    int ans=dp[(1<<n)-1];
    if(ans==MAX) ans=-1;
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3624
import os
import sys
from io import BytesIO, IOBase


def solution(n, arr):
    dp = [float('inf')] * n
    dp[0] = 0

    for i in range(n):
        for j in [i + 1, i + 2]:
            if j < n:
                dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]))

    write(dp[-1])


def main():
    n = r_int()
    arr = r_array()
    solution(n, arr)


BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def input():
    return sys.stdin.readline().rstrip("\r\n")


def write(*args, end='\n'):
    for x in args:
        sys.stdout.write(str(x) + ' ')
    sys.stdout.write(end)


def r_array():
    return [int(x) for x in input().split()]


def r_int():
    return int(input())


def p_array(arr):
    for x in arr:
        write(x, end=' ')
    write()


if __name__ == "__main__":
    main()


Measured memory_bytes: 57872
h, w = gets.split(" ").map(&:to_i)

x = y = -1

h.times { |i|
  a = gets.split(" ")
  if a.include?("snuke")
    x = ('A'.ord+a.index("snuke"))
    y = i+1
  end
}

puts "#{x.chr}#{y}"


Measured memory_bytes: 1788
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

h,w = map(int,input().split())
s = [str('#'+input())+'#' for i in range(h)]

test = ''
for i in range(w+2):
	test = test + '#' 

#リストsの頭にtestを追加
s.insert( 0,test)

#リストsの最後にtestを追加
s.insert(len(s),test)

for i in range(h+2):
	print(''.join(s[i]))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[][] m = new int[n][n];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++) {
                m[i][j] = 0;
            }
        }
        for(int i = 0; i < n; i++) {
            int v = input.nextInt();
            int in = input.nextInt();
            for(int j = 0; j < in; j++) {
                int u = input.nextInt();
                m[v-1][u-1] = 1;
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++) {
                System.out.print(m[i][j]);
                if(j != n-1) {
                    System.out.print(" ");
                } else {
                    System.out.println();
                }
            }
        }
    }
}



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

int main() {
    int a, b;
    cin >> a >> b;
    int n = 0;
    while(true) {
        if(a * n - n + 1 >= b) break;
        n++;
    }
    cout << n << endl;
}


Measured memory_bytes: 256
use std::io::{BufRead, StdinLock};

fn read(stdin_lock: &mut StdinLock, buf: &mut Vec<u8>, delimiter: u8) -> i32 {
    buf.clear();
    let l = stdin_lock.read_until(delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap()
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a = read(&mut stdin_lock, &mut buf, b' ');
    let b = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(a, b));
}

fn solve(a: i32, b: i32) -> i32 {
    if a >= 13 {
        b
    } else if a >= 6 {
        b / 2
    } else {
        0
    }
}

#[test]
fn example1() {
    assert_eq!(100, solve(30, 100))
}

#[test]
fn example2() {
    assert_eq!(50, solve(12, 100))
}

#[test]
fn example3() {
    assert_eq!(0, solve(0, 100))
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <ios>
#include <iomanip>
#include <ctime>

constexpr long double INF = 1e15;

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

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

int main() {
	std::clock_t start = std::clock();
	
	std::size_t n;
	std::cin >> n;
	std::vector<int> x(n), y(n), dx(n, 0), dy(n, 0);
	
	for (std::size_t i = 0; i < n; i++) {
		char c;
		std::cin >> x[i] >> y[i] >> c;
		if (c == 'U') dy[i] = 1;
		else if (c == 'D') dy[i] = -1;
		else if (c == 'L') dx[i] = -1;
		else dx[i] = 1;
	}
	
	auto f = [&](long double t) -> long double {
		long double x_max = -INF, x_min = INF;
		long double y_max = -INF, y_min = INF;
		
		for (std::size_t i = 0; i < n; i++) {
			long double cur_x = (0.0 + (t * dx[i]) + x[i]);
			long double cur_y = (0.0 + (t * dy[i]) + y[i]);
			chmax(x_max, cur_x); chmin(x_min, cur_x);
			chmax(y_max, cur_y); chmin(y_min, cur_y);
		}
		
		long double h = x_max - x_min, w = y_max - y_min;
		return (h * w);
	};
	
	long double l = 0.0, r = 1e10;
	while (clock() < start + 4000000) {
		long double c1 = (l + l + r) / 3.0;
		long double c2 = (l + r + r) / 3.0;
		if (f(c1) >= f(c2)) l = c1;
		else r = c2;
	}
	
	std::cout << std::fixed << std::setprecision(12) << f(l) << '\n';
	
	return 0;
}

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

const int MN = 1000005;

int N, A[MN], cnt[3], mul, Ans;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%1d", &A[i]), --A[i];
//	for (int i = 1; i <= N; ++i) printf("%d", A[i]); puts("");
	for (int i = 1; i <= N; ++i) ++cnt[A[i]];
	if (cnt[0] == N) return puts("0"), 0;
	if (cnt[0] + cnt[2] == N) {
		for (int i = 1; i <= N; ++i) A[i] >>= 1;
		mul = 1;
	} else {
		for (int i = 1; i <= N; ++i) A[i] &= 1;
		mul = 0;
	}
//	for (int i = 1; i <= N; ++i) printf("%d", A[i]); puts("");
	for (int i = 1; i <= N; ++i) if (A[i] && !((i - 1) & (N - i))) Ans ^= 1;
	printf("%d\n", Ans << mul);
	return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cnt = 0;
        int a[] = new int[n];
        /*input*/
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }
        /*sort*/
        for(int i=0; i<n-1; i++){
            for(int j=n-1; j>0; j--){
                if(a[j]<a[j-1]){
                    int swap = a[j];
                    a[j] = a[j-1];
                    a[j-1] = swap;
                    cnt++;
                }
            }
        }
        /*output*/
        for(int i=0; i<n-1; i++) System.out.printf("%d ", a[i]);
        System.out.println(a[n-1]);
        System.out.println(cnt);
    }
}


Measured memory_bytes: 26404
#include<stdio.h>
int ary[100000];
int num;

int judge(int i,int n1,int n2){
    if(i==0)return 1;
    if(n2-n1>1)return 0;
    if(n2-n1<=0&&judge(i-1,n2,ary[i-2]))return 1;
    if(judge(i-1,n2-1,ary[i-2]))return 1;
    return 0;
}

int main(void){
    scanf("%d",&num);
    int i;
    for(i=0;i<num;i++){
        scanf("%d",&ary[i]);
    }
    if(judge(num-1,ary[num-1],ary[num-2])){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=1e6+5;
string s[maxm];
int ans;
int n;
struct Trie{
    int a[maxm][26],tot;
    int type[maxm];//节点x的字符类型
    int val[maxm];//节点x为根的子树endpos个数
    int ed[maxm][26];//ed[i][j]表示i为根的子树中经过j的endpos数
    void add(string s){
        int len=s.size();
        int node=0;
        for(int i=len-1;i>=0;i--){
            int v=s[i]-'a';
            if(!a[node][v]){
                a[node][v]=++tot;
                type[tot]=v;
            }
            node=a[node][v];
        }
        val[node]++;
    }
    void dfs(int x){
        for(int i=0;i<26;i++){
            int v=a[x][i];
            if(!v)continue;
            dfs(v);
            val[x]+=val[v];
            for(int j=0;j<26;j++){
                ed[x][j]+=ed[v][j];
            }
        }
        ed[x][type[x]]=val[x];//
    }
    void cal(string s){
        int len=s.size();
        int node=0;
        for(int i=len-1;i>=1;i--){
            int v=s[i]-'a';
            node=a[node][v];
        }
        for(int i=0;i<26;i++){
            int v=a[node][i];
            if(!v)continue;
            ans+=ed[v][s[0]-'a'];
        }
    }
}T;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        T.add(s[i]);
    }
    T.dfs(0);
    for(int i=1;i<=n;i++){
        T.cal(s[i]);
    }
    ans-=n;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 544224
def main():
    n, *t = map(int, open(0).read().split())
    l = [(0, 0, 0)] + list(zip(*[iter(t)] * 3))
    for x, y in zip(l, l[1:]):
        dt = y[0] - x[0]
        dd = abs(y[1] - x[1]) + abs(y[2] - x[2])
        f = dd <= dt
        g = dt % dd == 0 or dt % dd == 2
        h = f and g
        if not h:
            print('No')
            break
    else:
        print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 26632
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
int ans = 0;
int gcd(int m, int n) {
	return n == 0 ? m : gcd(n, m % n);
}
int lcm(int m, int n) {
	return (m / gcd(m, n))*n;
}
int main() {
	cin >> N;
	vector<int>a(N);
	for (int i = 0; i < N; i++)cin >> a[i];
	vector<int>f(N), b(N);
	f[0] = a[0];
	for (int i = 1; i < N; i++) {
		f[i] = gcd(a[i], f[i-1]);
	}
	b[N - 1] = a[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		b[i] = gcd(a[i], b[i + 1]);
	}
	ans = max(f[N - 2], b[1]);
	for (int i = 1; i < N-1; i++) {
		ans = max(ans, gcd(f[i - 1], b[i + 1]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
int main(){
    int A;
    int B;
    int C;
    int max=0;
    int mid=0;
    int min=0;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
 
    max = A;
  
  if(max < B){
    max = B;
    mid = A;
  }else{
    mid = B;
  }
  
  if(max < C){
    min = mid;
    mid = max;
    max = C;
  }else if(mid < C){
    min = mid;
    mid = C;
  }else{
    min = C;
  }
  
    printf("%d\n",(max*10+mid+min));  
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

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

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

    cout << N-K << endl;
}

Measured memory_bytes: 256
def rangesum(a, b=0):
    return (abs(a-b)+1) * (a+b) // 2

n, k = map(int, input().split())

mod = 10**9+7
res = 0
for i in range(k, n+2):
    res += rangesum(n-i+1, n) - rangesum(i-1) + 1
    res %= mod

print(res)


Measured memory_bytes: 9188
#include<iostream>
#include<iomanip>
int main()
{
    int n;
    std::cin>>n;
    double ans=0;
    for(int i=0;i<n;i++){
        double tmp;
        std::cin>>tmp;
        ans += 1.0/tmp; 
    }
    std::cout<<std::setprecision(10)<<1.0/ans<<std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;


signed main() {
	int N,M;
	cin >> N >> M;
	int a[1010],b[1010],c[1010];
	int dist[1100][1100];
	for(int i = 0;i < N;i++) {
		for(int j = 0;j < N;j++) {
			dist[i][j] = INF;
		}
		dist[i][i] = 0;
	}
	for(int i = 0;i < M;i++) {
		cin >> a[i] >> b[i] >> c[i];
		--a[i],--b[i];
		dist[a[i]][b[i]] = c[i];
		dist[b[i]][a[i]] = c[i];
	}
	for(int k = 0;k < N;k++) {
		for(int i = 0;i < N;i++) {
			for(int j = 0;j < N;j++) {
				dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
			}
		}
	}
	int res = 0;
	for(int i = 0;i < M;i++) {
		if(c[i] > dist[a[i]][b[i]]) {
			res++;
		}
	}
	cout << res << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int x = 1;
  for (int i = 0; i < N; i++){
    if (x + K < x * 2){
      x += K;
    }
    else x *= 2;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int a, b; cin >> a >> b;
    cout << (a+b<10 ? to_string(a+b) : "error") << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++) cin >> a[i];

  ll ans = 1;
  ll prev;
  ll limit = 1;
  for(int i=0;i<18;i++){
    limit *= 10;
  }
  bool flag = true;
  for(int i=0;i<n;i++){
    if(a[i] == 0){
      ans = 0;
      flag = false;
      break;
    }
  }
  if(flag){
    for(int i=0;i<n;i++){
      if(a[i] <= limit/ans){
        ans *= a[i];
      }else{
        ans = -1;
        break;
      }
    }
  }

  cout << ans << endl;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

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

Measured memory_bytes: 256
//prepared by dumb
#include<bits/stdc++.h>
using namespace std;
#define   ll long long int
#define   dl double  
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   INF 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ll a, b, c=1, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
    string  str1, str2,str;

      scll(n);
      map<string,ll>mp;
      while(n--)
      {
        cin>>str;
        mp[str]++;
      }
      cout<<"AC x "<<mp["AC"]<<'\n';
     cout<<"WA x "<<mp["WA"]<<'\n';
     cout<<"TLE x "<<mp["TLE"]<<'\n';
     cout<<"RE x "<<mp["RE"]<<'\n';
return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
// #include <chrono>
// #include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846
 
ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}
 
int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}



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

// int t;
// cin >> t;
// while(t--){



// }

int n,m;
cin >> n >> m;

int arr[n];
ld total = 0;
fo(i,0,n)cin >> arr[i];
// fo(i,0,n)cout << arr[i] << ' ';
// cout << endl;

fo(i,0,n)total += arr[i];
total = total/4;
total = total/m;


total = ceil(total);
int count = 0;
for(int i = 0; i< n;i++){
	if(arr[i] < total)continue;
	count++;
}

if(count >= m)cout << "Yes" << endl;
else cout << "No" << endl;


return 0;
	
	}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

#define ll long long

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

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

using namespace std;

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

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

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

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	LL n; cin >> n;
	vector<LL> a(n);

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

	LL ans = INF2;

	for (int i = 0; i < 2; i++) {
		LL tmp = 0;
		LL sum = 0;
		for (int j = 0; j < n; j++) {
			sum += a[j];
			
			//sumが正になっていてほしい
			if ((i + j) % 2 == 0) {
				if (sum <= 0) {
					tmp += (1 + abs(sum));
					sum = 1;
				}
			}
			//sumが負になっていてほしい
			else {
				if (sum >= 0) {
					tmp += (1 + abs(sum));
					sum = -1;
				}
			}
		}
		ans = min(ans, tmp);
	}

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

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

int gcd(int a,int b){
    int tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main(){
    ll a;
    cin>>a;
    ll ans=0;
    for (int i = 1; i <= a; ++i) {
        for (int j = 1; j <=a ; ++j) {
            for (int k = 1; k <=a ; ++k) {
                ans+=gcd(gcd(i,j),k);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
int main()
{
    long long int n;
    cin >> n;
    long long int sum = 0;
    for(long long int i = 1;i < n;i++)
    {        
        sum = sum + i;    
    }
    cout << sum;
 
    return 0;
}

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

using ll = long long;
const ll MOD = 1e9 + 7;

void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

// 組合せを素数で割った値を求める
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  
  map<ll, ll> mp;
  factoring(m, mp);
  
  COMinit();
  
  ll ans = 1;
  for (auto i : mp) {
    // cout << i.first << " " << i.second << endl;
    ans *= COM(i.second + n - 1, n - 1);
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 12288
#include <stdio.h>

typedef long long ll;

void solve_142D();
ll GetGCD_ll(ll a, ll b); // ll な 最大公約数取得関数
int GetNumFactors(ll n); // 素因数の数を数える

ll A, B; // 入力の２数字, 制約：A, B <= 10^12 なので ll

void solve_142D()
{
  ll gcd = GetGCD_ll(A, B);
  int numFactors = GetNumFactors(gcd);
  printf("%d\n", numFactors + 1);
}

ll GetGCD_ll(ll a, ll b)
// ll な 最大公約数取得関数
{
  ll swap_tmp;
  if (a < b){ // 下の計算のために a > b にしておく
    swap_tmp = a; a = b; b = swap_tmp;
  }

  // ユークリッドの互除法により GDC を求める
  ll remainder = a % b;
  while (remainder != 0L){
    a = b; b = remainder; remainder = a % b;
  }
  return b;
}

int GetNumFactors(ll n)
// 素因数の数を数える
// 戻り値：素因数の数
// 内容や何乗かといった情報は返さない
{
  if (n == 1) return 0; // GDC が 1 の場合は 0 を返して終了

  int numFactors = 0;
  if (n % 2 == 0){ // 偶数の場合は numFactors を 1 にして 2 で割れるだけ割る
    numFactors = 1;
    while (1){
      n /= 2;
      if (n % 2 != 0) break;
    }
  }

  for (ll divisor = 2; divisor * divisor <= n; ++divisor){
    if (n % divisor == 0){ // divisor で割れる場合は numFactors を +1 して divisor で割れるだけ割る
      ++numFactors;
      while (1){
        n /= divisor;
        if (n % divisor != 0) break;
      }
    }
  }
  if (n > 2) // divisor * divisor の比較にして落ちてしまう分を追加；ツイッターで教えてもらっちゃいました（競技終了後）
    numFactors++;
  return numFactors;
}

int main()
{
  scanf("%lld %lld", &A, &B);

  solve_142D();

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (50)
#define INF (4000000000000000000L)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, K;
  long xs[MAX_N], ys[MAX_N];
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%ld %ld", &xs[i], &ys[i]);
  }

  long ans = INF;
  for (int i_min_x = 0; i_min_x < N; i_min_x++) {
    const long min_x = xs[i_min_x];
    for (int i_max_x = 0; i_max_x < N; i_max_x++) {
      const long max_x = xs[i_max_x];
      if (min_x > max_x) {
        continue;
      }
      for (int i_min_y = 0; i_min_y < N; i_min_y++) {
        const long min_y = ys[i_min_y];
        for (int i_max_y = 0; i_max_y < N; i_max_y++) {
          const long max_y = ys[i_max_y];
          if (min_y > max_y) {
            continue;
          }
          int num_point = 0;
          for (int i = 0; i < N; i++) {
            if (xs[i] >= min_x && xs[i] <= max_x && ys[i] >= min_y &&
                ys[i] <= max_y) {
              num_point++;
            }
          }
          if (num_point >= K) {
            ans = min(ans, (max_x - min_x) * (max_y - min_y));
          }
        }
      }
    }
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 128
//In the name of Allah
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; 

const int maxN = 1000 * 100 + 100; 
const int mx = 2500 + 10; 

ll a[maxN]; 
map<ll,int> cnt; 
vector<int> pr; 
int mark[maxN]; 

int main() { 
	for( int i = 2 ; i < mx ; i++ ) if( !mark[i] ) { 
		pr.push_back(i); 
		for( int j = i + i ; j < mx; j += i ) 
			mark[j] = true; 
	}
	cerr << pr.size() << endl;

	ios::sync_with_stdio(false); cin.tie(0); 
	int n; cin >> n; 
	for( int i = 0 ; i < n ; i++ ) { 
		cin >> a[i]; 
		for( auto x : pr ) { 
			ll z = x * 1ll * x * x; 
			while( a[i] % z == 0 ) 
				a[i] /= z; 
		}
		cnt[a[i]]++; 
	}
	sort( a , a + n ); 
	int ans = 0; 
	if( cnt[1] ) ans = 1; 
	cnt[1] = 0; 

	for( int i = 0 ; i < n ; i++ ) 
		if( cnt[a[i]] ) { 
			ll x = a[i]; 
			ll z = 1; 
			for( auto y : pr ) 
				if( x % y == 0 ) { 
					int v = 0; 
					while( x % y == 0 ) { 
						v++; 
						x /= y;
					}
					if( v == 1 ) z *= y * 1ll * y; 
					else if( v == 2 ) z *= y; 
					if( x == 1 ) break; 
				} 			
			if( x > 1 ) 
				z *= x * 1ll * x; 
			ans += max( cnt[a[i]] , cnt[z] ); 
			cnt[z] = 0;
			cnt[a[i]] = 0; 
			//cerr << a[i] << "   " << z << " ANS CHANGED TO " << ans << endl;
		}
	cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= b) {
        for(int i = 0; i < b; i++) {
            cout << a;
        }
        cout << endl;
    }else{
        for(int i = 0; i < a; i++) {
            cout << b;
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int n;
    cin >> n;

    ll ans = 0;

    for(int i = 1;i <= n;i++){
        if(i % 15 == 0){}
        else if(i % 3 == 0){}
        else if(i % 5 == 0){}
        else ans += i;
    }

    cout << ans << endl;

    return 0;
}

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

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      k: i64,
      a: i64,
      b: i64,
    }

    if b-a <= 2 {
        return puts!("{}\n", k+1);
    }
    if 1 + k <= a {
        return puts!("{}\n", 1+k);
    }
    let k = k-(a-1);
    let ans = if k%2 == 0 {
        a + (b-a) * (k/2)
    } else {
        a + (b-a) * (k/2) + 1
    };
    puts!("{}\n", ans);
}


Measured memory_bytes: 4352
//#include<iostream>
#include<cstring>
#include<cstdio>
//#include<math.h>
//#include<set>
//#include<queue>
//#include<bitset>
//#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std;
//#define int long long
#define LL long long
int qread()
{
	char c; int s=0,f=1; while ((c=getchar())<'0' || c>'9') (c=='-') && (f=-1);
	do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s*f;
}

//Pay attention to '-' , LL and double of qread!!!!

int n;
#define maxn 200011
LL Abs(LL x) {return x>0?x:-x;}
int a[maxn],b[maxn],c[maxn]; LL sum[maxn];

LL Max(LL a,LL b,LL c,LL d) {return max(max(a,b),max(c,d));}
LL Min(LL a,LL b,LL c,LL d) {return min(min(a,b),min(c,d));}
LL kkk(int x,int y,int z)
{return Max(sum[n]-sum[z],sum[z]-sum[y],sum[y]-sum[x],sum[x])-Min(sum[n]-sum[z],sum[z]-sum[y],sum[y]-sum[x],sum[x]);}

signed main()
{
	n=qread(); for (int i=1;i<=n;i++) a[i]=qread(),sum[i]=sum[i-1]+a[i];
//	for (int i=1;i<=n;i++) cout<<sum[i]<<' ';cout<<endl;
	for (int i=2,j=1;i<=n;i++)
	{
		LL tmp=Abs(sum[i]-sum[j]-sum[j]),now;
		while (j<i-1 && (now=Abs(sum[i]-sum[j+1]-sum[j+1]))<tmp) tmp=now,j++;
		b[i]=j;
	}
	
	for (int i=n-2,j=n-1;i>=1;i--)
	{
		LL tmp=Abs(sum[n]-sum[j]-(sum[j]-sum[i])),now;
		while (j>i+1 && (now=Abs(sum[n]-sum[j-1]-(sum[j-1]-sum[i])))<tmp) tmp=now,j--;
		c[i]=j;
	}
	
	LL ans=1e18;
	for (int i=2;i<=n-2;i++)
		ans=min(ans,kkk(b[i],i,c[i]));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4096
W,H,x,y,r = map(int,input().split())

if (x-r>=0) & (y-r>=0) & (x+ r<= W) & (y + r <= H):
    print('Yes')
elif x-r<0 or y-r<0 or x +r >W or y+r >H:
    print('No')


Measured memory_bytes: 5596
# https://atcoder.jp/contests/arc080/tasks/arc080_a
N = int(input())
A = list(map(int, input().split()))

# 2の倍数ならばどのように並んでてもよい
# 4の倍数ならば隣り合うものは2の倍数でなくともよい

multi4 = 0
multi2 = 0
other = 0
for a in A:
    if a % 4 == 0:
        multi4 += 1
    elif a % 2 == 0:
        multi2 += 1
    else:
        other += 1

if multi2 == 0:
    print('Yes' if other <= multi4 + 1 else 'No')
else:
    print('Yes' if other <= multi4 else 'No')


Measured memory_bytes: 85336
H,W,M = map(int,input().split())

hs = [0] * H
ws = [0] * W
s = set()
for i in range(M):
  h,w = map(int, input().split())
  hs[h-1] += 1
  ws[w-1] += 1
  s.add((h-1,w-1))
  
mh = 0
mw = 0
for i in range(H):
  mh = max(mh, hs[i])
for j in range(W):
  mw = max(mw, ws[j])
  
i_s = list()
j_s = list()
for i in range(H):
  if mh == hs[i]:
    i_s.append(i)
for j in range(W):
  if mw == ws[j]:
    j_s.append(j)

ans = mh + mw
for i in i_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    exit()
ans -= 1
print(ans)

Measured memory_bytes: 83496
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    int n;
    char in[4002];
    scanf("%d%s",&n,in+1);
    int a=0,b=0,c=0;
    for(int i=1;i<=n;i++){
        if(in[i]=='R'){
            a++;
        }else if(in[i]=='G'){
            b++;
        }else{
            c++;
        }
    }
    //printf("%d %d %d",a,b,c);
    long long ans = 1ll*a*b*c;
    for(int i =1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int k = j+j-i;
            if(k>n){
                break;
            }
            if(in[i]!=in[j]&&in[j]!=in[k]&&in[i]!=in[k]){
                ans--;
            }
        }
    }
    printf("%lld",ans);
    return 0;

}


Measured memory_bytes: 1708
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip>
#include<sstream>
using namespace std;
int main()
{
	int a, n;
	bool i;
	while (cin >> n)
	{
		i = 0;
		while (n--)
		{
			cin >> a;
			if (a % 2 == 0)
				if (a % 3 == 0);
				else if (a % 5 == 0);
				else i = 1;
		}
		if (i == 0)
			cout << "APPROVED" << '\n';
		else cout << "DENIED" << '\n';
	}
}

Measured memory_bytes: 256
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = iM // iN
    if iM % iN == 0:
        print(iD)
    elif 2*iN > iM :
        print(1)
    else:
        aD = []
        for i in range(1,int(iM**0.5)+1):
            if iM % i == 0:
                if iD > i : aD.append(i)
                j = iM // i
                if iD > j :aD.append(j)
        print(max(aD))
解()


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

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p.at(i);
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, k) {
        ans += p.at(i);
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
      x = root(x); y = root(y);
      if (x != y) {
        if (data[y] < data[x]) swap(x, y);
        data[x] += data[y]; data[y] = x;
      }
      return x != y;
    }
    bool findSet(int x, int y) {
      return root(x) == root(y);
    }
    int root(int x) {
      return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
      return -data[root(x)];
    }
};


void solve(long long N, long long M, std::vector<long long> A,
           std::vector<long long> B) {
  UnionFind uf(N);
  for(int i = 0 ; i < M  ; i ++){
    A[i]--;
    B[i]--;
  }
  long long ans = 0;
  vector<long long> r;


  for(int i = M - 1 ; i >= 0 ; i--){
    r.push_back(N * (N-1) / 2 - ans);
    if( uf.root(A[i]) != uf.root(B[i]) ){
      ans -= 1ll * uf.size(A[i]) * (uf.size(A[i])-1) / 2;
      ans -= 1ll * uf.size(B[i]) * (uf.size(B[i])-1) / 2;
      uf.unionSet(A[i], B[i]);
      ans += 1ll * uf.size(B[i]) * (uf.size(B[i])-1) / 2;
    }

  }
  reverse(r.begin(), r.end());
  for(int i = 0 ; i < r.size() ; i++){
    cout << r[i] << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 4212
N,T = gets.chomp.split(" ").map(&:to_i)
t = gets.chomp.split(" ").map(&:to_i)
ans = 0
(N-1).times do |i|
  if t[i+1] - t[i] > T
    ans += T
  else
    ans += t[i+1] - t[i]
  end
end
ans += T
puts ans

Measured memory_bytes: 29852
#include<iostream>
#include<string>
#include<queue>

using namespace std;
struct data{
    string name;
    int time;
};
int n,q;
long int sumTime=0;
queue<data> Q;
queue<data> ans;
void deal(){
    while(!Q.empty()){
        data d=Q.front();
        Q.pop();
        if(d.time-q>0){
            sumTime+=q;
            d.time-=q;
            Q.push(d);
        }else{
            sumTime+=d.time;
            d.time=sumTime;
            ans.push(d);
        }
    }
}

int main(){
    cin>>n>>q;
    string tmp;
    int num;
    for(int i=0;i<n;i++){
        data d;
        cin>>tmp>>num;
        d.name=tmp;
        d.time=num;
        Q.push(d);
    }
    deal();
    while(!ans.empty()){
        data d=ans.front();
        ans.pop();
        cout<<d.name<<' '<<d.time<<endl;
    }
    return 0;
}



Measured memory_bytes: 6132
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
  #define DUMP(i) 
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


const int EPS = 1e-9;
const int MOD = 1e9+7;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k,s;
  cin >> k >> s;
  int ans = 0;
  REP(x,k+1){
    REP(y,k+1){
      if(s-x-y >= 0 && s-x-y <= k)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
# 以下のようになっているとする：
# 1 i    j    n
# xxaaaaaayyyyy
#
# aaaaaa*10^5 + yyyyy = aaaaaayyyyy
# aaaaaa*10^5 = aaaaaayyyyy - yyyyy
#
# ここで
# aaaaaa      = A (mod 2019)
#        10^5 = K (mod 2019)
# aaaaaayyyyy = B (mod 2019)
#       yyyyy = C (mod 2019)
# とすると、以下が成り立つ：
# AK = B - C (mod 2019)
#
# 10^nは2019の倍数にならないので、K != 0 (mod 2019)
# また、K != 3, K != 673 (mod 2019)
# なので、A != 0のときにAKが0になることはない。
# よって、A = 0 (mod 2019) <=> B = C (mod 2019)
# したがって、下からn桁の数を見て、2019で割った余りが等しい組み合わせを探せばいい。
# 
# Kが3もしくは673にならないことは背理法で示せる。
# もしなるなら
# 10^n = 2019*k + 3 = 3 * (673*k + 1)
#      = 2019*l + 673 = 673 * (3*l + 1)
# となるk, lが存在するが、10^nは3の倍数にも673の倍数になることもないので矛盾。

s = gets.chomp

mod_count = Array.new(2019, 0)
mod = 0 # 下から0桁の場合、0 % 2019 = 0
mod_count[mod] = 1

bias = 1
s.reverse.each_char do |c|
  mod = (mod + c.to_i * bias) % 2019
  mod_count[mod] += 1
  bias = (bias * 10) % 2019
end
puts mod_count.each.map{|v| v*(v-1)/2}.sum


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

struct edge{/*重み付き,有向*/
	int to , cost;/*toは接続先*/
	edge(ll to_ ,ll cost_ = 1){ to=to_; cost=cost_; };/*全てのcost=1 <=> 無向グラフ*/
};
bool operator<(edge e1 ,edge e2){return e1.cost < e2.cost; }
bool operator>(edge e1 ,edge e2){return e1.cost > e2.cost; }
using graph =  vector< vector<edge> >;

ll n;
graph g;
Vi ck;

ll bfs(ll id){
	queue<PLL> q;
	ll ans = 0;
	q.push(mp(id,1LL));
	while(!q.empty()){
		PLL id = q.front();
		q.pop();
		if(ck[id.first]!=-1){
			if(abs(ck[id.first]-id.second)!=0 && id.second-ck[id.first]!=2)return INF;
			continue;
		}
		ck[id.first] = id.second;
		chmax(ans,id.second);
		rep(i,g[id.first].size()){
			q.push(mp(g[id.first][i].to,id.second+1));
		}
	}
	return ans;
}


int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n;
	g.resize(n);
	rep(i,n){
		ll in;
		string s;
		cin>>s;
		rep(j,s.size()){
			in = s[j]-'0';
			if(in==1){
				g[i].pb(edge(j));
				//g[j].pb(edge(i));
			}
		}
	}
	ll ans=0;
	rep(i,n){
		ck.clear();
		ck.resize(n,-1);
		ll tp = bfs(i);
		chmax(ans,tp);
	}
	if(ans==INF)print(-1);
	else print(ans);
	return 0;
}

Measured memory_bytes: 1392
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

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

  puts( (a == b+c) || (b == a+c) || (c == a+b) ? "Yes": "No");

  return 0;
}



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

using namespace std;

#define ff first
#define ss second
#define int long long
#define pii pair<int,int>
#define mp make_pair

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,i,j;
	cin>>n;
	pii dx[3] = {mp(1,2),mp(0,2),mp(0,1)};
	int mat[n][3],memo[n][3];
	for(i=0;i<n;i++){
		for(j=0;j<3;j++){	
			cin>>mat[i][j];
		}
	}
	for(i=0;i<3;i++)memo[0][i]=mat[0][i];
	for(i=1;i<n;i++){
		for(j=0;j<3;j++){
			memo[i][j]=max(memo[i-1][dx[j].ff],memo[i-1][dx[j].ss])+mat[i][j];
		}	
	}
	int maior=-1;
	for(i=0;i<3;i++){
		if(memo[n-1][i]>maior)maior=memo[n-1][i];
	}	

	cout<<maior<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define long int64_t

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

   if(a>=13)
   {
   	cout<<b<<endl;
   	return 0;
   }

   else if(a<=12 && a>=6)
   {
   	cout<<b/2<<endl;
   	return 0;
   }
   
   else
   	cout<<0;
   cout << endl;
   return 0;
}
 

Measured memory_bytes: 256
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Measured memory_bytes: 25240
#include<stdio.h>

int main(void){
	int h,w,n,k,i,j,m[256][256] = {0},t = 1;
	unsigned long long int x = 1,r = 0;
	scanf("%d%d%d%d",&h,&w,&n,&k);
	for(i = 0;i < h;i++){
		for(j = 0;j < w;j++){
			printf("? %d %d %d %d\n",i,j,i,j);
			fflush(stdout);
			scanf("%d",&m[i][j]);
			if(m[i][j] == 1){n--;}
			if(n == 0){t = 0;break;}
		}
		if(!(t)){break;}
	}
	for(i = 0;i < h;i++){
		for(j = 0;j < w;j++){
			if(m[i][j]){r+=x;r%=k;}
			x*=2;x%=k;
		}
	}
	printf("! %llu\n",r);
	return 0;
}

Measured memory_bytes: 848