akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, long double> P;
struct edge { LL to; long double cost; };

const LL inf = 11234567890123;
long double xs, ys, xt, yt;
LL N;
std::vector<long double>dist;
std::vector<std::vector<edge>>G;

void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(dist.begin(), dist.end(), inf);
	dist[s] = 0.;
	que.push(P(0., s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (dist[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (dist[e.to] > dist[v] + e.cost)
			{
				dist[e.to] = dist[v] + e.cost;
				que.push(P(dist[e.to], e.to));
			}
		}
	}
}

int main()
{
	in >> xs >> ys >> xt >> yt >> N;
	std::vector<long double>x(N + 2), y(N + 2), r(N + 2);
	dist.resize(N + 2);
	G.resize(N + 2);
	x[0] = xs; y[0] = ys; r[0] = 0;
	rep(i, N) in >> x[i + 1] >> y[i + 1] >> r[i + 1];
	x[N + 1] = xt; y[N + 1] = yt; r[N + 1] = 0;
	for (int i = 0; i <= N + 1; ++i)
	{
		for (int j = i + 1; j <= N + 1; ++j)
		{
			auto dis = std::max<long double>(sqrtl((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j])) - (r[i] + r[j]), 0.);
			G[i].push_back({ j,dis });
			G[j].push_back({ i,dis });
		}
	}
	dijkstra(0);
	out << std::fixed << std::setprecision(10);
	out << dist[N + 1] << std::endl;
	return 0;
}


Measured memory_bytes: 42860
#include<cstdio>
#include<cmath>
using namespace std;
#define MAXN 10
bool U[MAXN+5];
bool C(int n){
	while(n){
		if(U[n%10]) return 0;
		n/=10;
	}
	return 1;
}
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=k;i++){
		int x;
		scanf("%d",&x);
		U[x]=1;
	}
	while(1){
		if(C(n)){
			printf("%d",n);
			break;
		}
		n++;
	}
}


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> p1(n + 1), p2(m + 1);
  partial_sum(all(a), p1.begin() + 1);
  partial_sum(all(b), p2.begin() + 1);

  int l = 0, r = n + m;
  while (l < r) {
    int mi = (l + r + 1) / 2;
    ll total = p1[min(n, mi)] + p2[max(0, mi - n)];
    // cout << mi << ' ' << total << endl;
    int i = 0;
    while (total > k && min(n, mi) - 1 - i >= 0 && max(0, mi - n) + i < m) {
      total -= a[min(n, mi) - 1 - i];
      total += b[max(0, mi - n) + i];
      i++;
    }

    if (total > k) r = mi - 1;
    else l = mi;
  }
  cout << l;

  return 0;
}


