akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
 
const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;
 
const ll MOD = 1000000007;
const int MAXN = 500005;
 
int cnt[MAXN];
int num[MAXN];
int distinct;
int answers[MAXN]; 

//Mo's algorithm from cp-algorithms.com
 
void remove(int idx) {
	if (cnt[num[idx]]==1) {
		distinct--;
	}
	cnt[num[idx]]--;
}
void add(int idx) {
	if (!cnt[num[idx]]) {
		distinct++;
	}
	cnt[num[idx]]++;
}
int get_answer() {
	return distinct;
}
 
const int block_size = 708;
 
struct Query {
	int l, r, idx;
	bool operator<(Query &other) const
	{
		return make_pair(l / block_size, r) <
			   make_pair(other.l / block_size, other.r);
	}
};
 
void mo_s_algorithm(vector<Query> &queries) {
	sort(queries.begin(), queries.end());
 
 
	int cur_l = 0;
	int cur_r = -1;
	for (Query q : queries) {
		while (cur_l > q.l) {
			cur_l--;
			add(cur_l);
		}
		while (cur_r < q.r) {
			cur_r++;
			add(cur_r);
		}
		while (cur_l < q.l) {
			remove(cur_l);
			cur_l++;
		}
		while (cur_r > q.r) {
			remove(cur_r);
			cur_r--;
		}
		answers[q.idx] = get_answer();
	}
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, q;
	cin >> n >> q;
	FOR(i,0,n){
		cin >> num[i];
	}
	vector<Query> queries;
	FOR(i,0,q){
		Query qq;
		cin >> qq.l >> qq.r;
		qq.l--;
		qq.r--;
		qq.idx=i;
		queries.pb(qq);
	}
	mo_s_algorithm(queries);
	FOR(i,0,q){
		cout << answers[i] << "\n";
	}
	
 
}


Measured memory_bytes: 15544
#include <iostream>

int main(){

	int a,b;

	std::cin >> a >> b;

	if (a*b%2 == 1) {
		std::cout << "Odd"
			<< std::endl;
	}
	else {
		std::cout << "Even"
			<< std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1;i < sqrt(n);i++){
    if((n-i)%i == 0 && (n-i)/i > i) ans += (n-i)/i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<bool> ac(n,false);
    int c = 0;
    vector<int> p(n);
    rep(i,m) {
        int a; string s;
        cin>>a>>s; --a;
        if (!ac[a]) {
            if (s=="AC") {
                ac[a] = true;
                c++;
            }
            else {
                p[a]++;
            }
        }
    }


    int ps = 0;
    rep(i,n) if (ac[i]) ps+=p[i];
    cout << c << ' ' << ps << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a[111111],b[55555],c[55555],f=0,s=0;
	int bs[111111]={0},cs[111111]={0},n1=50001,sum=0,kb,sum1=0;
	int tmp,maxn=0; 
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i%2==0)
		{
			b[f]=a[i];
			f++;
		}
		if(i%2==1)
		{
			c[s]=a[i];
			s++;
		}
	}
	for(int i=0;i<f;i++)
		bs[b[i]]++;
	for(int i=0;i<s;i++)
		cs[c[i]]++;
	for(int i=1;i<100001;i++)
		if(bs[i]>maxn)
		{
			maxn=bs[i];
			tmp=i;
		}
	sum=f-maxn;
	maxn=0;
	for(int i=1;i<100001;i++)
		if(i!=tmp)
			maxn=max(maxn,cs[i]);
	sum+=s-maxn;
	for(int i=1;i<100001;i++)
		if(cs[i]>maxn)
		{
			maxn=cs[i];
			tmp=i;
		}
	sum1=s-maxn;
	maxn=0;
	for(int i=1;i<100001;i++)
		if(i!=tmp)
			maxn=max(maxn,bs[i]);
	sum1+=f-maxn;
	cout<<min(sum,sum1)<<endl;
	return 0;
}

Measured memory_bytes: 1920
while True:
    n = int(input())
    if n == 0:
        break
    flag = False
    dic = {}
    for j in range(n):
        i,p,q = map(int, input().split())
        if i not in dic:
            dic[i] = [p*q, 0]
        else:
            dic[i][0] += p*q
        
        if dic[i][0] >= 10**6 and dic[i][1] == 0:
            print(i)
            dic[i][1] = 1
            flag = True
    if flag == False:
        print("NA")

Measured memory_bytes: 7844
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>

using namespace std;

struct Node {
	int parent;
	int left;
	int right;
};

Node T[25];

void pre(int node) {
	if (node == -1) {
		;
	}
	else {
		printf(" %d", node);
		pre(T[node].left);
		pre(T[node].right);
	}
}

void printPre(int root) {
	printf("Preorder\n");
	pre(root);
	printf("\n");
}

void in(int node) {
	if (node == -1) {
		;
	}
	else {
		in(T[node].left);
		printf(" %d", node);
		in(T[node].right);
	}
}

