akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

int caterpillar(const vector<int>& a, int K) {
   int N = a.size();
   map<int,int> cnt;
   int num = 0;
   int l = 0, r = 0, s = 0;
   int ans = INF;
   for (;;) {
      while (r < N && num < K) {
         if (cnt[a[r++]]++ == 0 && 1 <= a[r-1] && a[r-1] <= K) {
            num++;
         }
      }
      if (num < K) break;
      chmin(ans, r - l);
      if (--cnt[a[l++]] == 0 && 1 <= a[l-1] && a[l-1] <= K) {
         num--;
      }
   }
   return ans;
}

signed main()
{
   int N, K; cin >> N >> K;
   V<int> a(N);
   REP(i, N) {
      cin >> a[i];
   }
   int ans = caterpillar(a, K);
   cout << (ans == INF ? 0 : ans) << endl;

   return 0;
}



Measured memory_bytes: 9848
def solve():
    ret = 0
    most_right = 0
    for left, right in sects:
        if left < most_right:
            continue
        ret += 1
        most_right = right
    print(ret)

if __name__ == "__main__":
    N, M = map(int, input().split())
    sects = []
    for _ in range(M):
        sects.append(list(map(int, input().split())))
    sects.sort(key=lambda x: x[1])
    solve()

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

using namespace std;
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define freopen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
#define var register int
#define F(i, a, b, k) for (var i = a; i <= b; i += k)

const int INF = 0x3f3f3f3f;
const double Pi = acos(-1.0);
const int MOD = 1e9 + 7;

struct Node {
	int x, y;
	Node operator + (const Node t) const {
		return (Node) {x + t.x, y + t.y};
	}
	Node operator - (const Node t) const {
		return (Node) {x - t.x, y - t.y};
	}
	Node operator * (const Node t) const {
		return (Node) {x * t.x - y * t.y, x * t.y + y * t.x};
	}
};

int read();

// Math {{{
inline int mul(int x, int y);
inline int pow(int x, int y);
inline int inv(int t);
// TODO
inline int fft(int *t, int type);
// }}}

/*
// Graph {{{
int top, fi[N], ne[N << 1], to[N << 1], lo[N << 1];
inline void add(int u, int v);
inline void add(int u, int v, int w);
// }}}
*/

int main() {
	int n = read(), k = read();
	if (k == 1) cout << 0 << endl;
	else cout << n - k << endl;
  return 0;
}

int read() {
  int a = 0, c = 0, s = 0;
  while (!isdigit(c = getchar())) s |= c == '-';
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}

// Math {{{
inline int pow(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = (1LL * res * x) % MOD;
		x = (1LL * x * x) % MOD;
		y >>= 1;
	}
	return res;
}

inline int inv(int t) { return pow(t, MOD - 2); }

inline int mul(int x, int y) { return (1LL * x * y) % MOD; }
// }}}

/*
// Graph {{{
inline void add(int u, int v) {
	ne[++top] = fi[u], fi[u] = top, to[top] = v;
}

inline void add(int u, int v, int w) {
	ne[++top] = fi[u], fi[u] = top, to[top] = v, lo[top] = w;
}
// }}}
*/


Measured memory_bytes: 256
def factmod(n):
    a = 1
    d = 1
    while d <= n:
        a *= d
        a %= 10**9+7
        d += 1
    return a

n,m = map(int, raw_input().split())
d = abs(n-m)
if d == 0:
    print (factmod(n) * factmod(m) * 2) % (10**9 + 7)
elif d == 1:
    print (factmod(n) * factmod(m)) % (10**9 + 7)
else:
    print 0


Measured memory_bytes: 2568
import sys
input = sys.stdin.readline
H, N = map(int, input().split())
dp = [float("inf")] * (H + 1)
dp[H] = 0
for _ in range(N):
  a, b = map(int, input().split())
  for x in range(H, -1, -1):
    dp[max(0, x - a)] = min(dp[max(0, x - a)], dp[x] + b)
print(dp[0])

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

int N, A[1000+1][1000+1], idx[1000+1][1000+1];

