akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll n,m;
    cin>>n>>m;
    cout<<(n*(n-1)+m*(m-1))/2<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 256
from collections import deque

H,W=map(int,input().split())
s=[input() for _ in range(H)]

q= deque([[0,0]])
f=[[-1 for j in range(W)]for i in range(H)]
f[0][0] = 0
dxy=[[1,0],[-1,0],[0,1],[0,-1]]

while q:
    x,y =q.popleft() 
    for dx,dy in dxy:
        dx += x
        dy += y
        if dx >=0 and dy >= 0 and dx<H and dy<W:
            if s[dx][dy] == "." and f[dx][dy]==-1:
                f[dx][dy] = f[x][y]+1
                q.append([dx,dy])

res = 0
for i in range(H):
    res += s[i].count(".")
if f[H-1][W-1]==-1:
    print(-1)
else:
    print(res - f[H-1][W-1] -1)

Measured memory_bytes: 40636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;

int N;
int bit[MAX];

void add(int a, int w) {
    for (int x = a; x <= N; x += x&-x) {
        bit[x] += w;
    }
}

int sum(int a) {
    int res = 0;
    for (int x = a; x > 0; x -= x&-x) res += bit[x];
    return res;
}


void solve(void){
    cin >> N;

    ll ans = 0LL;

    vector <int> v(N), vc(N);
    map <int, int> mp;
    rep(N, i) {
        cin >> v[i];
    }
    vc = v;
    sort(all(vc));
    rep(N, i) mp[vc[i]] = i+1;
    rep(N, i) v[i] = mp[v[i]];

    rep(N, i) {
        ans += i-sum(v[i]);
        add(v[i], 1);
    }

    cout << ans << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}



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

int main(){
  long long int n,a,b;
  cin >> n >> a >> b;
  
  long long int syou = n/(a+b);
  long long int sa = n-syou*(a+b);
  if(sa > a) sa = a;
  
  cout << syou*a+sa << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mo 1000000007ll
#define N 110
#define int long long
struct no{
	int x,y;
};
vector<no>v[N];
int f[N],q;
signed main(){
	v[1].push_back((no){1,2});
	v[1].push_back((no){1,3});
	v[1].push_back((no){1,4});
	f[0]=f[1]=1;
	for(int i=2;i<=100;i++)
		f[i]=f[i-1]+f[i-2];
	for(int i=1;i<=97;i++)
		for(auto x:v[i]){
			int a=x.y,b=x.x+a;
			while(b<=f[i+3]+f[i])
				v[i+1].push_back((no){a,b}),b+=a;
		}
	cin>>q;
	while(q--){
		int n,m;
		cin>>n>>m;
		if(n>m)swap(n,m);
		int g=1,r=0;
		while(f[g+1]<=n&&f[g+2]<=m)g++;
		cout<<g<<' ';
		if(g==1)cout<<n%mo*m%mo<<'\n';
		else{
			for(auto x:v[g-1]){
			int a=x.x,b=x.y;
			if(b<=n)r=(r+(m-a)/b)%mo;
			if(b<=m)r=(r+(n-a)/b)%mo;
		}
		cout<<r<<'\n';
		}
	}
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int f = sc.nextInt();
		String s = sc.next();
		Dice dice = new Dice(a, b, c, d, e, f);
		dice.move(s);
		System.out.println(dice.top);
	}
}
class Dice {
	int north;
	int south;
	int east;
	int west;
	int top;
	int bottom;
	public Dice(int... ary){
		this.top = ary[0];
		this.south = ary[1];
		this.east = ary[2];
		this.west = ary[3];
		this.north = ary[4];
		this.bottom = ary[5];
	}
	public void move(String s){
		char[] chars = s.toCharArray();
		for(char c : chars){
			switch(c){
				case 'N': this.toNorth();
				break;
				case 'S': this.toSouth();
				break;
				case 'E': this.toEast();
				break;
				case 'W': this.toWest();
				break;
			}
		}
	}
	public void toNorth(){
		int swap = north;
		north = top;
		top = south;
		south = bottom;
		bottom = swap;
	}
	public void toSouth(){
		int swap = south;
		south = top;
		top = north;
		north = bottom;
		bottom = swap;
	}
	public void toEast(){
		int swap = east;
		east = top;
		top = west;
		west = bottom;
		bottom = swap;
	}
	public void toWest(){
		int swap = west;
		west = top;
		top = east;
		east = bottom;
		bottom = swap;
	}
}



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

