akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int m,n,o,i,j,k;
    float f,g,h;
    char c;
    //string a;
    //cin>>m;
    cin>>m>>n>>i>>j;
    //cin>>f>>g;
    //cin>>c;
    cout<<(m-i)*(n-j);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
a = [int(input())-1 for _ in range(N)]

pushed = [False] * N
now = 0
ret = 0
while True :
    if pushed[now] :
        print(-1)
        break
    if now == 1 :
        print(ret)
        break
    pushed[now] = True
    now = a[now]
    ret += 1

Measured memory_bytes: 44124
A, B, C, D = gets.chomp.split(' ').map(&:to_i)

lcm = C.lcm(D)
primes = B - A

div_candidates = [C, D, lcm].map { |i|
  size = B - A + 1
  times = size / i
  offset = i - A % i
  times + (size%i > offset ? 1 : 0)
}

size = B - A + 1
size -= div_candidates[0]
size -= div_candidates[1]
size += div_candidates[2]

puts size


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

using namespace std;

int main(){
	int x,i;
	i=0;
	while(1){
		cin>>x;
		if(x==0)
			break;
		i++;
		cout<<"Case"<<" "<<i<<":"<<" "<<x<<endl;
	}
	return 0;
}

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

int dist[1010][1010];

int main(){
    int H, W;
    queue<pair<int, int>> que;
    const int dh[4] = {1, 0, -1, 0};
    const int dw[4] = {0, 1, 0, -1};
    string A[1010];

    cin >> H >> W;
    for(int h=0;h<H;h++) cin >> A[h];
    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            dist[h][w] = -1;
            if(A[h][w] == '#'){
                que.push(pair<int, int>(h, w));
                dist[h][w] = 0;
            }
        }
    }

    int max_dist = 0;
    while(!que.empty()){
        pair<int, int> hw = que.front(); que.pop();
        for(int i=0;i<4;i++){
            int next_h = hw.first + dh[i];
            int next_w = hw.second + dw[i];
            if(0 <= next_h && next_h < H && 0 <= next_w && next_w < W && dist[next_h][next_w] == -1 && A[next_h][next_w] == '.'){
                dist[next_h][next_w] = dist[hw.first][hw.second] + 1;
                max_dist = max(max_dist, dist[next_h][next_w]);
                que.push(pair<int, int>(next_h, next_w));
            }
        }
    }
    cout << max_dist << endl;
    return 0;
}

Measured memory_bytes: 13456
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll cnt[100010];
int main()
{
	int N;
	cin >> N;
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll A;
		cin >> A;
		cnt[A]++;
		ans += A;
	}
	int Q;
	cin >> Q;
	while (Q--) {
		ll B, C;
		cin >> B >> C;
		ans += C * cnt[B];
		ans -= B * cnt[B];
		cnt[C] += cnt[B];
		cnt[B] = 0;
		cout << ans << endl;
	}
}

Measured memory_bytes: 4364
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();

		//int[] a = new int[n];
		int[] b = new int[n];


		for(int i =0 ; i<n-1;i++) {
			b[i] = sc.nextInt();
		}
		b[n-1]=-1;



		long sum = 0;
		for(int i =1;i<n-1;i++) {
			sum+=Math.min(b[i-1], b[i]);
		}
		sum+=b[0];
		sum+=b[n-2];



		System.out.println(sum);
	}
}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/

Measured memory_bytes: 21844
#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)
typedef long long ll;
using ll = long long;
using vi = vector<int>;