int memo[1000+1][1000+1], cycle[1000+1][1000+1];
int tsort(auto a, auto b) {
  if(a > b) swap(a, b);
  if(memo[a][b]) return memo[a][b];
  if(cycle[a][b]++) {cout << -1 << endl; exit(0);}
  auto i = idx[a][b] - 1;
  auto j = idx[b][a] - 1;
  auto res = 0;
  if(0 <= i) res = max(res, tsort(a, A[a][i]));
  if(0 <= j) res = max(res, tsort(b, A[b][j]));
  return memo[a][b] = 1 + res;
}

int main() {
  cin >> N;
  for(auto i=0; i<N; ++i) for(auto j=0; j<N-1; ++j) cin >> A[i][j], idx[i][--A[i][j]] = j;
  auto ans = 0;
  for(auto i=0; i<N; ++i) for(auto j=i+1; j<N; ++j) ans = max(ans, tsort(i, j));
  cout << ans << endl;
}


Measured memory_bytes: 16000
import Data.IntMap ((!))
import qualified Data.IntMap as M
import Data.List
import Control.Monad

main = do
 n <- readLn
 as <- map read . words <$> getContents
 putStrLn $ maybe "-1" show (trained n (M.fromAscList (zip [1..] as)))

trained n as = do
 let lg = take n $ unfoldr (\i -> Just (i, as!i)) 1
 guard (elem 2 lg)
 return $ length $ (takeWhile (/=2) lg)

Measured memory_bytes: 46332
import sys
import numpy as np

input = sys.stdin.readline

def minus(a):
    return int(a)-1

M = 10**5
N = int(input())
A = list(map(minus, input().split()))
Q = int(input())


def solve():
    hist = list(np.histogram(A, M, (0, M))[0].astype(int))
    cur = sum(A) + N
    for _ in range(Q):
        b, c = map(minus, input().split())
        dh = hist[b]
        cur += dh*(c-b)
        hist[b] -= dh
        hist[c] += dh
        print(cur)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 38588
n = int(input())

a = [[int(i) for i in input().split()] for j in range(n)]

def happy(n, a):
    d = [[0] * 3 for j in range(n)]
    for i in range(3):
        d[0][i] = a[0][i]

    for i in range(1, n):
        d[i][0] = max(d[i - 1][1], d[i - 1][2]) + a[i][0]
        d[i][1] = max(d[i - 1][0], d[i - 1][2]) + a[i][1]
        d[i][2] = max(d[i - 1][0], d[i - 1][1]) + a[i][2]

    return max(d[n - 1])

print(happy(n, a))


Measured memory_bytes: 44148
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 998244353ll;
const dou pi=3.141592653589793*2;

int main(){
    dou a,b,h,m;
    std::cin >> a>>b>>h>>m;
    dou t1=0.5*m+30*h,t2=6*m;
    dou dd=pi/360;
    //ppri(t1,t2);
    t1*=dd;t2*=dd;
    //ppri(t1,t2);
    dou x=a*cos(t1),y=a*sin(t1);
    dou xx=b*cos(t2),yy=b*sin(t2);
    std::cout <<keta(15)<< sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y)) << std::endl;
    
}

Measured memory_bytes: 4188
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



#define MAX 10

int main() {
	vci dist(MAX);
	int vi, vj; char c;
	
	while (cin >> dist[0]) {
		for_(i, 1, MAX) {
			int d;
			cin>>c>>d;
			dist[i] = dist[i-1] + d;
		}
		cin >>c>> vi>>c >> vj;
		
		double lb = 0.0, rb = (double)dist[MAX-1]/(double)max(vi,vj);
		while (rb-lb>1e-9) {
			double mb = (lb+rb)/2.;			
			double pi = (double)vi*mb, pj = (double)dist[MAX-1] - (double)vj*mb;
			
			if (pi==pj) { lb = mb; break; }
			if (pi < pj) lb = mb;
			else rb = mb;
		}
		
		double p = vi*lb;
		for_(i, 0, MAX) if ((double)dist[i]>=p) {
			cout << i+1 << endl; break;
		}
	}	
	
	return 0;
}

