akhauriyash/Code-Regression huggingface dataset:
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	ll N, M; cin >> N >> M;
	vector<ll> A(M);
	rep(i, M) cin >> A[i];
	ll sum = accumulate(ALL(A), 0LL);

	if(sum > N){
		cout << -1 << endl;
		return 0;
	}
	cout << N - sum << endl;
	return 0;
}


Measured memory_bytes: 3708
#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <stdio.h>
#include <string.h>

using namespace std;
#define MFOR(i,end) for(size_t i = 0, end_i = (end); i < end_i; ++ i)

int main()
{
	std::string a_, b_, c_;
	cin >> a_ >> b_ >> c_;
	auto a = a_.begin();
	auto b = b_.begin();
	auto c = c_.begin();
	auto* turn = &a;
	auto* turn_ = &a_;
	while (*turn != turn_->end())
	{
		auto char_ = **turn;
		++(*turn);
		if (char_ == 'a') {
			turn = &a; turn_ = &a_;
		}
		else if(char_ == 'b') {
			turn = &b; turn_ = &b_;
		}
		else{
			turn = &c; turn_ = &c_;
		}

	}
	if (turn == &a) {
		cout << 'A';
	}
	else if (turn == &b) {
		cout << 'B';
	}
	else {
		cout << 'C';
	}
	cout << std::endl;
}

Measured memory_bytes: 888
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	int mod = 1000000007;

	void run() {
		for (;;) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int m = sc.nextInt();
			if ((n | k | m) == 0) {
				return;
			}
			ArrayList<Integer> al = new ArrayList<Integer>();
			for (int i = 1; i <= n; i++) {
				al.add(i);
			}
			m--;
			while (al.size() > 1) {
				al.remove(m);
				m = (m + k - 1) % al.size();
			}
			System.out.println(al.get(0));
		}
	}

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

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

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

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

Measured memory_bytes: 37764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define min(a,b) ((a>b)? b:a)
#define max(a,b) ((a>b)? a:b)
int main()
{
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  vector<ll> cost;
  for(int i=0;i<=max(x,y);i++){
    ll tmp=i*2*c;
    if(x-i>0) tmp+=(x-i)*a;
    if(y-i>0) tmp+=(y-i)*b;
    cost.push_back(tmp);
  }
  cout<<*(min_element(cost.begin(),cost.end()));
}

Measured memory_bytes: 1400
if __FILE__ == $0
  n, q = gets.split.map{|i| i.to_i}
  wakasagi = Array.new(n, 0)
  currMaxUser = []
  currMaxWakasagi = 0
  q.times do
    a, v = gets.split.map{|i| i.to_i}
    wakasagi[a - 1] += v
    if wakasagi[a - 1] > currMaxWakasagi
      currMaxUser = [a]
      currMaxWakasagi = wakasagi[a - 1]
    elsif wakasagi[a - 1] == currMaxWakasagi
      currMaxUser << a
    elsif wakasagi[a - 1] < currMaxWakasagi
      if currMaxUser.include?(a)
        currMaxUser.delete(a)
        if currMaxUser.length() == 0
          currMaxWakasagi = wakasagi.max
          currMaxUser = []
          wakasagi.each_with_index do |w, idx|
            if w == currMaxWakasagi
              currMaxUser << idx + 1
            end
          end
        end
      end
    end
    puts "#{currMaxUser.sort[0]} #{currMaxWakasagi}"
  end
end

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

using namespace std;

int main()
{
    int num[27] = {0};
    char ch[105];
    scanf("%s",ch);
    for(int i=0;i<strlen(ch);i++)
    {
        num[ch[i]-'a']++;
    }
    int flag=0;
    for(int i=0;i<26;i++)
    {
        if(num[i]%2!=0)
        {
            flag=1;
            break;
        }
    }
    if(flag) printf("No\n");
    else printf("Yes\n");
}

Measured memory_bytes: 764
use std::collections::BinaryHeap;
use std::cmp::Reverse;

fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let c: Vec<char> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().chars().collect()
    };

    let mut rheap = BinaryHeap::new();
    let mut wheap = BinaryHeap::new();
    for i in 0..n {
        if c[i] == 'R' {
            rheap.push(i);
        } else {
            wheap.push(Reverse(i));
        }
    }

    let mut ans = 0;
    while !rheap.is_empty() && !wheap.is_empty() {
        let x = rheap.peek().unwrap();
        let Reverse(y) = wheap.peek().unwrap();
        if x < y {
            break;
        } else {
            ans += 1;
            rheap.pop();
            wheap.pop();
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4632
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
#include <iostream>
#include <cmath>
#include <string>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


typedef long long ll;
string number;
int N;
string flag[3];

int main() {
    cin >> number;
    N = number.length();
    rep(i,0,1 << (N - 1)) {
        ll sm = number[0] - '0';
        ll a = sm;
        rep(j,0,N - 1){
            a = number[j + 1] - '0';
            if(i & (1 << j)){ 
                sm -= a;
                flag[j] = "-";
            } else {
                sm += a;
                flag[j] = "+";
            }
        }
     
        if(sm == 7){
            cout << number[0] << flag[0] << number[1] << flag[1] << number[2] << flag[2] << number[3] <<"=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,m;
    cin >> n >> m;
    vi a(n);
    while(m--){
        int x,y;
        cin >> x >> y;
        rep(i,y)a[(x+i)%n] = 1;
    }
    rep(i,n)if(!a[i] && a[(i+1)%n]){
        vi ans;
        rep(j,n){
            if(!a[(i+j)%n] && a[(i+j+1)%n])ans.push_back(0);
            if(a[(i+j)%n])ans.back()++;
        }
        vi cnt(200);
        rep(j,ans.size())cnt[ans[j]]++;
        for(int j = 199; j > 0; j--)if(cnt[j])cout << j << " " << cnt[j] << endl;
        return 0;
    }
    cout << n << " " << 1 << endl;
}



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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (const auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2*i
#define rc(i) 2*i+1
//#define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;
using vivi = vector<vi>;

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

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    int k;
    cin >> k;
    while (k--) cout << "ACL";
}

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

int main() {
    int a, b; cin >> a >> b;
    if (a+b > 16) cout << ":(" << endl;
    else if (abs(a-b) > 2) cout << ":(" << endl;
    else cout << "Yay!" << endl;

    return 0;
}


Measured memory_bytes: 256
//0050
#include<cstdio>
#include<cstring>
#include<limits>
using namespace std;

int main(void)
{
	const int STR_LENGTH = 1024;
	char str[STR_LENGTH];
	fgets(str, STR_LENGTH, stdin);

	const char apple[] = "apple",
				peach[] = "peach";
	char* pa = str, *pp = str;
	char *min = str;
	const char *fruit = NULL;

	for(;;)
	{
		pa = strstr(min, apple);
		pp = strstr(min, peach);
		if(!pa && !pp)
			break;
		else if(!pa)
		{
			min = pp;
			fruit = apple;
		}
		else if(!pp)
		{
			min = pa;
			fruit = peach;
		}
		else
		{
			if(pa < pp)
			{
				min = pa;
				fruit = peach;
			}
			else
			{
				min = pp;
				fruit = apple;
			}
		}

		min[0] = fruit[0];
		min[1] = fruit[1];
		min[2] = fruit[2];
		min[3] = fruit[3];
		min[4] = fruit[4];
		min++;
	}
	printf("%s", str);	//fgets()ツづ嘉シツ行ツ禿シツづゥ
	return 0;
}

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

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) iter(v) {pr(*it)} nl
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int32_t main()
{
    #ifdef DEBUG
    //freopen("B.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n;
    cin >> n;
    vector<int> vals(n,0);
    for0(i,n) {
        read(vals[i]);
    }
    
    bool ok = true;
    ll low=2, high=2;
    for (int i=n-1; i>=0; i--) {
        ll new_low = (low+vals[i]-1)/vals[i] * vals[i];
        if (not (low <= new_low and new_low <= high)) {
            ok = false;
            break;
        }
        ll new_high = (high/vals[i]+1) * vals[i] -1;
        low = new_low;
        high = new_high;
        pr(low) pr(high) nl
    }
    if (ok) {
        cout<<low<<" "<<high<<endl;
    }
    else {
        cout<<-1<<endl;
    }
    return 0;
}


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

int main(){
	int n;cin >> n;
	bool t=true;
	for(int i=0;i<n;i++){
		int a;cin >> a;
		if(!(a&1)){
			if(a%3!=0 && a%5!=0)
				t=false;
		}
	}
	if(!t)cout << "DENIED\n";
	else cout << "APPROVED\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcopy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

int n,k;ll r;

int main(){
	scanf("%d%d",&n,&k);
	if(k==0){printf("%lld\n",1LL*n*n);return 0;}
	fore(b,k+1,n+1){
		int qq=0;
		while(qq<=n){
			int s=qq+k;
			int e=min(qq+b,n+1);
			r+=max(e-s,0);
			qq+=b;
		}
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N + 1];
            for (int i = 0; i < N + 1; i++) {
                A[i] = in.nextInt();
            }
            int[] B = new int[N];
            for (int i = 0; i < N; i++) {
                B[i] = in.nextInt();
            }

            long count = 0;
            for (int i = 0; i < N; i++) {
                int min = Math.min(A[i], B[i]);
                A[i] -= min;
                B[i] -= min;
                count += min;

                int min2 = Math.min(A[i + 1], B[i]);
                A[i + 1] -= min2;
                B[i] -= min2;
                count += min2;
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 65036
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);i--)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n,x;
  cin >> n >> x;

  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  int ans = 1, cur = 0;
  REP(i,n){
    cur += a[i];
    if(cur <= x) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>

template <typename T>
T absF(T v){
    if(v>0){
        return v;
    }else{
        return -v;
    }
}

int main(){
    long long buf;
    unsigned long long X;
    unsigned long long K,D,cnt=0;
    std::cin>>buf>>K>>D;
    // std::cout<<X<<K<<D<<std::endl;

    X=absF(buf);

    cnt=X/D;
    if(cnt>K){
        cnt=K;
    }
    if(X>0){
        X-=cnt*D;
    }else{
        X+=cnt*D;
    }

    // std::cout<<X<<K<<D<<cnt<<std::endl;
    if(cnt==K){
        std::cout<<X<<std::endl;
    }
    else{
        if((K-cnt)%2==0){
            std::cout<<X<<std::endl;
        }else{
            std::cout<<D-X<<std::endl;
        }
    }
}

Measured memory_bytes: 3572
A,B,H,M=map(int,input().split())

import math  #三角関数・円周率
import numpy

H = H + M / 60
H_A = H / 12 * 360 * math.pi /180
M_A = M / 60 * 360 * math.pi / 180
H_x = math.cos(H_A) * A  #針の先端の座標計算（中心基準）
H_y = math.sin(H_A) * A
M_x = math.cos(M_A) * B
M_y = math.sin(M_A) * B

a = numpy.array([H_x, H_y])
b = numpy.array([M_x, M_y])
u = b - a
print(numpy.linalg.norm(u))

Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e6+10;
const int mod=1e9+7;
int a[maxn];
int vis[maxn];
bool check(int n)
{
	while(n)
	{
		if(vis[n%10])
			return false;
		n/=10;
	}
	return true;
}
int main()
{
	
	int n,k;
	int x;
	cin>>n>>k;
	for(int i=0;i<k;i++)
	{
		cin>>x;
		vis[x]=1;
	}
	for(int i=n;;i++)
	{
		if(check(i))
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    string s;
    cin >> n >> s;
    if(n % 2 == 1){
        cout << "No" << endl;
        return 0;
    }

    int hn = n / 2;
    rep(i, n / 2){
        if(s[i] != s[i+hn]){
            cout << "No" << endl;
            return 0; 
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>; 

int main() {
    string N;
    cin >> N;
    rep(i, 3){
        if(N[i] == '7'){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3632
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
n,u,v=map(int,input().split())
node=[[]for _ in range(n)]
for _ in range(n-1):
	a,b=map(int,input().split())
	node[a-1].append(b-1)
	node[b-1].append(a-1)
def dfs(i):
	visited[i]=1
	for x in node[i]:
		if visited[x]==0:
			dis[x]=dis[i]+1
			dfs(x)
inf=10**9
dis=[inf]*n;dis[u-1]=0;visited=[0]*n
dfs(u-1)
dis2=[]
from copy import copy
dis_dash=copy(dis)
dis2.append(dis_dash)
dis[v-1]=0;visited=[0]*n
dfs(v-1)
dis2.append(dis)
cnt=0
for i in range(n):
	if dis2[0][i]<dis2[1][i]:
		cnt=max(cnt,dis2[1][i])
print(cnt-1)

Measured memory_bytes: 102804
#include <iostream>
using namespace std;
int gcd(int,int); //最大公約数
int lcm(int,int); //最小公倍数
int main(){
    int a,b;
    while (cin >>a >>b){
        cout << gcd(a,b) << " " << lcm(a,b) << endl;
    }
}

int gcd(int a,int b){
    int n;
    if (a>b){
        n=b;
        b=a;
        a=n;
    }
    n = a;
    while(b%a!=0){
        n=b%a;
        b=a;
        a=n;
    }
    return n;
}

int lcm(int a,int b){
    int n = a/gcd(a,b)*b;
    return n;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;

int main() {
    int n, m; scanf("%d%d", &n, &m);
    vector<int> a(n);
    repeat (i, n) {
        scanf("%d", &a[i]); -- a[i];
    }
    vector<int> cnt(n);
    vector<int> covered(n);
    int sum = 0;
    auto push = [&](int x) {
        cnt[x] += 1;
        int l = x + 1 - cnt[x];
        if (l >= 0) {
            if (covered[l] == 0) sum += 1;
            covered[l] += 1;
        }
    };
    auto pop = [&](int x) {
        int l = x + 1 - cnt[x];
        if (l >= 0) {
            covered[l] -= 1;
            if (covered[l] == 0) sum -= 1;
        }
        cnt[x] -= 1;
    };
    repeat (i, n) {
        push(a[i]);
    }
    repeat (i, m) {
        int x, y; scanf("%d%d", &x, &y); -- x; -- y;
        pop(a[x]);
        a[x] = y;
        push(a[x]);
        printf("%d\n", n - sum);
    }
    return 0;
}


Measured memory_bytes: 3840
import sys
def input(): return sys.stdin.readline().rstrip()
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    gcd_a=gcd(*A)
    if k%gcd_a==0 and max(A)>=k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


if __name__=='__main__':
    main()

Measured memory_bytes: 16268
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
ll S_list[200000];
ll dp[2019][2];

void rec(ll i){
	
	ll dp_tmp[2019][2];
	REP(j,2019){
		dp_tmp[j][0] = dp[j][0];
		dp_tmp[j][1] = dp[j][1];
	}

	REP(j,2019){
		if (dp[j][0]>0){
			// printf("j: %lld, j*10+i: %lld\n", j, j*10+S_list[i]);
		}
		dp_tmp[j][1] += dp[j][0]; // 右が確定
		dp_tmp[(j*10+S_list[i])%2019][0] = dp[j][0] ;
	}
	dp_tmp[S_list[i]][0] += 1; // 右が未定
	REP(j,2019){
		dp[j][0] = dp_tmp[j][0];
		dp[j][1] = dp_tmp[j][1];
	}
}


// 検索タグ
int main() {
	// 入力
	string S;cin>>S;
	ll S_size = S.size();
	REP(i,S_size){
		S_list[i] = stoi(S.substr(i,1));
	}

	// 解法
	REP(i,2019){
		dp[i][0] = 0;
		dp[i][1] = 0;
	}
	// dp[0][0] = ;
	REP(i,S_size){
		rec(i);
		// printf("S: %lld, %lld, %lld\n", S_list[i], dp[0][0],  dp[0][1]);
		// printf("[1817], %lld, %lld\n", dp[1817][0],  dp[1817][1]);
	}
	ll ans = dp[0][0] + dp[0][1];
	//出力
	printf("%lld\n", ans);
}


Measured memory_bytes: 5464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

//const ll mod = 998244353;
const ll mod = 1e9 + 7;
const ll MAX_SIZE = 1000005;
ll fac[MAX_SIZE], inv[MAX_SIZE], finv[MAX_SIZE];
ll fac_init() {
    // combination init
    fac[0] = 1;
    for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % mod;
    finv[0] = modpow(fac[MAX_SIZE - 1], mod - 2, mod);
    repe(i, 1, MAX_SIZE) finv[i] = finv[i - 1] * (MAX_SIZE - i) % mod;
    reverse(finv, finv + MAX_SIZE);

    //inv init
    repe(i, 1, MAX_SIZE) inv[i] = modpow(i, mod - 2, mod);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % mod; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % mod * finv[a - b] % mod; }

int main() {
    init();
    ll N, M, K;
    cin >> N >> M >> K;
    ll S = N * M;
    fac_init();
    ll ans = 0;
    vl sum(S + 1, 0);
    rep(i,S)
        sum[i + 1] = sum[i] + i + 1;

    ll C = comb(S - 2, K - 2);
    rep(i,N)rep(j,M){
        ll tmp = 0;
        ll l, r;
        // 探索点の右で縦にわって２つの四角形の累積和を考える, l=探索点を含む列のマンハッタン距離, r=探索点の右隣
        l = sum[i] + sum[N - i - 1];
        r = l + N;
        l = (j + 1) * l % mod + N * (j + 1) * j % mod * inv[2] % mod;
        r = (M - j - 1) * r % mod + N * (M - j - 1) * (M - j - 2) % mod * inv[2] % mod;
        ans = (ans + l * C % mod + r * C % mod) % mod;
    }
    ans = ans * inv[2] % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25216
from sys import stdin
from collections import deque
nii=lambda:map(int,stdin.readline().split())

n=int(input())

tree=[[] for i in range(n)]
for i in range(n-1):
  u,v,w=nii()
  u-=1
  v-=1
  tree[u].append([v,w])
  tree[v].append([u,w])

dist=[-1]*n
dist[0]=0

ans=[-1]*n
ans[0]=0

dq=deque()
dq.append(0)

while dq:
  x=dq.popleft()
  for vv,ww in tree[x]:
    if dist[vv]==-1:
      dq.append(vv)
      dist[vv]=dist[x]+ww
      if dist[vv]%2==0:
        ans[vv]=0
      else:
        ans[vv]=1

for i in ans:
  print(i)

Measured memory_bytes: 52144
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    int N;
    cin >> N;
    vector<ll> A(N+1),B(N);
    REP(i,N+1) cin >> A[i];
    REP(i,N) cin >> B[i];
    ll sum=0;
    ll cnt,tmp;
    REP(i,N){
        cnt=B[i]-A[i];
        if(cnt>=0){
            sum+=A[i];
            tmp=A[i+1];
            A[i+1]=max((ll)0,A[i+1]-cnt);
            sum+=(tmp-A[i+1]);
        }else{
            sum+=B[i];
        }
    }

    cout << sum << endl;
   
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

enum State{
  NONE,
  LEFT,
  RIGHT
};

int main (){
  const string right = "yhnujmikolp";
  while( 1 ){
    string s;
    cin >> s;
    if( s == "#" ){ return EXIT_SUCCESS; }
    int counter = 0;
    int len = s.length();
    State prev = NONE;
    State temp;
    for( int i = 0; i < len; i++ ) {
      if( right.find( s[ i ] ) == -1 ) {
        temp = LEFT;
      }else{
        temp = RIGHT;
      }
      if( temp != prev && prev != NONE ){
        counter++;
      }
      prev = temp;
    }
    cout << counter << endl;
  }
}

Measured memory_bytes: 1192
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>

using namespace std;

#define FOR(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define REP(i,n) FOR((i),0,(n))
#define FORCLS(i,a,b) for(int (i) = (a); i <= (b); (i)++)
#define REPCLS(i,n) FORCLS((i),1,(n))

#if defined(DEBUG) && true
#define DOUT(x) {cout << #x << ":" << x << endl;}
#define DOUTA(ary,n) {cout << #ary << ": "; for(int i = 0; i < (n); i++) { cout << (ary)[i] << ", ";} cout << endl; }
#else
#define DOUT(x)
#define DOUTA(ary,n)
#endif

using Int = long;

const int N_MAX = 200003;
Int n,m;
bool Onetoi[N_MAX];
bool itoN[N_MAX];

void solve() {
    cin >> n >> m;
    REP(i, m) {
        Int a,b;
        cin >> a >> b;
        if (a == 1){
            Onetoi[b] = true;
        }
        if (b == n) {
            itoN[a] = true;
        }
    }
    bool isok = false;
    REPCLS(i,n) {
        if (Onetoi[i] && itoN[i]) {
            isok = true;
            break;
        }
    }
    cout << (isok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

#ifdef DEBUG
#define MAIN hoge
#else
#define MAIN main
#endif

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


Measured memory_bytes: 640
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST
import Data.Maybe (fromJust)
import qualified Data.Map as M
import Text.Printf
import Debug.Trace

sieve n = runSTArray $ do
  isp <- newListArray (0,n) (False:False:repeat True)
  forM_ (takeWhile (\x->x*x <= n) [2..]) $ \i -> do
    ok <- readArray isp i
    when ok $ do
      forM_ [i*2,i*3..n] $ \j -> do
        writeArray isp j False
  return isp
plist n = foldr (\(i,e) acc -> if e then i:acc else acc) [] $ assocs $ sieve n

adjustDefault f k z m = if k `M.member` m
                        then M.adjust f k m
                        else M.insert k z m

factor 1 _ m = m
factor x (p:ps) m
  | x `mod` p == 0 = factor (x `div` p) (p:ps) (adjustDefault (+1) p 1 m)
  | otherwise = factor x ps m

pm :: Integer
pm = 1000000007

main = do
  [n] <- getInts
  let ps = plist n
  let m = M.unionsWith (+) [factor i ps (M.empty) | i <- [2..n]]
  print $ M.foldl (\x y -> x*(y+1) `mod` pm) 1 m

-- util
getInts :: IO [Integer]
getInts = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine

substr :: Int -> Int -> B.ByteString -> B.ByteString
substr b l s = B.take l $ B.drop b s


Measured memory_bytes: 1148
#include <stdio.h>

char s[90];
int a[4];
char*p;
int f(){
	if('a'<=*p&&*p<='d')return a[*p++-'a'];
	p++;
	char op=*p++;
	int x=f();
	int y=f();
	p++;
	int ans=-1;
	if(op=='+')ans=x|y;
	if(op=='*')ans=x&y;
	if(op=='^')ans=x^y;
	return ans;
}

int g(int n){
	for(int j=3;j>=0;j--)a[j]=n%10,n/=10;
	p=s;
	return f();
}

int ans[16];
int main(){
	while(scanf(" %s",s),*s!='.'){
		int t;
		scanf("%d",&t);
		for(int i=0;i<16;i++)ans[i]=0;
		for(int i=0;i<10000;i++)ans[g(i)]++;
		printf("%d %d\n",g(t),ans[g(t)]);
	}
}


Measured memory_bytes: 2144
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int T; cin >>T;
  REP(t, T){
    int N, a = 0, b = 0, c, d; cin >>N;
    cin >>c;
    FOR(i, 1, N){
      cin >>d;
      if(c < d) a = max(a, d - c);
      else b = max(b, c - d);
      c = d;
    }
    cout <<a <<" " <<b <<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main()
{
    int a ,b,c,d;
    cin>>a>>b>>c>>d;
    int e;
    e=a-c;
    if(e<0)
      e=-e;
     int f,q,w,r,t;
     f=c-a;
    if(f<0)
      f=-f;
      q=b-a;
       if(q<0)
      q=-q;
      w=a-b;
       if(w<0)
      w=-w;
      r=b-c;
       if(r<0)
      r=-r;
      t=c-b;
       if(t<0)
      t=-t;
    if(e<=d||f<=d)
      cout<<"Yes"<<endl;
      else
    {
        if((q<=d||w<=d)&&(r<=d||t<=d))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  i64 n;
  cin >> n;
  if (n & 1) {
    cout << 0 << endl;
    return;
  }
  n >>= 1;
  int m = 0;
  while (exp((i64) 5, m + 1) <= n) m++;
  if (m == 0) {
    cout << 0 << endl;
    return;
  }
  vi64 cnt(m);
  rep(i, m) {
    cnt[i] = n / exp((i64) 5, i + 1);
  }
  rrep(i, m) repi(j, i + 1, m) {
    cnt[i] -= cnt[j];
  }
  i64 ans = 0;
  rep(i, m) {
    ans += cnt[i] * (i + 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
s = input()
N = len(s)
s = 'L' + s + 'R'

cl = [1] * (N + 1)
for i in range(1, N + 1):
  if s[i] == 'R' and s[i + 1] == 'R':
    cl[i + 2] += cl[i]
    cl[i] = 0

for i in range(N, 0, -1):
  if s[i] == 'L' and s[i - 1] == 'L':
    cl[i - 2] += cl[i]
    cl[i] = 0
    
print(' '.join([str(n) for n in cl[1:(N + 1)]]))

Measured memory_bytes: 11160
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int cnt = 0, ans = 0;
  for(int i = 0; i < 1e7; i++){
    cnt = ( cnt*10 + 7) % n;
    ans += 1;
    if(cnt==0){
      break;
    }
  }
  if(ans==1e7){
    cout<<-1;
  } else{
    cout<<ans;
  }
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
  // constant

  static final int MAX_INT = 1 << 30;

  static final int[][] DRCS = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

  // inner classes

  static class Masu implements Comparable<Masu> {
    int level, x, y;

    Masu(int level, int x, int y) {
      this.level = level;
      this.x = x;
      this.y = y;
    }

    public int compareTo(Masu m) {
      return this.level - m.level;
    }
  }

  // main
  public static final void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);

    for (;;) {
      int r = sc.nextInt();
      if (r == 0) break;

      int[][] mlss = new int[2][r + 1];
      int[] mlslen = new int[2];

      for (int k = 0; k < 2; k++) {
        int w = sc.nextInt();
        int h = sc.nextInt();
        int ex = sc.nextInt() - 1;
        int ey = sc.nextInt() - 1;

        int[][] als = new int[h][w];
        int[][] mls = new int[h][w];
        boolean[][] notq = new boolean[h][w];

        for (int y = 0; y < h; y++)
          for (int x = 0; x < w; x++) {
            als[y][x] = sc.nextInt();
            mls[y][x] = MAX_INT;
            notq[y][x] = true;
          }

        mls[ey][ex] = als[ey][ex];
        notq[ey][ex] = false;

        PriorityQueue<Masu> q = new PriorityQueue<Masu>();
        q.add(new Masu(mls[ey][ex], ex, ey));

        mlss[k][0] = 0;
        mlslen[k] = 1;

        while (! q.isEmpty()) {
          Masu min_u = q.poll();

          mlss[k][mlslen[k]++] = min_u.level;
          if (mlslen[k] > r) break;

          for (int[] drc: DRCS) {
            int vx = min_u.x + drc[0];
            int vy = min_u.y + drc[1];
            if (vx < 0 || vx >= w || vy < 0 || vy >= h) continue;

            int l = min_u.level;
            if (l < als[vy][vx]) l = als[vy][vx];

            if (mls[vy][vx] > l) {
              mls[vy][vx] = l;
              if (notq[vy][vx]) {
                notq[vy][vx] = false;
                q.add(new Masu(mls[vy][vx], vx, vy));
              }
            }
          }
        }
      }

      int min_sum = MAX_INT;

      int i0 = 0;
      int i1 = r - i0;

      if (i1 >= mlslen[1]) {
        i1 = mlslen[1] - 1;
        i0 = r - i1;
      }

      while (i0 < mlslen[0] && i1 >= 0) {
        int sum = mlss[0][i0] + mlss[1][i1];
        if (min_sum > sum) min_sum = sum;

        i0++; i1--;
      }

      System.out.println(min_sum);
    }
  }
}

Measured memory_bytes: 168736
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,cnt=0;
	double sum = 0.0,ave=0.0;
	cin >> n;
	vector<ll>x(n), y(n), point(n);
	rep(i, n){
		cin >> x[i] >> y[i];
		point[i] = i;
	}
	do {
		for (ll i = 0; i < n-1; i++) {
			sum += sqrt(pow(x[point[i]]-x[point[i+1]],2)+pow(y[point[i]]-y[point[i+1]],2));
		}
		cnt++;
	} while (next_permutation(all(point)));
	cout << setprecision(10) << fixed <<  sum / cnt <<endl;
}




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

bool mir(bool n){
    return (n+1)%2;
}

int x_or(int a,int b){
    return (a+b)%2;
}

int main(){
    cin.tie(0);
    ios:: sync_with_stdio(false);
    string ss;
    deque<char> s;
    int q;
    cin >> ss >> q;
    for(char x:ss) s.push_back(x);
    int qi;
    int f;
    char c;
    bool mirror = 0;
    rep(i,q){
        cin >> qi;
        if(qi == 1)
            mirror = mir(mirror);
        
        if(qi == 2){
        cin >> f >> c;
        f = f%2;
            if(x_or(mirror,f) == 1)
                s.push_front(c);
            else
                s.push_back(c);
        }
    }
    if(mirror == 1){
        reverse(s.begin(),s.end());
    }
    string ans;
    for (char x:s) ans += x;
    cout << ans;
}


Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const int64_t mod = 1e9+7;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s;
    cin >> s;

    modint ary[2010];
    modint sigma[2010];
    ary[0] = ary[1] = ary[2] = 0;
    sigma[0] = sigma[1] = sigma[2] = 0;
    REP(i,3,  2010)
    {
        ary[i] = sigma[i-3] + 1;
        sigma[i] = sigma[i-1] + ary[i];
    }

    cout << ary[s] << endl;

    // rep(i,10)
    // {
    //     cout << ary[i] << endl;
    // }

}


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

int main() {
  int N;
  cin >> N;  
  int A[210];
  
  for (int i = 0; i<N; i++){
    cin >> A[i];
  }
    
  int res =0;
    
  while (true){
    bool exist_odd = false;    
    for (int i=0;i<N;i++){      
      if (A[i]%2!=0)  exist_odd = true;
    }
      
    if (exist_odd){
      break;
    }
      
    for (int i=0;i<N;++i){
      A[i]/=2;
    }
      
    ++res;
  }
    
  cout << res <<endl;
}
      
      

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
//use std::cmp::*;

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
        d: usize
    }
    let m = 998244353u64;
    let mut dp: Vec<Vec<u64>> = vec![vec![0; d + 1]; c + 1];
    // dp[i][j][0]=i行j列で、最後(i-1)の行目に黒が1つだけ。つまり最後の操作は行の追加。
    // dp[i][j][1] 最後の操作は列(j-1)の追加。
    // 初期値として、
    dp[a][b] = 1;
    //println!("{:?}", dp);
    for i in a..c + 1 {
        for j in b..d + 1 {
            if i == a && j == b {
                continue;
            };
            dp[i][j] = m + dp[i - 1][j] * (j as u64) + dp[i][j - 1] * (i as u64);
            dp[i][j] -= dp[i - 1][j - 1] * (i as u64 - 1) * (j as u64 - 1) % m;
            dp[i][j] = dp[i][j] % m;
        }
    }
    //println!("{:?}", dp);

    println!("{}", dp[c][d] % m);
}
//ij=5,6,7
//[[[0, 0], [0, 1], [0, 1], [0, 1], [0, 1]],
// [[0, 0], [----], [0, 0], [0, 0], [0, 1]],
// [[0, 0], [----], [0, 2], [0, 4], [4, 8]],
// [[0, 1], [1, 0], [4, 1], [12, 7], [48, 33]]]


Measured memory_bytes: 72444
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}

inline LL fastpo(LL x, LL n, LL mod) {
	LL res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}

inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}
template<const LL mod> struct MI{
	LL a;
	MI operator + (const MI & b) {
		MI res{a + b.a};
		if(res.a >= mod) res.a -= mod;
		return res;
	}
	MI operator - (const MI & b) {
		MI res{a - b.a};
		if(res.a <= 0) res.a += mod;
		return res;
	}
	MI operator * (const MI & b) {
		return MI{a * b.a % mod};
	}
	MI operator / (const MI & b) {
		return MI{a * fastpo(b.a, mod - 2, mod) % mod};
	}
};
const int N = 3333;
const int LOG = 20;
const int mod = 998244353;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[N][N];
int main() {
	int n, s;
	scanf("%d%d", &n, &s);
	int pw = fastpo(2, n - 1, mod);
	int inv2 = mod + 1 >> 1;
	for(int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		for(int j = 0; j <= s; j++) {
			if(j + x <= s) {
				dp[i][j + x] = (LL)dp[i - 1][j] * inv2 % mod;
			}
		}
		for(int j = 0; j <= s; j++) {
			dp[i][j] = (dp[i - 1][j] + dp[i][j]) % mod;
		}
		dp[i][x] = (dp[i][x] + pw) % mod;
	}
	cout << dp[n][s] << endl;
}






Measured memory_bytes: 42732