akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll vis[1000005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll m,k;
    cin>>m>>k;
    ll n=pow(2,m);
    if(k>=n||(k==1&&m==1)){
        cout<<"-1";
        exit(0);
    }
    else if(k==0){
        for(ll i=0;i<n;i++)
        cout<<i<<" "<<i<<" ";
        exit(0);
    }
    for(ll i=0;i<n;i++)
    if(!vis[i]){
        cout<<i<<" "<<(k^i)<<" ";
        vis[k^i]=1;
    }
    for(ll i=0;i<1000005;i++)
    vis[i]=0;
    for(ll i=0;i<n;i++)
    if(!vis[i]){
        cout<<(k^i)<<" "<<i<<" ";
        vis[k^i]=1;
    }
}

Measured memory_bytes: 9600
import java.util.*;
import java.io.*;

public class Main {

  void solve(InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int m = in.nextInt();

      int ans = (n*(n-1)) / 2;
      ans += (m*(m-1)) / 2;
      out.println(ans);
  }

  public static void main(String[] args) throws Exception {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Main solver = new Main();
    solver.solve(in, out);
    out.close();
  }

  static class InputReader {
    BufferedReader in;
    StringTokenizer st;

    public InputReader(InputStream is) {
      in = new BufferedReader(new InputStreamReader(is));
    }

    public String next() {
      try {
        while (st == null || !st.hasMoreTokens()) {
          st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
  }
}


Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define MAX 105
#define NIL -1

struct node {
	int prnt, left, right;
};
int n;
node tr[MAX];

vector<int> preord(MAX);
vector<int> inord(MAX);
vector<int> pstord;

vector<int> preIdx(500);
vector<int> inIdx(500);

void setPst(int me) {

	if (me == NIL) return;
	setPst(tr[me].left);
	setPst(tr[me].right);
	pstord.push_back(me);

}


void dfs(int pr, int st, int ed, bool isLeft) {
	int lftEd, rgtSt, nrIdx, tmp, nrt, mn;

	if (ed - st <= 1) {
		tmp = inord[st];

		tr[tmp].prnt = pr;
		if (isLeft) tr[pr].left = tmp;
		else tr[pr].right = tmp;

	}
	else
	{
		mn = 999;
		for (int i = st; i < ed; i++)
		{
			tmp = preIdx[inord[i]];
			if (mn > tmp) mn = tmp;
		}
		nrt = preord[mn];
		nrIdx = inIdx[nrt];

		lftEd = nrIdx;
		rgtSt = nrIdx + 1;

		tr[nrt].prnt = pr;
		if (isLeft) tr[pr].left = nrt;
		else tr[pr].right = nrt;

		// left
		if (lftEd - st > 0)		dfs(nrt, st, lftEd, true);

		// right
		if (ed - rgtSt > 0)		dfs(nrt, rgtSt, ed, false);

	}
}



int main() {


	int i, rt, left, right, rtIdx;
	cin >> n;
	for (i = 0; i < MAX; i++) tr[i].prnt = tr[i].left = tr[i].right = NIL;

	for (i = 0; i < n; i++) 		cin >> preord[i];
	for (i = 0; i < n; i++) 		cin >> inord[i];

	for (int i = 0;i < n;i++) {
		preIdx[preord[i]] = i;
	}

	for (int i = 0;i < n;i++) {
		inIdx[inord[i]] = i;
	}


	rt = preord[0];
	rtIdx = inIdx[rt];

	if (rtIdx - 0 > 0)	dfs(rt, 0, rtIdx, true);
	if (n - (rtIdx + 1) > 0)	dfs(rt, rtIdx + 1, n, false);

	rt = 1;
	while (tr[rt].prnt != NIL)
	{
		rt = tr[rt].prnt;
	}

	setPst(rt);

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




Measured memory_bytes: 3280
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int s;
    cin >> s;
    //処理
    //出力
	cout << s/3 << ENT;
    return 0;
}

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


Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    A = int(input())
    B = int(input())

    if A > B:
        print("GREATER")
    elif A < B:
        print("LESS")
    else:
        print("EQUAL")


main()


Measured memory_bytes: 4688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
string stu[5]={"AC","WA","TLE","RE"};
string s;
ll num[5];
int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>s;
		for(ll j=0;j<4;j++)
			if(s==stu[j]) num[j]++;
	}
	for(ll i=0;i<4;i++)
		cout<<stu[i]<<" x "<<num[i]<<endl;
	return 0;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    if N % 10 in [2,4,5,7,9]:
        ret = 'hon'
    elif N % 10 == 3:
        ret = 'bon'
    else:
        ret = 'pon'
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

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

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main(){

  string s;
  cin >> s;
  bool flag = 0;
  for(int i = 0; i < s.size(); ++i)flag |= (s[i] == '7');
  if(flag)cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
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; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int n,k;
           cin>>n>>k;
           cout<<n-k+1<<endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
 
//****************************************************                
#define f(var,start,end) for(ll var = start; var <end ; ++var)
#define rf(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define vvll vector<vector<ll>>
#define mtp make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define nl cout<<"\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions
void solve();

int binary(int a[],int l,int r,int find)
{
    if(l>r)
    {
        return -1; 
    }else
    {
        int mid=(l+r)/2;
        if(a[mid]==find)
        {
            return mid+1;
        }else if(a[mid]>find)
        {
            binary(a,l,mid-1,find);
        }else
        {
            binary(a,mid+1,r,find);
        }   
    }   
}

int main()
{
    FAST_IO;
    ll testcases = 1;
    // cin >> testcases; //comment for 1 test case
    while(testcases--)
    {
        solve();
    }
}

void solve()
{
	ll n;
	cin>>n;
	vll a(n);
	unordered_map<ll,ll>umap;
	f(x,0,n)
	{
		cin>>a[x];
		umap[a[x]]++;
	}   
	ll ans=0;
	f(x,0,n)
	{
		ll f=0;
		for(ll y=1;y*y<=a[x];y++)
		{
			if(a[x]%y==0)
			{
				ll v1=y,v2=a[x]/y;
				// cout<<"v1 "<<v1<<" v2 "<<v2;
				// nl;
				if(v1==a[x])
				{
					if((umap[v1]-1)!=0)
					{
						f=1;
						break;
					}
				}else
				{
					if(umap[v1]!=0)
					{
						f=1;
						break;
					}
				}
				// ll v1=y,v2=x/y;
				if(v2==a[x])
				{
					if((umap[v2]-1)!=0)
					{
						f=1;
						break;
					}
				}else
				{
					if(umap[v2]!=0)
					{
						f=1;
						break;
					}
				}
			}
		}
		if(f==0)
		{
			// cout<<a[x]<<" $";
			// nl;
			ans++;
		}
	}
	cout<<ans;
	nl;
}

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

const ll inf = 1e18;

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll>a(n), b(m);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<m;i++) cin >> b[i];