Measured memory_bytes: 1192
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K, cnt[105];

int main(){
  cin >> N >> K;
  for (int i = 0; i < K; i++){
    int D; cin >> D;
    for (int j = 0; j < D; j++){
      int A; cin >> A;
      cnt[A]++;
    }
  }

  int ans = 0;
  for (int i = 1; i <= N; i++){
    if (cnt[i] == 0) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3588
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline--------------------------------------------
    s = input()
    sl = [i for i in s]
    n = len(s) - 1
    sublist = [-1]*n
    anslist = [sl[0]]
    ans = []
    for i in range(1 << n):
        for j in range(n):
            if i >> j & 1:
                sublist[j] = "+"
        for j in range(n):
            if sublist[j] == "+":
                anslist.append("+"+sl[j+1])
            else:
                anslist.append(sl[j+1])
        ans.append(eval("".join(anslist)))
        anslist = [sl[0]]
        sublist = [-1]*n
    print(sum(ans))
#endline===============================================
if __name__ == "__main__":
    main()

Measured memory_bytes: 65900
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;

int n;
ld dp[301][301][301];

ld func(int a,int b,int c){
    int i,j,l;
    if(a==0 && b==0 && c==0) return 0;
    if(dp[a][b][c]!=-1) return dp[a][b][c];
    ld x,y,z;
    j=a+b+c;
    x=(ld)n/(ld)j;
    y=0.0;
    
    if(j==0) return 0;
    
    if(a>0) y= y + a*func(a-1,b,c);
    if(b>0) y= y + b*func(a+1,b-1,c);
    if(c>0) y= y + c*func(a,b+1,c-1);
    
    y= (ld)y/(ld)j;
    x=x+y;
    return dp[a][b][c] = x;
}

int main(){
    cin>>n;
    int i,j,l;
    int a=0,b=0,c=0;
    //memset(dp,-1.0,sizeof(dp));
    for(i=0;i<=n;i++) for(j=0;j<=n;j++) for(l=0;l<=n;l++) dp[i][j][l]=-1;
    for(i=0;i<n;i++){
        cin>>j;
        if(j==1) a++;
        else if(j==2) b++;
        else c++;
    }
    ld ans = func(a,b,c);
    cout<<fixed<<setprecision(20)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 426496
n = int(input())
b_list = list(map(int,input().split()))

dp = [10**8] * n

for i in range(n-1):
    if dp[i] > b_list[i]:
        dp[i] = b_list[i]
    if dp[i+1] > b_list[i]:
        dp[i+1] = b_list[i]
        
print(sum(dp))

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    // Here your code !
    int kumi;
    int start, end;
    int sum = 0;
    
    scanf("%d", &kumi);
    
    for (int i = 0; i < kumi; i++) {
        scanf("%d%d", &start, &end);
        sum = sum + (end - start) + 1;
    }
    
    printf("%d", sum);
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

const int N = 100005;

int n, b[N], up[N], dt[1<<15], ans;

vector<int> er;
vector<pii> adj[N];

void calc (int C, int P) {
	int X = 0;
	for(auto &T : adj[C]) {
		int A, B;
		tie(A, B) = T;
		if(A == P) continue;
		up[A] = B;
		calc(A, C);
		X ^= B;
	}
	if(C && (X^up[C])) {
		X ^= up[C];
		if(b[X]) b[X] = 0;
		else {
			b[X] = 1;
			ans++;
		}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++) {
		int A, B, C;
		scanf("%d%d%d",&A,&B,&C);
		adj[A].push_back({B, C});
		adj[B].push_back({A, C});
	}
	calc(0, -1);
	int X = 0;
	for(int i=0;i<15;i++) {
		if(b[i+1]) X += (1<<i);
	}
	for(int i=1;i<=X;i++) {
		int T = 0;
		for(int j=0;j<15;j++) {
			if(i&(1<<j)) T ^= j+1;
		}
		if(!T) er.push_back(i);
		for(auto &T : er) {
			if((T&i)==T) dt[i] = max(dt[i], dt[i-T]+1);
		}
	}
	printf("%d\n", ans - dt[X]);
}


Measured memory_bytes: 13696
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;

const int MAX = 128;

bool go[2][MAX][MAX];
ll dp[MAX][MAX];

void solve(void){
    int N;
    cin >> N;
    rep(N, meaningless_) {
        int gx, gy, p;
        cin >> gx >> gy >> p;
        memset(go, true, sizeof(go));
        memset(dp, 0LL, sizeof(dp));
        rep(p, i) {
            int lx, ly, rx, ry;
            cin >> lx >> ly >> rx >> ry;
            if (lx == rx) {
                go[0][rx][min(ly, ry)] = false;
            }
            else {
                go[1][min(rx, lx)][ly] = false;
            }
        }
        dp[0][0] = 1LL;
        rep(gx+1, x) rep(gy+1, y) {
            if (go[1][x][y]) dp[x+1][y] += dp[x][y];
            if (go[0][x][y]) dp[x][y+1] += dp[x][y];
        }
        /*
        rep(gy+1, y) {
            rep(gx+1, x) {
                cout << dp[x][y] << ' ';
            }
            cout << endl;
        }*/
        if (dp[gx][gy]) cout << dp[gx][gy] << endl;
        else cout << "Miserable Hokusai!" << endl;
    }
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}



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

int main() {
int a;
  int b;
  int c;
  
  cin >> a;
  cin >> b;
  cin >> c;
  
  
  if( b-a==c-b ) {cout << "YES" <<endl;}
  else {cout << "NO" <<endl;}
}

Measured memory_bytes: 256
def main():
    target = input()
    source = input()
    diff = len(target) - len(source)
    max_change = len(source)
    for i in range(diff+1):
        temp = target[i:len(target)-diff+i]
        change = sum([1 for t, s in zip(temp, source) if(t!=s)])
        if(change < max_change):
            max_change = change
    print(max_change)
if __name__ == '__main__':
    main()

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

bool p[1000000];
void prime() {
  fill(p, p+1000000, true);
  p[0] = false;
  p[1] = false;
  for(int i = 2; i < 1000000; i++) {
    if(p[i]) {
      for(int j = 2; i*j < 1000000; j++) {
	p[i*j] = false;
      }
    }
  }
}

int main() {
  int n;
  prime();

  while(cin >> n, n) {
    int ans = 0;
    for(int i = 2; i <= n/2; i++) {
      if(p[i] && p[n-i]) ans++;
    }
    cout << ans << endl;
  } 
}

Measured memory_bytes: 2136
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int num[]=new int[n];
  boolean b=true;
  int count=0;
  for(int i=0;i<n;i++){
  num[i]=sc.nextInt();
    if(((num[i]/=2)%2)==1)b=false;
  }
  
  while(b){
    if(count==0)
    count++;
  for(int i=0;i<n;i++){
    if(((num[i]/=2)%2)==1)b=false;
  }
    count++;
  }
  System.out.println(count);
}
}

Measured memory_bytes: 21844
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    count = 0
    now = 1
    visited = [-1] * N
    visited[now - 1] = 0 # 町1 は0かいでいける
    while count < K:
        now = A[now - 1]
        count += 1
        if visited[now - 1] == -1:
            visited[now - 1] = count
        else:
            loop = count - visited[now - 1]
            rest = (K - visited[now - 1]) % loop
            #print("resr", rest)
            if rest == 0:
                break
            for i in range(len(visited)):
                if visited[i] == visited[now - 1] + rest:
                    now = i + 1
                    count = K # break
                    break
    #print(visited[0])
    print(now)




    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 32328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author palayutm
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt(), K = in.nextInt();
            long ans = 0;
            for (int i = K + 1; i <= n; i++) {
                for (int j = 0; j * i <= n; j++) {
                    if (i * (j + 1) - 1 <= n) {
                        ans += i - K;
                    } else {
                        ans += Math.max(i - K - (i * (j + 1) - 1 - n), 0);
                    }
                }
            }
            if (K == 0) ans -= n;
            out.println(ans);
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream out) {
            super(out);
        }

        public OutputWriter(Writer out) {
            super(out);
        }

        public void close() {
            super.close();
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

int main(){
	int N;
	vector<pair<int,pair<int,int>>> vec;
	cin>>N;
	
	for(int i=0;i<N;i++){
		int a,b;
		cin>>a>>b;
		vec.push_back(make_pair(a+b,make_pair(a,b)));
	}
	long long A=0;
	long long B=0;
	sort(vec.begin(),vec.end(),greater<pair<int,pair<int,int>>>());
	
	for(int i=0;i<N;i++){
		if(i%2==0){
			A+=vec[i].second.first;
		}
		else{
			B+=vec[i].second.second;
		}
	}
	cout<<A-B<<endl;
	
	
	return 0;
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bool ok = a == b || b == c || a == c;
	if(ok) {
		ok =(a != b) || (a != c);
	}
	cout << (ok ? "Yes" : "No");
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e18 + 7;

ll N, P;
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> res;
	for (ll i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	return res;
}
long long mod_pow(long long x, long long n) {
	if (n == 0) return 1;
	long long res = mod_pow(x*x % MOD, n / 2);
	if (n & 1) res = res * x % MOD;
	return res;
}
int main(void) {
	ll ans = 1;
	cin >> N>> P;
	map<ll, ll> mp = prime_factor(P);
	for (auto ite = mp.begin(); ite != mp.end(); ++ite) {
		if((ite->second / N)>0)ans =ans* mod_pow(ite->first,ite->second/N);
	}
	if (N == 1)ct(P);
	else ct(max(ll(1), ans));
	
	return 0;
}

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

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

	int N, W; cin >> N >> W;
	vector<int> weight(N); vector<int> value(N);
	for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];
	vector<vector<long long> > dp(110, vector<long long>(100010, 0));

	for (int i = 0; i < N; ++i) {
		for (int sum_w = 0; sum_w <= W; ++sum_w) {
			if (sum_w - weight[i] >= 0) {
				dp[i + 1][sum_w] 
					= max(dp[i + 1][sum_w] , dp[i][sum_w - weight[i]] + value[i]);
			}
			dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w]);
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 87296
#define DINGER_GISBAR
#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
#ifdef ZEROKUGI
#include <dumper.hpp>
#define dump(x) dumper::dumper(cerr, __LINE__, (#x), (x), 50, 1, 1)
#define tick(...) dumper::tick(__VA_ARGS__)
#pragma message "Compiling " __FILE__
#else
#define dump(x)
#define tick(...)
#endif
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n) \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)   \
    sort(all(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) { return 1LL << x; }
template <class T>
inline int size(const T& a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
    return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto& x : v) is >> x;
    return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
    bool t = 0;
    for (const T& x : v.first) {
        if (t) os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
        tick(0, 0);
    };
} __before_main;
//}}}TEMPLATE_END