void printIn(int root) {
	printf("Inorder\n");
	in(root);
	printf("\n");
}

void post(int node) {
	if (node == -1) {
		;
	}
	else {
		post(T[node].left);
		post(T[node].right);
		printf(" %d", node);
	}
}

void printPost(int root) {
	printf("Postorder\n");
	post(root);
	printf("\n");
}


int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		T[i].parent = -1;
	}

	for (int i = 0; i < n; ++i) {
		int id;
		scanf("%d", &id);
		int left, right;
		scanf("%d%d", &left, &right);
		T[id].left = left;
		T[id].right = right;
		if (left != -1) {
			T[left].parent = id;
		}
		if (right != -1) {
			T[right].parent = id;
		}
	}

	int root;
	for (int i = 0; i < n; ++i) {
		if (T[i].parent == -1) {
			root = i;
		}
	}

	printPre(root);
	printIn(root);
	printPost(root);

	return 0;
}

Measured memory_bytes: 1048
x = int(input())
a = [1,4,8,16,32,64,128,256,512,9,27,81,243,729,
     25,125,625,36,216,49,343,100,1000,121,144,
     169,196,225,289,324,361,400,441,484,529,576,
     676,784,841,900,961]
b =[]
for num in a:
  if x >= num:
    b.append(num)
print(max(b))

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

#define ld			long double
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define sd(t) 		scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii 		cout << "hii" << endl
#define okay 		cout << "okay" << endl
#define hey 		cout << "hey" << endl

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int inf = 1e18;
const int mod = 1e9+7;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
} 

clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int N = 1e5+5;
int arr[N];

void solve()
{
    int n, k;
    cin >> n >> k;
    vi arr(n+1, 0);
    int cnt = 0;
    rep(i, 0, k){
        int d;
        cin >> d;
        vi v(d);
        rep(i, 0, d){
            cin >> v[i];
            arr[v[i]] = 1;
        }
    }

    rep(i, 1, n+1){
        if(arr[i]==0) cnt++;
    }

    cout << cnt << endl;
}			 	      	   	        