Measured memory_bytes: 9516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans;
void dfs(ll s,ll r,bool a,bool b,bool c){
    if(s>n)return;
    if(a&b&c)ans++;
    dfs(s+r*3,r*10,true,b,c);
    dfs(s+r*5,r*10,a,true,c);
    dfs(s+r*7,r*10,a,b,true);
}
int main(void){
    cin>>n;
    dfs(0,1,false,false,false);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    string s,t; cin>>s>>t;
    cout<<t<<s<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int card[50];

void change_card(int n, int p, int c){
  int tmp[50];
  int i,j;

  //c?????????????????????tmp????????????
  for(i=0;i<=50;i++){
    tmp[i]=0;
  }


  //tmp???C????????¨??????????????£??\
  for(i=1;i<=c;i++){
    tmp[i]=card[n-p-c+1+i];
    //printf("tmp[%d] = %d\n",i,tmp[i]);
  }

  for(i=1,j=1;j<=c;i++){
    if(i<=p-1){
      card[n-p-c+1+i]=card[n-p+1+i];
      //printf("??°??????%d\n",card[n-p+i]);
      //printf("??°??????card[%d] = %d\n",n-p-c+1+i,card[n-p-c+1+i]);
    }else{
      card[n-p-c+1+i]=tmp[j];
      //printf("card[%d] = %d\n",n-p-c+1+i,tmp[j]);
      j++;
    }
  }
/*
  for(i=1;i<=n;i++){
    printf("card[%d] = %d\n",i,card[i]);
  }
*/
};


int main(){

  int n,r,p,c;
  int i;

  for(;scanf("%d %d",&n,&r),n,r;){
    //?????????????????????
    for(i=0;i<=50;i++){
      card[i]=i;
    }
    for(i=1;i<=r;i++){
      scanf("%d %d",&p,&c);
      change_card(n,p,c);
    }
    printf("%d\n",card[n]);
  }

  return 0;

}

Measured memory_bytes: 600
# ABC 047: B – すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
w, h, n = [int(s) for s in input().split()]

x = []
y = []
a = []
for i in range(n):
    tmp = [int(s) for s in input().split()]
    x.append(tmp[0])
    y.append(tmp[1])
    a.append(tmp[2])

w_start = 0
h_start = 0

for i in range(n):
    if a[i] == 1:
        if w_start < x[i]:
            w_start = x[i]
    elif a[i] == 2:
        if w > x[i]:
            if x[i] > w_start:
                w = x[i]
            else:
                w = w_start
    elif a[i] == 3:
        if h_start < y[i]:
            h_start = y[i]
    elif a[i] == 4:
        if h > y[i]:
            if y[i] > h_start:
                h = y[i]
            else:
                h = h_start

print((w - w_start) * (h - h_start))

Measured memory_bytes: 3064
def para(ax,ay,bx,by):
    return True if ax*by-bx*ay==0 else False


def otr(ax,ay,bx,by):
    return True if ax*bx+ay*by==0 else False


n=int(input())
for i in range(n):
    x0,y0,x1,y1,x2,y2,x3,y3=map(int,input().split())
    x1 -=x0
    y1 -=y0
    x3 -=x2
    y3 -=y2
    if para(x1,y1,x3,y3):print(2)
    elif otr(x1,y1,x3,y3):print(1)
    else:print(0)


Measured memory_bytes: 5620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;


int main()
{
	int n;
	cin >> n;
	ll sum = 0LL;
	int min;
	vector<int> dp(n);
	for (int i = 0; i < n; i++) {
		cin >> dp[i];
	}

	for (int i = 0; i < n; i++) {
		if (i == 0) {
			min = dp[i];
		} else {
			if (min < dp[i]) {
				min = dp[i];
			} else {
				sum += (ll)min - (ll)dp[i];
			}
		}
	}

	printf("%lld", sum);

	return 0;
}


Measured memory_bytes: 4028
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int map[2000][2000];

int main(void) {
    memset(map, 0, sizeof(map));
    char x[2000]={}, y[2000]={};
    scanf("%s%s",x,y);
    int xl=strlen(x),yl=strlen(y);

    for(int m=0; m<=xl; m++)
        map[m][0] = m;
    for(int n=0; n<=yl; n++)
        map[0][n] = n;

    for(int m=1; m<=xl; m++)
        for(int n=1; n<=yl; n++) {
            if(x[m-1] == y[n-1])
                map[m][n] = min(min(map[m-1][n-1],map[m][n-1]+1),map[m-1][n]+1);
            else
                map[m][n] = min(min(map[m-1][n-1],map[m][n-1]),map[m-1][n])+1;
        }
    printf("%d\n", map[xl][yl]);
    return 0;
}

Measured memory_bytes: 16600
h, w, k = map(int,input().split())
S = [list(map(int,list(input()))) for _ in range(h)]
ans = 10**9+7

for i in range(1<<(h-1)):
    group  = [[0] * w]
    g_id = 0
    group[g_id] = [s + b for s, b in zip(S[0], group[0])]

    for j in range(1, h):
        if (i >> (j-1)) & 1:
            g_id += 1
            group.append([0]*w)
        group[g_id] = [s + b for s, b in zip(S[j], group[g_id])]


    #畳み込んだ時点ですでにその列の白チョコの個数がk個より多かったら論外
    if not all([all([i<=k for i in b]) for b in group]):
        continue
    
    cnt = len(group) - 1
    g_cnts = [0] * len(group)

    for jj in range(w):
        for g_id in range(len(group)):
            g_cnts[g_id] += group[g_id][jj]
        if any([c > k for c in g_cnts]):
            cnt += 1
            for g_id in range(len(group)):
                g_cnts[g_id] = group[g_id][jj]
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
 
using namespace std;
 
 
 
int main() {
    int d,d1,i,j,k;
    int c[26];
    int s[365][26];
    cin >> d;
    d1 = 0;
    for(i = 0; i < 26; ++i) cin >> c[i];
    for(i = 0; i < d; ++i) for(j = 0; j < 26; ++j) cin >> s[i][j];
 
    int arr[365] = {};
 
    int t1,t2,s1,s2, diff, count;
    count = 0;
    int max, loc;
    int a[26];
    for(int i = 0; i < 26; ++i) a[i] = 1;
    int b[26] = {};
    for(i = 0; i < 365; ++i) {
        for(j = 0; j < 26; ++j) {
            b[j] = s[i][j]+3*a[j]*c[j];
            a[j]++;
        }
        max = *max_element(b,b+26);
        loc = find(b,b+26,max)-b;
        arr[i] = loc;
        a[loc] = 1;
    }
    
    
    while(true) {
 
 
        label1:
        for(i = 0; i < d; ++i) {
            for(j = 0; j < 26; ++j) {
                if(arr[i]==j) continue;
                if(count>22000000) goto label2;
                ++count;
                for(s1 = i+1; s1 < d; ++s1) {
                    if(arr[s1]==arr[i]) break;
                }
                for(t1 = i-1; t1 >= 0; --t1) {
                    if(arr[t1]==arr[i]) break;
                }
                for(s2 = i+1; s2 < d; ++s2) {
                    if(arr[s2]==j) break;
                }
                for(t2 = i-1; t2 >= 0; --t2) {
                    if(arr[t2]==j) break;
                }
                diff = s[i][j]-s[i][arr[i]]+(((s1-i)*(s1-i-1))/2+((i-t1)*(i-t1-1))/2-((s1-t1)*(s1-t1-1))/2)*c[arr[i]] + (-((s2-i)*(s2-i-1))/2-((i-t2)*(i-t2-1))/2+((s2-t2)*(s2-t2-1))/2)*c[j];
                if(diff>0) {
                    arr[i] = j;
                    goto label1;
                }
            }
        }
    }
    label2:
    for(i = 0; i < d; ++i) {
        cout<<(arr[i]+1)<<"\n";
    }
 
 
    return 0;
}

Measured memory_bytes: 3560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		
		int n, a, b, c, x, count;
		while(!(string = reader.readLine()).equals("0 0 0 0 0")){
			n = Integer.valueOf(string.split(" ")[0]);
			a = Integer.valueOf(string.split(" ")[1]);
			b = Integer.valueOf(string.split(" ")[2]);
			c = Integer.valueOf(string.split(" ")[3]);
			x = Integer.valueOf(string.split(" ")[4]);
			count = 0;
			
			ArrayList<Integer> que = new ArrayList<Integer>();
			string = reader.readLine();
			for(int i = 0; i < n; i++){
				que.add(Integer.valueOf(string.split(" ")[i]));
			}
			
			while(true){
				if(que.get(0) == x) que.remove(0);
				if(count > 10000){
					count = -1;
					break;
				}
				x = (a * x + b) % c;
				if(que.isEmpty()) break;
				count++;
			}
			System.out.println(count);
		}
		reader.close();
	}
}

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

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

  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<ll> MIN(N);
  vector<ll> MAX(N);
  MIN[0] = A[0];
  MAX[N-1] = A[N-1];

  for (int i = 1; i < N; i++) {
    MIN[i] = min(MIN[i - 1], A[i]);
  }

  for (int i = N - 2; i >=0; i--) {
    MAX[i] = max(MAX[i + 1], A[i]);
  }

  ll ans = -1e10;
  for (int i = 0; i < N - 1; i++) {
    ans = max(ans, MAX[i + 1] - MIN[i]);
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 7592
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	long long d;
	cin>>n>>d;
	long long i;
	long long xi;
	long long yi;
	long long ans=0;
	for ( i=1; i<=n; i++) {
	     cin>>xi>>yi;
	     if (d*d>=(xi*xi+yi*yi)){
	     	 ans++;
	     }
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
const int AMAX = 100000; 
using namespace std;
#define rep(i, n) for (i64 i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define down(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
using LL = long long;
using ULL = unsigned long long;
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;
}
 
int main()
{
   LL n,a;
  cin >> n;
  vector<LL> l;
   rep(i,n){
   cin >> a;
     l.pb(a);
   }
  a=0;
   SORT(l);
   REVE(l);
   rep(i,n){
    for(int j = i+1;j<n;j++){
     for(int k = j+1;k<n;k++){
   if(l[i]<l[j]+l[k])
      {
                              a++;
    }
     }
    }
   }
                              cout << a;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <climits>

using namespace std;
typedef long long ll;
typedef pair<string, int> P;

//const ll p10[11] = {1LL, 10LL, 100LL, 1000LL, 10000LL, 100000LL, 1000000LL, 10000000LL, 100000000LL, 1000000000LL, 10000000000LL};

int N;
//map<vector<int>, int> mp[2];
unordered_map<string, int> mp[2];

void bfs(const string& start, const int idx) {

  mp[idx][start] = 0;
  queue<P> Q;
  Q.push(P(start, 0));
  while(!Q.empty()) {
    
    //vector<int> now = Q.front().first;
    const string now = Q.front().first;
    const int cost = Q.front().second;
    Q.pop();
    
    const int ncost = cost+1;
    if(ncost >= 5) continue;
    
    for(int i=0; i<N; i++) {
      for(int j=i+1; j<=N; j++) {
        /*
          撃墜ケース N = 10
        ll next = 0;
        for(int k=N-1; k>=0; k--) {
          if(i <= k && k <= j) {
            (next *= 10) += (now / p10[j-k+i]) % 10;
          }
          else {
            (next *= 10) += (now / p10[k]) % 10;
          }
        }
        */
        //cout << "(" << i << ", " << j << ") : " << now << " " << next << endl;
        string next = now;
        reverse(next.begin()+i, next.begin()+j);
        unordered_map<string, int>::iterator it = mp[idx].find(next);
        if(it != mp[idx].end()) {
          if(it->second < ncost) {
            continue;
          }
        }
        mp[idx][next] = ncost;
        Q.push(P(next, ncost));
      }
    }
  }
}

int main() {
  
  cin >> N;
  string str; str.resize(N);
  for(int i=0; i<N; i++) {
    int in; cin >> in;
    str[i] = 'a'+in;
  }
  
  bfs(str, 0);

  sort(str.begin(), str.end());
  bfs(str, 1);
  
  int ans = N-1;
  for(auto i : mp[0]) {
    unordered_map<string, int>::iterator it = mp[1].find(i.first);
    if(it != mp[1].end()) {
      ans = min(ans, i.second+it->second);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 219164
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    if N % 1000 == 0:
        print(0)
    else:
        print(1000 - N%1000)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9464
#include <iostream>

using namespace std;

long long gcd(long long a,long long b)
{
    if(!b) return a;
    else return gcd(b,a%b);
}

long long cnt(long long a,long long b,long long d)
{
    return (b/d)-((a-1)/d);
}

int main()
{
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << (b-a+1)-cnt(a,b,c)-cnt(a,b,d)+cnt(a,b,c*d/gcd(c,d)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <functional>
#include <set>
#include <string>
#include <stdlib.h>
#include <iomanip>
#include <utility>
 
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i = a;i<=b;i++)
#define ll long long int
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define iii pair<ii,int >
#define ff first
#define ss second
#define vi vector<int>
#define vc vector<char>
 
using namespace std;
const int MAXN = (int)2e5 + 4;
ll st[4*MAXN];
void init(){
	FOR(i,4*MAXN)st[i] = 0;
}
ll sum(ll a,ll b){
	return a+b;
}
void update(int node,int ss,int se,int i,ll val){
	if( i > se or i < ss)return;
	
	if(ss == se){
		st[node] = val;
		//cout << "value set" << endl;
		return;
	}
	int mid = (ss+se)/2;
	update(node*2+1,ss,mid,i,val);
	update(node*2+2,mid+1,se,i,val);
	st[node] = max(st[node*2+1] , st[node*2+2]);
}
ll get(int node,int ss,int se,int qs,int qe,bool ok){
	if(qs > se or qe < ss)return 0;
	if(qs <= ss and se <= qe)return st[node];
	int mid = (ss+se)/2;
	ll a= get(node*2+1,ss,mid,qs,qe,ok);ll b = get(node*2+2,mid+1,se,qs,qe,ok);
	if(a != 0 and b != 0 and ok){
	//	cout << ss << " " << se << " " << qs << " " << qe << endl;
	}
	return max(a,b);
}

int main(){	
	int n;
	cin >> n;
	int h[n];
	ll a[n];
	FOR(i,n)cin >> h[i];
	FOR(i,n)cin >> a[i];
	init();
	ll dp[n];
	FOR(i,n)dp[i] = 0;
	ll mx = 0;
	FOR(i,n){
		//FOR(i,n+1)cout << get(0,0,MAXN-1,i,i,1) <<" ";cout << endl;
		dp[i] = a[i] + get(0,0,MAXN-1,0,h[i],0);
		mx = max(mx,dp[i]);
		//cout << "update : " << h[i] << " " << dp[i] << endl;
		update(0,0,MAXN-1,h[i],dp[i]);
		//FOR(i,n+1)cout << get(0,0,MAXN-1,i,i,1) <<" ";cout << "LALAL " <<endl;

	}
	//FOR(i,n)cout << dp[i] << " ";cout << endl;
	cout << mx << endl;

	return 0;
}

Measured memory_bytes: 10368
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int M = sc.nextInt();

		int[] A = new int[N];

		int[] B = new int[M];

		int[] C = new int[N];

		for(int i=0;i<N;i++) {

			A[i] = sc.nextInt();
		}

		for(int i=0;i<M;i++) {

			B[i] = sc.nextInt();
		}

		Arrays.fill(C, 0);

		int a,b;

		for(int i=0;i<M;i++) {

			b = B[i];

			for(int j=0;j<N;j++) {

				a = A[j];

				if(a<=b) {

					C[j]++;

					break;
				}
			}
		}

		int r = 0;

		int ans = 0;

		for(int i=0;i<N;i++) {

			if(C[i]>r) {

				r = C[i];

				ans = i;
			}
		}

		System.out.println(ans+1);
	}

}



Measured memory_bytes: 33376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = (int)1e5 + 10;
string s;
int n;
bool ok[maxN];
void bad() {
    cout << -1;
    exit(0);
}
vector < pair < int, int > > ans;
int main() {
    ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);
    cin >> s;
    n = s.size();
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') ok[i + 1] = false;
        else ok[i + 1] = true;
    }
    if (ok[n] == true) {
        bad();
    }
    for (int i = 1; i <= n - 1; i++) {
        if (ok[i] != ok[n - i]) bad();
    }
    if (ok[1] == false) {
        bad();
    }
    vector < int > good;
    for (int i = 1; 2 * i <= n; i++) {
        if (ok[i]) good.push_back(i);
    }
    good.push_back(n);
    for (int i = 0; i + 1 < good.size(); i++) {
        ans.emplace_back(make_pair(i + 1, i + 2));
    }
    int sz = good.size() + 1;
    for (int i = 0; i + 1 < good.size(); i++) {
        int dif = good[i + 1] - good[i] - 1;
        for (int j = 0; j < dif; j++) {
            ans.push_back(make_pair(i + 2, sz));
            sz++;
        }
    }
    for (auto t : ans) {
        cout << t.first << " " << t.second << '\n';
    }
    return 0;
}

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

int main(void){
    int A,B,C;
    cin>>A>>B>>C;
    int coin_per_week=7*A+B;
    int day=0;

    day=(C/coin_per_week)*7;
    int rest=C%coin_per_week;
    if(rest==0){;}
    else if(rest<=A){day+=1;}
    else if(rest<=2*A){day+=2;}
    else if(rest<=3*A){day+=3;}
    else if(rest<=4*A){day+=4;}
    else if(rest<=5*A){day+=5;}
    else if(rest<=6*A){day+=6;}
    else{day+=7;}
    cout<<day<<endl;
    return 0;
}



Measured memory_bytes: 3108
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

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

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 79776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, m, s, t, h;
  ll g = 9999999999999;
  in3(a, b, m);
  vector<ll> c(a), d(b);
  rep(i, a)
    in(c[i]);
  rep(i, b)
    in(d[i]);
  rep(i, m){
    in3(s, t, h);
    g = min(g, c[s - 1] + d[t - 1] - h);
  }
  s = t = 999999999999;
  rep(i, a)
    s = min(s, c[i]);
  rep(i, b)
    t = min(t, d[i]);
  g = min(g, s + t);
  out(g);
  memi;
}

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

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1<<30;
const ll MOD = 1e9+7;

int main(){
	map<string, int> mp;
	int n;
	cin>>n;
	int maxi = 0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(mp.count(s) == 0)
			mp[s] = 1;
		else
			mp[s]++;
		maxi = max(maxi, mp[s]);
	}
	map<string, int>::iterator it;
	vector<string> ans;
	for(it = mp.begin();it!=mp.end();it++){
		if(it->second == maxi){
			ans.pb(it->first);
		}
	}
	sort(ans.begin(), ans.end());
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<"\n";
	}
	return 0;
}

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