int idx[202020];
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;

    rep(i, n){
        idx[a[i]] = i;
    }

    lint ans = 0;

    set<int> S;
    S.insert(-1);
    S.insert(n);

    for(int x = 1; x <= n; x++){
        int i = idx[x];
        auto it = S.lower_bound(i);
        auto itt = prev(it);
        lint l = i - *itt;
        lint r = *it - i;
        ans += x * l * r;
        S.insert(i);
    }

    cout << ans << endl;
}



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

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N)
    {
        cin >> L[i];
    }
    int ans = 0;

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

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                if (L[i] > L[k] - L[j])
                    ans++;
                else
                    continue;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int n;
  std::cin >> n;
  vector<int> x(n);
  for(int i=0; i<n; i++) std::cin >> x[i];

  long long ans = LLONG_MAX;
  for(int p=1; p<=100; p++){
    long long sum = 0;
    for(int i=0; i<x.size(); i++){
      sum += pow(x[i] - p, 2);
    }
    if( sum < ans ){
      ans = sum;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-14 22:54:55
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;

  vector<string> ans;

  auto DFS = [&](const auto& DFS, string s, char cur) -> void {
    if ((int) s.size() == n) {
      ans.emplace_back(s);
    } else {
      for (char c = 'a'; c <= cur; ++c) {
        if (c != cur) {
          DFS(DFS, s + c, cur);
        } else {
          DFS(DFS, s + c, (char)(cur + 1));
        }
      }
    }
  };

  DFS(DFS, "", 'a');

  sort(all(ans));
  for (auto x : ans) {
    cout << x << '\n';
  }

  return 0;
}

Measured memory_bytes: 7796
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;

int a[200000+50];
 
int main ()
{
	int n,k,i;
	cin>>n>>k;
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++)
	{
		int tmp;
		cin>>tmp;
		a[tmp]++;
	}
	sort(a,a+n);
	int tmp1=0;
	for(i=1;i<=k;i++)
		tmp1+=a[n-i];
	cout<<n-tmp1<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <vector>
#include <iostream>
using namespace std;

double dist(pair<double, double> s, pair<double, double> e){
    double x = s.first - e.first;
    double y = s.second - e.second;
    return sqrt( pow(x,2)+pow(y,2) );
}

vector<pair<double, double>> findMidPoints(pair<double, double> s, pair<double, double> e){
    vector<pair<double, double>> output;
    pair<double, double> s1, t, u;
    s1 = make_pair(s.first + (e.first - s.first)/3, s.second + (e.second - s.second)/3);
    t = make_pair(s.first + 2*(e.first - s.first)/3, s.second + 2*(e.second - s.second)/3);
    double theta;
    if(t.second < s1.second) theta = M_PI/3 -  acos( (t.first - s1.first)/ dist(s1,t) );
    else theta = M_PI/3 +  acos( (t.first - s1.first)/ dist(s1,t) );

    // cout << acos( (t.first - s1.first)/ dist(s1,t) ) << endl;
    u = make_pair(s1.first + cos(theta)*dist(s1,t), s1.second + sin(theta)*dist(s1,t));
    output.push_back(s1);
    output.push_back(u);
    output.push_back(t);
    return output;
}

vector<pair<double, double>> koachCurve(int n, vector<pair<double, double>>& v){
    if(n == 0) return v;
    vector<pair<double, double>> output;
    output.push_back(v[0]);
    vector<pair<double, double>> temp;
    for(int i=0; i<v.size()-1;i++){
        temp = findMidPoints(v[i], v[i+1]);
        output.insert(output.end(), temp.begin(), temp.end());
        output.push_back(v[i+1]);
    }
    n--;
    return koachCurve(n--, output);
}


int main(void){
    int n;
    cin >> n;
    vector<pair<double, double> > v = {make_pair(0.0, 0.0), make_pair(100.0, 0.0)};
    vector<pair<double, double> > output;

    output = koachCurve(n, v);

    for(auto& e: output){
        cout << e.first << " " << e.second << endl;
    }
    return 0;
}



Measured memory_bytes: 3700
#include<stdio.h>
int main()
{
	int a,b,c,end=0;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<=100;i++)
	{
		if((a*i)%b==c)
		{
			end=3;
			break;
		}
	}
	if(end==3)
	printf("YES");
	else
	printf("NO");
	return 0;
}

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

