akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    int x_max = 100, y_max = 100;
    vint x(n), y(n), h(n);
    vvint data(n, vint(3));
    rep(i, n) {
        cin >> data[i][1] >> data[i][2] >> data[i][0];
    }
    if (n == 1) cout << x[0] << " " << y[0] << " " << h[0] << endl;
    sort(rall(data));
    int H, H_t;
    rep(cx, x_max+1) {
        rep(cy, y_max+1) {
            H = data[0][0] + abs(data[0][1] - cx) + abs(data[0][2] - cy);
            rep(i, n) {
                H_t = max(H - abs(data[i][1] - cx) - abs(data[i][2] - cy), 0);
                if (data[i][0] != H_t) break;
                if (i == n-1) {
                    cout << cx << " " << cy << " " << H << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == t.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;

fn solve(H: u128, W: u128) -> u128 {
    // 1行あたり、(W/2.0).ceil()マス動ける
    let even_row = if W % 2 == 0 { W / 2 } else { (W + 1) / 2 };
    let odd_row = W / 2;

    if H == 1 || W == 1 {
        return 1;
    }

    let ans: u128 = if H % 2 == 0 {
        H / 2 * (even_row + odd_row)
    } else {
        (H - 1) / 2 * (even_row + odd_row) + even_row
    };

    return ans;
}

fn main() {
    input! {
        H: u128,
        W: u128,
    }

    let ans = solve(H, W);
    println!("{}", ans);
}


Measured memory_bytes: 2128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main()
{
	vector<ll> a{111,222,333,444,555,666,777,888,999};
	ll inp;
	cin >> inp;
	rep(i, a.size()){
		if(a[i] >= inp) {
			cout <<  a[i] << endl;
			return 0;
		}
	}



    return 0;
}

/*
/^[\w!\x22\#$%&@\'() * +,-.\/;:]+$/
*/


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using static System.Math;

class Program
{
    static void Main()
    {
        int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = input[0];
        int a = input[1];
        int b = input[2];

        Console.WriteLine("{0} {1}", Min(a, b), Max(a + b - n, 0));
    }
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(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 INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll r, d, x;
    cin >> r >> d >> x;
    REP(i, 10){
        x = r * x - d;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}


int main() {

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

    vector<bool>red(n+1,false);
    vector<int>sum(n+1,1);
    red[1]=true;
    sum[0]=0;

    rep(i,m){
        int x,y;
        cin>>x>>y;

        sum[x]--;
        sum[y]++;
        if(red[x]){
            red[y]=true;
            if(sum[x]==0)red[x]=false;
        }

    }

    int cnt=0;

    rep2(i,1,n)if(red[i])cnt++;

    cout<<cnt<<endl;

}





Measured memory_bytes: 640
#include <stdio.h>
int main(void) {
	char X;
	scanf("%c", &X);
	if (X == 'A')
	{
		X = 'T';
	}
	else if (X == 'T') {
		X = 'A';
	}
	else if (X == 'G') {
		X = 'C';
	}
	else if (X == 'C') {
		X = 'G';
	}
	printf("%c", X);
	return 0;
}

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

const int MAX_N = 100100;
ll A[MAX_N], B[MAX_N];
ll N, M;

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

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

int main()
{
    scanf("%lld %lld", &N, &M);
    for(int i = 0; i < N; ++i) scanf("%lld", &A[i]);
    for(int i = 0; i < N; ++i) B[i] = A[i]/2LL;
    ll LCM1 = 1LL;
    for(int i = 0; i < N; ++i) LCM1 = lcm(LCM1, B[i]);
    ll LCM2 = 2LL*LCM1;
    //printf("%lld %lld\n", LCM1, LCM2);
    for(int i = 0; i < N; ++i) if((LCM1/B[i])%2==0) { printf("0\n"); return 0;}
    if(LCM1 > M ) { printf("0\n"); return 0;}
    ll res = 1LL + (M - LCM1)/LCM2;
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 1792
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (N, P) = rd.readIntArray()
    val A = rd.readIntArray()
    val AMAX = 100
    val dp = Array(N+2){LongArray(AMAX*(N+2)){0L} }

    dp[0][0] = 1L
    for (i in 0 until N) {
        for (j in 0 until AMAX*N+1) {
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j] += dp[i][j]
        }
    }

    var ans = 0L
    for (j in P until AMAX*N+1 step 2) {
        ans += dp[N][j]
    }
    println(ans)
}


//val rd = debug.Reader("agc", "017", "a", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 40256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int cnt[1111][1111];
int rot[1210100];
typedef pair<int, int>pii;
int maxis[1111];
int get(vector<pii>v1, vector<pii>v2, int hen)
{
	for (int i = 0; i < hen; i++)maxis[i] = 0;
	for (int i = 0; i < v1.size(); i++)
	{
		if (v1[i].first < v1[i].second)
		{
			maxis[0] = max(maxis[0], v1[i].first);
			maxis[v1[i].first + 1] = max(maxis[v1[i].first + 1], v1[i].second);
			maxis[v1[i].second + 1] = max(maxis[v1[i].second + 1], v1[i].first + hen);
		}
		else
		{
			maxis[0] = max(maxis[0], v1[i].second);
			maxis[v1[i].second + 1] = max(maxis[v1[i].second + 1], v1[i].first);
			maxis[v1[i].first + 1] = max(maxis[v1[i].first + 1], v1[i].second + hen);
		}
	}
	for (int i = 0; i < v2.size(); i++)
	{
		if (v2[i].first < v2[i].second)
		{
			maxis[0] = max(maxis[0], v2[i].second);
			maxis[v2[i].first + 1] = max(maxis[v2[i].first + 1], v2[i].first+hen);
			maxis[v2[i].second + 1] = max(maxis[v2[i].second + 1], v2[i].second + hen);
		}
		else
		{
			maxis[0] = max(maxis[0], v2[i].first);
			maxis[v2[i].first + 1] = max(maxis[v2[i].first + 1], v2[i].first + hen);
			maxis[v2[i].second + 1] = max(maxis[v2[i].second + 1], v2[i].second + hen);
		}
	}
	int mini = 1000000000;
	for (int i = 0; i < hen; i++)
	{
		mini = min(mini, maxis[i] - i);
		maxis[i + 1] = max(maxis[i + 1], maxis[i]);
	}
	return mini;
}
int main()
{
	int num, hen;
	scanf("%d%d", &num, &hen);
	for (int i = 0; i < num; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		cnt[za%hen][zb%hen]++;
	}
	for (int i = 1; i < 1050; i++)
	{
		for (int j = (i - 1)*(i - 1) + 1; j <= i*i; j++)rot[j] = i;
	}
	vector<pii>v1, v2;
	int maxi = -1;
	for (int i = 0; i < hen; i++)
	{
		for (int j = 0; j < hen; j++)
		{
			if (cnt[i][j]>0)
			{
				int l = rot[cnt[i][j]] - 1;
				if (maxi < l)v1.clear(), v2.clear(), maxi = l;
				if (maxi == l)
				{
					if (cnt[i][j] <= l*(l + 1))v1.push_back(make_pair(i, j));
					else v2.push_back(make_pair(i, j));
				}
			}
		}
	}
	int mini = 1000000000;
	for (int i = 0; i < hen; i++)
	{
		for (int j = 0; j < v1.size(); j++)v1[j].first = (v1[j].first + 1) % hen;
		for (int j = 0; j < v2.size(); j++)v2[j].first = (v2[j].first + 1) % hen;
		mini = min(mini, get(v1, v2, hen));
	}
	printf("%d\n", mini + hen*maxi);
}

Measured memory_bytes: 10996
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
		ll a;
		cin>>a;
		ll p;
		ll q;
		ll r;
		p=a;
		q=a*a;
		r=a*a*a;
		cout<<p+q+r<<"\n";
	return 0;
}


Measured memory_bytes: 3508
def solve(N, D, Xs):
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 0
            for d in range(D):
                k += pow(Xs[i][d] - Xs[j][d], 2)
            d = pow(k, 0.5)
            if d == int(d):
                ans += 1
    return ans

if __name__ == "__main__":
    N, D = tuple(map(int, input().split(" ")))
    Xs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, D, Xs))


Measured memory_bytes: 3188
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

int32_t N;
std::string S[100];
int main()
{
	using std::endl;

	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		std::cin >> S[i];
	}
	
	//if (std::find_if(S, S + N, [](const std::string& s) { return s == "Y"; }) == S + N) {
	if (std::find(S, S + N, "Y") == S + N) {
		std::cout << "Three" << endl;
	}
	else {
		std::cout << "Four" << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 504
(* O(n) *)
Scanf.scanf " %d %d %d %d %d" @@ fun n a b c d ->
  let a, b, c, d = a - 1, b - 1, c - 1, d - 1 in
  let s = Scanf.scanf " %s" @@ fun s -> s in
  let l, l_end, r, r_end = if a < b then a, c, b, d else b, d, a, c in
  (try
    let i = Str.search_forward (Str.regexp "##") s l in
    if i <= max l_end r_end then (print_endline "No"; exit 0) with
  | _ -> ());
  print_endline @@
    if l_end > r_end then
      try
        let i = Str.search_forward (Str.regexp "\\.\\.\\.") s @@ r - 1 in
        if i <= r_end - 1 then "Yes" else "No" with
      | _ -> "No"
    else "Yes"

Measured memory_bytes: 2944
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        int ans = Math.max(A, Math.max(C, B));
        int ch = Math.max(A, Math.max(C, B));
        for (int i = 0; i < K; i++) {
            ans = ans * 2;
        }
        if (ch == A) {
            System.out.println(ans + B + C);
        } else if (ch == B) {
            System.out.println(ans + A + C);
        } else {
            System.out.println(ans + A + B);
        }
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
vector<vector<int> > v;
int visit[100001];
int N,M;
void BFS(int sx){
	queue<int> q;
	visit[sx]=1;
	q.push(sx);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(auto nx : v[x]){
			if(visit[nx]==0){
				q.push(nx);
				visit[nx]=1;
			}
		}
	}
}
int main(){
	scanf("%d %d",&N,&M);
	v.resize(N+1);
	for(int i=0;i<M;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int cnt=0;
	for(int i=1;i<=N;i++){
		if(visit[i]==0){
			BFS(i);
			cnt++;
		}
	}
	printf("%d",cnt);
}

Measured memory_bytes: 6904
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
	int r,g,b,n;
	cin>>r>>g>>b>>n;
	ll ans=0;
	for(int i=0;i*r<=n;i++){
		for(int j=0;r*i+g*j<=n;j++){
			ll t=n-(r*i)-(g*j);
				//cout<<i<<" "<<j<<" "<<t<<endl;
			if(t%b==0||t==0){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int cnt[100005]={0};
int main(){
    long long int n,q,a,b,c,sum=0;
    cin>>n;
    while(n--){
        cin>>a;
        cnt[a]++;
        sum+=a;
    }
    cin>>q;
    while(q--){
        cin>>b>>c;
        sum+=(c-b)*cnt[b];
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 3896
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	LL T1,T2,A1,A2,B1,B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
	LL a=T1*A1+T2*A2;
	LL b=T1*B1+T2*B2;
	if(a==b){
		cout << "infinity" << endl;
		return 0;
	}
	if(a<b){
		swap(A1,B1);
		swap(A2,B2);
		swap(a,b);
	}
	if(B1<A1){
		cout << 0 << endl;
		return 0;
	}

	LL d=a-b;
	LL c=T1*(B1-A1);
	//cerr << d << endl;
	if(c%d==0){
		cout << 2*(c/d) << endl;
	}
	else{
		cout << 2*(c/d)+1 << endl;
	}

	return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> B(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    B[0] = 0;
    for (int i = 1; i <= N; i++) {
        B[i] = B[i - 1] + A[i - 1];
    }

    long long ans = 0;
    sort(B.begin(), B.end());
    for (int i = 1; i <= N;) {
        long long cnt = 1;
        while (B[i] == B[i - 1] && i <= N) {
            cnt++;
            i++;
        }
        ans += cnt * (cnt - 1) / 2;
        i++;
    }

    cout << ans << endl;
}

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

int a[105][105];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int T;
    scanf("%d",&T);
    int x=1,y=1;
    for(int i=1;i<=T;i++)
    {
        int tmp;
        scanf("%d",&tmp);
        while(tmp)
        {
            a[x][y]=i;
            if(x&1){
                y++;
                if(y>m){
                    x++;y--;
                }
            }
            else{
                y--;
                if(y<=0){
                    y++;
                    x++;
                }
            }
            tmp--;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            printf("%d%c",a[i][j],j==m?'\n':' ');
        }
    }
    return 0;
}


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

using namespace std;

long double n, m, d, times;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> m >> d;
    if(d == 0)
        times = 1 / n;
    else
        times = (2 * (n - d)) / (n * n);
    cout << setprecision(15) << fixed << times * (m - 1) << "\n";
}


Measured memory_bytes: 256
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))


from collections import defaultdict, deque, Counter
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

MOD = 10 ** 9 + 7

def dist(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])
def solve():
    n, m = getList()
    st = []
    for i in range(n):
        st.append(getList())

    ch = []
    for i in range(m):
        ch.append(getList())

    for s in st:
        tmp = 10 ** 9
        ans = -1
        for idx, c in enumerate(ch):
            if dist(s, c) < tmp:
                ans = idx + 1
                tmp = dist(s,c)

        print(ans)


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()

Measured memory_bytes: 64620
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

X = [0] * N

for i in range(N):
    X[A[i] - 1] += 1

X = sorted(X, reverse=True)

S = sum(X[:K])

ans = N - S

print(ans)

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

int main(){
    int n;
    cin >> n;
    n %= 10;
    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon" << endl;
    if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
    if(n == 3) cout << "bon" << endl;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
   // System.out.println(S);
    
    if(S.equals("ABC")){
      System.out.println("ARC");
    }
    else{
      System.out.println("ABC");
    }
  }
}

Measured memory_bytes: 35556
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
char S[100000];
map<char,ll> m;
ll cnt=0;
int main()
{
	scanf("%s",S);
	for(ll i=0;i<4;i++) m[S[i]]++;
	for(ll i='A';i<='Z';i++){
		if(m[i]==2) cnt++;
	}
	if(cnt==2) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 256
n,d,a=map(int,input().split())
xh=[list(map(int,input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
from collections import deque
minusd=deque()
nowd=0
ans=0
for x,h in xh:
  while minusd and minusd[0][1]<=x:
    d_,_=minusd.popleft()
    nowd-=d_
  tmp=max(0,(h-nowd+a-1)//a)
  ans+=tmp
  nowd+=tmp*a
  minusd.append([tmp*a,x+2*d+1])
  #print(ans,nowd)
print(ans)

Measured memory_bytes: 75708
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

void halve(lint d, lint c, lint &cnt, vector<lint> &rem) {

	if (c == 1) {
		rem.emplace_back(d);
		return;
	}

	if (c & 1) rem.emplace_back(d);

	if (d <= 4) {
		d *= 2;
		cnt += c / 2;
	}
	else {
		d = 1 + 2 * d % 10;
		cnt += c - (c & 1);
	}

	halve(d, c / 2, cnt, rem);

};

void simulate(vector<lint> &vec, lint &cnt) {

	if (vec.size() <= 1) return;

	lint back1 = vec.back();
	vec.pop_back();
	lint back2 = vec.back();

	DMP(back1, back2);

	lint sum = back1 + back2;
	if (sum <= 9) {
		cnt++;
		vec.back() = sum;
	}
	else {
		cnt += 2;
		vec.back() = 1 + sum % 10;
	}

	simulate(vec, cnt);

}

int main() {

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

	int M;
	cin >> M;
	lint ans = 0;
	vector<lint> rem;
	for (int i = 0; i < M; i++) {

		lint d, c;
		cin >> d >> c;
		halve(d, c, ans, rem);

	}

	DMP(ans, rem);
	simulate(rem, ans);

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 35172
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;

#define INF 0

int main(void)
{
    int L;
    cin >> L;
    double A = double(L) / 3;
    cout << fixed << setprecision(20);
    cout << A * A * A << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a%b==0){
          System.out.println(0);
        }
      else{
         System.out.println(1);
      }
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 12 21:00:01 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

const std::string T = "RGB";
signed main() {
    Int n;
    std::string s;
    std::cin >> n >> s;
    auto acc = make_vec<Int>(n + 1, 3, 0);
    REP(i, n) {
        REP(j, 3) { acc[i + 1][j] = acc[i][j]; }
        acc[i + 1][T.find(s[i])]++;
    }
    Int ans = 0;
    REP(i, n) {
        REP(k1, 3) {
            REP(k2, 3) {
                if (k1 == k2 || k1 == T.find(s[i]) || k2 == T.find(s[i])) continue;
                ans += acc[i][k1] * (acc[n][k2] - acc[i + 1][k2]);
            }
        }
        REP(j, 1, n) {
            if (i - j < 0 || i + j >= n) break;
            ans -= s[i - j] != s[i] && s[i] != s[i + j] && s[i + j] != s[i - j];
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3844
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

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;
    vector<vector<int>> a(n, vector<int>(3));
    rep(i, n) rep(j, 3) cin >> a[i][j];

    vector<vector<ll>> dp(n + 1, vector<ll>(3, 0));
    rep(i, 3) dp[0][i] = 0;
    rrep(i, n) {
        rep(j, 3) {
            rep(k, 3) {
                if(j == k) continue;
                chmax(dp[i][k], dp[i - 1][j] + a[i - 1][k]);
            }
        }
    }
    ll ans = 0;
    rep(i, 3) ans = max(ans, dp[n][i]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A;
  cin >>N;
  vector<int>Z(N,0);
  for(int i=0; i<N; i++){
    cin >>A;
    Z[A]++;
  }
  for(int i=0; i<N; i+=2){
    if(i==0 && N%2==0) i++;
    if(i==0 && N%2==1){
      if(Z[0]!=1){
        cout << '0' << endl;
        return 0;
      }
    }
    else{
      if(Z[i]!=2){
        cout << '0' << endl;
        return 0;
      }
    }    
  }
  long long ans=1;
  for(int i=0; i<N/2; i++){
    ans*=2;
    ans%=1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	int on = 0, fi = 0; int x;
	for(int i = 0 ; i < 3; i++){
		cin>>x;
		x == 5 ? fi++ : on++;
	}
	if(fi == 2) cout<<"YES"<<"\n";
	else cout<<"NO"<<"\n";
	
	
	
}

Measured memory_bytes: 256
N = gets.to_i
H = gets.chomp.split(" ").map(&:to_i)

ans = 0
wk = 0
(0..H.size-2).each{|i|
  if H[i] >= H[i+1] then
    wk += 1
  else
    ans = wk if ans < wk
    wk = 0
  end
  ans = wk if ans < wk
}

puts ans


Measured memory_bytes: 9604
#include <iostream>

using namespace std;

int main() {
    int N;
    int A[2][110];
    int max = 0;

    cin >> N;
    for(int j = 0; j < 2; j++) {
        for(int i = 0; i < N ; i++) {
            cin >> A[j][i];
        }
    }

    int temp = 0;
    for(int i = 0; i < N; i++) {
        temp = 0;
        for(int j = 0; j < N; j++) {
            if(j <= i) {
                temp += A[0][j];
            }
            if(j >= i) {
                temp += A[1][j];
            }
        }
        if(temp >= max) {
            max = temp;
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int> > v;
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        pair<int, int> p = make_pair(a, i);
        v.push_back(p);
    }
    sort(v.begin(), v.end());
    for(int i = 0 ; i < v.size(); i++){
        cout << v[i].second << " ";
    }
    cout << endl;
    return 0;
}


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


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(rng(a));
  reverse(rng(a));
  ll ans = 0;
  deque<int> mi;
  mi.push_back(a[0]);
  rep(i,n-1) {
    ans += mi.front();
    mi.push_back(a[i+1]);
    if(i%2==0) mi.pop_front();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
int cnt[27];
int ans = 0;
void solve(int indx, int T) {
	if (indx == 26) return void(ans = (ans + T) % mod);
	solve(indx + 1, T);
	solve(indx + 1, (T * 1ll * cnt[indx]) % mod);
}
int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	for (auto c : s)
		cnt[c - 'a']++;
	solve(0, 1);
	cout << (ans - 1 + mod) % mod << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
string s;
cin>>s;
int n=0;
if(s=="AAA"){
  n=1;
}
else if(s=="BBB"){
  n=1;
}
if(n==1){
  cout<<"No"<<endl;
}else{
  cout<<"Yes"<<endl;
}
return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int h,w;
	while(scanf("%d%d",&h,&w)&&h!=0&&w!=0){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(i==0||i==h-1||j==0||j==w-1)printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;
	if(s == u) {
		cout << a - 1 << ' ' << b << endl;
	}
	else {
		cout << a << ' ' << b - 1 << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};

int N,W;
vector<long> w0,w1,w2,w3;
long w,v;
long wf;

int main() {
    cin >> N >> W;
    rep(i,N){
        cin >> w >> v;
        if(i==0) wf = w;
        if(w-wf==0) w0.push_back(v);
        else if(w-wf==1) w1.push_back(v);
        else if(w-wf==2) w2.push_back(v);
        else w3.push_back(v);
    }

    sort(w0.begin(), w0.end()),sort(w1.begin(), w1.end()),
            sort(w2.begin(), w2.end()),sort(w3.begin(), w3.end());

    long pr = 0;
    rep(i,N+1) rep(j,N+1) rep(k,N+1) rep(l,N+1){
                    long ans = 0;
                    if(i<=w0.size() && j<=w1.size() && k <= w2.size() && l <= w3.size() && i+j+k+l <= N && i*wf+j*(wf+1)+k*(wf+2)+l*(wf+3) <= W){
                        rep(a,i) ans += w0[w0.size()-1-a];
                        rep(a,j) ans += w1[w1.size()-1-a];
                        rep(a,k) ans += w2[w2.size()-1-a];
                        rep(a,l) ans += w3[w3.size()-1-a];
                    }
                    pr = max(pr,ans);
                }

    cout << pr << endl;
    return 0;
}


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

int main(void)
{
	//変数の宣言
	int n;
	int a[60];
	int maxid,minid;
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	max=a[0];
	min=a[0];
	maxid=0;
	minid=0;
	
	for(i=0;i<n;i++){
		if(max<a[i]){
			max=a[i];
			maxid=i;
		}
		if(min>a[i]){
			min=a[i];
			minid=i;
		}
	}
	
	if(max+min>0){
		printf("%d\n",2*n-1);
		for(i=0;i<n;i++){
			printf("%d %d\n",maxid+1,i+1);
		}
		for(i=1;i<n;i++){
			printf("%d %d\n",i,i+1);
		}
	}else{
		printf("%d\n",2*n-1);
		for(i=0;i<n;i++){
			printf("%d %d\n",minid+1,i+1);
		}
		for(i=n-1;i>0;i--){
			printf("%d %d\n",i+1,i);
		}
	}
	
//	printf("計算部分終了\n");
	//出力
	
	//printf("%d\n",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 128
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t N;
  cin >> N;
  vector<int32_t> V(N);
  for (int32_t i = 0; i < N; ++i) {
    cin >> V[i];
  }

  vector<int32_t> guu(100000 + 1, 0);
  vector<int32_t> ki(100000 + 1, 0);
  for (int32_t i = 0; i < N; ++i) {
    if (i % 2 == 0) {
      ++guu[V[i]];
    } else {
      ++ki[V[i]];
    }
  }

  vector<pair<int32_t, int32_t>> guu_list, ki_list;
  for (int32_t i = 1; i <= 100000; ++i) {
    if (guu[i] > 0) {
      guu_list.push_back(pair<int32_t, int32_t>(guu[i], i));
    }
    if (ki[i] > 0) {
      ki_list.push_back(pair<int32_t, int32_t>(ki[i], i));
    }
  }
  sort(guu_list.begin(), guu_list.end());
  reverse(guu_list.begin(), guu_list.end());
  sort(ki_list.begin(), ki_list.end());
  reverse(ki_list.begin(), ki_list.end());
  if (guu_list[0].second != ki_list[0].second) {
    cout << (N - guu_list[0].first - ki_list[0].first) << endl;
  } else {
    if (guu_list.size() == 1 && ki_list.size() == 1) {
      cout << N / 2 << endl;
    } else if (guu_list.size() == 1) {
      cout << (N - guu_list[0].first - ki_list[1].first) << endl;
    } else if (ki_list.size() == 1) {
      cout << (N - guu_list[1].first - ki_list[0].first) << endl;
    } else {
      if (guu_list[1].first < ki_list[1].first) {
        cout << (N - guu_list[0].first - ki_list[1].first) << endl;
      } else {
        cout << (N - guu_list[1].first - ki_list[0].first) << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 2428
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const ll inf=1000000007;
const ll MOD=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};


int main(){
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k%2==0)print(a-b);
	else print(b-a);
}

	


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;cin >> s;
    int n = s.size();
    vl val(2019,0);
    ll fac=1;
    ll cur=0;
    val[cur]++;
    for (int i=0; i<n; ++i) {
        ll add = s[n-1-i]-'0';
        cur = (cur+fac*add)%2019;
        fac = (fac*10)%2019;
        val[cur]++;
    }
    ll res = 0;
    for(int i=0; i<val.size(); ++i) {
        res += val[i]*(val[i]-1)/2;
    }
    ct(res);
}


Measured memory_bytes: 3740
import java.util.*;
import java.lang.*;
import java.math.*;


public class Main {
	
	Scanner sc = new Scanner(System.in);
	
	void run() {
		
		int n;
		boolean[] p;
		int count;
		
		while (sc.hasNext()) {
			
			n = sc.nextInt();
			
			if ( n <2 ) {
				System.out.println(0);
				continue;
			}
			
			p = new boolean [n+1];
			
			for(int i=0;i<=n;i++) {
				p[i] = true;
			}
			
			count = 0;
			
			for (int i=2;i<=n;i++) {
				
				if ( p[i] ) {
					
					count++;
					
					for (int j=2;j<=n/i;j++) {
						
						p[j*i] = false; 
						
					}
				}
			}
			
			System.out.println(count);
		
		}
	}
	
	public static void main(String[] args) {
		
		new Main().run();
		
	}
	
}

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

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int L,N;

signed main(){
    int p=0,q=0;
    cin>>L>>N;
    rep(i,N){
        int x,w;
        cin>>x>>w;
        if(x>0)p+=x*w;
        else q+=(-x)*w;
    }

    if(p==q)puts("0");
    else{
        puts("1");
        if(p<q)printf("1 %lld\n",q-p);
        else printf("-1 %lld\n",p-q);
    }
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
int main(){
    string S; cin>>S;
    if(S[5]=='1'||S[6]>='5'){
        cout<<"TBD";
    }
    else if(S[5]=='0'&&S[6]<'5'){
        cout<<"Heisei";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <functional>
#include <cstring>

constexpr int CANT_GO = 114514;

int field[60][30] = {0};
int dp[2][60][30][5][3] = { 0 }; //[?¬???????][??????y][x][?????????y][x] = cost
int dx[] = {1, 1, 1, 1, 1, 2, 2, 2, 3};
int dy[] = {2, 1, 0, -1, -2, 1, 0, -1, 0};

struct Node {
	int x, y; 
	int rx, ry; //????¶???????????????????
	int cost;
	bool nextR; //?¬?????????????????????????true
	bool operator>(const Node& rhs) const {
		if (cost == rhs.cost) return y > rhs.y;
		return cost > rhs.cost;
	}
};
int main() {
	int w, h;
	while (std::cin >> w >> h && (w || h)) {
		std::memset(dp, 0x7f, sizeof(int) * 2 * 60 * 30 * 5 * 3);
		std::vector<int> startList;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				char c; std::cin >> c;
				if ('0' <= c && c <= '9') field[i][j] = c - '0';
				else if(c == 'X') field[i][j] = CANT_GO;
				else if (c == 'S') {
					field[i][j] = 0;
					startList.push_back(j);
				}
				else if (c == 'T') field[i][j] = 0;
			}
		}

		std::priority_queue<Node, std::vector<Node>, std::greater<Node>> q;
		bool isOk = false;
		//??¨start???????????????
		for (int i = 0; i < startList.size(); i++) {
			q.push({ startList[i], h - 1, 1, 0, 0, true }); //??????????????????
			q.push({ startList[i] - 1, h - 1, 1, 0, 0, false }); //??????????????????
		}
		int minCost = 0;
		while (!q.empty() && !isOk) {
			auto node = q.top(); q.pop();
			if ((field[node.y][node.x] == 0 && node.y == 0) || (field[node.y + node.ry][node.x + node.rx] == 0 && node.y + node.ry == 0)) {
				isOk = true;
				minCost = node.cost;
				break;
			}
			for (int i = 0; i < 9; i++) {
				auto next = node;
				if (node.nextR) {
					next.rx = dx[i]; //?????´????????????????????????OK?????????????????????????§????
					next.ry = dy[i];
				}
				else {
					int rx = node.x + node.rx; //????¶???§?¨?
					int ry = node.y + node.ry;
					next.x = rx - dx[i]; //????¶???????????????????????????§?¨?
					next.y = ry + dy[i];
					next.rx = rx - next.x;//????????§?¨??????????
					next.ry = ry - next.y;
				}
				next.nextR = !node.nextR;
				//check
				if (next.x < 0 || next.x >= w || next.y < 0 || next.y >= h) continue;
				if (next.x + next.rx < 0 || next.x + next.rx >= w || next.y + next.ry < 0 || next.y + next.ry >= h) continue;
				if (!next.rx) continue;

				int cost;
				if (node.nextR) {
					cost = field[next.y + next.ry][next.x + next.rx];
				}
				else cost = field[next.y][next.x];

				if (cost < 0 || 9 < cost) continue; //X?????¨???

				next.cost += cost;
				if (dp[next.nextR][next.y][next.x][next.ry + 2][next.rx - 1] <= next.cost) continue;
				dp[next.nextR][next.y][next.x][next.ry + 2][next.rx - 1] = next.cost;
				//std::cout << next.x << ", " << next.y << ", " << next.x + next.rx << ", " << next.y + next.ry << ", " << next.cost << ", " << next.nextR << std::endl;
				q.push(next);
			}
		}
		if (isOk) std::cout << minCost << std::endl;
		else std::cout << -1 << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3356
N, K = gets.split(" ").map(&:to_i)
P = gets.split(" ").map(&:to_i)
tmp = P[0..(K - 1)].inject(:+)
ans = [tmp]
(N - K).times do |i|
    tmp += P[K + i] - P[i]
    ans << tmp
end
puts (ans.sort[-1] + K) / 2.0

Measured memory_bytes: 19512
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

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

void solve() {
    int n,k;
    cin >> n >> k;
    VI h(n);
    REP(i,0,n) cin >> h[i];
    VI dp(n, 1000000000+1);
    dp[0] = 0;
    REP(i,1,n) REP(j,max(0,i-k),i)
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
    cout << dp[n-1] << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1024