    for(int i=1;i<n;i++) a[i] += a[i-1];
    for(int i=1;i<m;i++) b[i] += b[i-1];
    a.push_back(inf);
    b.push_back(inf);

    vector<ll>aa(n, 0), bb(m, 0);
    for(int i=0;i<n;i++){
        if(a[i] > k)break;
        aa[i] = (int)(upper_bound(b.begin(), b.end(), k-a[i])-b.begin());
        aa[i] += i + 1;
    }
    for(int i=0;i<m;i++){
        if(b[i] > k)break;
        bb[i] = (int)(upper_bound(a.begin(), a.end(), k-b[i])-a.begin());
        bb[i] += i + 1;
    }

    ll ans = 0;
    for(int i=0;i<n;i++) ans = max(ans, aa[i]);
    for(int i=0;i<m;i++) ans = max(ans, bb[i]);

    cout << ans << endl;
}

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

#define show(x) cout << #x << " = " << x << endl

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

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

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


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int N;

inline bool ask(ll n)
{
    //    static int cnt = 0;
    cout << "? " << n << endl;
    char c;

    // cnt++;
    // assert(cnt <= 64);
    // if (((n < N) and (to_string(n) < to_string(N))) or ((n >= N) and (to_string(n) >= to_string(N)))) {
    //     cout << "Y\n";
    //     return true;
    // } else {
    //     cout << "N\n";
    //     return false;
    // }


    cin >> c;
    return (c == 'Y');
}

inline void answer(ll n)
{
    cout << "! " << n << endl;
    //    assert(n == N);
}

int main()
{
    // cin >> N;

    ll digit = -1;
    for (ll i = 0; i <= 10; i++) {
        const bool b = ask(pow(10, i));
        if (not b) {
            digit = i;
            break;
        }
    }
    if (digit == -1) {
        for (ll i = 1; i <= 10; i++) {
            const bool b = ask(pow(10, i) - 1);
            if (b) {
                digit = i;
                break;
            }
        }
    }

    ll inf = pow(10, digit - 1);
    ll sup = pow(10, digit);
    while (inf < sup) {
        const ll mid = (inf + sup) / 2;
        const bool b = ask(mid * 10);
        if (not b) {
            if (inf == mid) {
                break;
            }
            inf = mid;
        } else {
            if (mid == sup) {
                break;
            }
            sup = mid;
        }
    }
    answer(sup);

    return 0;
}


Measured memory_bytes: 648
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
using namespace std;

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

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

const long long INFLL = 1LL << 60;
const int INF = 1 << 30;

typedef long long ll;
typedef unsigned long long ull;

int N, W;
int w[100];
int v[100];
ll memo[100][100001];

// n  : n-1番目の品物まで見て，今n番目の品物を見ている
// cw : ナップサックの残り容量
// 0 <= n <= N-1
ll solve(int n, int cw) {
  if (n < 0) return 0;
  if (memo[n][cw] != -1) return memo[n][cw];
  
  ll res = solve(n-1, cw);
  if (cw >= w[n]) chmax(res, solve(n-1, cw - w[n]) + v[n]);

  return memo[n][cw] = res;
}

int main(void) {
  cin >> N >> W;
  rep(i, N) cin >> w[i] >> v[i];
  memset(memo, -1, sizeof(memo));
  cout << solve(N-1, W) << endl;
  return 0;
}


Measured memory_bytes: 78336
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

struct node
{
    int x,y;
} a[55];

map<int,int> mpx,mpy;
map<int,int> invx,invy;

int sum[55][55];
int b[55][55];

bool cmp1(node aa,node bb)
{
    return aa.x < bb.x;
}

bool cmp2(node aa,node bb)
{
    return aa.y < bb.y;
}

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    long long ans;
    sort(a+1,a+n+1,cmp1);
    for(int i=1;i<=n;i++)
    {
        invx[i]=a[i].x;
        mpx[a[i].x]=i;
    }
    long long dx=a[n].x - a[1].x;
    sort(a+1,a+n+1,cmp2);
    for(int i=1;i<=n;i++)
    {
        invy[i]=a[i].y;
        mpy[a[i].y]=i;
    }
    long long dy=a[n].y - a[1].y;
    ans=dx * dy;
    for(int i=1;i<=n;i++)
    {
        int x=a[i].x,y=a[i].y;
        b[mpx[x]][mpy[y]]=1;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            sum[i][j]=sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + b[i][j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            for(int s=i;s<=n;s++)
                for(int q=j;q<=n;q++)
                {
                    if(sum[s][q] - sum[s][j-1] - sum[i-1][q] + sum[i-1][j-1] >= k)
                    {
                        long long dx=invx[s] - invx[i];
                        long long dy=invy[q] - invy[j];
                        long long tmp=abs(dx) * abs(dy);
                        ans=min(ans,tmp);
                    }
                }
    printf("%lld\n",ans);
    return 0;
}

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


int main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;
    string t;
    rep(qi, q) {
        int ty;
        cin >> ty;
        if (ty == 1) {
            swap(s, t);
        } else {
            int f; char c;
            cin >> f >> c;
            if (f == 1) {
                t += c;
            } else {
                s += c;
            }
        }
    }

    reverse(t.begin(), t.end());
    t += s;
    cout << t << endl;

    return 0;
}

Measured memory_bytes: 4036
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
ans=[]
for i in data:
    cnt = 0
    while i % 2 == 0:
        i = i / 2
        cnt += 1
    ans.append(cnt)
print(min(ans))

Measured memory_bytes: 3060
main()
{
	register long long l,r,k,res=0;long long n;
	scanf("%lld",&n);
	for(l=1;l<=n;l=r+1)
		k=n/l,r=n/k,res+=(l<=r-1&&r*k==n)?(r-1):0;
	printf("%lld\n",res);
}

Measured memory_bytes: 1724
def prepare(n, MOD):
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return fn, invs


n = int(input())
MOD = 998244353
fn, invs = prepare(n, MOD)
ans = pow(3, n, MOD)
impossible = 0
mul = 2
for i in range(n // 2):
    tmp = fn * invs[i] * invs[n - i] % MOD * mul
    impossible = (impossible + tmp) % MOD
    mul = mul * 2 % MOD
print((ans - impossible) % MOD)


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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  
  cout << x2 + (y1 - y2) << " " << y2 - (x1 - x2) << " ";
  int x3 = x2 + (y1 - y2), y3 = y2 - (x1 - x2);
  cout << x3 + (y2 - y3) << " " << y3 - (x2 - x3) << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
s = n % 2
odd = n // 2
count = 0
if s == 0:
    for i in range(odd):
        k = 2 * i + 1
        if a[k -1] % 2 == 1:
            count += 1      
elif s == 1:
    for i in range(odd + 1):
        k = 2 * i + 1
        if a[k - 1] % 2 == 1:
            count += 1

print(count)

Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <unordered_map>


using namespace std;

int main(int argc, char** argv) {
    long int N;
    long int K;
    cin >> N >> K;

    vector<long int> A(N, 0);
    vector<long int> S(N + 1, 0);
    unordered_map<long int, long int> R;

    S[0] = 0;
    for(long int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] = A[i] - 1;
        S[i + 1] = (S[i] + A[i]) % K;
    }

    long int t;
    long long int total = 0;
    // initial step
    for(long int i = 1; i < K; i++) {
        if (i >= N + 1) {
            break;
        }
        t = S[i] % K;
        if (R.find(t) == R.end()) {
            R[t] = 0;
        }

        R[t] += 1;
    }

    total += R[S[0] % K] - 1;
    if (S[0] % K == 0) {
        total += 1;
    }
    // cout << "init: " << total << endl;

    // Move until the end
    long int s = 0;
    while(s < N) {
        // remove current count
        t = S[s] % K;
        R[t] -= 1;

        // next count
        s = s + 1;
        if (s >= N) {
            break;
        }

        if (s + K - 1 <= N) {
            t = S[s + K - 1] % K;
            if (R.find(t) == R.end()) {
                R[t] = 0;
            }
            R[t] += 1;
        }

        // update total
        total += R[S[s] % K] - 1;
        if (S[s] % K == 0) {
            total += 1;
        }
        // cout << "Step: " << s << " total: " << total << endl;
    }

    cout << total << endl;
}


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

int main()
{
  int N,count,i,j,flag;
  scanf("%d",&N);
  
  int H[N];
  
  for(i=0;i<N;i++){
    scanf("%d",&H[i]);
  }
  
  count=1;
  for(i=1;i<N;i++){
    flag=0;
    for(j=0;j<i;j++){
      if(H[j]>H[i]){
        flag=1;
        break;
      }
    }
    if(flag==0){
      count++;
    }
  }
  
  printf("%d",count);
  return 0;

}

Measured memory_bytes: 128
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int a = cin.nextInt();
    int b = cin.nextInt();