ll dp[45][450][450];

int main(){
  int n,ma,mb;
  int a[50],b[50],c[50];
  int i,j,k;
  int suma = 0;
  int sumb = 0;

  scanf("%d %d %d", &n, &ma, &mb);
  for(i = 0;i < n;i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    suma += a[i];
    sumb += b[i];
  }

  for(i = 0;i <= n;i++){
    for(j = 0;j <= suma;j++){
      for(k = 0;k <= sumb;k++) dp[i][j][k] = 100100100100;
    }
  }

  dp[0][0][0] = 0;
  for(i = 0;i < n;i++){
    for(j = 0;j <= suma;j++){
      for(k = 0;k <= sumb;k++){
        dp[i + 1][j][k] = min(dp[i + 1][j][k],dp[i][j][k]);
        dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]],dp[i][j][k] + c[i]);
      }
    }
  }

  ll ans = 100100100100;

  for(i = 1;i <= suma;i++){
    for(j = 1;j <= sumb;j++){
      if(mb*i == ma*j) ans = min(ans,dp[n][i][j]);
    }
  }

  if(ans == 100100100100) printf("-1\n");

  else printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 65152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
	// TODO Auto-generated method stub
		String[]	params = null;

		while ((params = parseParams()) != null) {
			Stack<String>	stack = new Stack<String>();
			
			for(String param:params) {
				try {
					Double.parseDouble(param);
					stack.push(param);
				} catch (NumberFormatException e) {
					double	val2 = Double.parseDouble(stack.pop());
					double	val1 = Double.parseDouble(stack.pop());
					String	res  = calc(param, val1, val2);
					if (res != null) {
						stack.push(res);
					}
				}
			}

			System.out.println(stack.pop());
		}
	}

	private	static String calc(String sign, double val1, double val2) {
		String	result = null;
 
		if (sign.equals("+")) {
			result = String.format("%.6f", val1 + val2);
		}
		else if (sign.equals("-")) {
			result = String.format("%.6f", val1 - val2);
		}
		else if (sign.equals("*")) {
			result = String.format("%.6f", val1 * val2);
		}
		else if (sign.equals("/")) {
			result = String.format("%.6f", val1 / val2);
		}
		 
		return result;
	}
 
	private static String[] parseParams() {
		String[]	params = null;
		String		strIn  = null;
 
		if ((strIn = parseStdin()) != null) {
			params = strIn.split(" ");
		}
		 
		return params;
	}
 
	private static String parseStdin() {
        String  stdin = null;
        
        try {
       		stdin = br.readLine();
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 17308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		// ?????°?????\???
		while (true) {

			int mid = sc.nextInt();
			int fnl = sc.nextInt();
			int ret = sc.nextInt();

			if(mid == -1 && fnl == -1 && ret == -1)
				break;

			if( mid == -1 || fnl == -1){

				System.out.println("F");

			} else if(mid + fnl >= 80){

				System.out.println("A");

			} else if (mid + fnl < 80 && mid + fnl >= 65){

				System.out.println("B");

			} else if (mid + fnl < 65 && mid + fnl >= 50){

				System.out.println("C");

			} else if (mid + fnl < 50 && mid + fnl >= 30){

				if(ret >= 50){

					System.out.println("C");

				} else {

				System.out.println("D");

				}

			} else if (mid + fnl < 30){

				System.out.println("F");

			}
		}
		sc.close();
	}
}