int main(void){
  int n,m,x,in;
  cin>>n>>m>>x;
  int a[100];  
  for(int i = 0 ; i < 100 ; i++)a[i] = 0;
  for(int i = 0 ; i < m ; i++){
    cin>>in;
    a[in] = 1;
  } 
  
  int ret = 200;
  int cost = 0;
  for(int i = x ; i < n ; i ++){
    cost += a[i];
  }
  ret = min(ret, cost);
  
  cost = 0;
  for(int i = 0 ; i <= x ; i ++){
    cost += a[i];
  }
  ret = min(ret, cost);
  cout<<ret<<endl;
}




Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import math

n = int(input())
ret_just = math.floor(n/1.08)
ret_minus1 = ret_just - 1
ret_plus1 = ret_just + 1

if math.floor(ret_just*1.08) == n:
    print(ret_just)
elif math.floor(ret_minus1*1.08) == n:
    print(ret_minus1)
elif math.floor(ret_plus1*1.08) == n:
    print(ret_plus1)
else:
    print(":(")


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i*j == N) {
                cout << YES << endl;
                return;
            }
        }
    }

    cout << NO << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<queue>
#include <iostream>
#define inf 1000000
using namespace std;
int H,W,N,x0,y0;
char map[1005][1005];int d[1005][1005];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
typedef pair<int,int>P;
struct position
{
	int rx,ry,e;
}xy[9];
bool comp(const position a,const position b)
{
	return a.e<b.e;
}
int bfs(int sx,int sy,int gx,int gy)
{
	int tx,ty;
	queue<P>q;

	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		d[i][j]=inf;
	}
	q.push(P(sx,sy));
	d[sx][sy]=0;
	while(!q.empty())
	{
		P p=q.front();
		if(p.first==gx&&p.second==gy)
		return d[p.first][p.second];
		q.pop();
		for(int i=0;i<4;i++)
		{
			tx=p.first+dx[i];
			ty=p.second+dy[i];
			if(tx>=0&&tx<H&&ty>=0&&ty<W&&map[tx][ty]!='X'&&d[tx][ty]==inf)
			{
				d[tx][ty]=d[p.first][p.second]+1;
				q.push(P(tx,ty));
			}
		}
	}
}
int main(void)
{
	while(scanf("%d%d%d",&H,&W,&N)==3)
	{
		int x1[9],y1[9];
		for(int i=0;i<H;i++)
		scanf("%s",&map[i]);
		int t=0;
		for(int i=0;i<H;i++)
		{
			for(int j=0;j<W;j++)
			{
				if(map[i][j]=='S')
				{
					x0=i;
					y0=j;
				}
				if(map[i][j]-'0'>0&&map[i][j]-'0'<=9)
				{
					xy[t].rx=i;
					xy[t].ry=j;
					xy[t].e=map[i][j]-'0';
					t++;
				}
			}
		}

		sort(xy,xy+N,comp);
		int ans=bfs(x0,y0,xy[0].rx,xy[0].ry);
		for(int i=0;i<N-1;i++)
		ans+=bfs(xy[i].rx,xy[i].ry,xy[i+1].rx,xy[i+1].ry);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 6148
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	ll N; cin >> N; vector<string> s(N); rep(i, N)cin >> s[i];
	ll M; cin >>M; vector<string> t(M); rep(i, M)cin >> t[i];

	map<string, int> p;
	rep(i, N)p[s[i]]++;
	rep(i, M)p[t[i]]--;

	ll mx = 0;
	auto begin = p.begin(), end = p.end();
	for (auto i = begin; i != end; i++) {
		if (i->second > mx) {
			mx = i->second;
		}
	}

	cout << mx << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define SIZE 26 
int main()
{
  //FAST IO       
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll a,b,c,k;
cin>>a>>b>>c>>k;
ll sum=0;
if(k==a)
cout<<k<<"\n";
else if(k<a)
cout<<k<<"\n";
else
{
	if(k-a>0)
	{
		sum+=a;
		ll p=k-(a+b);
		if(p>0)
		sum+=p*(-1);
		cout<<sum<<"\n";
	}
}
return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

template<typename T>
using V = vector<T>;

int main() {
	for (int N; (N = in());) {
		int W = in() + 1, H = in() + 1;
		V<V<int>> v = V<V<int>>(H, V<int>(W)), w = v;
		while (N--) {
			int x = in(), y = in();
			v[y][x] = 1;
		}
		auto all = [](int si, int ei, int sj, int ej, auto f) {
			for (int i = si; i < ei; i++)
				for (int j = sj; j < ej; j++)
					f(i, j);};
		all(1, H, 1, W, [&](int i, int j) {
			  v[i][j] = v[i - 1][j] + v[i][j], w[i][j] = v[i][j] + w[i][j - 1];});
		int S = in(), T = in(), m = 0;
		all(T, H, S, W, [&](int i, int j) {
				m = max(m, w[i][j] - w[i - T][j] - w[i][j - S] + w[i - T][j - S]);});
		outl(m);
	}
}


Measured memory_bytes: 2532
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B,L;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD = 998244353;

int main(){
    cin>>N;
    vec a(N+1,0), b(N,0);
    rep(i,N+1) cin>>a[i];
    rep(i,N) cin>>b[i];
    ll ans = 0, rest = 0;
    rep(i,N+1){
        ll temp = rest;
        if(i != N) temp += b[i];
        ans += min(a[i],temp);
        rest = min(max(0LL,temp-a[i]),b[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}
int main() {
int s=0;
string N;
  cin>>N;
  for(int i=0; i<N.size(); i++){
    s+=ctoi(N.at(i));}
  int ans = stoi(N);
  if(ans%s==0){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}




Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem122b(s))
}

fun problem122b(s: String): Int {
    var max = 0
    var count = 0
    val acgt = arrayOf('A', 'C', 'G', 'T')
    for (i in s.indices) {
        if (acgt.contains(s[i])) {
            count++
            max = Math.max(max, count)
        } else {
            count = 0
        }
    }
    return max
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
typedef long long unsigned int ll;
#define mod 1000000007
// #define mod 13
using namespace std;

int func(string s,string t,int i, int j){
    if(j<0){
        return 0;
    }
    else if(i<0){
        return j+1;
    }
    else if(t[j]==s[i]){
        return(func(s,t,i-1,j-1));
    }
    else{
        return (min(func(s,t,i-1,j-1)+1,func(s,t,i-1,j)));
    }
}
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }
    return(gcd(b%a,a));
}
ll power(ll x,ll y){
    if(y==0){
        return 1;
    }
    ll p=power(x,y/2);
    p=(p*p)%mod;
    return (y&1)? (x*p)%mod : p;
}
ll modInverse(ll a){
    return (power(a,mod-2));
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    scanf("%d",&n);
    ll a[n];
    for (int i=0;i<n;i++){
        scanf("%llu",&a[i]);
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        sum=(sum+a[i])%mod;
    }
    sum=(sum*sum)%mod;
    ll square_sum=0;
    for(int j=0;j<n;j++){
        square_sum=(square_sum+(a[j]*a[j])%mod)%mod;
    }
    ll modinv=modInverse(2);
    // printf("%llu\n",modinv);
    ll ans=(((sum-square_sum+mod)%mod)*modinv)%mod;
    printf("%llu\n",ans);
    return 0;
}

Measured memory_bytes: 5380
using System;
using System.Collections.Generic;


//namespace _5_D

class Program
{
    static void Main(string[] args)
    {
        //????????????
        string a = Console.ReadLine();

        //int?????´???
        int n = int.Parse(a);

        //?????????????????°????????§3??????1?????????????????°?????????????????????
        for (int i = 3; i <= n; i++)
        {
            if (i % 3 == 0)
            {
                //3????????°??????????????????
                Console.Write(" " + i);
            }
            else if (i < n)
            {

                //i?????°????????????????????´???
                string s = i.ToString();

                //??????????????????3?????\??£????????????????????????
                if (s.Contains("3"))
                {
                    //i???3???????????????????????°????????????
                    Console.Write(" " + s);
                }

            }

        }
        Console.WriteLine();
    }
}

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

int main(){
	int n;
	cin >> n;
	vector<int> t(n+1);
	vector<int> x(n+1);
	vector<int> y(n+1);

	for(int i = 1; i <= n; i++) cin >> t.at(i) >> x.at(i) >> y.at(i);

	bool can = true;
	rep(i, n){
		int dt = t.at(i+1) - t.at(i);
		int dist = abs(x.at(i+1)-x.at(i)) + abs(y.at(i+1)-y.at(i));

		if(dt < dist) can = false;
		if(dt%2 != dist%2) can = false;
	}

	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
 
char s[99];
int main(){
	int n;
	scanf("%d",&n);
	puts("0");fflush(0);
	scanf("%s",s);
	if(*s=='V')return 0;
	
	char pre=*s;
	ll l=0,r=n;//(l,r)をにぶたん　preはlの席
	while(1){
		ll m=(l+r)/2;
		printf("%lld\n",m);fflush(0);
		scanf("%s",s);
		if(*s=='V')return 0;
		if(((m-l)%2)^(pre==*s)){
			l=m;
			pre=*s;
		}else{
			r=m;
		}
	}
	return 0;
}

Measured memory_bytes: 760
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  x = list(int(i) for i in input().split())
  ans = 10**15
  for i in range(1,101):
    score = 0
    for j in range(n):
      score += (x[j]-i)**2
    ans = min(ans,score)    
  print(ans)
solve()

Measured memory_bytes: 2940
N = int(input())
W_list = list(map(int, input().split()))

S1 = 0
S2 = sum(W_list)

res = abs(S2 - S1)

for i in range(N):
    S1 += W_list[i]
    S2 -= W_list[i]
    r = abs(S2 - S1)
    if r < res:
        res = r

print(res)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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 string YES = "Yes";
const string NO = "No";
#define judge(f) cout<<(f?YES:NO)<<"\n";

void solve(long long A, long long B, long long C){
    bool f=false;
    if(A==B && B==C){
        f=false;
    }else if(A==B || B==C || C==A){
        f=true;
    }else{
        f=false;
    }
    judge(f);
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int N, M;
  cin >> N >> M;
  vector<string> A(N);
  vector<string> B(M);
  rep(i, N) cin >> A.at(i);
  rep(i, M) cin >> B.at(i);
  for (int j = 0; j <= N - M; j++) {
    string s = A.at(j);
    size_t pos = 0;
  LABEL:
    pos = s.find(B.at(0), pos);
    if (pos != string::npos) {
      for (int i = 1; i < M; i++) {
        if (A.at(j + i).substr(pos, M) != B.at(i)) {
          pos++;
          goto LABEL;
        }
      }
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    s = ns()

    n = len(s)
    if n % 2 == 1:
        print("No")
    else:
        tmp = ""
        for i in range(n//2):
            tmp += "hi"
        if s == tmp:
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
// Author @MAC_19

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define double long double
#define pb push_back
#define pf push_front
#define mkp make_pair
#define ft first
#define sd second
#define sz(x) (ll)x.size()
#define fbo find_by_order
#define ook order_of_key
#define sp " "
#define nl "\n"
#define loop int t; cin>>t; while(t--)

#define vi vector<ll>
#define vpii vector<pii>
#define pii pair<ll,ll>
#define piii pair<ll,pii>
#define mi map<ll,ll>

#define VARGS_(_10, _9, _8, _7, _6, _5, _4, _3, _2, _1, N, ...) N  
#define VARGS(...) VARGS_(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define CONCAT_(a, b) a##b
#define CONCAT(a, b) CONCAT_(a, b)
#define f_4(x,a,b,B) for(int x=a;(B ? x<=b : x<b); ++x) 
#define f_3(x,a,b) f_4(x,a,b,0)
#define f(...) CONCAT(f_, VARGS(__VA_ARGS__))(__VA_ARGS__)
#define rf_4(x,a,b,B) for(int x=a;(B ? x>=b : x>b); --x) 
#define rf_3(x,a,b) rf_4(x,a,b,0)
#define rf(...) CONCAT(rf_, VARGS(__VA_ARGS__))(__VA_ARGS__)
#define elif else if
#define beg(a) a.begin()
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()  
#define allf(i) for(auto it=i.begin(); it!=i.end(); it++)
#define inf LLONG_MAX

using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> PBDS;

const ll LIM=2e5+7;
const ll MAX=1e9+7;
const ll MOD=998244353;

template<typename T> istream& operator >> (istream& i, vector<T>& a){ for(auto &x : a) i>>x; return i; }
template<typename T> ostream& operator << (ostream& o, vector<T>& a){ for(auto &x : a) o<<x<<sp; return o; }

void deb(){ cerr<<nl; }
template <typename T1, typename ... T2>
void deb(T1 p, T2... lp) { cerr<<p<<sp; deb(lp...); }
#define deb(...) cerr<<"["<<#__VA_ARGS__<<"] : "; deb(__VA_ARGS__)

/*ll fact[1000005];
void _fact(ll M)
{
	ll x=1;
	fact[0]=1;
	f(i,1,200005)
	{
		x=(x*i)%M;
		fact[i]=x;
	}
}

ll pow(int x, int y, ll p=MAX) 
{ 
	ll ans = 1; 
	x = x % p;    
	while (y > 0) 
	{ 
		if (y & 1) 
			ans = (ans*x) % p;
		y = y>>1; 
		x = (x*x) % p;   
	} 
	return ans; 
}*/

signed main() 
{
	fast
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	
	
	ll n; cin>>n; vi v(n+1); v[0]=MAX;
	f(i,1,n+1) cin>>v[i];
	vi cost(n+1,-1);
	cost[1]=0,cost[2]=abs(v[2]-v[1]);
	f(i,3,n+1)
	{
	    cost[i]=min(cost[i-1]+abs(v[i]-v[i-1]),cost[i-2]+abs(v[i]-v[i-2]));
	}
	cout<<cost[n]<<nl;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i < n + 1; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

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()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define int long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define br '\n'
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;


int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a,b;
	cin>>a>>b;
	char c;
	cin>>c;
	int d;
	cin>>d;
	b *= 100;
	b += d;
	a = a*b;
	a /= 100;
	cout<<a<<endl;
	return 0;
} 

Measured memory_bytes: 3188
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

int N,K;
vector<long> dequeue;

long ans = 0;

void solve(){
	for(int left=0;left<=K;left++){
		for(int right=0;right<=K-left;right++){
			if(right+left>N) break;
			priority_queue<long,vector<long>,greater<long>> hands;//小さい順に優先度がつく
			long sumval = 0;
			for(int l=0;l<left;l++){
				hands.push(dequeue[l]);
				sumval += dequeue[l];
			}
			for(int r=0;r<right;r++){
				hands.push(dequeue[N-r-1]);
				sumval += dequeue[N-r-1];
			}
			for(int i=0;i<K-(left+right);i++){
				if(!hands.empty()){
					long lowval = hands.top();
					if(lowval>=0) break;
					sumval -= lowval;
					hands.pop();
				}
			}
			ans = max(ans,sumval);
		}
	}
}
 
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++){
		long v;
		cin >> v;
		dequeue.push_back(v);
	}
 
	solve();
 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import bisect

n = int(input())
l = list(map(int, input().split()))
ans = 0
l.sort()

for i in range(n-2):
    for j in range(i+1, n-1):
        c_i = bisect.bisect_left(l, l[i]+l[j])
        if c_i > j:
            ans += c_i - j - 1
        else:
            continue
print(ans)

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

using namespace std;
#define ll long long
#define ld long double

set<int> s;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int a[5];
    for(int i=0;i<5;i++) cin >> a[i];
    int k;
    cin >> k;
    sort(a, a + 5);
    if(abs(a[4] - a[0]) > k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define print(o) for(auto it=(o).begin();it!=(o).end();it++) cout<<*it<<" ";
#define vll vector<ll>
#define pb push_back
#define FOR(n) for(ll i=0;i<=n;i++)
#define FORd(n) for(ll i=n;i>=0;i--)
#define FORrd(a,b) for(ll i=a;i>=b;i--)
#define FORr(a,b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(),(x).end()
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ff first
#define ss second
#define w(t) ll t;cin>>t;while(t--)

int main()
{
    //FIO;
    ll n,ans=0;
    cin>>n;
    vll a(n),p(n);
    FOR(n-1){cin>>a[i];}
    ll m=a[0];
    p[0]=m;
    FORr(1,n-1){
        p[i]=min(a[i],p[i-1]);
    }
    FOR(n-1)
    {
        if(a[i]<=p[i])
            ans++;
    }
    cout<<ans<<'\n';
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


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

map<ll,ll> memo, nmemo;

ll pay(ll n, int a, int b, int c, int d){
    
    //cout << n << endl;
    
    if(n==0)return 0;
    if(n==1)return d;
    
    if(memo.count(n)) return memo.at(n);
    
    ll rtn;
    
    rtn = d*(n-(n/2)*2) + a + pay(n/2,a,b,c,d);
    rtn = min(rtn, d*(((n+1)/2)*2-n) + a + pay((n+1)/2,a,b,c,d));
    rtn = min(rtn, d*(n-(n/3)*3) + b + pay(n/3,a,b,c,d));
    rtn = min(rtn, d*(((n+2)/3)*3-n) + b + pay((n+2)/3,a,b,c,d));
    rtn = min(rtn, d*(n-(n/5)*5) + c + pay(n/5,a,b,c,d));
    rtn = min(rtn, d*(((n+4)/5)*5-n) + c + pay((n+4)/5,a,b,c,d));
    if(rtn/d >=n)
        rtn = d*n;
    
    memo[n] = rtn;
    return rtn;
}

int main(){
    int t;
    cin >> t;
    vector<ll> ans;
    for(int i=0; i<t; i++){
        
        ll n;
        int a,b,c,d;
        cin >>n>>a>>b>>c>>d;
        
        memo.clear();
        ans.push_back(pay(n,a,b,c,d));
    }
    for(int i=0; i<t; i++){
        cout << ans[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 4276
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(c.begin(), c.end(), greater<int>());
    int a = 0;
    int b = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            a += c[i];
        } else {
            b += c[i];
        }
    }
    cout << a - b << endl;
    return 0;
}

Measured memory_bytes: 256
N,L = gets.split.map(&:to_i)

T = []

min_abs = 500
min_i = 0
(1..N).each do |i|
  t = L+i-1
  T << t
  if t.abs < min_abs
    min_abs = t.abs
    min_i = i
  end
end
T.delete_at(min_i-1)
puts T.inject(:+)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int j;
        cin >> j;
    }
    cout << (N + K - 3) / (K - 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0,h,w;
int main() {
    int n,A,B,x,y; cin >>A>>B>> n;
    vector<int> a(1010, 0);
    rep(i, n) {
        cin >> x >> y;
        for (int j = x; j < y; j++)a[j]++;
    }for (int j = A; j < B; j++)a[j]++;
    rep(i, 1005) {
        if (a[i] > 1) {
            cout << 1 << endl;
            return 0;
        }
    }cout << 0 << endl;
}


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

int main()
{
	int m, d;
	int a[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	string dt[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };

	cin >> m >> d;

	while (m > 0 || d > 0) {
		for (int i = 0; i < m - 1; i++)
			d += a[i];

		d += 2;
		d %= 7;	

		cout << dt[d] << endl;

		cin >> m >> d;
	}

	return 0;
}


Measured memory_bytes: 3220
s=input()

ans=0
a=0

i=0
while i<=len(s)-1:
    if s[i]=='A':
        a+=1
        i+=1
    elif i<=len(s)-2 and s[i]+s[i+1]=='BC':
        ans+=a
        i+=2
    else:
        a=0
        i+=1

print(ans)

Measured memory_bytes: 40304
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    reverse(t.begin(), t.end());
    if(s == t)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


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

uint64_t calc(uint64_t x) {
  uint64_t v = 1;
  for (uint64_t i = 1; i < x; i++) {
    v *= 2;
  }
  return v % 1000000007;
}

int main() {
  uint64_t n;
  std::string s;
  std::cin >> n;
  std::cin >> s;

  std::vector<int> alpha(26, 0);
  for (const auto c : s) {
    alpha[c - 'a']++;
  }
  uint64_t i = 1;
  for (const auto n : alpha) {
    i *= n + 1;
    i = i % 1000000007;
  }
  std::cout << i - 1 << std::endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b,c;
	cin >> a >> b >> c;
	int x=0;
	while(1){
		if(x==0){
			if(a.size()==0){
				cout << "A" << endl;
				return 0;
			}else if(a[0]=='a'){
				x=0;
			}else if(a[0]=='b'){
				x=1;
			}else if(a[0]=='c'){
				x=2;
			}
			a.erase(a.begin());
		}else if(x==1){
			if(b.size()==0){
				cout << "B" << endl;
				return 0;
			}else if(b[0]=='a'){
				x=0;
			}else if(b[0]=='b'){
				x=1;
			}else if(b[0]=='c'){
				x=2;
			}
			b.erase(b.begin());
		}else if(x==2){
			if(c.size()==0){
				cout << "C" << endl;
				return 0;
			}else if(c[0]=='a'){
				x=0;
			}else if(c[0]=='b'){
				x=1;
			}else if(c[0]=='c'){
				x=2;
			}
			c.erase(c.begin());
		}
	}
	return 0;
}

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> B;
	
		char a = B[0];
		char b = B[1];
		char c = B[2];
		char d = B[3];
		if ((a == b && c == d&&a!=c) || (a == c && b == d && a != b) || (a == d && b == c && d!=b))
		{
			cout << "Yes" << '\n';
		}
		else
		{
			cout << "No" << '\n';
		}
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
long long int ketawa(long long int b, long long int n)
{
	long long int res = 0;
	while (n > 0)
	{
		res += n % b;
		n /= b;
	}
	return res;
}
int main()
{
	long long int n, s;
	scanf("%lld %lld", &n, &s);
	if (n < s)
	{
		printf("-1\n");
		return 0;
	}
	if (n == s)
	{
		printf("%lld\n", n + 1);
		return 0;
	}
	long long int i;
	for (i = 2; i <= (long long int)sqrt(n); i++)
	{
		if (ketawa(i, n) == s)
		{
			printf("%lld\n", i);
			return 0;
		}
	}
	long long int x, y, b;
	for (i = 1; i <= (long long int)sqrt(n - s); i++)
	{
		if ((n - s) % i == 0)
		{
			b = i + 1;
			x = (n - s) / i;
			y = s - x;
			if (x >= 0 && y >= 0 && b >= 0 && x < b && y < b)
			{
				printf("%lld\n", b);
				return 0;
			}
		}
	}
	for (i = (long long int)(sqrt(n - s)); i > 0; i--)
	{
		if ((n - s) % i == 0)
		{
			x = i;
			y = s - x;
			b = (n - y) / x;
			if (x >= 0 && y >= 0 && b >= 0 && x < b && y < b)
			{
				printf("%lld\n", b);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    char prev = 'Z';
    string s1;
    for (int i = 0; i < s.size(); i++) {
        char cur = s[i];
        if (prev != cur) {
            s1 += cur;
        }
        prev = cur;
    }

    cout << s1.size() - 1 << endl;

    return 0;
}


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

ll ceiling(ll a, ll b) {
    return (a - 1 + b) / b;
}

int main() {
    int k, q;
    cin >> k >> q;
    vector<ll> d(k);
    rep(i, k) cin >> d[i];

    while (q--) {
        ll n, x, m;
        cin >> n >> x >> m;
        ll last = x, eq = 0;
        rep(i, k) {
            ll num = ceiling(n - 1 - i, k);
            last += (d[i] % m) * num;
            if (d[i] % m == 0) eq += num;
        }
        ll ans = (n - 1) - (last / m - x / m) - eq;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3656
# https://atcoder.jp/contests/abc135/tasks/abc135_d

# む ず す ぎ に き あ く ん 笑

# 全探索すると最悪O(10^100000)となり宇宙が崩壊するので桁の独立性について考えてみる。
# まず文字列Sについて式を書き換える。下からi桁目の数字をSi、len(S)=n (桁数)とすると、
# S=S0 + S1*10 + S2*100 + S3*1000 ... となる。これは(mod 13)において
# S≡S0 + S1*10 + S2*9   + S3*12 ... (mod 13)であり、Si=='?' の中でS≡5となる通りの数を求めれば良い。という問題になる。
# 以上により、i番目の項までの余りはi-1番目の項までの余りを足して法を取り直すことで得られることがわかる。
# 具体的には桁DPなるテクニックで、dp[i][j] (n,13) ... i番目の項まで足したときに13で割った余りがjである通りの数 を更新していけば良い。

MOD = 10**9 + 7
S = input()[::-1]
n = len(S)

dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
    mul = pow(10, i, 13)
    if s != '?':
        shift = (int(s) * mul) % 13
        for j in range(13):
            dp[i + 1][(j + shift) % 13] = dp[i][j]
    else:
        for candi in range(10):
            shift = (candi * mul) % 13
            for j in range(13):
                dp[i + 1][(j + shift) % 13] += dp[i][j] % MOD
print(dp[-1][5] % MOD)


Measured memory_bytes: 61404
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, k;

	cin >> a >> b >> k;

	if (b - a+1 >= 2 * k) {
		rep(i, a, a + k) {
			cout << i << endl;
		}
		rep(i, b-k+1, b+1) {
			cout << i << endl;
		}

	}
	else {
		rep(i, a, b + 1) {
			cout << i << endl;
		}
	}
	

}
	

Measured memory_bytes: 256
function main(input)
{
  var s = input[0].split('');
  var res = '';
  for (var i = 1; i <= s.length; i++){
  	res += 'x'
  }
  console.log(res);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))

Measured memory_bytes: 21064
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayLong();
            var a = input[0];
            var b = input[1];
            var c = input[2];
            var ans = true;
            if (c - a - b <= 0) ans = false;
            if (4 * a * b >= (c - a - b) * (c - a - b)) ans = false;

            Console.WriteLine(ans ? "Yes" : "No");
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static string[] ReadArrayString() { return Read().Split(' '); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A[i] = pair<int, int>(a, i + 1);
    }
    sort(A.begin(), A.end());

    for (int i = 0; i < N; i++) {
        cout << A[i].second << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
import math


def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))
    cnt = [0] * (N+1)
    ans = []
    for i in range(N, 0, -1):
        if cnt[i] != A[i]:
            ans.append(i)
            mx = int(math.sqrt(i))
            for j in range(1, mx+1):
                if i % j == 0:
                    cnt[j] ^= 1
                    if j ** 2 != i:
                        cnt[i // j] ^= 1
    print(len(ans))
    if len(ans):
        print(*ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67676
a,b,c=map(int,input().split())
cnt=0
if a==b and b==c and a%2==1:
  print(0)
  exit()
while True:
  if a==b==c:
    print(-1)
    exit()
  elif a%2==1 or b%2==1 or c%2==1:
    break
  _a=a
  _b=b
  _c=c
  a=_b//2+_c//2
  b=_c//2+_a//2
  c=_a//2+_b//2
  cnt+=1
print(cnt)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  string str[11000];

  int cur = 0;
  REP(i, N) {
    REP(j, a[i]) {
      str[cur] = to_string(i + 1);
      cur++;
    }
  }

  string ans[H][W];
  cur = 0;
  REP(i, H) {
    if (i % 2 == 0) {
      REP(j, W) {
        ans[i][j] = str[cur];
        cur++;
      }
    } else {
      for (int j = W - 1; j >= 0; j--) {
        ans[i][j] = str[cur];
        cur++;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 896
use std::cmp::min;

// poisonous-cookies.rs --- Poisonous Cookies
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
    }

    let ans = b + min(a + b + 1, c);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;


int main () {
    int n;
    cin >> n;
    int cnt1=0;
    int cnt2=0;
    int cnt4=0;
    for (int i=0;i<n;i++){
        int m;
        cin >> m;
        if (m%4==0) cnt4+=1;
        else if (m%2==0) cnt2+=1;
        else cnt1+=1;
    }
    int ans;
    if (cnt2>=1) {
        if(cnt1<=cnt4){
            cout << "Yes";
        }
        else cout << "No" ;
    }
    else {
        if (cnt1<=cnt4+1){
            cout << "Yes";
        }
        else cout << "No" ;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int sum = 1;
	rep(i, n - 1) {
		if (s[i] != s[i + 1]) ++sum;
	}
	cout << sum << endl;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  long long int a=0,b=0,c=0,d=0,n=0,count=0,ans=0;
  string s;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  rep(i,8){
    rep(j,n){
      if(i*400<=v[j] && v[j]<(i+1)*400){
        ans++;
        break;
      }
    }
  }
  rep(i,n){
    if(v[i]>=3200){
      count++;
    }
  }
  int mi=0,ma=0;
  ma=ans;
  if(ans==0){
    mi=1;
  }else{
    mi=ans;
  }
  ma+=count;
  if(count>8){
    count=8;
  }
  
  cout<<mi<<' '<<ma<<endl;
  
}
///////////////////////////

Measured memory_bytes: 256