    if (a <= b && b % a == 0) {
      System.out.println(b + a);
    } else {
      System.out.println(b - a);
    }

  }

}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
const int INF = 999999;

int w, h;
int d[40][40];
int px[40][40];
int py[40][40];
queue<pair<int, int> > que;

void bfs(){
	//init rows=h, clumns=w
	/*
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++) d[i][j] = INF;
	}
	*/

	//get start point
	que.push(make_pair(0, 0));
	//init distance with start point
	d[0][0] = 1;


	//loop until queue is empty
	while(que.size()){
		int x = que.front().second;
		int y = que.front().first;
		que.pop();

		//cout << "d = " << d[y][x] << endl;
		//cout << "x = " << x << endl;
		//cout << "y = " << y << endl;

		//if x, y is goal, stop
		if(x == w - 1 and y == h - 1) break;

		//search around
		//up
		if(py[y - 1][x] == 0 and d[y - 1][x] == INF){
			que.push(make_pair(y - 1, x));
			d[y - 1][x] = d[y][x] + 1;
			//cout << "up" << endl;
		}
		//down
		if(py[y][x] == 0 and d[y + 1][x] == INF){
			que.push(make_pair(y + 1, x));
			d[y + 1][x] = d[y][x] + 1;
			//cout << "down" << endl;
		}
		//lf
		if(px[y][x - 1] == 0 and d[y][x - 1] == INF){
			que.push(make_pair(y, x - 1));
			d[y][x - 1] = d[y][x] + 1;
			//cout << "lf" << endl;
		}
		//rh
		if(px[y][x] == 0 and d[y][x + 1] == INF){
			que.push(make_pair(y, x + 1));
			d[y][x + 1] = d[y][x] + 1;
			//cout << "rh" << endl;
		}
	}

	return;
}