Measured memory_bytes: 26368
def is_prime(q):
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(5, q-1, q)*pow(7, q-1, q) == 1
    
s = [561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831]
b = [5,7]
for i in range(2,10**5):
  if i in s:
    continue
  if is_prime(i):
    b.append(i)

a = set([2*i-1 for i in b])
b = set(b)
chk = sorted(list(a&b))
 
from bisect import bisect,bisect_left
import sys
input = sys.stdin.readline
 
q = int(input())
for i in range(q):
  l,r = map(int,input().split())
  print(bisect(chk,r)-bisect_left(chk,l))

Measured memory_bytes: 5520
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[5];
        for(int i=0;i<5;i++){
            a[i] = sc.nextInt();
        }
        int k=sc.nextInt();

        for(int i=0;i<4;i++){
            for(int j=i+1;j<5;j++){
                if(Math.abs(a[i]-a[j])>k){
                    System.out.println(":(");
                    return;
                }
            }
        }
        System.out.println("Yay!");
    }
}

Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef unsigned long long ll;

const int MAX = 2e6 + 5;

int n,p[MAX],dp[MAX],cnt=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	dp[0] = 0; dp[1] = 0;
	cin>>n;
	REP(i,n){
		cin>>p[i];
	}
	REP(i,n){
		if(i == 0)
			dp[0] = p[i];
		else{
			if(p[i] >= dp[i-1]){
				dp[i] = dp[i-1];
				cnt++;
			}
			else
				dp[i] = p[i];
		}
	}
	cout<<n-cnt<<endl;
	return 0;
}