int main()
{
    int ans = 0;
    vi a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if((a[1]-a[0])%2 == 1) {
        a[1]++;
        a[2]++;
        ans++;
    }
    ans += (a[1] - a[0]) / 2;
    ans += a[2]-a[1];
    cout << ans << endl; 
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 string s;
  cin>>s;
  int sum = 0;
  for(int i=0;i<s.length();i++)
  {
    sum+=(s[i]-'0');
  }
  if(sum%9==0)
    cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cout << fixed << setprecision(30);

  int n;
  cin >> n;

  long long sx = 0, sy = 0, ans = 0;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i].first >> p[i].second;
    sx += p[i].first;
    sy += p[i].second;
  }

  sort(p.begin(), p.end(), [&](auto a, auto b) {
    return atan2(a.first, a.second) < atan2(b.first, b.second);
  });

  auto val = [&](long long a, long long b) {
    return a * a + b * b;
  };

  for (int i = 0; i < n; ++i) {
    long long cx = 0, cy = 0; 
    for (int j = i; j < n; ++j) {
      cx += p[j].first, cy += p[j].second;
      ans = max(ans, val(cx, cy));       
      ans = max(ans, val(sx - cx, sy - cy));
    }
  }

  cout << sqrt(ans) << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	int N, M, D, count;
	cin >> N >> M >> D;
	vector<string> S(N);
	rep(i, N) cin >> S[i];
	ll ans = 0;
	rep(i, N)
	{
		rep(j, M-D+1)
		{
			count = 0;
			if(S[i][j]=='.')
			{
			    while(S[i][j+count]=='.')
			    {
				    count++;
				    if(j+count>M-1) break;
			    }
			    if(count-D>=0) ans += count - D + 1;
			    j += count;
		    }
	    }
	}
	rep(i, M)
	{
		rep(j, N-D+1)
		{
			count = 0;
			if(S[j][i]=='.')
			{
			    while(S[j+count][i]=='.')
			    {
				    count++;
				    if(j+count>N-1) break;
			    }
			    if(count-D>=0)
			    {
				    ans += count - D + 1;
				    j += count;
			    }
			}
		}
	}
	cout << ans << endl;
}



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

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

    for (int i = 0; i < S.size(); i++){
        S.at(i) = (S.at(i) - 'A' + N) % 26 + 'A';
    }

    cout << S << endl;

}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define MAX_N 200005

ll factorial[MAX_N];
void make_factorial_tableMOD(){
    factorial[0] = 1;
    for(int i = 1; i < MAX_N; i++){
        factorial[i] = factorial[i-1]*i%MOD;
    }
}

ll bisection_powerMOD(ll x,ll y){
    if(y==0)        { return 1; }
    ll t = bisection_powerMOD(x*x%MOD,y/2);
    if(y%2==1)      { t = t*x%MOD; }
    return t;
}

ll nCrMOD(int n, int r){
    if(n<r || n<=0 || r<0){return 0;}
    ll a = factorial[n];
    ll b = a*bisection_powerMOD(factorial[r],(MOD-2))%MOD;
    ll c = b*bisection_powerMOD(factorial[n-r],MOD-2)%MOD;
    return c % MOD;
}

int main(){
    ll n, k;
    cin >> n >> k;

    if(n==1 && k==1){
        cout << 1 << endl;
        return 0;
    }
    
    make_factorial_tableMOD();
    for(int i = 1; i <= k; i++){
        ll val1 = nCrMOD(n-k+1,i);
        ll val2 = nCrMOD(k-1,i-1);
        ll ans = val1 * val2;
        ans %= MOD;
        cout << ans << endl;
    }
    return 0;

}


Measured memory_bytes: 1792
using System;
using System.IO;

