akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	ll n, i, j, w, v = 0;
	cin >> n >> w;
	vll a(n), b(n), dp;
	for(i = 0; i < n; i++)
		cin >> a[i] >> b[i], v += b[i];
	dp.resize(v + 1);
	for(i = 1; i <= v; i++)
		dp[i] = 1e14;
	for(i = 0; i < n; i++)
		for(j = v - b[i]; j >= 0; j--)
			dp[b[i] + j] = min(dp[j] + a[i], dp[b[i] + j]);
	for(i = v; i >= 0; i--)
	{
		if(dp[i] <= w)
			break;
	}
	cout << i << endl;	
	return 0;
}

Measured memory_bytes: 1024
while(s=gets.gsub(/\d+/){|k|?1*k.to_i})!~/#/
n=s.reverse.index ?/
eval's[n*x-n+y-1]=?1;s[n*z-n+w-1]=?b!&%'.tr('x!y&z%w',gets)
$><<s.gsub(/1+/,&:size)
end

Measured memory_bytes: 8752
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;



int main(){
    int n;
    cin >> n;
    int p[100];
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    
    int ans=0;
    for(int i=1; i<n-1; i++){
        if(p[i]>min(p[i-1],p[i+1]) && p[i]<max(p[i-1],p[i+1])){
            ans++;
        }
    }
        
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int i=0,x,m,n=0;
	cin>>x>>m;
	x=x-1;
	int j=m;
	int s=(2*x)-1;
	int h[s];
	for(i=0;i<x;i++){
		j--;
		h[n]=j;
		n++;
		}
	j=m;
	h[n]=j;
	n++;
	for(i=0;i<x;i++){
		j++;
        h[n]=j;
        n++;
	}
	int k=n;
    sort(h,h+k);
	for(i=0;i<n;i++)
        cout<<h[i]<<" " ;
	return 0;
}

Measured memory_bytes: 256
/***
        ***Fresher***
    Md Mahfujur Rahman Khan
    Dept. of CSE
    CSE-28 Batch
    JU-48 Batch
    Jahangirnagar University

***/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque
/***PAIR***/
#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>
/***MAP***/
#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>
#define mci map<char, ll>
/***VECTOR***/
#define vi vector<ll>
#define vs vector<string>
/***ITERASTORS***/
#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator
#define imci map<char, ll> :: iterator
/*** FAST ***/
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/***FUNCTIONS AND MACROS***/
#define F first
#define S second
#define M_P(x, y) make_pair(x, y)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT(x) count(x)
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT(x) getline(cin , x)
#define NL_   "\n"
#define SP_ " "
#define R_0 return 0
#define R_ return

#define ul unsigned long long int
#define ll long long int
/***
//prime fact
#define most_prime_loop 10001
#define most_prime_number 20000010
#define prime_MAX_arr 20000010/2
ll PRIME[prime_MAX_arr];
void seive()
{
    PRIME[0] = 0;
    for(auto &x: PRIME )
        x = 1;
    for(ll i= 3; i <= most_prime_loop; i+=2)
    {
        for(ll j = i*i; j <= most_prime_number; j+=2*i)
            PRIME[j/2] = 0;
    }
}
***/
#define fr(i, n) for( ll i = 0; i < n; i++)
#define fe(x, n) for( ll i = x; i <= n; i++)
#define fa(x,a)    for(auto &x : a)

#define pi acos(-1)

#define SR(x) sqrt(x)
#define IC   (ll)

const ll  inf = 1000000000;
ll i=0, T=0, N=0, tc =0, t= 0;
ll n=0, k=0;

int main()
{
    ll n;
    cin >> n;
    ll arr[n];
    fa(x, arr) cin >> x;
    ll mn = LLONG_MAX;
    for(ll i= 0; i <101; i++)
    {
        ll res =0;
        for(ll j=0; j < n; j++)
        {
            res += (i-arr[j])*(i-arr[j]);
        }
        mn = min(res, mn);
    }
    cout << mn;
    R_0;
}



Measured memory_bytes: 256
#include <stdio.h>