Measured memory_bytes: 5120
//15-7
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int club[100005];
vector<int> friends[100005];

bool check(int person){
    bool re = false;
    for(int i=0; i<friends[person].size(); i++){
        int tmp = friends[person][i];
        if(club[tmp] == club[person]){

        }
        else if(club[tmp] == -1){
            club[tmp] = club[person];
            re = (re | check(tmp));
        }
        else{
            re = true;
        }
        if(re) return re;
    }
    return re;
}

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    for(int i=0; i<N+1; i++){
        club[i] = -1;
    }
    
    bool flg = true;
    for(int i=0; i<K; i++){
        if(flg == false){
            int a,b,c;
            cin >> a >> b >> c;
            continue;
        }
        int tmp;
        cin >> tmp;
        if(tmp == 1){
            int a,b;
            cin >> a >> b;
            friends[a].push_back(b);
            friends[b].push_back(a);
            bool state = false;
            if(club[a] != -1) state = (state | check(a));
            if(club[b] != -1) state = (state | check(b));
            if(state){
                cout << i+1 << endl;
                flg = false;
                continue;
            }
        }
        else{
            int c,x;
            cin >> c >> x;
            if(club[c] != -1 && club[c] != x){
                cout << i+1 << endl;
                flg = false;
                continue;
            }
            club[c] = x;
            bool state = check(c);
            if(state){
                cout << i+1 << endl;
                flg = false;
                continue;
            }
        }
    }
    if(flg) cout << 0 << endl;

    return 0;
}



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

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