class Solve
{
    static void Main(string[] args) {
        var N = int.Parse(Console.ReadLine());
        var L = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Array.Sort(L);
        var answer = 0;
        for (int i = 0; i < N - 2; i++) {
            for (int j = 1; j < N - 1; j++) {
                if (j < i) continue;
                if (i == j || L[i] == L[j]) continue;
                for (int k = 2; k < N; k++) {
                    if (k < j) continue;
                    if (j == k || L[j] == L[k]) continue;
                    if (L[i] + L[j] <= L[k]) break;
                    answer++;
                }
            }
        }
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 27536
import java.util.Scanner;

/**
 * https://abc061.contest.atcoder.jp/tasks/abc061_d
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		Node[] nodeList = new Node[N];
		Edge[] edgeList = new Edge[M];
		for(int i=0; i<N; i++) nodeList[i] = new Node(i);
		for(int i=0; i<M; i++){
			Node a = nodeList[Integer.parseInt(sc.next())-1];
			Node b = nodeList[Integer.parseInt(sc.next())-1];
			long c = Long.parseLong(sc.next());
			edgeList[i] = new Edge(a,b,-c);
		}
		sc.close();
		
		long cost = getSingleSourceMinimumCostByBellmanFordMethod(edgeList, nodeList, nodeList[0], nodeList[N-1]);

		System.out.println(cost == Long.MIN_VALUE ? "inf" : -cost);
	}
	
	static long getSingleSourceMinimumCostByBellmanFordMethod(Edge[] edgeList, Node[] nodeList, Node start, Node end){
		for(Node n: nodeList){
			n.cost = n == start ? 0 : Long.MAX_VALUE;
		}
		for(int i=0; i<nodeList.length-1; i++){
			for(Edge e: edgeList){
				if(e.from.cost < Long.MAX_VALUE && e.to.cost > e.from.cost + e.cost){
					e.to.cost = e.from.cost + e.cost;
				}
			}
		}
		for(int i=0; i<nodeList.length; i++){
			for(Edge e: edgeList){
				if(e.from.cost < Long.MAX_VALUE && e.to.cost > e.from.cost + e.cost){
					if(e.to == end) return Long.MIN_VALUE;
					e.to.cost = e.from.cost + e.cost;
				}
			}
		}
		return end.cost;	
	}
	
	static class Node{
		int id;
		long cost;
		Node(int id){
			this.id = id;
		}
	}
	
	static class Edge{
		Node to;
		Node from;
		long cost;
		Edge(Node from, Node to, long cost){
			this.to = to;
			this.from = from;
			this.cost = cost;
		}
	}

}

Measured memory_bytes: 28908
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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

	class State {
		int i;
		int parent;
		int j;// in next step,go into g[i][j]

		public State(int i_, int parent_, int j_) {
			i = i_;
			parent = parent_;
			j = j_;
		}
	}

	int strongly_connected_componets(ArrayList<Integer>[] g, int[] col) {
		int n = g.length;
		Arrays.fill(col, -1);
		int cols = 0;
		int[] low = new int[n];
		int[] ord = new int[n];
		boolean[] marked = new boolean[n];
		Arrays.fill(low, -1);
		Arrays.fill(ord, -1);
		int order = 0;
		ArrayDeque<State> stk = new ArrayDeque<>();
		ArrayDeque<Integer> pnd = new ArrayDeque<>();
		for (int ii = 0; ii < n; ++ii) {
			if (ord[ii] == -1) {
				stk.add(new State(ii, -1, 0));
			}
			while (!stk.isEmpty()) {
				State s = stk.pollFirst();
				if (ord[s.i] == -1) {
					low[s.i] = (ord[s.i] = order++);
					pnd.addFirst(s.i);
				}
				if (s.j > 0 && s.parent != g[s.i].get(s.j - 1) && !marked[g[s.i].get(s.j - 1)]) {
					if (low[g[s.i].get(s.j - 1)] == -1) {
						throw new AssertionError();
					}
					low[s.i] = Math.min(low[s.i], low[g[s.i].get(s.j - 1)]);
				}
				if (s.j == g[s.i].size() && low[s.i] == ord[s.i]) {
					while (true) {
						int v = pnd.pollFirst();
						col[v] = cols;
						marked[v] = true;
						if (v == s.i)
							break;
					}
					++cols;
					continue;
				}
				if (s.j == g[s.i].size())
					continue;
				int v = g[s.i].get(s.j);
				stk.addFirst(new State(s.i, s.parent, s.j + 1));
				if (ord[v] == -1) {
					stk.addFirst(new State(v, s.i, 0));
				} else if (!marked[v]) {
					low[s.i] = Math.min(low[s.i], low[v]);
				}
			}
		}
		return cols;
	}

	@SuppressWarnings("unchecked")
	public void run() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int V = sc.nextInt();
		int E = sc.nextInt();
		ArrayList<Integer>[] g = new ArrayList[V];
		for (int i = 0; i < V; ++i) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < E; ++i) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			g[s].add(t);
		}
		int[] col = new int[V];
		strongly_connected_componets(g, col);
		int q = sc.nextInt();
		while (q-- > 0) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			System.out.println(col[u] == col[v] ? "1" : "0");
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 100836
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[]a = new int[n];
		int p = 1;
		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		scan.close();

		for(int i = 0; i < n; i++) {
			p = lcm(p, a[i]);
		}
		System.out.println(p);
	}
	static int gcd(int n, int m) {
		if(n > m) {
			return gcd(m, n);
		}
		int k = m % n;
		if(k == 0) {
			return n;
		}else {
			return gcd(n, k);
		}
	}
	static int lcm(int n, int m) {
		return n * m / gcd(n, m);
	}
}


Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  map <ll, ll> score;
  rep(i, n) {
    cin >> v.at(i);
    if (score.count(v.at(i))) score.at(v.at(i))++;
    else score[v.at(i)] = 1;
  }
  sort(v.begin(), v.end());
  if (v.at(0)==1 && score.at(1)==1) cout << 1 << endl;
  else if (v.at(0) == 1) cout << 0 << endl;
  else {
    ll res = 0, max = v.at(n-1);
    vector <bool> used(1000000, 1);
    rep(i, n) {
      if (used.at(v.at(i)-1)) {
        if (score.at(v.at(i)) == 1) res++;
        for (ll j = v.at(i)-1; j < max; j += v.at(i)) used.at(j) = 0;
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 17288
//在庫少すぎて悲しい
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;
const int INF=1e9;
const int N=4500;
int dp[N][N];
 
int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,x,y;
  cin>>n>>x>>y;
  vector<int> a(n),b(n),c(n);
  rep(i,n) cin>>a[i]>>b[i]>>c[i];
  fill(dp[0],dp[N],INF);
  dp[0][0]=0;
  rep(t,n){
    rrep(i,N-100)rrep(j,N-100) MN(dp[i+a[t]][j+b[t]],dp[i][j]+c[t]);
  }
  int re=INF;
  rep(i,N)rep(j,N)if(i&&j) if(i*y==j*x) MN(re,dp[i][j]);
  cout<<(re==INF?-1:re)<<endl;
  return 0;
}



Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, c;
  string b;
  cin >> a >> b >> c;
  if (b == "+") {
    cout << a + c << endl;
  }
  else if (b == "-") {
    cout << a - c << endl;
  }
}

Measured memory_bytes: 256
// Chat tam phan
#include <bits/stdc++.h>
using namespace std;
vector<pair<double,double>> p;
int n;


double dis(pair<double,double> u,pair<double,double> v){
    return sqrt((u.first - v.first)*(u.first - v.first) + (u.second - v.second)*(u.second - v.second));
}

double f(double x,double y){
    double ans = 0;
    for (auto pp : p) ans = max(ans,dis(pp,make_pair(x,y)));
    return ans;
}


double g(double y){
    double lef = 0, rig = 1000;
    for (int Loop = 0; Loop < 1000; Loop++){
        double x1 = (lef*2 + rig)/3;
        double x2 = (lef + 2*rig)/3;
        if (f(x1,y) < f(x2,y)) rig = x2;
        else lef = x1;
    }
    return f(lef,y);
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    p.resize(n);
    for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;

    double lef = 0, rig = 1000;
    for (int Loop = 0; Loop < 100; Loop++){
        double y1 = (2*lef + rig)/3;
        double y2 = (lef + 2*rig)/3;
        if (g(y1) < g(y2)) rig = y2;
        else lef = y1;
    }
    cout << fixed << setprecision(10) << g(lef);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  double d,t,s;cin>>d>>t>>s;
  
  if(d/s<=t){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}



Measured memory_bytes: 3728
from sys import stdin
input = stdin.readline

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

n = int(input().rstrip())
a = list(map(int, input().rstrip().split()))

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

for i in range(n-1):
    ans += a[i] * s[n-2-i]

ans = ans % MOD

print(ans)


Measured memory_bytes: 31564
import sys
input = sys.stdin.buffer.readline

INF = 10**18

class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.seg = [ide_ele]*2*self.num
        # set_val
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        # built
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

    def update(self, k, x):
        k += self.num
        self.seg[k] = x
        while k:
            k = k >> 1
            self.seg[k] = self.segfunc(self.seg[2*k], self.seg[2*k+1])

    def query(self, l, r):
        if r <= l:
            return self.ide_ele
        l += self.num
        r += self.num
        res = self.ide_ele
        while l < r:
            if r & 1:
                r -= 1
                res = self.segfunc(res, self.seg[r])
            if l & 1:
                res = self.segfunc(res, self.seg[l])
                l += 1
            l = l >> 1
            r = r >> 1
        return res

def main():

    n, x = map(int,input().split())
    A = list(map(int,input().split()))

    seg = SegTree(A, INF, min)
    ans = INF
    for k in range(n):
        t = k*x
        for i in range(n):
            if k <= i:
                t += seg.query(i-k, i+1)
            else:
                t += min(seg.query(0, i+1), seg.query(n-(k-i), n))
        ans = min(t, ans)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 70008
a,b,c = gets.split.map(&:to_i)
c = c * Math::PI / 180
puts s = a * b * Math.sin(c) / 2
puts l = a + b + Math.sqrt(a ** 2 + b ** 2 - 2 * a * b * Math.cos(c))
puts h = b * Math.sin(c)

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

public class Main {
  private static long solve(int n, int[] as) {
    long total = 0;
    for (int a : as) {
      total += a;
    }
    long sum = 0;
    long answer = Long.MAX_VALUE;
    for (int i = 0; i < n - 1; i++) {
      sum += as[i];
      answer = Math.min(answer, Math.abs(total - 2 * sum));
    }
    return answer;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] as = reader.nextInt(n);
    out.println(solve(n, as));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 45556
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline void goodbye(const T& val) { cout << val << endl; exit(0); }

void solve()
{
	auto n = fetch<int>();
	vector<int> a(n);

	for(auto& x: a)
		cin >> x;

	int smallest = *min_element(a.begin(), a.end());
	int biggest = *max_element(a.begin(), a.end());

	if(biggest - smallest > 1)
		goodbye("No");

	if(biggest == smallest)
		goodbye(biggest <= n / 2 || biggest == n - 1 ? "Yes" : "No");

	int cnt_small = 0;

	for(auto& x: a)
		cnt_small += (x == smallest);

	int cnt_big = n - cnt_small;
	int groups = biggest - cnt_small;

	goodbye(groups <= cnt_big / 2 && cnt_big > 1 && groups > 0 ? "Yes" : "No");
}

int main()
{
	fast_io();
	solve();

	return 0;
}


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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		long x[] = new long[3];
		int a=0, b=0;
		
		for(int i=0; i<3; i++){
			x[i] = sc.nextLong();
			if (x[i]==5){
				a++;
			}
			else if (x[i]==7){
				b++;
			}
		}
		
		if(a==2 && b==1){
			System.out.println("YES");
		}
		else {
			System.out.println("NO");

		}
		
		
//		System.out.println(num[0]);


	}
}


Measured memory_bytes: 9932
import sys

def main():
    N = int(input())
    A = list(map(lambda i: int(i), input().split(' ')))
    count = 0
    while True:
        for index, a in enumerate(A):
            if a % 2 == 0:
                A[index] = a // 2
            else:
                print(count)
                sys.exit()
        count += 1
    print(count)

main()


Measured memory_bytes: 2940
a,b,c = (int(x) for x in input().split())
if(b<a):
    tmp = b
    b = a
    a = tmp
if(c<b):
    tmp = c
    c = b
    b = tmp
if(b<a):
    tmp = a
    a = b
    b = tmp

print(a,b,c)




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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int A, B, C;
  cin >> A >> B >> C;

  cout << min({C, B/A}) << endl;

  return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,operator,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
N = I()
A = LI()
count = collections.Counter(A)
for i in range(N):
    print(count[i+1])


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

using namespace std;

typedef long long ll;

ll d[1000004];

int main() {
    ll n, k; scanf("%lld%lld",&n,&k);
    for (ll i=0; i<n; i++) scanf("%lld",&d[i]);
    sort(d, d+n);
    ll sum=0;
    for (ll i=0; i<n-k; i++) sum+=d[i];
    printf("%lld",sum);
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int s1 = a * b;
    int s2 = c * d;

    int s;
    if (s1 >= s2) {
        s = s1;
    } else {
        s = s2;
    }

    cout << s << endl;

    return 0;
}

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

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            M, T, P, R = map(int, raw_input().split())
            if (M, T, P, R) == (0, 0, 0, 0):
                break
            record = [[[], [], 0, i] for i in range(T+1)]
            for i in range(R):
                m, t, p, j = map(int, raw_input().split())
                if j == 0:
                    record[t][0].append(p)
                    record[t][2] += m + 20 * record[t][1].count(p)
                else:
                    record[t][1].append(p)
            record = [(len(correct), time, team) for correct, wrong, time, team in record[1:]]
            record.sort(key=lambda x: (x[0], -x[1], x[2]), reverse=True)
            ans = str(record[0][2])
            prev = (record[0][0], record[0][1])

            for elem in record[1:]:
                if (elem[0], elem[1]) == prev:
                    ans += '='
                else:
                    ans += ','
                ans += str(elem[2])
                prev = (elem[0], elem[1])
            print ans
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 4756
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

ll dp[1<<17],cost[1<<17];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,i;
    cin>>n;
    ll a[n][n],sum=0,cmask,s;
    ifr(i,0,n) ifr(j,0,n) cin>>a[i][j];
    ifr(mask,0,1<<n) ifr(i,0,n) ifr(j,i,n)
        if(((mask>>i)&1) && ((mask>>j)&1))
            cost[mask]+=a[i][j];
    ifr(mask,0,1<<n) {
        cmask = (((1<<n)-1) ^ mask);
        for(s=cmask;s>0;s=(s-1)&cmask)
            dp[mask|s] = max(dp[mask|s],dp[mask]+cost[s]);
    }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}

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

int main(void)
{
    int i;
    scanf("%d",&i);
    while (i > 0){

    if (i % 10 == 7)
    {
        printf("Yes");
        return (0);
    }
    else
        i /= 10;
    }
    printf("No");
    return (0);
}


Measured memory_bytes: 1736
#include <stdio.h>
#define MAX 17

int xy[MAX][MAX]={0};
int dx[2]={0,1};
int dy[2]={1,0};
int a,b;

void init(int a,int b){
	int i,j;
	for(i=1;i<=a;i++){
		for(j=1;j<=b;j++){
			xy[i][j]=0;
		}
	}
	xy[a][b]=2;
}

int solve(int x,int y){
	int ans=0;
	int i;
	for(i=0;i<2;i++){
		if( x+dx[i] > a || y+dy[i] > b ){}
		else if( xy[x+dx[i]][y+dy[i]]==2 ) return 1;
		else if( xy[x+dx[i]][y+dy[i]]==1 ){}
		else
		ans+=solve(x+dx[i],y+dy[i]);
	}
	return ans;
}

int main(void)
{
	int n,i;
	int x,y;
	int ans;
	
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0 && b==0) break;
		init(a,b);
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&x,&y);
			xy[x][y]=1;
		}
		
		ans=solve(1,1);
		
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()	{
       int n,l=0;
       long long x,y,d;
       cin>>n>>d;
       while(n--){
          cin>>x>>y; 
       
       
         if(x*x+y*y<=d*d){
            l+=1;
         }
       }
     cout<<l<<endl;
 return 0;        
}      


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int n,ans[10000];
char ch;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>ch;
        if(ch=='I') ans[i]=ans[i-1]+1;
        if(ch=='D') ans[i]=ans[i-1]-1;
    }
    sort(ans+1,ans+n+1);
    if(ans[n]>=0) cout<<ans[n]<<endl;
    else cout<<0;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
            int hpT = Integer.parseInt(sc.next());
            int atkT = Integer.parseInt(sc.next());
            int hpA = Integer.parseInt(sc.next());
            int atkA = Integer.parseInt(sc.next());

            String win = ""; 

            while(hpT > 0 && hpA > 0){
                hpA -= atkT;
                if(hpA <= 0){
                    win = "takahashi";
                    break;
                } 

                hpT -= atkA;
                if(hpT <= 0){
                    win = "aoki";
                    break;
                }
            }

            if(win.equals("takahashi")) System.out.println("Yes");
            else if(win.equals("aoki")) System.out.println("No");

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin>>n;
    cout<<n*(n-1)/2<<"\n";
    return 0;
}


Measured memory_bytes: 256
N, K = gets.split(' ').map(&:to_i)
A = gets.split(' ').map(&:to_i)

require 'pp'
def debug obj
  # PP.pp obj, STDERR
end
debug [N,K]
debug A
sum = 0
sumA = A.map{|a| sum += a }
bt_list = []

(0..(N)).to_a.combination(2) do |l,r|
  bt_list.push(((sumA[r] || 0) - sumA[l]).abs)
end

bt_list.sort!.reverse!
debug bt_list

r = 0

max = sumA.last

maxlog = Math.log2(max).to_i
maxlog.downto(0) do |i|
  count = 0
  ra = r + (1 << i)
  bt_list.each_with_index do |bt, j|
    if ra == ( ra & bt )
      count += 1
      if count >= K
        r = ra
        break
      end
    end
    # if (bt_list.size - j -1) < K - count
    #   break
    # end
  end
end

puts r

Measured memory_bytes: 11696
# include <iostream>
# include <iomanip>

int main() {
	int n;
	std::cin >> n;
	long int min, max, sum, x;
	min = 1000000;
	max = -1000000;
	sum = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> x;
		if (x < min)
			min = x;
		if (x > max)
			max = x;
		sum += x;
	}
	std::cout << min << " " << max << " " << sum << std::endl;
	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int max_len;
int Ds[32];
int myans[32];
ll memo[32][32][2][2];

int dfs(int l, int r, int lc, int rc){
    if(l == r){
        if(rc * 10 == Ds[l] + lc) return 10;
        else return 0;
    }else if(r < l){
        if(lc != rc) return 0;
        else return 1;
    }
    if(memo[l][r][lc][rc] != -1) return memo[l][r][lc][rc];
    int ret = 0;
    for(int d=0;d<=9;d++){
        int a = Ds[l] + d + lc;
        int nlc = a / 10;
        a %= 10;
        if(r == max_len-1 && a == 0) continue;
        int nrc = d - ((a + Ds[r]) - 10 * rc);
        if(nrc == 0 || nrc == 1){
            myans[l] = d;
            myans[r] = a;
            ret += dfs(l+1, r-1, nlc, nrc);
        }
    }
    memo[l][r][lc][rc] = ret;
    return ret;
}

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

    max_len = 0;
    while(D > 0){
        Ds[max_len++] = D % 10;
        D /= 10;
    }

    memset(memo, -1, sizeof(memo));
    int ans = dfs(0, max_len-1, 0, 0);
    for(int i=0;i<20;i++){
        memset(memo, -1, sizeof(memo));
        Ds[max_len++] = 0;
        ans += dfs(0, max_len-1, 0, 0);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def d_knight():
    X, Y = [int(i) for i in input().split()]

    if (abs(X) + abs(Y)) % 3 != 0 or Y > 2 * X or 2 * Y < X:
        return 0

    n = (abs(X) + abs(Y)) // 3
    k = -1
    for x in range(n, 2 * n + 1):
        if Y == 3 * n - x:
            k = x - n
            break

    class Combination(object):
        """参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb"""
        __slots__ = ['mod', 'factorial', 'inverse']

        def __init__(self, max_val_arg: int = 10**6, mod: int = 10**9 + 7):
            fac, inv = [1], []
            fac_append, inv_append = fac.append, inv.append

            for i in range(1, max_val_arg + 1):
                fac_append(fac[-1] * i % mod)

            inv_append(pow(fac[-1], mod - 2, mod))

            for i in range(max_val_arg, 0, -1):
                inv_append((inv[-1] * i) % mod)

            self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]

        def combination(self, n, r):
            if n < 0 or r < 0 or n < r:
                return 0
            return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod
    return Combination().combination(n, k)

print(d_knight())

Measured memory_bytes: 90036
#include <iostream>

using namespace std;

int main()
{
    
    int N;
    cin >> N;
    
    if(N % 1000 == 0){
        cout << 0 << endl;
    }
    else{
        cout << 1000 - (N%1000) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3192
import java.io.*;
import java.math.BigInteger;
import java.util.*;



public class Main {
	

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (2e5);
    static List<Integer>[] edges;
    
	public static void main(String[] args) throws IOException {
		int k = sc.nextInt();
		char[] s = sc.next().toCharArray();
		
		for(int i=0;i<s.length;++i) {
			if(i < k) out.print(s[i]);
			else {
				out.print("...");
				break;
			}
		}
		out.close();
	}

   
}





Measured memory_bytes: 32724
#include<iostream>
#include<algorithm>
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;

int main(){
    long long n,W;
    long long V=0;
    long long w[110],v[110];
    cin>>n>>W;
    for(int i=0;i<n;++i){
        cin>>w[i]>>v[i];
        V+=v[i];
    }

    long long dp[110][100010];
    for(int i=0;i<=n;++i){
        for(int j=0;j<=V;++j){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;++i){
        for(int j=0;j<=V;++j){
            chmin(dp[i+1][j],dp[i][j]);
            if(j>=v[i]) chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
        }
    }

    long long ans=0;
    for(int j=0;j<=V;++j){
        if(dp[n][j]<=W) ans=j;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 81152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="SAT")
        cout<<"1"<<endl;
    else if(s=="SUN")
        cout<<"7"<<endl;
    else if(s=="MON")
        cout<<"6"<<endl;
    else if(s=="TUE")
        cout<<"5"<<endl;
    else if(s=="WED")
        cout<<"4"<<endl;
    else if(s=="THU")
        cout<<"3"<<endl;
    else
        cout<<"2"<<endl;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll Pow_mod(ll a, ll b, ll p){
    ll ans = 1;
    a %= p;
    while (b){
        if (b & 1) ans = (ans * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return (ans % p);
}

int n, k, h, ans;

int main(){
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i ++ ){
        scanf("%d", &h);
        if (h >= k)
            ans ++ ;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
     
     
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;
     
     
int main(){
  ll D;

  cin >> D;

#ifdef DEBUG
  cout << "D = " << D << endl;
#endif

  if(D == 25){
    cout << "Christmas" << endl;
  } else if (D == 24) {
    cout << "Christmas Eve" << endl;
  } else if (D == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else if (D == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  }
  
  return 0;
}


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

const int maxn = 200010;
int n, m, L, sx, sy;
char s[maxn], t[maxn];

int main() {
    scanf("%d %d %d %d %d", &n, &m, &L, &sx, &sy);
    scanf("%s %s", s + 1, t + 1);
    int xl = 1, xr = n, yl = 1, yr = m;
    for (int i = L; i; i--) {
        if (t[i] == 'D') xl--;
        if (t[i] == 'U') xr++;
        if (t[i] == 'R') yl--;
        if (t[i] == 'L') yr++;
        xl = max(xl, 1), xr = min(xr, n);
        yl = max(yl, 1), yr = min(yr, m);
        if (s[i] == 'D') xr--;
        if (s[i] == 'U') xl++;
        if (s[i] == 'R') yr--;
        if (s[i] == 'L') yl++;
        xl = max(xl, 1), xr = min(xr, n);
        yl = max(yl, 1), yr = min(yr, m);
        if (xl > xr || yl > yr) break;
    }
    if (xl <= sx && sx <= xr && yl <= sy && sy <= yr) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    ll n, k, ans = 0;
    scanf("%lld%lld", &n, &k);
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        a[i]--;
    }
    while(k > 0){
        if(k & 1 == 1){
            ans = a[ans];
        }
        vector<int> na(n);
        for(int j = 0; j < n; j++){
            na[j] = a[a[j]];
        }
        a.swap(na);
        k >>= 1;
    }
    ans++;
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 5324
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
n,m = map(int, input().split())

uf = UnionFind(n)

for i in range(m):
    a,b = map(int, input().split())
    uf.union(a-1, b-1)
ans = 0
roots = uf.roots()
cnt = []
for r in roots:
    cnt.append(uf.size(r))
cnt.sort(reverse=True)
ans = cnt[0]
print(ans)

Measured memory_bytes: 20056
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();

        for(int i = 1; i <= 10; i++) {
            if(1000 * i >= N){
                os.println(1000*i-N);
                return;
            }
        }
    }
}

Measured memory_bytes: 26972