int main() {
  int a,b,temp,d1,d2;
  int ans = 0;
  cin >> a >> b;
  for (int i=a; i<=b; i++) {
    temp = i;
    d1 = temp/10000;
    d2 = (temp%10000)/1000;
    temp %= 100;
    if (temp/10==d2 and temp%10==d1) {
      ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define mod 1000000007LL
 
ll h[100010],f[100010],n,k,tot,ans;
 
inline ll rd()
{
    ll x=0;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar());
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x;
}
 
inline ll ksm(ll x,ll y) { ll res=1LL;for (;y;x=x*x%mod,y>>=1) if (y&1) res=res*x%mod;return res; }
 
int main()
{
    n=rd();k=rd();tot=0;
    int sqrtn=(int)sqrt(n);
    for (int i=1;i<=(int)sqrt(n);i++) if (n%i==0) h[++tot]=i;
    if (n==sqrtn*sqrtn)
    {
        for (int i=1;i<tot;i++) h[tot*2-i]=n/h[i];
        tot=tot*2-1;
    }
    else
    {
        for (int i=1;i<=tot;i++) h[tot*2-i+1]=n/h[i];
        tot<<=1;
    }
    f[1]=ans=k;
    for (int i=2;i<=tot;i++)
    {
        f[i]=ksm(k,(ll)((h[i]+1)>>1));
        for (int j=1;j<i;j++) if (h[i]%h[j]==0) f[i]=(f[i]-f[j]+mod)%mod;
        if (h[i]&1) ans=(ans+f[i]*h[i])%mod;
        else ans=(ans+f[i]*(h[i]>>1))%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

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

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

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

  int zero = 0, one = 0;
  rep(i, S.size()) {
    if (S[i] == '0') {
      zero++;
    } else {
      one++;
    }
  }

  cout << 2 * min(zero, one) << endl;

  return 0;
}


Measured memory_bytes: 512
let even s =
    let n = String.length s in
    if n mod 2 != 0 then false
    else
        let first  = String.sub s 0 (n / 2) in
        let second = String.sub s (n / 2) (n / 2) in
        if first = second then true
        else false;;

let rec solution s =
    let n = String.length s in
    if even s then n
    else solution @@ String.sub s 0 (n - 1);;

Printf.printf "%d\n" @@
Scanf.scanf "%s\n" @@ fun s ->
    solution @@ String.sub s 0 @@ String.length s - 1;;



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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(), p.end());
    p[n-1] /= 2;
    int sum = 0;
    rep(i,n) sum += p[i];
    cout << sum << endl;
}

Measured memory_bytes: 3620
//https://atcoder.jp/contests/abc149/tasks/abc149_b
//B - Greedy Takahashi
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,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 (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll A,B,K; cin>>A>>B>>K;    
    ll a=max(A-K,0LL);
    ll rest=max(K-(A-a),0LL);
    ll b=max(B-rest,0LL);
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define NAME "INPUT"
using namespace std;
ifstream fi (NAME".inp");
ofstream fo (NAME".out");
int main(){
    int k;
    string s;
    cin>>k;
    cin>>s;
    if(k>=s.size())
        cout<<s;
    else{
        for(int i=0;i<k;i++)
            cout<<s[i];
        cout<<"...";
    }
}





Measured memory_bytes: 3600
a=[]#入力画面の二文字を別々の文字に格納
a=input().split(" ")
A=int(a[0])
B=int(a[1])
C=int(a[2])
D=int(a[3])
#最大公約数を作る
def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x % y ==0:
        return y
    else:
        while x % y != 0:
            z=x%y
            x=y
            y=z
        else:
            return z
#最小公倍数を作る
def lcm(m,n):
    return int(m*n/gcd(m,n))

X=lcm(C,D)
Y=B-A+1-(B//D-(A-1)//D)-(B//C-(A-1)//C)+(B//X-(A-1)//X)
print(Y)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	string A, B;
	while (cin >> A >> B) {
		int N = (int)A.size();
		int ans = INF;
		rep(rev, 2) {
			vector<int> distL(N, INF), distR(N, INF);
			rep(i, N) rer(j, i, i + N) if (B[j % N] == '1')
				amin(distR[i], j - i);
			rep(i, N) rer(j, i - N, i) if (B[(j + N) % N] == '1')
				amin(distL[i], i - j);
			rep(shift, N) {
				vector<bool> diff(N);
				vpii dists;
				rep(i, N) {
					diff[i] = A[(shift + i) % N] != B[i];
					if (diff[i])
						dists.emplace_back(distR[i], distL[i]);
				}
				sort(dists.begin(), dists.end());
				int di = (int)dists.size();
				int minl = 0;
				for (int r = N - 1; r >= shift; -- r) {
					for (; di > 0 && dists[di - 1].first > r; -- di)
						amax(minl, dists[di - 1].second);
					if (minl < N) {
						int cost = 0;
						cost += minl * 2 + r + (r - shift);
						cost += (int)dists.size();
						amin(ans, cost);
					}
				}
			}
			reverse(A.begin(), A.end());
			reverse(B.begin(), B.end());
		}
		printf("%d\n", ans == INF ? -1 : ans);
	}
	return 0;
}


Measured memory_bytes: 384
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

typedef long double LD;
const LD EPS = 1e-8;

struct Point {
	long double x;
	long double y;
	long double z;
	int i;
	bool operator < (const Point& p) const {
		return x < p.x || (x == p.x && y < p.y);
	}
};

long double cross(const Point& O, const Point& A, const Point& B) {
	return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
}

vector<Point> convex_hull(vector<Point>& P)
{
	int n = (int)P.size(), k = 0;
	if (n <= 2) {
		return P;
	}
	vector<Point> H(2 * n);
	sort(P.begin(), P.end());
	for (int i = 0; i < n; ++i) {
		while (k >= 2 && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--;
		H[k++] = P[i];
	}
	for (int i = n - 2, t = k + 1; i >= 0; i--) {
		while (k >= t && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--;
		H[k++] = P[i];
	}
	return vector<Point>(H.begin(), H.begin() + k - 1);
}

void circumscribed_circle(LD x1, LD y1, LD x2, LD y2, LD x3, LD y3, LD& cx, LD& cy, LD& r)
{
	LD x21 = x2 - x1, x31 = x3 - x1, y12 = y1 - y2, y13 = y1 - y3;
	cy = (x31 * (x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2) - x21 * (x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3)) /
		(2 * x31 * y12 - 2 * x21 * y13);
	if (fabs(x21) <= EPS) {
		cx = (2 * y13 * cy - x1 * x1 - y1 * y1 + x3 * x3 + y3 * y3) / (2 * x31);
	} else {
		cx = (2 * y12 * cy - x1 * x1 - y1 * y1 + x2 * x2 + y2 * y2) / (2 * x21);
	}
	r = sqrt((x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy));
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1;
		cin >> n;
		if (n <= 0) return 0;
		vector<Point> xy(n);
		for (int i = 0; i < n; ++i) {
			cin >> xy[i].x >> xy[i].y;
			xy[i].i = i;
		}
		LD ans = 1e10;
		vector<Point> ch = convex_hull(xy);
		int sz = ch.size();
		for (int i = 0; i < sz; ++i) {
			for (int j = i + 1; j < sz; ++j) {
				LD cx = (ch[i].x + ch[j].x) * 0.5, cy = (ch[i].y + ch[j].y) * 0.5;
				LD dx = ch[i].x - ch[j].x, dy = ch[i].y - ch[j].y;
				LD r = sqrt(dx * dx + dy * dy) * 0.5;
				auto ok = [&] {
					for (int l = 0; l < sz; ++l) {
						LD dx = ch[l].x - cx;
						LD dy = ch[l].y - cy;
						if (sqrt(dx * dx + dy * dy) > r + EPS) {
							return false;
						}
					}
					return true;
				};
				if (ok()) {
					ans = min(ans, r);
				}
				for (int k = j + 1; k < sz; ++k) {
					circumscribed_circle(ch[i].x, ch[i].y, ch[j].x, ch[j].y, ch[k].x, ch[k].y, cx, cy, r);
					if (ok()) {
						ans = min(ans, r);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
// ABC082B - Two Anagrams

#include <bits/stdc++.h>
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

	if (s < t) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

struct line{
  P a,b;
};

int main(){
  Real ax,ay,bx,by,cx,cy,dx,dy;
  while(~scanf("%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy)){
    line s,t;
    s.a = P(ax,ay);
    s.b = P(bx,by);
    t.a = P(cx,cy);
    t.b = P(dx,dy);
    P vx,vy;
    vx = s.b-s.a;
    vy = t.b-t.a;
    if(EQ(dot(vx,vy)))printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 1200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int K = Integer.parseInt(br.readLine());
		long sum = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				for (int c = 1; c <= K; c++) {
					sum += gcd(a, b, c);
				}
			}
		}
		System.out.println(sum);
	}

	static int gcd(int a, int b, int c) {
		return gcd(a, gcd(b, c));
	}

	static int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}
}

Measured memory_bytes: 25884