// o=0: add, o=1: mul
int f(const vector<string> &str, int i=0, int d=0, int o=0){
  vector<int> cand;
  for(int j=i; j<str.size(); j++){
    const string &s=str[j];
    int k=0;
    while(s[k]=='.') k++;
    if(k==d) cand.push_back(j);
    else if(k<d) break;
  }
  int ret=o;
  for(int j: cand){
    const char ch=str[j][d];
    if(o==0){
      if(ch=='+') ret+=f(str, j+1, d+1, 0);
      else if(ch=='*') ret+=f(str, j+1, d+1, 1);
      else ret+=(ch-'0');
    }else{
      if(ch=='+') ret*=f(str, j+1, d+1, 0);
      else if(ch=='*') ret*=f(str, j+1, d+1, 1);
      else ret*=(ch-'0');
    }
  }
  return ret;
}

int main(){

  while(true){
    int n; cin>> n;
    if(n==0) break;
    vector<string> str(n);
    rep(i, n) cin>> str[i];
    cout<< f(str)<< endl;
  }

  return 0;
}

/*

  *
  .+
  ..2
  ..3
  .4
  .+
  ..5
  ..6

  (2+3)*4+(5+6)

*/


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

int main(){
    ll n = 0, s = 0, w = 0, e = 0;
    string S;
    cin >> S;
    rep(i, 0, S.size()){
        if(S[i] == 'N') n++;
        if(S[i] == 'S') s++;
        if(S[i] == 'E') e++;
        if(S[i] == 'W') w++;
    }
    string ans = "Yes";
    if(n == 0 && s > 0) ans = "No";
    if(s == 0 && n > 0) ans = "No";
    if(e == 0 && w > 0) ans = "No";
    if(w == 0 && e > 0) ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq

n = int(input())
hq = []
for _ in range(n):
    start, end = map(int, input().split())
    heapq.heappush(hq, (end, start))

ans = 0
time = 0
while len(hq) > 0:
    end, start = heapq.heappop(hq)
    if time < start:
        time = end
        ans += 1

print(ans)



Measured memory_bytes: 19088
import java.util.*;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long res = 0;
        for (int i = 0; i < S.length();) {
            long a = 0;
            long b = 0;
            while (i < S.length() && S.charAt(i) == '<') {
                a++;
                i++;
            }
            while (i < S.length() && S.charAt(i) == '>') {
                b++;
                i++;
            }
            res += a*(a-1)/2 + b*(b-1)/2 + Math.max(a, b);
        }
        System.out.println(res);
    }
    
}