int main(){
while(1){//start

	int w, h;
	cin >> w >> h;
	if(w == 0 and h == 0) break;

	//init
	for(int i = 0; i < 40; i++){
		for(int j = 0; j < 40; j++){
			d[i][j] = 0;
			px[i][j] = 0;
			py[i][j] = 0;
		}
	}

	int idx = 0, idy = 0;
	for(int i = 0; i < 2*h - 1; i++){
		if(i % 2 == 0){
			for(int j = 0; j < w-1; j++){
				int tmp;
				cin >> tmp;
				px[idx][j] = tmp;
			}
			idx++;
		}
		else{
			for(int j = 0; j < w; j++){
				int tmp;
				cin >> tmp;
				py[idy][j] = tmp;
			}
			idy++;
		}
	}

	//init rows=h, clumns=w
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++) d[i][j] = INF;
	}

	bfs();

	/*
	//debug
	//cout << "px" << endl;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w - 1; j++) cout << px[i][j] << " ";
		cout << endl;
	}

	cout << endl;
	//cout << "py" << endl;
	for(int i = 0; i < h - 1; i++){
		for(int j = 0; j < w; j++) cout << py[i][j] << " ";
		cout << endl;
	}
	cout << endl;

	//cout << "d" << endl;
	for(int i = 0; i < 31; i++){
		for(int j = 0; j < 31; j++) cout << d[i][j] << " ";
		cout << endl;
	}
	*/

	if(d[h-1][w-1] == INF) cout << 0 << endl;
	else cout << d[h-1][w-1] << endl;

}//end

	return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    rep(i,n){
        if(b[i]<a[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    bool flag = 0;
    ll sm = 0;
    while(1){
        flag = 0;
        rep(i,n){
            int x = i-1;
            int y = i;
            int z = i+1;
            if(i==0){
                x = n-1;
            }
            if(i==n-1){
                z = 0;
            }
            if(b[y]>=b[x]+b[z]){
                int k = (b[y]-a[y])/(b[x]+b[z]);
                if(k>0){
                    flag = 1;
                    b[y] -= k*(b[x]+b[z]);
                    sm += k;
                }
            }
        }
        if(!flag)break;
    }
    rep(i,n){
        if(a[i]!=b[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << sm << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long
using namespace std;


int main() {
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;
    
    
    // (Ax+By)*100 and (Cz+Dw)
    
    
    ll sugar_opt = -1;
    ll water_opt = -1;
    for(int x=0;100*A*x<=F;x++)
        for(int y=0;100*A*x+100*B*y<=F;y++)
            for(int z=0;100*A*x+100*B*y+C*z<=F;z++)
                for(int w=0;100*A*x+100*B*y+C*z+D*w<=F;w++) {
                    
                    ll water = (A*x+B*y)*100;
                    ll sugar = (C*z+D*w);
                    
                    if (sugar + water > 0 && sugar + water <= F && sugar*100 <= water*E && (water_opt==-1 ||sugar*water_opt > water*sugar_opt)) {
                        sugar_opt = sugar;
                        water_opt = water;
                    }
                }
    
    printf("%lld %lld\n",sugar_opt+water_opt, sugar_opt);

}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(n)]
res=0
for t in a:
    ts=0
    for i in range(m):
        ts+=t[i]*b[i]
    if ts+c>0:
        res+=1
print(res)

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

int main(){
    ll n; cin >> n;
    vector<ll> A(n);
    ll ans=0;
    ll sum=0;
    for (ll i=0;i<n;i++){
        cin >> A[i];
        sum+=A[i];
        sum=sum%mod;
    }
    for (ll i=0;i<n-1;i++){
        sum=sum-A[i];
        if (sum<0){
            sum=mod+sum;
        }
        ans+=A[i]*sum;
        ans=ans%mod;
    }
    cout << ans%mod << "\n";
}
















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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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 main() {
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;

    ll d = c - a - b;

    if (d > 0 && 4 * a * b < d * d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N, C, K = map(int, input().split())  # 人数N, バスの定員C, Ti以上Ti+K以下の時刻に出発するバスに乗らせる必要がある
T = [int(input()) for _ in range(N)]
# print(T)
T.sort()
ans = 1
bus_passengers = 1  # 最大Cまでいける
time_limit = T[0]+K
for i in range(1, N):
    # print(i, ans, time_limit)
    if time_limit >= T[i] and C > bus_passengers:
        bus_passengers += 1
    else:
        # 定員数的に乗りきらないもしくは，時間的に乗れない
        time_limit = T[i]+K
        bus_passengers = 1
        ans += 1
print(ans)


Measured memory_bytes: 81148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}

void solve(){
	int h,w,k;
	cin>>h>>w>>k;
	vector<vector<char> >v(h,vector<char>(w));
	int ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>v[i][j];
		}
	}
	for(int i=0;i<(1<<h);i++){
		for(int j=0;j<(1<<w);j++){
			int cnt=0;
			for(int k=0;k<h;k++){
				for(int l=0;l<w;l++){
					if(v[k][l]=='#'&&!(i&(1<<k))&&!(j&(1<<l))){
						cnt++;
					}
				}
			}
			if(cnt==k)ans++;
		}
	}
	cout<<ans;
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	while(numberofsubtestcases--){
		solve();
	}
}




Measured memory_bytes: 3648
#include <stdio.h>

int main(void)
{
	int n, num[11][11], sum;
	int i, j;
	
	while(1){
		sum = 0;
		
		scanf("%d", &n);
		if(n == 0)    break;
		
		/*入力*/
		for(i = 0; i < n; i++){
			for(j = 0; j < n; j++){
				scanf("%d", &num[i][j]);
			}
		}
		
		/*合計を出す*/
		for(i = 0; i < n; i++){
			for(j = 0; j < n; j++){
				sum +=  num[i][j];
			}
			num[i][10] = sum;
			sum = 0;
		}
		
		for(j = 0; j < n; j++){
			for(i = 0; i < n; i++){
				sum += num[i][j];
			}
			num[10][j] = sum;
			sum = 0;
		}
		
		for(i = 0; i < n; i++){
			sum += num[i][10];
		}
		num[10][10] = sum;
		
		/*出力*/
		for(i = 0; i < n; i++){
			for(j = 0; j < n; j++){
				printf("%5d", num[i][j]);
			}
			printf("%5d\n", num[i][10]);
		}
		
		for(j = 0; j < n; j++){
			printf("%5d", num[10][j]);
		}
		printf("%5d\n", num[10][10]);
	}
	
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

const int MAX_N = (int)1e5 + 77;
int a[MAX_N], n;
int b[MAX_N], ord[MAX_N];

int fenwick[MAX_N];

void init() {
	memset(fenwick, 0, sizeof(fenwick[0]) * (n + 17));
}

void inc(int pos) {
	for(; pos <= n; pos |= pos + 1)
		++fenwick[pos];
}

int get(int r) {
	int acc = 0;

	for(; r >= 0; r = (r & (r + 1)) - 1) {
		acc += fenwick[r];
	}

	return acc;
}

int64 count(int k) {
	b[0] = 0;

	for(int i = 1; i <= n; ++i) {
		int val = a[i - 1];

		if(val > k) {
			b[i] = 1;
		} else {
			b[i] = -1;
		}

		b[i] += b[i - 1];
	}
	
	for(int i = 0; i <= n; ++i) {
		ord[i] = b[i];
	}

	sort(ord, ord + n + 1);

	for(int i = 0; i <= n; ++i) {
		b[i] = lower_bound(ord, ord + n + 1, b[i]) - ord;
	}

	int64 answ = 0;
	init();

	for(int i = 0; i <= n; ++i) {
		answ += i - get(b[i]);
		inc(b[i]);
	}

	return answ;
}

void solve() {
	cin >> n;

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

	int MX = (int)1e9 + 777;
	int low = 0, high = MX;
	int64 segments = (n * 1LL * (n + 1)) / 2;

	while(high - low > 1) {
		int mid = (low + high) / 2;
		//DBG(mid); DBG(count(mid));

		if(2 * count(mid) > segments) {
			high = mid;
		} else {
			low = mid;
		}
	}

	cout << high << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <string>
#include <map>
using namespace std;

unsigned int l;

int next(int a) {
    stringstream ss;
    ss << a;
    string as;
    ss >> as;
    while (as.size() < l) {
        as = "0" + as;
    }
    int m[10] = {};
    for (string::iterator it = as.begin(); it != as.end(); it++) {
        m[*it - '0']++;
    }
    string max_as, min_as;
    for (int i = 0; i < 10; i++) {
        if (m[i] > 0) {
            max_as.insert(max_as.begin(), m[i], '0' + i);
            min_as.insert(min_as.end(), m[i], '0' + i);
        }
    }
    int max_a;
    ss.clear();
    ss << max_as;
    ss >> max_a;
    int min_a;
    ss.clear();
    ss << min_as;
    ss >> min_a;
    return max_a - min_a;
}

int main() {
    int a;
    while (cin >> a >> l, a|l) {
        map<int, int> m;
        m[a] = 0;
        int a0 = a;
        for (int i = 1; ; i++) {
            int a1 = next(a0);
            map<int, int>::iterator it = m.find(a1);
            if (it == m.end()) {
                m[a1] = i;
            } else {
                int j = it->second;
                cout << j << " " << a1 << " " << i - j << endl;
                break;
            }
            a0 = a1;
        }
    }
}

Measured memory_bytes: 1252
#include <iostream>
using namespace std;

int main() {
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int k = 0;
    for(int i = 0; i < N; i++) {
        if(a[i] != i + 1)
            k++;
    }
    if(k == 0 || k == 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[200010]={0};
    int b[200010];
    int n;
    cin>>n;
    int i;
    long long sum=0;
    for(i=0; i<n; i++)
    {
        cin>>b[i];
        sum+=a[b[i]];
        a[b[i]]++;
    }
    for (i=0;i<n;i++)
    {
       cout<<sum-a[b[i]]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 4096
#include<stdio.h>

int main(){
	int a,b,c,d,p,i;
	double q=0;
	while(scanf("%d %d",&a,&b)!=-1){
		c=a;
		d=b;
		while((a>b?b:a)){
			p=a%b;
			a=b;
				if(!p) break;
			b=p;
		}
		for(i=0;i<d;i++) q+=c/b;
		printf("%d %d\n",b,(int)q);
		q=0;
	}
	return 0;
}

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


int main(){
  ll n;
  cin >> n;
  map<int,int> a;
  rep(i,n){
    int num;
    cin >> num;
    a[num]++;
  }
  if( a.size() == n ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
bool isdigit(char c) {
	if (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9' )
		return true;
	return false;
}
int main (void) {
	int a, b; cin >> a >> b;
	string s; cin >> s;
	bool flag = true;
	for (int i = 0; i < (int)s.size(); i++) {
		if (i == a && s[i] != '-' ) {
			flag = false;
			break;
		}
		else if (i != a){
			if (!isdigit(s[i])) {
					flag = false;
				break;
			}
		}
	}
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		float D=sc.nextFloat();
		float T=sc.nextFloat();
		float S=sc.nextFloat();
		float temp=D/S;
		if ( temp<=T)
		System.out.print("Yes");
		else
		System.out.print("No");
	}
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[1005];
ll B[1005];

//! Nを置ける場所が何通りあるか
ll T[1000005];
ll Map[1005][1005];
//! 場所が決まっている
bool S[1000005];

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, N)
    {
        cin >> A[i];
    }
    REP(i, M)
    {
        cin >> B[i];
    }

    bool same = false;
    REP(i, N)
    {
        FOR(j, N, i + 1)
        {
            if (A[i] == A[j])
                same = true;
        }
    }
    REP(i, M)
    {
        FOR(j, M, i + 1)
        {
            if (B[i] == B[j])
                same = true;
        }
    }
    if (same)
    {
        cout << 0 << endl;
        return 0;
    }
    REP(h, N)
    {
        REP(w, M)
        {
            Map[h][w] = std::min(A[h], B[w]);
            T[Map[h][w]]++;
            if (A[h] == B[w])
                S[Map[h][w]] = true;
        }
    }

    ll ans = 1;
    ll next = 0;
    for (int i = N * M; i > 0; --i)
    {
        if (T[i] == 0)
        {
            T[i] += next;
            next = 0;
        }
        if (!S[i])
            ans = (ans * T[i]) % MOD;
        next += T[i] - 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n,d;
    cin>>n>>d;
    vector<vector<int>> data(n, vector<int>(d));
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>data.at(i).at(j);
        }
    }
    int sum=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            float len=0;
            for(int k=0;k<d;k++){
                
                len+=(data.at(i).at(k)-data.at(j).at(k))*(data.at(i).at(k)-data.at(j).at(k));
            }
            for(int l=0;l<=len;l++){
                if(l*l==len) sum++;
            }
        }
    }
    cout<<sum<<endl;
}


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

int main()
{
  long long a, b, k;

  cin >> a >> b >> k;
  if (k <= a)
  {
    cout << a - k << " " << b << endl;
  }
  else if (k <= a + b)
  {
    cout << 0 << " " << b-(k-a)<< endl;
  }
  else
  {
    cout << 0 << " " << 0 << endl;
  }
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(){
   int H,W;
   cin>>H>>W;
   for(int i=0; i<W+1; i++){
      cout<<"#";
   }
   cout<<"#"<<endl;
   vector<int> tate(H);
   vector<char> yoko(W);
   for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
         cin>>yoko.at(j);
      }
      cout<<"#";
      for(int j=0; j<W; j++){
         cout<<yoko.at(j);
      }
      cout<<"#"<<endl;
   }
   for(int i=0; i<W+1; i++){
      cout<<"#";
   }
   cout<<"#"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<int,int> P;
ll mod=pow(10,9)+7;
ll INF=pow(10,18);

int main(){
    string S;cin>>S;
    int N=S.size();
    mat dp(2,vec(15,0));dp[0][0]=1;
    for(int i=0;i<N;i++){
        for(int j=0;j<13;j++){
            if(S[i]=='?'){
                for(int k=0;k<10;k++){
                    dp[1][(10*j+k)%13]=(dp[1][(10*j+k)%13]+dp[0][j])%mod;
                }
            }
            else{
                int a=S[i]-'0';
                dp[1][(10*j+a)%13]=dp[0][j];
            }
        }
        dp[0]=dp[1];
        fill(dp[1].begin(),dp[1].end(),0);
    }
    cout<<dp[0][5]<<endl;
    return 0;
}

Measured memory_bytes: 512
n=int(input())
w=list(map(int,input().split()))
w_1=[]
w_2=[]
s1=0
s2=0
a=[]
for i in range(1,n):
            w_1=w[:i]
            w_2=w[i:]
            s1=sum(w_1)
            s2=sum(w_2)
            a.append(abs(s1-s2))
print(min(a))      
            
            


Measured memory_bytes: 3064
samp = input()
samp = samp.split()

W = int(samp[0])
H = int(samp[1])
x = int(samp[2])
y = int(samp[3])
r = int(samp[4])

west = x - r
east = x + r
north = y + r
south = y - r
isIn = True
if(west < 0):
    isIn = False
elif(east > W):
    isIn = False
elif(north > H):
    isIn = False
elif(south < 0):
    isIn = False

if(isIn == True):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int mod=1000000007;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
if(n==m)
{
	cout<<"Yes\n";
	
}
else
{
		cout<<"No\n";
}
return  0;
}





Measured memory_bytes: 256
object Main extends App {
    val scan = new java.util.Scanner(System.in)
    val n = scan.next().toInt
    
    val graph: Dijkstra.Graph = Array.fill(n)(List())

    for (_ <- 1 to n) {
      val u, k = scan.next().toInt
      graph(u) = (1 to k).toList
                .map(_ => Dijkstra.Edge(scan.next().toInt, scan.next().toInt))
    }

    Dijkstra.shortest_path(graph, 0,n-1).zip(0 until n)
      .map(t => t._2.toString ++ " " ++ t._1.toString)
      .foreach(println(_))
}

object Dijkstra {
    case class Edge(to: Int, cost: Long)
    type Edges = List[Edge]
    type Graph = Array[Edges]
    val inf = (1e9+7).toLong
    
    def shortest_path(graph: Graph, start: Int, goal: Int): Array[Long] = {
        val pq = new collection.mutable.PriorityQueue[(Long, Int)]
        val cost = Array.fill(graph.length)(inf)
        cost(start) = 0
        pq += ((cost(start), start))
        while (pq.nonEmpty) {
            val current_edge = pq.dequeue()
            if (cost(current_edge._2) < current_edge._1) {
            } else {
                for (tmp <- graph(current_edge._2)) {
                    val sumCost = current_edge._1 + tmp.cost
                    if (cost(tmp.to) > sumCost) {
                        cost(tmp.to) = sumCost
                        pq += ((cost(tmp.to), tmp.to))
                    }
                }
            }
        }
        cost
    }
}



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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            var a = true;


            var list = new List<int>();

            while (a)
            {

                var input = Console.ReadLine();

                if (input == "0")
                {
                    a = false;
                }
                else
                {

                    var ans = numbersum(input);

                    list.Add(ans);
                }

            }
            list.ForEach(x => Console.WriteLine(x));
            Console.ReadLine();
        }
        static int numbersum(string number)
        {
            var rnum = number.Select(x => int.Parse(x.ToString())).Sum();
            return rnum;

        }


    }
}



Measured memory_bytes: 16364
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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++)
using namespace std;
typedef long long ll;

ll A;
string B;

int main(){
  cin >> A >> B;
  B.erase(B.begin()+1);
  cout << (ll) (A * stoi(B) / 100) << endl;
}


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

char game(char x, string sa, string sb, string sc, int& current_a, int& current_b, int& current_c, int size_a, int size_b, int size_c){
  
  if(x == 'a'){
    if(current_a == size_a) return 'p';
    current_a++;
    return sa.at(current_a - 1);
  }
  if(x == 'b'){
    if(current_b == size_b) return 'q';
    current_b++;
    return sb.at(current_b - 1);
  }
  if(x == 'c'){
    if(current_c == size_c) return 'r';
    current_c++;
    return sc.at(current_c - 1);
  }
}

int main(){
  string sa,sb,sc;
  cin >> sa >> sb >> sc;

  int current_a = 0, current_b = 0, current_c = 0;

  int size_a = sa.size(), size_b = sb.size(), size_c = sc.size();

  char x = 'a';
  while(x == 'a' || x == 'b' || x == 'c') {
    x = game(x, sa, sb ,sc, current_a, current_b, current_c, size_a, size_b, size_c);
  }

  if(x == 'p') cout << 'A' << endl;
  else if(x == 'q') cout << 'B' << endl;
  else if(x == 'r') cout << 'C' << endl;
  
}



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

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

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

  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    if(a[i]%2!=0){
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3620
n = int(input())
lis = []
for _ in range(n):
    inp = list(map(int, input().split()))
    lis.append(inp)
lis.sort(key = lambda x:x[1])
time = 0
for i in range(len(lis)):
    time += lis[i][0]
    if time > lis[i][1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 116304
X,N = map(int,input().split())
p = list(map(int,input().split()))
diff = 0
while True:
    num_p = X + diff
    num_m = X - diff
    if num_m not in p:
        print(num_m)
        break
    elif num_p not in p:
        print(num_p)
        break
    else:
        diff += 1

Measured memory_bytes: 9180
x = int(input().split()[1])

ls = [int(n) for n in input().split()]

for index in range(len(ls)):
	list = ls[0:index]
	if sum(list) > x:
		print(index)
		break
	elif sum(list) == x:
		print(index + 1)
		break

	if index == len(ls) - 1:
		print(len(ls) + 1)

Measured memory_bytes: 3060
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順

using namespace std;
using ll = long long int;

int main(){
    ll A,B,N;cin>>A>>B>>N;
    if(N<B){
        cout << A*N/B << endl;
    }else{
        cout << A*(B-1)/B << endl;
    }
    return 0;
}

Measured memory_bytes: 3632