#define Affine(c) (c)-'a'
#define restore(n) (n)+'a'
#define isChar(c) ('a'<=(c) && (c)<='z')
#define F(r,a,b) ( ((a)*(r) + (b))%26 )

int isCatch(int seq[4], int *a, int *b)
{
	int i,j;
	const int that[4] = {Affine('t'), Affine('h'), Affine('a'), Affine('t')};
	const int this[4] = {Affine('t'), Affine('h'), Affine('i'), Affine('s')};
	
	/* 総当り */
	for(i=0; i<26; ++i){
		for(j=0; j<26; ++j){
			if(i%2!=0 && i%13!=0){
				int k;
				int flag = 1;
				for(k=0; k<4; ++k){
					if(seq[k]!=F(that[k], i,j) && seq[k]!=F(this[k], i,j)){
						flag = 0;
					}
				}
				if(flag){
					*a = i;
					*b = j;
					return 1;
				}
			}
		}
	}

	return 0;
}

char toOriginal(int target, int a, int b)
{
	char i;
	for(i='a'; i<='z'; ++i){
		if(F(Affine(i), a, b) == target){
			return i;
		}
	}
	
	return 0;
}

/*
	γに対するF(γ)が必ず１対１になるようなα, βを求める
	→ 文字列が"this" か "that"になるようなα, βを見つければよい。
 */
int main()
{
	int 	i=0, j=0,
		a=0, b=0,
		n=0;
	char str[256];
	int data[256];
	
	
	fscanf(stdin, "%d\n", &n);
	for(i=0; i<n; ++i){
		fgets(str, sizeof(str), stdin);
		for(j=0; j<256 && str[j]!='\0'; ++j){
			data[j] = isChar(str[j]) ? Affine(str[j]) : -1;
		}
		data[j] = EOF;
		
		/* キー(α, β)の取得 */
		{ 
			int len = j;
			int count = 0;
			int seq[4];
			for(j=0; j<len; ++j){
				if(data[j] == -1){
					if(count == 4){
						int k;
						for(k=0; k<4; ++k){
							seq[k] = data[j-4+k];
						}
						if(isCatch(seq, &a, &b)){
							break;
						}
					}
					count = 0;
				}else{
					++count;
				}
			}
		}
		
		/* 復元 */
		{
			char ans[256];
			for(j=0; j<256 && str[j]!='\0'; ++j){
				if(data[j] == -1){
					ans[j] = ' ';
				}else{
					ans[j] = toOriginal(data[j], a, b);
				}
			}
			ans[j-1] = '\0';
			
			fprintf(stdout, "%s\n", ans);
		}
	}

	return 0;
}

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

using LL = long long;
string s;
LL ret;