Measured memory_bytes: 28196
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 3141

int dp[N][N][2];

int n;
int arr[3141];

int get(int start,int end,int chance)
{
	if(start>end)return 0;
	//if(start==end)return arr[start];

	int&ans=dp[start][end][chance];
	if(ans!=MOD*MOD)return ans;

	if(chance==0)
	{
		ans=max(arr[start]+get(start+1,end,1),arr[end]+get(start,end-1,1));

	}
	else ans=min(get(start+1,end,0)-arr[start],get(start,end-1,0)-arr[end]);
	return ans;
}

signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    forn(i,0,3000)forn(j,0,3000)forn(k,0,1)dp[i][j][k]=MOD*MOD;
	cin>>n;
	forn(i,1,n)cin>>arr[i];
//	forn(i,1,n)cout<<arr[i]<<" ";nl;
	
	cout<<get(1,n,0);
	
	
    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 147840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();

		for(;;) {
			c -= b;

			if(c <= 0) {
				System.out.println("Yes");
				break;
			}

			a -= d;

			if(a <= 0) {
				System.out.println("No");
				break;
			}
		}
	}
}


Measured memory_bytes: 35816
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;cin>>N;
  vector<long>A(N);for(int i=0;i<N;i++)cin>>A[i];
  long ans=0;
  ans+=A[0]/2;A[0]%=2;
  for(int i=1;i<N;i++){
    ans+=(A[i]+A[i-1])/2;A[i]=min((A[i]+A[i-1])%2,A[i]);
  }
  cout<<ans;
}

Measured memory_bytes: 1024
/*
 * OfficialHouse.c
 *
 *  Created on: 2015/02/12
 *      Author: Takanori Hasegawa
 */

#include <stdio.h>

int roomcalc(int a[],int f,int r,int v){
	return a[(f-1)*10+(r-1)] += v;
}

int ShowArray(int a[]){
	int i;
	for(i=0;i<9;i++){
		printf(" %d",a[i]);
	}
	printf(" %d\n",a[i++]);
	for(i=10;i<19;i++){
		printf(" %d",a[i]);
	}
	printf(" %d\n",a[i++]);
	for(i=20;i<29;i++){
		printf(" %d",a[i]);
	}
	printf(" %d\n",a[i++]);

	return 0;
}

void printSHARP(){
	int i;
	for(i=0;i<20;i++){
		printf("#");
	}
	printf("\n");
}

int main(void){
	int a[30]={0},b[30]={0},c[30]={0},d[30]={0};
	int i=0,j,h,l;
	int e=0,f=0,r=0,v=0;
	int n=0;


	scanf("%d",&n);
	while(i<n){
		scanf("%d %d %d %d",&e,&f,&r,&v);

		switch(e){
			case 1:
				roomcalc(a,f,r,v);
				break;

			case 2:
				roomcalc(b,f,r,v);
				break;

			case 3:
				roomcalc(c,f,r,v);
				break;

			case 4:
				roomcalc(d,f,r,v);
				break;
		}
	i++;
	e=0;f=0;r=0;v=0;
	}
	ShowArray(a);
	printSHARP();
	ShowArray(b);
	printSHARP();
	ShowArray(c);
	printSHARP();
	ShowArray(d);

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int a[10];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    memset(a,0,sizeof(a));
    for(int i=0;i<k;i++){
        int p;
        scanf("%d",&p);
        a[p]++;
    }
    while(true){
        int m=n,flag=1;
        while(m){
            int j=m%10;
            if(a[j]){
                flag=0;
                break;
            }
            m/=10;
        }
        if(flag){
            printf("%d\n",n);
            break;
        }
        else n++;
    }
}


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