int32_t main(){
	fast();
    int t = 1;
    // cin>> t;
    for(int i=1; i<=t; i++){
    	// cout << "Case #" << i << ": ";
    	solve();
    }
    starboy1299();
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  string s1, s2;
  for (int n = a; n < b+1; n++) {
    s1 = to_string(n);
    s2 = s1;
    reverse(s1.begin(), s1.end());
    if (s1 == s2) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int i,ans=0,cnt=0;
	std::string s;
	std::cin >> s;
	s.push_back('@');
	for(i=0; i<4; ++i){
		if(s[i]=='R'){
			++cnt;
		}else{
			ans = std::max(ans,cnt);
			cnt = 0;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


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

namespace AOJ.Volume1
{
    public class LeagueMatchScoreSheet
    {
        public static int Main()
        {
            bool is_first = true;
            while (true)
            {
                int team_num = int.Parse(Console.ReadLine());
                if (team_num == 0) { break; }
                else if (!is_first) { Console.WriteLine(); }

                var result = new Dictionary<int, int>();
                var team_name = new string[team_num];
                for (int t = 0; t < team_num; t++)
                {
                    var input = Console.ReadLine().Split(' ');
                    team_name[t] = input[0];
                    int point = (int.Parse(input[1]) * 3) + int.Parse(input[3]);
                    result.Add(t, point);
                }

                foreach (var t in result.OrderByDescending(x => x.Value).ThenBy(y => y.Key))
                {
                    string output = string.Format("{0},{1}", team_name[t.Key], t.Value);
                    Console.WriteLine(output);
                }
                is_first = false;
            }
            return 0;
        }
    }
}

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

int main() {
vector<int> ant(5);
int k;
for (int i = 0;i < 5;i++) cin >> ant.at(i);

cin >> k;
bool ans = true;
for (int i = 0;i < 4;i++) {
    for (int j = 0;j < 5;j++) {
    if (abs(ant.at(i)-ant.at(j)) > k) ans = false;
}
}

if (ans == true) cout << "Yay!" << endl;
else cout << ":(" << endl;


return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n, m, ans = 0;
    long long temp = pow(10, 9) + 7;
    cin >> n >> m;
    if(n == m){
        ans = 1;
        for(int i=n;i>0;i--){
            ans = ans * i % temp;
        }
        ans = ans * ans % temp;
        ans = ans * 2 % temp;
    }else if(abs(n-m)==1){
        ans = 1;
        int Max = max(n, m);
        for(int i=Max-1;i>0;i--){
            ans = ans * i % temp;
        }
        ans = (ans*Max)%temp * ans % temp;
    }
    
    cout << ans << endl;
    return 0;
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

int main() {
  int x; cin >> x;
  if(x >= 1200) cout << "ARC" << endl;
  else cout << "ABC" << endl;

  return 0;
}


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

int main() {
  int N,M,X,Y; 
  cin>>N>>M>>X>>Y;
  vector<int> x(N);
  vector<int> y(M);
  rep(i,N) cin>>x[i];
  rep(i,M) cin>>y[i];
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  
  for(int i=X+1;i<=Y;i++){
    if(x[N-1]<i&&i<=y[0]){
      puts("No War");
      return 0;
    }
    else if(i==Y) puts("War");
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define N 100010

inline int read(){
	int x=0,sign=1;char c=getchar();
	for (;c<'0'||c>'9';){if(c=='-')sign=-1;c=getchar();}
	for (;c>='0'&&c<='9';)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*sign;
}

int n,m,Max,Min,en,vis[N];
struct edge{
	int e,d;
	edge *next;
}*v[N],ed[N<<2];

inline void add_edge(int s,int e,int d){
	ed[++en].next = v[s];
	v[s] = ed + en;
	v[s] -> e = e;
	v[s] -> d = d;
}

int dis[N];

inline int dfs(int u){
	Max = max(Max,dis[u]);
	Min = min(Min,dis[u]);
	vis[u] = 1;
	int mark = 1;
	for (edge *e=v[u];e;e=e->next)
		if (!vis[e->e]) {dis[e->e]=dis[u]+e->d;mark&=dfs(e->e);}
		else mark&=(dis[e->e]==dis[u]+e->d);
	return mark;
}

int main()
{
	n = read();
	m = read();
	for (int i=1;i<=m;i++){
		int x,y,z;
		x = read(); y = read(); z = read();
		add_edge(x,y,z);
		add_edge(y,x,-z);
	}
	Max = 0; Min = 0;
	for (int i=1;i<=n;i++){
		if (!vis[i]){
			dis[i] = 0;
			if (!dfs(i)){
				printf("No");
				return 0;
			}
		}
		if (Max-Min>1e9){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		String B;
		long n = Long.MAX_VALUE;

		for(int i = 1; i <= Math.sqrt(N); i++) {
			if(N % i == 0) {
				B = String.valueOf(N / i);
				n = B.length();
			}
		}
		System.out.println(n);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;


// const long long INF = 1LL << 30;
int choice[1000000];
int dp[1000000][3];

int in[1000000][3];

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

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

	// initialization
	for(int i=0; i<1000000; i++) choice[i] = -1;

	// A: 0 B: 1 C: 2
	dp[0][0] = in[0][0];
	dp[0][1] = in[0][1];
	dp[0][2] = in[0][2];

	for(int i=1; i<N; i++) {
		for(int j=0; j<3; j++) { // from 
			for(int k=0; k<3; k++) { // dest
				if(j == k) continue;

				int cost = dp[i-1][j] + in[i][k];
				if(dp[i][k] < cost) dp[i][k] = cost;
			}
		}
	}

	cout << max({dp[N-1][0],dp[N-1][1],dp[N-1][2]});

}


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

int main()
{
	int n;
	cin >> n;
	auto cnt = vector<vector<int>>(n, vector<int>('z' + 1));
	for(auto i = 0; i < n; ++i){
		string s;
		cin >> s;
		for(auto c : s) ++cnt[i][c];
	}
	auto com = vector<int>('z' + 1, 50);
	for(auto d : cnt){
		for(auto i = (int)'a'; i <= 'z'; ++i){
			com[i] = min(com[i], d[i]);
		}
	}
	for(auto i = 'a'; i <= 'z'; ++i){
		for(auto j = 0; j < com[i]; ++j){
			cout << i;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N, T;
    gc(N);
    gc(T);

    int bk, t;
    gc(t);
    bk = t;

    long long int overlap = 0LL;

    for (int i = 1; i < N; i++)
    {
        gc(t);

        int dif = T - (t - bk);

        overlap = dif < 0 ? overlap : overlap + dif;

        bk = t;
    }

    printf("%lld\n", (long long int)N * T - overlap);
    return 0;
}


Measured memory_bytes: 128
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    S = list(set(A))
    ND = [True]*(10**6 + 1)
    for e in S:
        m = e*2
        while m <= 10**6:
            ND[m] = False
            m += e
    ans = 0
    for a in A:
        if C[a] == 1 and ND[a]:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 45308
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int K;
    string S;
    cin >> K >> S;
    int N = S.size();
    if(N <= K) cout << S << endl;
    else cout << S.substr(0,K) + "..." << endl;
}

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

int l,n,now;
vector<pair<pair<int,int>,int> > res;

int main(){
	cin>>l;
	--l;
	n=1;
	while((1<<n)-1<=l)
		++n;
	for(int i=1;i<n;++i)
		res.push_back(make_pair(make_pair(i,i+1),0)),res.push_back(make_pair(make_pair(i,i+1),1<<i-1));
	now=(1<<n-1)-1;
	while(now<l){
		int x=0;
		while(now+(1<<x+1)<=l)
			++x;
		res.push_back(make_pair(make_pair(x+1,n),now+1));
		now+=1<<x;
	}
	cout<<n<<' '<<res.size()<<endl;
	for(int i=0;i<res.size();++i)
		cout<<res[i].first.first<<' '<<res[i].first.second<<' '<<res[i].second<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
const int maxn=3e3+5,mod=1e9+7;
int n,m;
int a[maxn],R[maxn],sum[maxn],f[maxn][maxn];
char str[maxn];
void upd(int &x,int y){
	x=(x+y)%mod;
}
int main(){
	read(n);read(m);
	scanf("%s",str+1);
	rep(i,1,n)a[i]=str[i]-'0',R[i]=i,sum[i]=sum[i-1]+a[i];
	rep(i,1,m){
		int x,y;read(x);read(y);
		R[x]=max(R[x],y);
	}
	rep(i,1,n)R[i]=max(R[i-1],R[i]);
	int pnt=0;
	f[0][0]=1;
	rep2(i,0,n)rep(j,0,n)if(f[i][j]){
		if(R[i]-i<j)continue;
		int dlt=sum[R[i+1]]-sum[R[i]];
		if(j+dlt-1>=0)upd(f[i+1][j+dlt-1],f[i][j]);
		upd(f[i+1][j+dlt],f[i][j]);
	}
	printf("%d\n",f[n][0]);
	return 0;
}

Measured memory_bytes: 33920
#include <iostream>
    #include <fstream>
    using namespace std;
    ifstream f("date.in");
    int n,val[500005],aint[2000005],poz,start,finish,sol,k;
    int d=(1<<26)-1,t;
    string s;
    int nr(int x)
    {
        int nm=0;
        do
        {
            x &= x-1;
            nm++;
        }
        while (x);
        return nm;
    }
    void build(int nod,int st,int dr)
    {
        //cout<<nod<<" "<<st<<" "<<dr<<"\n";
        if(st==dr)
        {
            aint[nod]=(aint[nod] | (1<<val[st]));
     
        }
        else
        {
            int mij=(st+dr)/2;
            build(2*nod,st,mij);
            build(2*nod+1,mij+1,dr);
            aint[nod]=(aint[2*nod] | aint[2*nod+1]);
        }
    }
    void update(int nod,int st,int dr)
    {
        if(st==dr)
        {
            aint[nod]=(aint[nod] & (d-(1<<val[st])));
            val[st]=k;
            aint[nod]=(aint[nod] | (1<<val[st]));
            return;
        }
        int mij=(st+dr)/2;
        if(poz<=mij)
        {
            update(2*nod,st,mij);
        }
        else
        {
            update(2*nod+1,mij+1,dr);
        }
        aint[nod]=(aint[2*nod] | aint[2*nod+1]);
    }
     
    void query(int nod,int st,int dr)
    {
        if(start<=st && dr<=finish)
        {
            sol=(sol | aint[nod]);
            return;
        }
        int mij=(st+dr)/2;
        if(start<=mij)
        {
            query(2*nod,st,mij);
        }
        if(mij<finish)
        {
            query(2*nod+1,mij+1,dr);
        }
    }
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int i,x,y,op;
        char c;
        cin>>n;
        cin>>s;
        for(i=0;i<n;i++)
        {
            val[i+1]=s[i]-'a';
        }
        build(1,1,n);
        cin>>t;
        while(t--)
        {
            cin>>op;
            if(op==1)
            {
                cin>>poz;
                cin>>c;
                k=c-'a';
                update(1,1,n);
            }
            else
            {
                cin>>start>>finish;
                sol=0;
                query(1,1,n);
                cout<<nr(sol)<<"\n";
            }
        }
        return 0;
    }

Measured memory_bytes: 10780
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;


struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i, N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	int W, a, b; cin >> W >> a >> b;

	if (a < b) {
		cout << max(0LL, b - a - W)<<endl;
	}
	else {
		cout << max(0LL, a - b - W) << endl;
	}



	//cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<climits>
using namespace std;
// 完成版。

int tree[(1 << 18)];

void Update(int s, int t, int m, int left = 0, int right = (1 << 17), int key = 0){
    if(t < left || right <= s) return;
    if(s <= left && right - 1 <= t){ tree[key] = max(tree[key], m); return; }
    Update(s, t, m, left, (left + right) / 2, 2 * key + 1);
    Update(s, t, m, (left + right) / 2, right, 2 * key + 2);
}

int Find(int i){
    i += (1 << 17) - 1;
    int m = tree[i];
    while(i){
        i = (i - 1) / 2;
        m = max(tree[i], m);
    };
    return m;
}

int main(){
    int i;
    for(i = 0; i < (1 << 18); i++) tree[i] = 0;
    int n, q;
    int x[100000];
    for(i = 0; i < 100000; i++) x[i] = INT_MAX;
    int s, t, value, m;
    m = 1;
    
    cin >> n >> q;
    int query;
    while(q){
        q--;
        cin >> query;
        if(query){
            cin >> i;
            cout << x[Find(i)] << endl;
        }else{
            cin >> s >> t >> value;
            x[m] = value;
            Update(s, t, m);
            m++;
        }
    };
    return 0;
}


Measured memory_bytes: 4520
#include<stdio.h>

int main(void)
{
  long int N,i,j,X,T;
  long int D[100001],A[100000];
  scanf("%ld\n",&N);
  for(i=1;i<=N;i++){
    scanf("%ld",&D[i]);
  }
  
  long int M=D[1];
  for(i=1;i<=N;i++){
    if(D[i]>M){
      M=D[i];
    }
  }
  
  for(j=0;j<=M;j++){
    A[j]=0;
  }
  T=1;
  for(i=1;i<=N;i++){
    X=D[i];
    A[X]++;
    if(i!=1&&D[i]==0){
      T=0;
    }
  }
  
  long int k,l;
  long int S=1;
  
  for(k=0;k<=M-1;k++){
    for(l=1;l<=A[k+1];l++){
      S=S*A[k];
      S=S%998244353;
    }
  }
  
  S=S*T;
  
  printf("%ld",S);
  
  
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll s[800001], mod = 998244353, t[200001], o[10][200001], la[800001];
void upd(ll id, ll l, ll r, ll v){
	s[id] = o[v][r - l + 1];
	la[id] = v;
}
void prop(ll id, ll l, ll r){
	if (la[id] != 0){
		ll mid = (l + r) / 2;
		upd(id * 2, l, mid, la[id]);
		upd(id * 2 + 1, mid + 1, r, la[id]);
		la[id] = 0;
	}
}
void build(ll id, ll l, ll r){
	if (l == r){
		s[id] = 1;
		return;
	}
	ll mid = (l + r) / 2;
	build(id * 2, l, mid);
	build(id * 2 + 1, mid + 1, r);
	(s[id] = s[id * 2] * t[r - mid] % mod + s[id * 2 + 1]) %= mod;
}
void update(ll id, ll l, ll r, ll L, ll R, ll v){
	if (r < L || R < l) return;
	if (L <= l && r <= R){
		upd(id, l, r, v);
		return;
	}
	prop(id, l, r);
	ll mid = (l + r) / 2;
	update(id * 2, l, mid, L, R, v);
	update(id * 2 + 1, mid + 1, r, L, R, v);
	(s[id] = s[id * 2] * t[r - mid] % mod + s[id * 2 + 1]) %= mod;
}
int main(){
	t[0] = 1;
	for (ll i = 1; i < 200001; i++) t[i] = t[i - 1] * 10 % mod;
	for (ll i = 0; i < 10; i++){
		for (ll j = 1; j < 200001; j++) (o[i][j] = o[i][j - 1] * 10 + i) %= mod;
	}
	ll n, q, x, y, z;
	scanf("%lld %lld", &n, &q);
	build(1, 0, n - 1);
	for (int i = 0; i < q; i++){
		scanf("%lld %lld %lld", &x, &y, &z);
		update(1, 0, n - 1, x - 1, y - 1, z);
		printf("%lld\n", s[1]);
	}
}

Measured memory_bytes: 29116
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        N: usize, M: usize,
    }
    let ans;
    if 2 * N <= M {
        ans = N + (M - 2 * N) / 4;
    } else {
        ans = M / 2;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
import static java.lang.System.*;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Scanner;

class Main {
    public static Scanner sc = new Scanner(in);
    public static Random rand=new Random();

    public void run() {
    	char[] vals=new char[52];

    	for(int i=0;i<26;i++)vals[i]=(char) ('A'+i);
    	for(int i=0;i<26;i++)vals[i+26]=(char) ('a'+i);


    	while(true){
    		int n=sc.nextInt();
    		if(n==0)return;

    		int[] key=new int[n];

    		for(int i=0;i<n;i++)
    			key[i]=sc.nextInt();

    		char[] str=sc.next().toCharArray();


    		int k=0;

    		for(int i=0;i<str.length;i++){
    			int c=Arrays.binarySearch(vals,str[i]);
    			str[i]=vals[(c-key[k]+52)%52];
    			k=(k+1)%n;
    		}

    		ln(new String(str));

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


	//output lib
	static final String br = System.getProperty("line.separator");
	static final String[] asep = new String[] { "", " ", br, br + br };

	static String str(Boolean o) {
		return o ? "YES" : "NO";
	}

	//	static String str(Double o){
	//		return String.format("%.8f",o);
	//	}
	static <K, V> String str(Map<K, V> map) {
		StringBuilder sb = new StringBuilder();
		boolean isFirst = true;
		for (Entry<K, V> set : map.entrySet()) {
			if (!isFirst)
				sb.append(br);
			sb.append(str(set.getKey())).append(":").append(str(set.getValue()));
			isFirst = false;
		}
		return sb.toString();
	}

	static <E> String str(Collection<E> list) {
		StringBuilder sb = new StringBuilder();
		boolean isFirst = true;
		for (E e : list) {
			if (!isFirst)
				sb.append(" ");
			sb.append(str(e));
			isFirst = false;
		}
		return sb.toString();
	}

	static String str(Object o) {
		int depth = _getArrayDepth(o);
		if (depth > 0)
			return _strArray(o, depth);
		Class<?> c = o.getClass();
		if (c.equals(Boolean.class))
			return str((Boolean) o);
		//if(c.equals(Double.class))return str((Double)o);

		return o.toString();
	}

	static int _getArrayDepth(Object o) {
		if (!o.getClass().isArray() || Array.getLength(o) == 0)
			return 0;
		return 1 + _getArrayDepth(Array.get(o, 0));
	}

	static String _strArray(Object o, int depth) {
		if (depth == 0)
			return str(o);
		StringBuilder sb = new StringBuilder();
		for (int i = 0, len = Array.getLength(o); i < len; i++) {
			if (i != 0)
				sb.append(asep[depth]);
			sb.append(_strArray(Array.get(o, i), depth - 1));
		}
		return sb.toString();
	}

	static void pr(Object... os) {
		boolean isFirst = true;
		for (Object o : os) {
			if (!isFirst)
				out.print(" ");
			out.print(o);
			isFirst = false;
		}
	}

	static void ln() {
		out.println();
	}

	static void ln(Object... os) {
		for (Object o : os) {
			pr(o);
			ln();
		}
	}
}

Measured memory_bytes: 24880
import math
# import numpy as np
import sys

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

a,b,h,m = map(int,input().split())
l = [math.cos(m*math.pi/30) * b, math.sin(m*math.pi/30) * b]
t = math.pi * (h*60 + m) / 360
s = [math.cos(t) * a, math.sin(t) * a]
print(math.sqrt((l[0]-s[0])**2 + (l[1]-s[1])**2))



Measured memory_bytes: 9608
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

#define chmin(x,y) x=std::min(x,y)

using ll = long long;
#define rep(i,n) for(int i = 0;i < (n);++i)
constexpr ll INF {100000000};

int main(int argc, char** argv) {
  std::string S;
  std::cin >> S;
  std::reverse(S.begin(), S.end());
  S += '0';
  ll S_size = S.size();
  std::vector<std::vector<ll>> dp(S_size, std::vector<ll>(2, INF));
  dp[0][0] = S[0] - '0' ;
  dp[0][1] = 10 - (S[0] - '0');
  for (auto i = 1;i < S_size;++i) {
    ll x = S[i] - '0';
    for (auto j = 0;j < 2;++j) {
      x += j;
      chmin(dp[i][0],dp[i-1][j]+x);
      chmin(dp[i][1],dp[i-1][j]+(10-x));
    }
  }
  std::cout << dp[S_size-1][0] << '\n';
}


Measured memory_bytes: 55924
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        S = S % 3600;
        int m = S / 60;
        int s = S % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <climits>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
#define INF LLONG_MAX;
//using ull = unsigned long long;
using ull = long long;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

/**
 *  @param bottom 与えられた竹の本数
 *  @param l 竹配列
 *  @param A 求めたいAの長さ
 *  @param B 求めたいBの長さ
 *  @param C 求めたいCの長さ
 *  @param depth 探索中の深さ
 *  @param a 現在までのAの長さ
 *  @param b 現在までのBの長さ
 *  @param c 現在までのCの長さ
 */
ull dfs(ull bottom, const vector<ull>& l, ull A, ull B, ull C, ull depth, ull a, ull b, ull c) {
  if (depth == bottom) {
    // 最下層まで行ったので延長魔法と短縮魔法を使用してMPを算出 (無は除外)
    if (a > 0 && b > 0 && c > 0) {
      return abs(A-a) + abs(B-b) + abs(C-c) - 30;
    } else {
      return pow(10, 9);
    }
  }

  vector<ull> res;

  // 選ばない
  res.push(dfs(bottom, l, A, B, C, depth+1, a, b, c));

  // Aの材料にする
  res.push(dfs(bottom, l, A, B, C, depth+1, a + l[depth], b, c) + 10);

  // Bの材料にする
  res.push(dfs(bottom, l, A, B, C, depth+1, a, b + l[depth], c) + 10);

  // Cの材料にする
  res.push(dfs(bottom, l, A, B, C, depth+1, a, b, c + l[depth]) + 10);

  return *min_element(res.begin(), res.end());
}

int main() {
  ull n, a, b, c;
  vector<ull> l;
  cin >> n >> a >> b >> c;
 
  each(i, n) {
    ull tmp;
    cin >> tmp;
    l.push(tmp);
  }

  /*
    1. 延長短縮したあとにがっちゃんこするのと、がっちゃんこしたあとに延長短縮するのは手数が同じ
    2. 延長短縮は求めたい値A,B,Cとがっちゃんこ後の絶対値差分ですぐわかるので、まずはがっちゃんこする
    3. 所有している竹に対して採用できる選択肢は下記
         (1) 求めたい竹長Aの材料にする
         (2) 求めたい竹長Bの材料にする
         (3) 求めたい竹長Cの材料にする
         (4) どこにも使わない
    4. 各竹(最大8本)に対して(1)〜(4)を採用するので、フルケースで4 ^ 8 = 65536通り
         l (竹1) : (1)〜(4)のいずれかを採用
         l (竹2) : (1)〜(4)のいずれかを採用
         l (竹3) : (1)〜(4)のいずれかを採用
         l (竹4) : (1)〜(4)のいずれかを採用
         l (竹5) : (1)〜(4)のいずれかを採用
         l (竹6) : (1)〜(4)のいずれかを採用
         l (竹7) : (1)〜(4)のいずれかを採用
         l (竹8) : (1)〜(4)のいずれかを採用
    5. AもBもCも1以上
  */

  auto r = dfs(n, l, a, b, c, 0, 0, 0, 0);
  cout << r << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i;
  int N,A,B,C,D,X,Y;
  scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);

  X=0;
  for(i=A; i<N+A; i+=A){
    X+=B;
  }

  Y=0;
  for(i=C; i<N+C; i+=C){
    Y+=D;
  }

  if(X>=Y)
    printf("%d\n",Y);
  else
    printf("%d\n",X);
  return 0;
}



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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
//#define ABS(a) ((a)>(0)?(a):-(a))


SINT32 main() {
    SINT32 a;
    scanf("%d",&a);

    SINT32 xdata[101] = {0};
    SINT32 ydata[101] = {0};
    SINT32 hdata[101] = {0};

    SINT32 hmax = 0;

    SINT32 ansx = 0;
    SINT32 ansy = 0;
    SINT32 temp = 0;

    for (SINT32 i = 0; i < a; i++) {
        scanf("%d%d%d", &xdata[i],&ydata[i],&hdata[i]);
        if (hdata[i] > 0) {
            temp = i;
        }
    }

    int ans = 0;
    int ok = 0;
    for (SINT32 i = 0; i < 101; i++) {
        for (SINT32 j = 0; j < 101; j++) {
            ans = 0;
            ok = 0;
            ans = abs(xdata[temp]-i) + abs(ydata[temp]-j) + hdata[temp];
            
            for (SINT32 k = 0; k < a; k++) {
                if (hdata[k] != MAX(0,ans -abs(xdata[k]-i) - abs(ydata[k]-j))) {
                    ok = 1;
                    break;
                }
            }
            if (ok == 0) {
                ansx = i;
                ansy = j;
                break;
            }
        }
        if (ok == 0) {
            break;
        }
    }

    printf("%d %d %d\n",ansx, ansy, ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#define MAX 1000000
int cnt,A[MAX];
void insertionSort(int *A,int n,int G){
  int i,j,v;
  for(i=G;i<n;i++){
    v=A[i];
    j = i - G;
    while( j >= 0 && A[j] > v ){
      A[j+G] = A[j];
      j = j - G;
      cnt++;
    }
    A[j+G] = v;
  }
}

void shellSort(int *A,int n){
  int i,m;
  cnt=0;
  m = pow(n,1.25);
  if(m>=100) m=100;
  int G[m];
  G[0]=1;
  for(i=1;i<m;i++){
    if((G[i]=3*G[i-1]+1)>n) break;
  }
  m=i;
  for(i=m-1;i>=0;i--){
    insertionSort(A,n,G[i]);
  }
    printf("%d\n",m);
    for(i=m-1;i>0;i--) printf("%d ",G[i]);
    printf("%d\n",G[i]);
    printf("%d\n",cnt);
    for(i=0;i<n;i++) printf("%d\n",A[i]);
}

int main(){
  int i,n,A[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  shellSort(A,n);
  return 0;
}

Measured memory_bytes: 4548
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#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 RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int a[SIZE],pn[SIZE],sn[SIZE];
int main(){
    DRII(N,M);
    REP(i,N)RI(a[i]);
    sort(a,a+N);
    for(int i=0,j;i<N;i=j){
        for(j=i+1;j<N&&a[j]==a[i];j++);
        pn[a[i]%M]+=(j-i)/2;
        sn[a[i]%M]+=(j-i)%2;
    }
    int an=0;
    an+=(pn[0]*2+sn[0])/2;
    if(M%2==0)
        an+=(pn[M/2]*2+sn[M/2])/2;
    for(int i=1;i<M-i;i++){
        if(pn[i]*2+sn[i]<pn[M-i]*2+sn[M-i]){
            an+=pn[i]*2+sn[i]+min(pn[M-i],(pn[M-i]*2+sn[M-i]-(pn[i]*2+sn[i]))/2);
        }
        else{
            an+=pn[M-i]*2+sn[M-i]+min(pn[i],(pn[i]*2+sn[i]-(pn[M-i]*2+sn[M-i]))/2);
        }
    }
    return 0*printf("%d\n",an);
}


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

#define range(i, n) for (int i = 0; i < n; ++i)
#define sz(v) int(v.size())
#define back_range(i, n) for (int i = n - 1; i >= 0; --i)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define eb emplace_back

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

void fastIO() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

template <class T1, class T2>
istream& operator >> (istream &in, pair <T1, T2> &a) {
    in >> a.first >> a.second;
    return in;
}

template <class T1, class T2>
ostream& operator << (ostream& out, pair <T1, T2> &a) {
    out << a.first << ' ' << a.second;
    return out;
}

template <class T>
istream& operator >> (istream &in, vector <T> &a) {
    for (T &i: a) in >> i;

    return in;
}

template <class T>
ostream& operator << (ostream& out, vector <T> &a) {
    for (T i: a) out << i << ' ';
    return out;
}

void solve();

ll n, k;

int main() {
    fastIO();

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

    int cur = 1;
    vector <bool> was(n + 1);
    vector <int> way;
    vector <int> d(n + 1);
    int len = 0;
    int st = 0;

    for (int i = 0; i < n; ++i) {
        if (was[cur]) {
            st = d[cur];
        }

        else {
            way.eb(cur);
            was[cur] = true;
            d[cur] = len++;

            cur = a[cur];
        }
    }

    if (k < st) {
        cur = 1;
        for (int i = 0; i < k; ++i) {
            cur = a[cur];
        }

        cout << cur;
    }

    else {
        k -= st;

        int cycle = len - st;
        for (int i = 0; i < k % cycle; ++i) {
            cur = a[cur];
        }

        cout << cur;
    }

    return 0;
}

/// ЗАПУСКАЕМ ГУСЯ
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


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

int main(){
    int H, W, K;
    std::cin >> H >> W >> K;
    std::vector< std::vector< int > > S(H, std::vector< int >(W));
    for(int i=0; i<H; i++){
        std::string tmp;
        std::cin >> tmp;
        for(int j=0; j<W; j++){
            S[i][j] = tmp[j] - '0';
        }
    }
    
    int min = 1e9;
    int H_line_max = (int)std::pow(2.0, H - 1);
    for(int i=0; i<H_line_max; i++){
        int i_tmp = i;
        std::vector< int > convert(H);
        convert[0] = 0;
        
        int cnt = 0;
        for(int j=1; j<H; j++){
            if(i_tmp & (int)std::pow(2.0, H - j - 1)){
                cnt++;
            }
            convert[j] = cnt;
        }
        
        int W_cut_cnt = 0;
        std::vector< int > white_cnt(cnt + 1, 0);
        for(int W_cnt=0; W_cnt<W; W_cnt++){
            std::vector< int > white_cnt_tmp(cnt + 1, 0);
            for(int H_cnt=0; H_cnt<H; H_cnt++){
                white_cnt_tmp[convert[H_cnt]] += S[H_cnt][W_cnt];
            }
            
            bool cut = false;
            bool cut_x = false;
            for(int H_cnt=0; H_cnt<cnt+1; H_cnt++){
                //std::cout << "i " << i << " H " << H_cnt << " W " << W_cnt << " cnt " << white_cnt[H_cnt] << " tmp " << white_cnt_tmp[H_cnt] << std::endl;
                if(white_cnt_tmp[H_cnt] > K){
                    cut_x = true;
                }
                if(white_cnt[H_cnt] + white_cnt_tmp[H_cnt] > K){
                    cut = true;
                }
            }
            if(cut_x){
                W_cut_cnt = 1e9;
                //std::cout << "i " << i << std::endl;
                break;
            }
            
            if(cut){
                for(int H_cnt=0; H_cnt<cnt+1; H_cnt++){
                    white_cnt[H_cnt] = white_cnt_tmp[H_cnt];
                }
                W_cut_cnt++;
            }else{
                for(int H_cnt=0; H_cnt<cnt+1; H_cnt++){
                    white_cnt[H_cnt] = white_cnt[H_cnt] + white_cnt_tmp[H_cnt];
                }
            }
        }
        if(min > cnt + W_cut_cnt){
            min = cnt + W_cut_cnt;
        }
    }
    
    std::cout << min << std::endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= sqrt(n); i ++) {
		if(n % i == 0) {
			if(i >= 1 && i <= 9 && (n / i) >= 1 && (n / i) <= 9) {
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
n, m, c = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for _ in range(n)]
cnt = 0
for i in range(n):
    s = c
    for j in range(m):
        s += a[i][j] * b[j]
    if s > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064