signed main() {
  // freopen("in", "r", stdin);
  LL a;
  while(cin >> s) {
    ret = 1E18;
    for(int i = 0; i < s.length(); i++) {
      if(i + 3 > s.length()) break;
      a = 0;
      for(int j = 0; j < 3; j++) {
        a *= 10;
        a += s[i+j] - '0';
      }
      ret = min(ret, (LL)abs(a-753));
    }
    printf("%lld\n", ret);
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
t = []
for i in range(n):
    s.append(input())
for j in range(int(input())):
    t.append(input())
s_set = set(s)
ans = 0
for i in s_set:
    if ans <= s.count(i) - t.count(i):
        ans = s.count(i) - t.count(i)
print(ans)

Measured memory_bytes: 3064
s=input()
s1=s2=''

for i in range(len(s)):
    if i%2==0:
        s1+='1'
        s2+='0'
    else:
        s1+='0'
        s2+='1'
c1=c2=0
for i in range(len(s)):
    if s1[i]!=s[i]:
        c1+=1
    if s2[i]!=s[i]:
        c2+=1
print(min(c1,c2))

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

class Program
{
    static void Main(string[] args)
    {
        var a = Console.ReadLine().Split();
        long b = long.Parse(a[0]) * long.Parse(a[1].Replace(".", "")) / 100;
        Console.WriteLine(b);
    }
}

Measured memory_bytes: 27500
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    ll ans = 1e9;

    rep(i,100){
        ll tmp = 0;
        rep(j,n){
            tmp += abs((i - x[j] + 1))*abs((i - x[j] + 1));
        }
        ans = min(ans,tmp);
    }

    dunk(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N;
    cin >> N;
    vector<ll> L(N);
    rep(i, N) cin >> L.at(i);
    ll c = 0;
    rep(i, N){
        rep2(j, i+1, N){
            rep2(k, j+1, N){
                if(L.at(i) == L.at(j) || L.at(j) == L.at(k) || L.at(k) == L.at(i)){
                    continue;
                }
                if(L.at(i)+L.at(j) > L.at(k) && L.at(j)+L.at(k) > L.at(i) && L.at(k)+L.at(i) > L.at(j)){
                    //cout << i << " " << j << " " << k << endl;
                    c++;
                }
            }
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  const int V = 12800;
  int h, w; cin >> h >> w;
  vector<vector<int> > a(h, vector<int>(w)), b(h, vector<int>(w));
  REP(i, h) REP(j, w) cin >> a[i][j];
  REP(i, h) REP(j, w) cin >> b[i][j];
  vector<vector<int> > diff(h, vector<int>(w));
  REP(i, h) REP(j, w) diff[i][j] = abs(a[i][j] - b[i][j]);
  vector<vector<vector<bool> > > dp(h, vector<vector<bool> >(w, vector<bool>(2 * V + 1, false)));
  dp[0][0][V + diff[0][0]] = true;
  dp[0][0][V - diff[0][0]] = true;
  REP(i, h) REP(j, w) {
    if (i == h - 1 && j == w - 1) break;
    if (i + 1 < h) {
      REP(k, 2 * V + 1) if (dp[i][j][k]) {
        if (k + diff[i + 1][j] <= 2 * V) dp[i + 1][j][k + diff[i + 1][j]] = true;
        if (k - diff[i + 1][j] >= 0) dp[i + 1][j][k - diff[i + 1][j]] = true;
      }
    }
    if (j + 1 < w) {
      REP(k, 2 * V + 1) if (dp[i][j][k]) {
        if (k + diff[i][j + 1] <= 2 * V) dp[i][j + 1][k + diff[i][j + 1]] = true;
        if (k - diff[i][j + 1] >= 0) dp[i][j + 1][k - diff[i][j + 1]] = true;
      }
    }
  }
  for (int ans = 0; ; ++ans) {
    if (dp[h - 1][w - 1][V + ans] || dp[h - 1][w - 1][V - ans]) {
      cout << ans << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 23040
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

int main(){
  char a,b,ch;
  bool flg[3] = {1,0,0};

  while(cin>>a>>ch>>b){
    swap(flg[a-'A'],flg[b-'A']);
  }
  cout<<(flg[0] ? 'A' : flg[1] ? 'B' : 'C')<<endl;
}

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

typedef long long ll;
int T;
int main(){
	for(cin>>T;T--;){
		int a,b,c,d;cin>>a>>b>>c>>d;
		int k=(a+b)/(min(a,b)+1);
		int l=0;
		if(k==1){
			if(a>=b)l=b;
			else l=0;
		}else l=((ll)a*k-b+1)/((ll)k*k-1);
		int na=a-l*k,nb=b-l;
		int u=na-(nb-1)/k,v=nb-(na-u)*k;
		for(int i=c;i<=d;++i){
			if(i<=l*(k+1)+u){
				if(i%(k+1))cout<<'A';
				else cout<<'B';
			}else if(i<=l*(k+1)+u+v)cout<<'B';
			else{
				if((i-u-v-1)%(k+1))cout<<'B';
				else cout<<'A';
			}
		}
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 384
fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val komaList = readLine()!!.split(" ").map { it.toInt() }.sorted()
    val kankaku = komaList.indices.filter { it > 0 }.map { komaList[it] - komaList[it-1] }
    var ans = 0
    if(n < m) {
        val subKankaku = kankaku.sortedDescending().drop(n-1)
        ans = subKankaku.sum()
    }
    println(ans)
}


Measured memory_bytes: 56256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using static System.Console;
using static System.Math;
class Simple {
    private int H, W;
    private string[] a;
    void Solve() {
        //input
        H = io.Int;
        W = io.Int;
        a = new string[H];
        for(int i = 0; i < H; ++i)
            a[i] = io.String;
        //cal
        var tmp = new string(Enumerable.Repeat('#', W + 2).ToArray());
        WriteLine(tmp);
        foreach(var VARIABLE in a) {
            Write("#");
            Write(VARIABLE);
            WriteLine("#");
        }
        WriteLine(tmp);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO {
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] {' ', '"', ','};
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
        AutoFlush = false
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if(_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while(st == "")
            st = ReadLine();
        if(st != null)
            _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        else
            st = "";
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}


Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	int a;
	cin >> a;
	int ans = a + (a * a) + (a * a * a);
	cout << ans << endl;


}


Measured memory_bytes: 3576
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		
		Map<String,Integer> map = new HashMap<>();
		
		for(int i = 0; i < n; i++) {
			String s = stdIn.next();
			if(map.containsKey(s)) {
				map.put(s,map.get(s)+1);
			}else {
				map.put(s,1);
			}
		}
		
		boolean flag = true;
		for(String s: map.keySet()) {
			if(s.equals("AC")) {
				flag = false;
				System.out.println("AC x "+map.get(s));
			}
		}
		if(flag) {
			System.out.println("AC x "+0);
		}
		
		flag = true;
		
		for(String s: map.keySet()) {
			if(s.equals("WA")) {
				flag = false;
				System.out.println("WA x "+map.get(s));
			}
		}
		if(flag) {
			System.out.println("WA x "+0);
		}
		
		flag = true;
		
		for(String s: map.keySet()) {
			if(s.equals("TLE")) {
				flag = false;
				System.out.println("TLE x "+map.get(s));
			}
		}
		
		if(flag) {
			System.out.println("TLE x "+0);
		}
		
		flag = true;
		for(String s: map.keySet()) {
			if(s.equals("RE")) {
				flag = false;
				System.out.println("RE x "+map.get(s));
			}
		}
		if(flag) {
			System.out.println("RE x "+0);
		}
		
		
	}

}


Measured memory_bytes: 58284
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using ll =  long long;
const int INF = 0x3f3f3f3f;

const int MAX_N = 1e5+10;
vector<pair<int,int>> g[MAX_N];
int color[MAX_N];
int N;

void dfs(int x, int c)
{
    color[x]=c;
    for(int i=0;i<g[x].size();++i){
        int y = g[x][i].first, w = g[x][i].second;
        if(color[y]==-1){ 
			if(w%2)dfs(y,c^1);
			else dfs(y, c);
		}
    }
}

void solve()
{
	memset(color,-1,sizeof(color));
	int root = -1;
	for(int i=1;i<=N;++i){
	    if(g[i].size()==1){
		    root = i;
		    break;
	    }
	}
	dfs(root, 0);
	for(int i=1;i<=N;++i)cout <<color[i]<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	int u,v,w;
	for(int i=1;i<=N-1;++i){
		cin >> u >> v >> w;
		g[u].push_back(make_pair(v,w));
		g[v].push_back(make_pair(u,w));
	}
	solve();
	return 0;
}

Measured memory_bytes: 10368
import java.util.*;

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()*2;
    int x=sc.nextInt();
    int y=sc.nextInt();
    int min=Integer.MAX_VALUE;
    for(int i=0;i<=100000;i++){
      min=Math.min(i*c+Math.max(x-i,0)*a+Math.max(y-i,0)*b,min);
    }
    System.out.println(min);
  }
}

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

int main(){
  int N; cin >> N;
  int ans= 0;
  int num=N;
  int d=0;
  while(num!=0){
    num/=10;
    d++;
  }
  for(int i =1; i < d+1; i+=2){
    int ten = 1;
    for(int j = 1; j < i+1; j++){
      ten *=10;
    }
    if(i==d&&d%2==1){
      ans += N-ten+1;
    }
    ans += ten -ten/10;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  int N;
  in(N);
  string S;
  in(S);
  int ans=0;
  up(i,1,N-1){
    if(S[i-1]!=S[i])ans++;
  }
  out(ans+1);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

//const ll mod = static_cast<int>(1e9 + 7);



int main() {
	int N, K;
	cin >> N >> K;
	
	Vl A(N);
	ll S = 0;
	for (int i = 0; i < N; ++i) {
		ll tmp;
		cin >> tmp;
		S += tmp;
		A[i] = tmp;
	}

	Vl yakusu;
	for (ll i = 1; i * i <= S; ++i) {
		if (S % i == 0) {
			if (i * i != S) {
				yakusu.push_back(i);
				yakusu.push_back(S / i);
			}
			else {
				yakusu.push_back(i);
			}
		}
	}

	sort(yakusu.begin(), yakusu.end(), greater<ll>());
	Vl R(N);
	Vl cs_R(N + 1);
	ll ans = -1;
	for (const auto& y : yakusu) {
		for (int i = 0; i < N; ++i) {
			R[i] = A[i] % y;
		}
		sort(R.begin(), R.end());
		for (int i = 0; i < N; ++i) {
			cs_R[i + 1] = cs_R[i] + R[i];
		}
		for (int i = 0; i < N + 1; ++i) {
			ll left = cs_R[i];
			ll right = cs_R[N] - cs_R[i];
			if (left == y * (N - i) - right) {
				if (left <= K) {
					ans = y;
					break;
				}
			}
		}
		if (ans != -1) {
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
tst = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        tst[i].append([x,y])
ans = 0
for bit in range(1<<n):
    honest = [0]*n
    check = 1
    for i in range(n):
        if (bit>>i)&1:
            honest[-1-i] = 1
    for i in range(n):
        if not honest[i]:
            continue
        for l in tst[i]:
            if l[1]!=honest[l[0]-1]:
                check = 0
                break
    if check:
        ans = max(ans,sum(honest))
print(ans)

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    if(abs(a-b)<=d && abs(b-c)<=d){
        cout << "Yes" << endl;
    }else if(abs(a-c)<=d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3536
import math

N = int(input())
lst = list(map(int, input().split(' ')))
cur_sum = sum(lst)

ans = 0
for val in lst:
    cur_sum -= val
    ans += cur_sum * val
    ans %= (math.floor(math.pow(10,9)) + 7)

ans %= (math.floor(math.pow(10,9)) + 7)
print(ans)


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    while(1){
        C -= B;
        if(C <= 0){
            cout << "Yes" << endl;
            return;
        }

        A -= D;
        if((A <= 0)){
            cout << "No" << endl;
            return;
        }
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7712
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    k = I()
    a, b = LI()
    flag = False
    if k == 1:
        print(
            'OK'
        )
        exit()
    for i in range(a, b+1):
        if i % k == 0:
            flag = True
    if flag == True:
        print('OK')
    else:
        print('NG')
    return


# Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 67220
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

ll gcd(ll a,ll b){
  if(a<b){
    ll tmp=a; a=b; b=tmp;
  }
  ll r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  ll a,b,ans=1;
  cin>>a>>b;
  ll p=gcd(a,b),q=p;
  map<ll,ll> mp;
  for(ll i=2; i<=sqrt(q); i++){
    if(p%i==0){
      p/=i;
      mp[i]++;
      i-=1;
    }
    if(p==1){
      break;
    }
  }
  if(p!=1){
  mp[p]++;
  }
  for(auto p:mp){
    ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int X, A, B;
  cin >> X >> A >> B;
  cout << (B<=A?"delicious":B<=A+X?"safe":"dangerous") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

int m, n;

int main(void)
{
	while(cin >> n && n)
	{
		int dice[] = { 0, 1, 2, 3, 4, 5, 6 };

		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			string str; cin >> str;

			int t;
			switch(str[0])
			{
			case 'N':
				t = dice[1];
				dice[1] = dice[2]; dice[2] = dice[6]; dice[6] = dice[5];
				dice[5] = t;
				break;
			case 'E':
				t = dice[1];
				dice[1] = dice[4]; dice[4] = dice[6]; dice[6] = dice[3];
				dice[3] = t;
				break;
			case 'W':
				t = dice[1];
				dice[1] = dice[3]; dice[3] = dice[6]; dice[6] = dice[4];
				dice[4] = t;
				break;
			case 'S':
				t = dice[1];
				dice[1] = dice[5]; dice[5] = dice[6]; dice[6] = dice[2];
				dice[2] = t;
				break;

			case 'R':
				t = dice[2];
				dice[2] = dice[3]; dice[3] = dice[5]; dice[5] = dice[4];
				dice[4] = t;
				break;
			case 'L':
				int t = dice[2];
				dice[2] = dice[4]; dice[4] = dice[5]; dice[5] = dice[3];
				dice[3] = t;
				break;
			}
			ans += dice[1];
		}
		cout << ans + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
N = int(input()) - 1
rst = ''
for i in range(1, 16):
    if N >= 26 ** i:
        N -= 26 ** i
        continue
    for j in range(i):
        rst += chr(ord('a') + N % 26)
        N //= 26
    print(rst[::-1])
    break

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

ll sum(ll x){
	return x*(x+1)/2;
}

int main(){
	ll x;
	cin>>x;
	ll count = 0;
	REP(i,1000000000){
		if(sum(i) >= x){
			cout << i << endl;
			return 0;
		}
	}
    return 0;
}



Measured memory_bytes: 256
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int A, B, C;
  cin >> A >> B >> C;

  repp(i, 1, 1000) {
    int M = A * i;
    if (M % B == C) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
}

Measured memory_bytes: 3460
#include<bits/stdc++.h>
#define ll long long
#define vl vector
#define pb push_back
using namespace std;
int main()
{
    ll a,b,i,j,n,k;
    cin>>n;
    long double c,d;
    c=n/1.08;
    //cout<<c<<endl;
    c=ceil(c);
    b=(ll)c;
    //cout<<c<<endl;
    c=c*1.08;
    //cout<<c<<endl;
    c=floor(c);
    //cout<<c<<endl;
    if(n==(ll)c) cout<<b;
    else cout<<":(";
}

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

int main(){
  int N,T,A;
  cin >> N >> T >> A;
  vector<int> v(N);
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  double min = abs(A - T + 0.006 * v.at(0));
  int min_index = 0;
  for(int i = 1; i < N; i++){
    double d = abs(A - T + 0.006 * v.at(i));
    if(d < min){
      min = d;
      min_index = i;
    }
  }
  cout << (min_index + 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits>
using namespace std;
int main(){
  int n,finish=0;
  int inf = 1000000000;
  int min = inf;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  while(1){
    finish = 0;
    for(int i=1;i<n;i++){
      if(a[0] == a[i]){
        finish ++;
      }
    }
    if(finish == n-1){
      break;
    }
    
    min = inf;
    for(int i=0;i<n;i++){
      if(min > a[i]){
        min = a[i];
      }
    }
    
    for(int i=0;i<n;i++){
      if(min < a[i]){
        a[i] = a[i]%min;
        if(a[i] == 0){
          a[i] = min;
        }
      }
    }
  }
  
  cout << a[0] << endl;
  
  return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  int s[m],c[m];
  rep(i,0,m){
    cin >> s[i] >> c[i];
    s[i]--;
  }

  int ans[n];
  rep(i,0,n) ans[i] = -1;

  if(m==0){
    if(n==1) cout << 0 << endl;
    if(n==2) cout << 10 << endl;
    if(n==3) cout << 100 << endl;
    return 0;
  }

  rep(i,0,m){
    if(ans[s[i]]==-1 || ans[s[i]]==c[i]) ans[s[i]] = c[i];
    else{
      cout << -1 << endl;
      return 0;
    }
  }

  int ANS = 0;
  if(ans[0]==0 && n!=1){
    cout << -1 << endl;
    return 0;
  }
  if(ans[0]==-1) ans[0] = 1;
  
  rep(i,1,n) if(ans[i]==-1) ans[i] = 0;

  int ten = 1;
  for(int i=n-1;i>=0;i--){
    ANS += ans[i]*ten;
    ten *= 10;
  }

  cout << ANS << endl;

  return 0;
}

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

void print_vi(vector<int> vi)
{
	rep(i, vi.size())
	{
		printf("%d ", vi[i]);
	}
}

static const int MMAX = 20;
static const int NMAX = 50000;
static const int INFTY = (1 << 29);

signed main()
{
	int n, m;
	int C[21];
	int T[NMAX + 1];

	cin >> n >> m;

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

	for (int i = 0; i <= NMAX; i++) T[i] = INFTY;
	T[0] = 0;
	for (int i=1; i<=m; i++)
	{
		for (int j=0; j+C[i] <= n; j++)
		{
			T[j + C[i]] = min(T[j+C[i]], T[j] + 1);
		}
	}

	cout << T[n] << endl;
}

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

public class Main {
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    String S = fs.next();
    int ans = 0;
    for (int i = 0; i < (S.length() + 1) / 2; i++)
      if (S.charAt(i) != S.charAt(S.length() - 1 - i)) ans++;
    System.out.println(ans);
  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte())
    return buffer[ptr++];
    else
    return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
    ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext())
    throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext())
    throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
      throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
    throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 21332
import sys
def LI():
    return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

k,q = LI()
d = LI()

from itertools import accumulate

for _ in range(q):
    n,x,m = LI()
    e = [0] + [d[i] % m for i in range(k)]
    f = list(accumulate(e))
    g = [0] + [d[i] % m == 0 for i in range(k)]
    h = list(accumulate(g))
    p,r = divmod(n - 1,k)
    print(n - 1 - p*h[k] - h[r] - (p*f[k] + f[r] + x % m) // m)


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

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

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


Measured memory_bytes: 256
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n>>m;
    //vector<vector<ll>> v(tate,vector<ll> (yoko));
    vector<ll> v(n);
    rep(i,n)   cin >> v[i];
    sort(v.begin(),v.end(),greater<ll>());
    vector<ll> w(n-1);
    rep(i,n-1){
        w[i]=v[i]-v[i+1];
    }

    vector<ll> x(n-m+1);
    rep(i,n-m+1){
        x[i]=v[i]-v[i+m-1];

    }
    sort(x.begin(),x.end());
    cout<<x[0]<<endl;

    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
const LL N=3005;
LL n,m;
LL JC[N],inv[N];
LL s[N][N];
LL pow (LL x,LL y,LL MOD)
{
	if (y==0) return 1;
	if (y==1) return x;
	LL lalal=pow(x,y>>1,MOD);
	lalal=lalal*lalal%MOD;
	if (y&1) lalal=lalal*x%MOD;
	return lalal;
}
LL C (LL x,LL y)
{
	if (x<y) return 0;
	return JC[x]*inv[y]%m*inv[x-y]%m;
}
int main()
{
	//printf("%lld\n",123456791LL*123456791LL);
	scanf("%lld%lld",&n,&m);
	JC[0]=1;for (LL u=1;u<=n;u++) JC[u]=JC[u-1]*u%m;
	inv[n]=pow(JC[n],m-2,m);for (LL u=n-1;u>=1;u--) inv[u]=inv[u+1]*(u+1)%m;inv[0]=1;
	s[0][0]=1;
	for (LL u=1;u<=n+1;u++)
		for (LL i=1;i<=u;i++)
			s[u][i]=(s[u-1][i-1]+s[u-1][i]*i%m)%m;
	LL ans=0;
//	printf("%lld\n",JC[n]);
	for (LL u=0;u<=n;u++)//有多少个不和法的 
	{
		LL w=0;
		for (LL i=0;i<=u;i++)	w=(w+pow(pow(2,n-u,m),i,m)*s[u+1][i+1]%m)%m;
		//	printf("%lld %lld\n",u,w);
		w=w*C(n,u)%m*pow(2,pow(2,n-u,m-1),m)%m;
		if (u&1) ans=ans-w;
		else ans=ans+w;
	/*	printf("%lld %lld\n",u,w);
		system("pause");*/
		ans=(ans%m+m)%m;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 69120
class Graph constructor(n: Int) {
    private val graph = Array(n) { mutableListOf<Int>() }
    private val dp = IntArray(100000) { -1 }

    fun add(x: Int, y: Int) {
        graph[x].add(y)
    }

    fun rec(v: Int): Int {
        if (dp[v] != -1) return dp[v]

        var res = 0
        graph[v].forEach {
            res = Math.max(res, rec(it) + 1)
        }
        dp[v] = res
        return res
    }

}

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val graph = Graph(n)
    repeat(m) {
        val (x, y) = readLine()!!.split(' ').map { it.toInt() }
        graph.add(x - 1, y - 1)
    }

    var res = 0
    (0 until n).forEach {
        res = Math.max(res, graph.rec(it))
    }
    println(res)
}


Measured memory_bytes: 69912
#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); ++i)
using namespace std;
typedef long long ll;

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

    int n, q;
    string s;
    cin >> n >> q >> s;

    vector<int> cnt(n);
    cnt[0] = 0;
    rep(i, n-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cnt[i+1] = cnt[i] + 1;
        }
        else cnt[i+1] = cnt[i];
    }
    // rep(i, n) cout << cnt[i] << " ";
    // cout << endl;

    rep(_, q){
        int l, r;
        cin >> l >> r;
        --l; --r;
        
        cout << cnt[r] - cnt[l] << endl; 
    }
}

Measured memory_bytes: 1488
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin >> a >> b;
  a--,b--;
  cout << a*b << endl;
}

Measured memory_bytes: 256
import sys
 
class Dice(object):
    def __init__(self, dice):
        self.__dice = dice
 
    def roll_north(self):
        self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
                       self.__dice[3], self.__dice[0], self.__dice[4])
 
    def roll_south(self):
        self.__dice = (self.__dice[4], self.__dice[0], self.__dice[2],
                       self.__dice[3], self.__dice[5], self.__dice[1])
 
    def roll_west(self):
        self.__dice = (self.__dice[2], self.__dice[1], self.__dice[5],
                       self.__dice[0], self.__dice[4], self.__dice[3])
 
    def roll_east(self):
        self.__dice = (self.__dice[3], self.__dice[1], self.__dice[0],
                       self.__dice[5], self.__dice[4], self.__dice[2])
 
    def number(self, face_id):
        return self.__dice[face_id - 1]
 
 
dice = Dice([int(i) for i in sys.stdin.readline().split()])
command = sys.stdin.readline().strip()
for c in command:
    if c == "N":
        dice.roll_north()
    elif c == "S":
        dice.roll_south()
    elif c == "W":
        dice.roll_west()
    elif c == "E":
        dice.roll_east()
print(dice.number(1))

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

bitset<2000009> dp;

int main()
{
    int n, i, j, a[2009], sum = 0;

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

    dp[0] = 1;


    for(i = 0; i < n; i++)
    {
        dp |= (dp << a[i]);
//        cout << dp << endl;
    }

    for(i = sum/2; i >= 0; i--)
    {
        if(dp[i])
        {
            printf("%d", sum - i);
            return 0;
        }
    }
}


Measured memory_bytes: 4528
/* B */

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main(){
	int dish[5];
	int dishmod[5];
	int x = 0;
	int k;

	for (int i = 0; i < 5; ++i)
	{
		cin >> dish[i];
		dishmod[i] = dish[i] % 10;
		if(dishmod[i]==0) dishmod[i] += 10;
		dish[i] = ( dish[i] + 9 ) / 10;
		x += dish[i];
	}

	x = (x - 1) * 10;

	sort(dishmod, dishmod+5);

	cout << x + dishmod[0] << endl; 

}

Measured memory_bytes: 384
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <vector>

using namespace std;

typedef unsigned long long ull;

int main(void)
{
    size_t n;
    cin >> n;

    vector<ull> a;
    for (size_t i = 0; i < n; ++i) {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }

    sort(a.begin(), a.end());

    ull streak = 0UL;
    ull sum = 0UL;
    for (size_t i = 0; i < n; ++i) {
        sum += a[i];
        ull next = a[i+1];
        if (next <= 2*sum)
            { ++streak; }
        else 
            { streak = 0UL; }
    }

    cout << streak << endl;
    return 0;
}


Measured memory_bytes: 1400