using namespace std;

int main()
{
  string s,t;

  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  if ( s < t ) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1
cnt = 0
#####################################

for i in range(0,n):
    minj = i
    for j in range(i,n):
        if A[j] < A[minj]:
            minj = j
    if(A[i] != A[minj]):
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
        cnt += 1

#####################################
for k in range(0,len(A)-1):
    print(A[k],end=" ")
print(A[len(A)-1])
print (cnt)

Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
vector<int> a, g[212345];

int dp[212345], ans[212345];

void dfs(int u, int par) {
	int idx = lower_bound(dp, dp + N, a[u]) - dp;
	int pre = dp[idx];
	dp[idx] = a[u];
	ans[u] = lower_bound(dp, dp + N, INF) - dp;
	
	for (int v : g[u]) if (v != par) dfs(v, u);
	dp[idx] = pre;
}

int main() {
	cin >> N;
	a.resize(N);
	REP(i, N) scanf("%d", &a[i]);
	REP(i, N - 1) {
		int u, v;
		scanf("%d %d", &u, &v);
		--u; --v;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	
	fill(dp, dp + N, INF);
	dfs(0, -1);
	
	REP(i, N) printf("%d\n", ans[i]);
	
	return 0;
}


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

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

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

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

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

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

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

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


ll a[10000007];

void solve() {
    ll K; cin >> K;
    a[0] = 0;
    rep1(i, 9*K){
        a[i] = a[i-1]*10+7;
        a[i] %= K;
        if(a[i] == 0){
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
}

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


Measured memory_bytes: 78064
//Princess's Marriage
#include<bits/stdc++.h>
using namespace std;

bool mysort(const pair<int, int> &s, const pair<int, int> &t){
  if(s.second!=t.second)return s.second > t.second;
  return s.first > t.first;
}

int main(){
  while(true){
    int N, M;
    cin>>N>>M;
    if(N==0&&M==0)break;
    vector<pair<int, int> > v;
    for(int i=0; i<N; i++){
      int D, P;
      cin>>D>>P;
      v.push_back(pair<int, int>(D, P));
    }
    sort(v.begin(), v.end(), mysort);
    int ans=0;
    for(int i=0; i<N; i++){
      if(M>=v[i].first){M-=v[i].first;}
      else{
        ans+=(v[i].first-M)*v[i].second;
        M=0;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1328
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int m,f,r;
	sctd(m,f,r);
	while(m!=-1 || f!=-1 || r!=-1)
	{
		int x=m+f;
		if(m==-1 || f==-1)
		{
			printf("F\n");
		}
		else if(x>=80)
		{
			printf("A\n");
		}
		else if(x>=65 && x<80)
		{
			printf("B\n");
		}
		else if(x>=50 && x<65)
		{
			printf("C\n");
		}
		else if(x>=30 && x<50)
		{
			if(r>=50)
			printf("C\n");
			else
			printf("D\n");
		}
		else
		printf("F\n");
		
		sctd(m,f,r);
	}
	return 0;
}

Measured memory_bytes: 3160
import Control.Monad
import Control.Applicative


main :: IO ()
main = do
  n <- readLn
  [d,x] <- map read . words <$> getLine
  ls <- replicateM n readLn
  print $ x + solve d ls

solve :: Int -> [Int] -> Int
solve _ [] = 0
solve 0 _ = 0
solve d (b:bs) = let m = div (d-1)  b +1 in m + solve d bs

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int k, s;
	cin>>k>>s;
	ll ans = 0;
	for(int i = 0; i <= k; i++)
	{
		for(int j = 0; j <= k; j++)
		{
			int z = s-i-j;
			if(z>=0&&z<=k) ans++;
		}
	}
	cout<<ans<<'\n';
}


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

int main()
{
  int n,k;cin>>n>>k;
  string S;cin>>S;
  
  S[k-1]+='a'-'A';
  
  for (int i=0;i<n;i++)
    cout<<S[i];
  cout<<endl;
}

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

int main() {
    int X;

    cin >> X;

    int happy = 0;

    while(X >= 500) {
        X-= 500;
        happy += 1000;
    }

    while(X >= 5) {
        X-= 5;
        happy += 5;
    }

    cout << happy << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;


int main()
{
	int n,t = 100000;
	cin >> n;

	for (int i = 0; i < n; i++){
		t = t + t*0.05 ;
		if (t % 1000 != 0){
			t = t - (t % 1000)+1000;
		}
	}

	cout << t << endl;
	return 0;
}

Measured memory_bytes: 1160
list_in=list(map(int,input().split()))
N=list_in[0]
M=list_in[1]

list_item= list(map(int,input().split()))
count = 0
threshold = sum(list_item) / (4 * M)
for item in list_item:
    if item >= threshold:
        count = count + 1

if count >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060