akhauriyash/Code-Regression huggingface dataset:
def solve(N, As):
    boxes = [-1 for _ in range(N + 1)]
    for k in range(N, 0, -1):
        s = 0
        for i in range(k + k, N + 1, k):
            s += boxes[i]
        s %= 2

        if s == As[k - 1]:
            boxes[k] = 0
        else:
            boxes[k] = 1
    boxes = boxes[1:]
    # print(boxes)
    m = sum(boxes)
    ans = []
    for i, b in enumerate(boxes):
        if b == 1:
            ans.append(str(i + 1))
    return "\n".join([str(m), " ".join(ans)])


# print(solve(3, [1, 0, 0]))
# print(solve(5, [0, 0, 0, 0, 0]))
# print(solve(5, [0, 0, 0, 0, 1]))
# print(solve(5, [0, 0, 0, 1, 1]))
# print(solve(5, [0, 0, 1, 1, 1]))

# print(solve(4, [0, 0, 0, 0]))
# print(solve(4, [0, 0, 0, 1]))
# print(solve(4, [0, 0, 1, 1]))
# print(solve(4, [0, 1, 1, 1]))

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))


Measured memory_bytes: 16052
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b; cin >> a >> b;
	if(a == 0){
		if(b <= 1911) cout << "M" << b - 1867 << endl;
		else if(b <= 1925) cout << "T" << b - 1911 << endl;
		else if(b <= 1988) cout << "S" << b - 1925 << endl;
		else cout << "H" << b - 1988 << endl;
	}
	else{
		if(a == 1) cout << b + 1867 << endl;
		else if(a == 2) cout << b + 1911 << endl;
		else if(a == 3) cout << b + 1925 << endl;
		else cout << b + 1988 << endl;
	}
	return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;


//int main(){
//  set<string> str;
//  string s;
//  cin>>s;
//  int x;
//  cin>>x;
//  str.insert(s);
//
//  for(int i=0; i<s.size(); i++){
//    string st;
//    for(int j=0; i+j<s.size(); j++){
//
//      int y=0;
//      for(int k=i; k<=j; k++){
//        st[y++]=s[k];
//        cout<<"st["<<y-1<<"] = "<<st[y-1]<<en
//      }
//      cout<<"st = "<<st<<en
//      str.insert(st);
//    }
//  }
//
//  int i=0;
//  for(set<string>::iterator it=str.begin(); it!=str.end(); it++){
//    i++;
//    string ss=*it;
//    cout<<"ss = "<<ss<<en
//    if(i==x) {
//      cout<<ss<<en
//      break;
//    }
//  }
//}


class DisjointSet{
public:
  vector<int> rank,p;
  
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i=0; i<size; i++) makeSet(i);
  }
  
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
  
  void unite(int x, int y){
    if(findSet(x)==findSet(y)) return;
    link(findSet(x),findSet(y));
  }
  
  void link(int x,int y){
    if(rank[x]>rank[y]) p[y]=x;
    else{
      p[x]=y;
      if(rank[x]==rank[y]) rank[y]++;
    }
  }
  
  int findSet(int x){
    if(x!=p[x]) x=findSet(p[x]);
    return x;
  }
};

#define MAX 100005
vector<int> v[MAX];

int main(){
  int n,m;
  int pp[MAX];
  cin>>n>>m;

  DisjointSet ds=DisjointSet(n+1);
  for(int i=1; i<=n; i++) cin>>pp[i];
  for(int i=0; i<m; i++){
    int a,b;
    cin>>a>>b;
    ds.unite(a, b);
  }
    
  
  
  int ans=0;
  for(int i=1; i<=n; i++){
    int atai=pp[i];
    if(atai==i){
      ans++;
      continue;
    }
    if(ds.same(atai, i)){
      ans++;
    }
  }
  
  cout<<ans<<en
  RE
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

int main(){
    ios::sync_with_stdio(false);
    string inp = strin();
    (inp == "ABC") ? puts("ARC") : puts("ABC");
}

Measured memory_bytes: 3568
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        char[] c = scanner.next().toCharArray();
        int white = 0;
        int red = 0;
        for(int i = 0; i < N; i++) {
            if(c[i] == 'W') white++;
            else red++;
        }
        int ret = 0;
        for(int i = 0; i < red; i++) {
            if(c[i] == 'W') ret++;
        }

        System.out.println(ret);
    }
}

Measured memory_bytes: 40616
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int a,b,c,x,y;
    cin >>a>>b>>c>>x>>y;
    int sum=0;
    if(a+b>2*c){//aピザとbピザを1枚ずつ買うより、ABピザを2枚買ったほうが安い
        if(x>=y){
            sum += 2*c*y;
            x -= y;
            if(a<2*c){
                sum += a*x;
            }
            else{
                sum += 2*c*x;
            }
        }
        else{
            sum += 2*c*x;
            y -= x;
            if(b<2*c){
                sum += b*y;
            }
            else{
                sum += 2*c*y;
            }            
        }
    }
    else{
        sum = a*x+b*y;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
n,a,b,c,d = map(int,input().split())

if n%a == 0:
    x = n//a*b
else:
    x = (n//a+1)*b
    
if n%c ==0:
    y = n//c*d
else:
    y = (n//c+1)*d

if x<=y:
    print(x)
else:
    print(y)


Measured memory_bytes: 5596
#include <stdio.h>
int main()
{
    int a,i,j,temp=0;
    scanf("%d",&a);
    for(i=1;i<10;i++)
    {
        for(j=1;j<10;j++)
        {
            if(j*i==a)
                temp=1;
        }
    }
    if(temp)
        printf("Yes\n");
    else
        printf("No\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, C; cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    vector<vector<int>> c(N, vector<int>(N));
    REP(i, 0, C) REP(j, 0, C) cin >> D[i][j];
    REP(i, 0, N) REP(j, 0, N) cin >> c[i][j];

    vector<vector<int>> cnt(3, vector<int>(C, 0));
    REP(i, 0, N) REP(j, 0, N) cnt[(i + j) % 3][c[i][j] - 1]++;

    int ans = 1 << 30;
    REP(i, 0, C) {
        REP(j, 0, C) {
            REP(k, 0, C) {
                if (i == j || j == k || i == k) continue;
                int sum = 0, colors[3];
                colors[0] = i; colors[1] = j; colors[2] = k;
                REP(l, 0, 3) {
                    REP(m, 0, C) {
                        sum += cnt[l][m] * D[m][colors[l]];
                    }
                }
                ans = min(ans, sum);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int n,m,ans;
int main()
{
	n=read(),m=read();
	ans=(n-m)*100+m*1900;
	ans<<=m;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#１文字をインプット
a=int(input())
#1行をint型でインプット
li = list(map(int,input().split()))

#初期値をセット
sum=1

#リストに入っている分だけ掛ける
if 0 in li:#もしリストに0が入っていたら合計を0にして、34行目へ
    sum = 0
else:
    for i in range(a):
        sum = sum*li[i]
        if sum > 10**18:
            break

if sum <= 10**18:#10の18乗以下の場合、答えを出力
    print(sum)
else:#10の18乗を超える場合、'-1'を出力
    print(-1)

Measured memory_bytes: 84552
s = input()
a = s.count("B")
b = s.count("W")
n = len(s)
if a == len(s) or b == len(s):
    print(0)
    exit()
ans = 0
ans2 = 0
for i in range(1,n):
    if s[i] != s[i-1]:
        ans+=1
for i in range(n-2,-1,-1):
    if s[i] != s[i+1]:
        ans2+=1
print(min(ans,ans2))

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
int main()
{
    int h,w,i,j,k;
    int x,y;
    char a[100][100];
    while(scanf("%d%d",&h,&w)!=EOF)
    {  getchar();
        for(i=0;i<h;i++)
            gets(a[i]);
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                k=0;
                if(a[i][j]!='#')
                {
                    for(x=-1;x<2;x++)
                    {
                        for(y=-1;y<2;y++)
                        {
                            if((a[i+x][j+y])=='#')
                                k=k+1;
                        }
                    }
                    a[i][j]=k+'0';
                }
            }
        }
        for(i=0;i<h;i++)
        printf("%s\n",a[i]);
    }
    return 0;
    }

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int A,B,X;
    char op;
    scanf("%d %c %d",&A,&op,&B);
    if(op=='+')
    {
        X=A+B;
        printf("%d\n",X);
    }
    else if(op=='-')
    {
        X=A-B;
        printf("%d\n",X);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<ll>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
bool ok=true;
struct edge{
    int to;
    int cost;
};
using graph=vector<vector<edge>>;
Vi dijkstra(graph _g,ll start){
    Vi dist; //for dijkstra. distance from start
    dist.resize(_g.size()); dist.resize(_g.size());
    rp(i,dist.size())dist[i]=INF;
    auto comp_pq = [](pair<ll,ll> x,pair<ll,ll> y){return x.second > y.second;};
    priority_queue< pair<ll,ll> , vector<pair<ll,ll>>, decltype(comp_pq)> pq{comp_pq};
    dist[start]=0; pq.push(mp(start,0));
    while (pq.size()>0){
        PLL p = pq.top();
        pq.pop();
        if(p.second > dist[p.first])continue;
        rp(i,_g[p.first].size()){
            if(dist[p.first]!=INF){
                if(((dist[p.first]+_g[p.first][i].cost)-dist[_g[p.first][i].to])%2==1) ok=false;
                if(chmin(dist[_g[p.first][i].to],dist[p.first]+_g[p.first][i].cost)){
                    pq.push(mp(_g[p.first][i].to,dist[_g[p.first][i].to]));
                }
            }
        }
    }
    return dist;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int n;
    cin >> n;
    graph G(n);
    rp(i,n){
        string s;
        cin >> s;
        rp(j,n){
            if(s[j]=='1'){
                edge e;
                e.to=j;
                e.cost=1;
                G[i].pb(e);
            }
        }
    }
    ll ans=0;
    rp(i,n){
        Vi dis=dijkstra(G,i);
        sort(all(dis));
        reverse(all(dis));
        chmax(ans,dis[0]);
    }
    if(!ok) print(-1);
    else print(ans+1);
    return 0;
}

Measured memory_bytes: 1056
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX_N = 100000;

int par[MAX_N];
int depth[MAX_N];
vector<int> to[MAX_N];
vector<int> from[MAX_N];

int main()
{
	int t,index,n,m,prev;
	string s;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&index);
		scanf("%d",&m);
		for(int j=0;j<m;j++){
			scanf("%d",&t);
			to[index].push_back(t);
			from[t].push_back(index);
		}
	}
	for(int i=0;i<n;i++){
		if(from[i].empty() == true){
			par[i] = -1;
		}else{
			par[i] = *(from[i].begin());
		}
	}
	fill(depth,depth+n,0);
	for(int i=0;i<n;i++){
		prev = par[i];
		while(prev != -1){
			prev = par[prev];
			depth[i]++;
		}
	}
	for(int i=0;i<n;i++){
		if(par[i] == -1){
			s = "root";
		}else if(to[i].empty() == true){
			s = "leaf";
		}else{
			s = "internal node";
		}
		printf("node %d: parent = %d, depth = %d, ",i,par[i],depth[i]);
		cout << s << ", [";
		vector<int>::iterator it = to[i].begin();
		if(it != to[i].end()){
			printf("%d",*it);
			it++;
		}
		while(it != to[i].end()){
			printf(", %d",*it);
			it++;
		}
		printf("]\n");
	}
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  vi s(n), t(n);
  vector<ull> u(n), v(n);

  rep(i,0,n) cin >> s[i];
  rep(i,0,n) cin >> t[i];

  rep(i,0,n) cin >> u[i];
  rep(i,0,n) cin >> v[i];

  auto solve = [&](vi &rt, vi &ct, vi &rows, vi &cols) -> vvi {
    vvi ans(n, vi(n));
    vi ch(n, n-1);
    rep(i,0,n) {
      if (rt[i] ^ rows[i]) ch[i] = 0;
      if (rows[i]) rep(j,0,n) ans[i][j] = 1;
    }

    rep(j,0,n) {
      if (ct[j] ^ cols[j]) {
        rep(i,0,n) if (ch[i]) {
          if (ans[i][j] != cols[j]) --ch[i];
          ans[i][j] = cols[j];
        }
      } else {
        int mi = 0;
        rep(i,0,n) {
          if (ans[i][j] == cols[j]) {
            mi=-1;
            break;
          }
          if (ch[i] > ch[mi]) {
            mi = i;
          }
        }
        if (mi >= 0 and ch[mi]) {
          ans[mi][j] = cols[j];
          --ch[mi];
        }
      }
    }

    return ans;
  };

  vector<vector<ull>> ans(n, vector<ull>(n));

  rep(i,0,64) {
    vi rt(n), ct(n);
    vi rows(n), cols(n);
    rep(j,0,n) {
      if ((u[j]>>i)&1) rows[j] = 1;
      if ((v[j]>>i)&1) cols[j] = 1;
      rt[j] = s[j];
      ct[j] = t[j];
    }

    vvi bit = solve(rt, ct, rows, cols);
    rep(j,0,n) rep(k,0,n) ans[j][k] |= ull(bit[j][k])<<i;
  }

  bool suc= true;
  rep(i,0,n) {
    ull val = 0;
    if (!s[i]) {
      val = ans[i][0];
      rep(j,0,n) val &= ans[i][j];
      suc &= val == u[i];
    } else {
      rep(j,0,n) val |= ans[i][j];
      suc &= val == u[i];
    }
  }

  rep(j,0,n) {
    ull val = 0;
    if (!t[j]) {
      val = ans[0][j];
      rep(i,0,n) val &= ans[i][j];
      suc &= val == v[j];
    } else {
      rep(i,0,n) val |= ans[i][j];
      suc &= val == v[j];
    }
  }

  if (suc) {
    rep(i,0,n) {
      rep(j,0,n) cout << ans[i][j] << ' ';
      cout << '\n';
    }
  } else {
    cout << -1 << '\n';
  }
}

Measured memory_bytes: 7724
n = int(input())
n_list = list(map(int,input().split()))
a = 0
for i in range(n - 2):
    num = n_list[i:(i + 3)]
    n1 = num[0]
    n2 = num[1]
    n3 = num[2]
    if ((n2 < n1 or n2 < n3) and (n2 > n1 or n2 > n3)):
        a += 1
print(a)

Measured memory_bytes: 3060
from collections import deque
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
def BFS(x,y):
  flag=False
  qu=deque([])
  qu.append([x,y])
  
  while len(qu)!=0:
    d=qu.popleft()
    now_x,now_y=d[0],d[1]
    #print(now_x,now_y)
    #print(now_x==w-1 and now_y==h-1)
    a[now_y][now_x]="."
    if now_x==w-1 and now_y==h-1:
      flag=True
      return flag
      
    if now_y<h-1 and a[now_y+1][now_x]=="#":
      qu.append([now_x,now_y+1])
    if now_x<w-1 and a[now_y][now_x+1]=="#":
      qu.append([now_x+1,now_y])
    if now_y<h-1 and a[now_y+1][now_x]=="#" and now_x<w-1 and a[now_y][now_x+1]=="#":
      return flag
  return flag
flag=BFS(0,0)
for i in a:
  for j in i:
    if j=="#":
      flag=False
if flag:
  print("Possible")
else:
  print("Impossible")

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

void lcs( string X, string Y, ll m, ll n )  
{  
    ll L[m + 1][n + 1];  
    
    memset(L,0,sizeof(L));
      
    
    for (ll i = 1; i <= m; i++)  
    {  
        for (ll j = 1; j <= n; j++)  
        {  
      
        if (X[i - 1] == Y[j - 1])  
            L[i][j] = L[i - 1][j - 1] + 1;  
      
        else
            L[i][j] = max(L[i - 1][j], L[i][j - 1]);  
        }  
    }  
          
    ll ind= L[m][n];  
    
    char A[ind+1];
    A[ind]='\0';
    
    int i = m, j = n; 
    
    while (i >= 0 && j >= 0) 
    { 
	    if (X[i-1] == Y[j-1]) 
	    { 
		    A[ind-1] = X[i-1]; 
		    i--; j--; ind--;	 
	    } 

	    else if (L[i-1][j] > L[i][j-1]) 
		        i--; 
	    else  j--; 
    }
    
    cout << A; 

}  
  

int main()  
{  
    string X,Y;
    cin >>X;
    cin >>Y;  
      
    ll m = X.size();  
    ll n = Y.size();  
      
    lcs( X, Y, m, n );  
      
    return 0;  
}

Measured memory_bytes: 73988
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;

    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> R[i];

    int maxv = -2000000000; // 十分小さい値を初期値に設定
    int minv = R[0];

    for ( int i = 1; i < n; i++ ) { // ここで毎回 R[i] を読み込めば、配列は不要
        maxv = max(maxv, R[i] - minv); // 最大値を更新
        minv = min(minv, R[i]); // ここまでの最小値を保持しておく
    }

    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 3848
#include <stdio.h>

int main(void)
{
	int x;
	int i = 1;
	scanf("%d",&x);
	

	while(x != 0){
	printf("Case %d: %d\n", i, x);
	i++;
	scanf("%d",&x);
	}
	
	


	return 0;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  string s, t;
  cin>>s>>t;
  ll cnt=0;
  rep(i, s.size()) {
    if(s.at(i)!=t.at(i)) cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 3916
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int k = scan.nextInt();

        int result = 0;

        if(a >= k) {
            result += k;
        } else if(a + b >= k) {
            result += a;
        } else {
            result += ( a - (k - a - b));
        }
        
        System.out.println(String.valueOf(result));

    }
}

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

int main() {
    int n,i;
    cin>>n;
    int a[n];
    int s[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=n-1;i>=0;i--)
    {
        if(i==n-1)
        s[i]=0;
        else if(i==n-2)
        s[i]=abs(a[i+1]-a[i]);
        else
        {
            s[i]=min(abs(a[i+1]-a[i])+s[i+1],abs(a[i+2]-a[i])+s[i+2]);
        }
    }
    cout<<s[0]<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = input()
t = s.count("R")*s.count("G")*s.count("B")
for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k < n and s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            t -= 1

print(t)


Measured memory_bytes: 9184
N = int(input())
A = list(map(int, input().split()))
bottom = sum(A)
 
if N == 0:
  if A[0] != 1:
    print(-1)
  else:
    print(1)
  exit()
 
ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)

Measured memory_bytes: 20068
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

signed main(){
	int n,t[10000];
	while(cin >> n,n){
		for(int i = 0;i < n;i++) cin >> t[i];
		sort(t,t + n,greater<int>());
		int res = 0;
		for(int i = 0;i < n;i++){
			res += t[i] * i;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll mod=1e9+7,i,j;
ll n;
ll a[300005];
ll x,y;
int main(){
    cin>>x>>y;
    ll ans=(x*y)/(__gcd(x,y));
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np

def main():
    INF = 10 ** 8
    N = int(input())
    weights = list(map(int, input().split()))
    
    dp_table = [INF] * N
    dp_table[0] = 0
    dp_table[1] = abs(weights[1] - weights[0])
    
    for i in range(2, N):
        dp_table[i] = min(dp_table[i-1] + abs(weights[i] - weights[i-1]), dp_table[i-2] + abs(weights[i] - weights[i-2]))

    print(dp_table[N-1])
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 22744
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let s: String = read();
    let n = s.len();

    let c: Vec<char> = s.chars().collect();

    for i in 0..n {
        if c[i] != c[n - 1 - i] {
            println!("No");
            return;
        }
    }

    for i in 0..n / 2 {
        if c[i] != c[n / 2 - 1 - i] {
            println!("No");
            return;
        }
    }

    for i in 0..n / 2 {
        if c[i + n / 2 + 1] != c[n - 1 - i] {
            println!("No");
            return;
        }
    }

    println!("Yes");
}


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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }
/*
#include <bits/stdc++.h>
using namespace std;
 */
struct BIT {
	vector<int> v;
	int n;

	BIT() { init(); }
	BIT(int size) :n(size){ init(); }

	void init() {
		v.clear();
		v.resize(n + 1);
	}

	int sum(int i, int idx = 1) {
//		idx--; idx *= -1; i += idx;
		int ret = 0;
		while (i) {
			ret += v[i];
			i -= i & -i;
		}
		return ret;
	}

	void add(int i, int x, int idx = 1) {
//		idx--; idx *= -1; i += idx;
		while (i <= n) {
			v[i] += x;
			i += i & -i;
		}
	}
};

int main() {
	int n = in(), q = in();
	BIT bit(n);

	rep(_, q) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if (a)
			printf("%d\n", bit.sum(c) - bit.sum(b - 1));
		else 
			bit.add(b, c);
	}
}

Measured memory_bytes: 3376
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));
		int M = sc.nextInt();
		long N = sc.nextLong();
		long[] a = new long[M+1];
		long all = 1;
		for(int i = 0;i< M;i++){
			a[i] = sc.nextLong();
			all = all * a[i] / gcd(all, a[i]);
		}
		all = all * a[M-1] / gcd(all, a[M-1]);
		sc.close();
		int flag = 0;
		for(int i = 0;i < M;i++){
			if(all/a[i]%2==0){
				System.out.println(0);
				break;
			}else{
				flag++;
			}
		}
		if(flag == M){
			System.out.println((2*N/all+1)/2);
		}
	}


	private static long gcd(long m, long n) {
	   //if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    long r = m%n;
	    return gcd(n, r);
	}
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  char a,b;
  cin>>a>>b;
  string s,t;
  rep(i,a-'0')s+=b;
  rep(i,b-'0')t+=a;
  if(s<t)cout<<s<<endl;
  else cout<<t<<endl;

}

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

int main() {
	int N;
	int P[200010];
	cin >> N;

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

	int min = P[0];
	int count = 0;

	for (int i = 0; i < N; i++) {
		if (P[i] <= min) {
			count++;
			min = P[i];
		}
	}

	cout << count << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int k;
  k = 38;
  // cin>>k;

  int n = k*(k-1)+1;

  vector<vector<int>> v(n);

  rep(i,k) v[i].pb(1);
  rep(i,k)rep(j,k-1) v[i].pb(2+i*(k-1) + j);
  rep(i,k-1) rep(j,k-1) v[k + i*(k-1) + j].pb(2+i);

  rep(i,k-1) rep(j,k-1){
    rep(x,k-1){
      // dbg(1 + i*(k-1) + (x+buff)%(k-1), 2+j*(k-1) + x);
      v[k + i*(k-1)+x].pb(k+1+j*(k-1) + (x + i*j)%(k-1));
    }
  }

  // validation
  // rep(i,n) assert(v[i].size() == k);
  // rep(i,n)rep(j,i+1,n){
  //   set<int> s(all(v[i]));
  //   bool cnt = 0;
  //   for(auto x : v[j]){
  //     if(s.count(x)>0){
  //       cnt++;
  //     }
  //   }
  //   if(cnt!=1){
  //     dbg(i,j,v[i],v[j],cnt);
  //     assert(false);
  //   }
  // }

  cout << n << " " << k << endl;
  for(auto &vv : v){
    rep(i,k) cout << vv[i] << " \n"[i==k-1];
  }

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    string s;cin>>s;
    int err1=0, err2=0;
//    bool isr=s.find('R')!=string::npos, isl=s.find('L')!=string::npos;
    for(int i=1;i<n;i++){
        if(s[i-1]==s[i]){
            err2++;
        }
    }
    // if(s[0]=='L' && isr) err1++;
    // if(s[n-1]=='R' && isl) err1++;
    cerr<<err1<<" "<<err2<<endl;
    // int ans = s.size()-err1-err2*2;
    // int k2 = min(err2, k);
    // k = min(k-k2, 2);
    // ans += k2*2+k;
    // cout<<ans<<endl;
    cout << min(err2+2*k, n-1) <<endl;
}

Measured memory_bytes: 512
N = int(input())
X = []
X_L = []
X_L_dict = {}
for i in range(N):
    x, l = map(int, input().split())
    X_L.append([x-l, x+l])
    X.append(x-l)
X_L.sort(key=lambda x:x[1])
X.sort()

last = None

count = 0
# print(X_L)
for x_l in X_L:
    # print(x_l, last)
    if last is None or last <= x_l[0]:
        count += 1
        last = x_l[1]
print(count)

Measured memory_bytes: 70408
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)
class Point {
public:
	long double x, y;
	Point(long double x = 0, long double y = 0) :x(x), y(y) {}
	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(x*a, y*a); }
	Point operator / (double a) { return Point(x / a, y / a); }
	long double abs() { return sqrt(norm()); }
	long double norm() { return x*x + y*y; }
	bool operator < (const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
	bool operator > (const Point &p) const { return x != p.x ? x > p.x : y > p.y; }
	bool operator == (const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; }
};
struct Segment {
	Point p1, p2;
};
long double norm(Point p) { return p.x*p.x + p.y*p.y; }
long double abs(Point p) { return sqrt(norm(p)); }
double dot(Point a, Point b) {
	return a.x*b.x + a.y*b.y;
}
double cross(Point a, Point b) {
	return a.x*b.y - a.y*b.x;
}
int ccw(Point a, Point b, Point c) {
	Point d = b - a;
	Point e = c - a;
	if (cross(d, e) > EPS) { return 0; }
	if (cross(d, e) < -EPS) { return 1; }
	if (dot(d, e) < -EPS) { return 2; }
	if (dot(d, e) < e.norm()) { return 3; }
	return 4;
}
Point projection(Segment a, Point b) {
	Point sa = a.p2 - a.p1;
	double hyp = dot(b - a.p1, sa); double r = hyp / norm(sa);
	return a.p1 + sa * r;
}
Point reflection(Segment a, Point b) {
	return b + ((projection(a, b) - b)*2.0);
}
int main() {
	Point P1, P2, P3; int q;
	cin >> P1.x >> P1.y >> P2.x >> P2.y;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> P3.x >> P3.y;
		int s = ccw(P1, P2, P3);
		if (s == 0) { cout << "COUNTER_CLOCKWISE" << endl; }
		if (s == 1) { cout << "CLOCKWISE" << endl; }
		if (s == 2) { cout << "ONLINE_BACK" << endl; }
		if (s == 3) { cout << "ONLINE_FRONT" << endl; }
		if (s == 4) { cout << "ON_SEGMENT" << endl; }
	}
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
using namespace std;
const int maxn=1e5+10;
int main()
{
	int n,dp[maxn],a[maxn];
	cin>>n;
	for(int i=1;i<=n;++i)
	 cin>>a[i];
	dp[1]=0;
	dp[0]=0;
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;++i)
	 dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 4360
///
// File:  alds1_5_c.cpp
// Author: ymiyamoto
//
// Created on Mon Oct  9 10:11:20 2017
//

#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

#define PI 3.14159265

struct point_t {
  double x;
  double y;
};

vector<point_t> calc_koch(point_t a, point_t b)
{
  vector<point_t> points;
  point_t s, u, t;
  s.x = (2 * a.x + 1 * b.x) / 3;
  s.y = (2 * a.y + 1 * b.y) / 3;
  t.x = (1 * a.x + 2 * b.x) / 3;
  t.y = (1 * a.y + 2 * b.y) / 3;
  u.x = (t.x - s.x) * cos(PI / 3) - (t.y - s.y) * sin(PI / 3) + s.x;
  u.y = (t.x - s.x) * sin(PI / 3) + (t.y - s.y) * cos(PI / 3) + s.y;

  points.push_back(s);
  points.push_back(u);
  points.push_back(t);

  return points;
}

void rec(vector<point_t> &p, uint32_t n)
{
  for (uint32_t _ = 0; _ < n; _++) {
    vector<point_t> points;

    for (uint32_t i = 0; i < p.size() - 1; i++) {
      vector<point_t> new_points = calc_koch(p[i], p[i + 1]);

      points.push_back(p[i]);
      for (uint32_t i = 0; i < new_points.size(); i++) {
        points.push_back(new_points[i]);
      }
    }
    points.push_back(p.back());
    p.clear();
    for (uint32_t i = 0; i < points.size(); i++) {
      p.push_back(points[i]);
    }
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  vector<point_t> points;
  points.push_back({0.0, 0.0});
  points.push_back({100.0, 0.0});

  rec(points, n);

  for (uint32_t i = 0; i < points.size(); i++) {
    cout << fixed;
    cout << setprecision(8) << points[i].x << " " << points[i].y << endl;
  }

  return 0;
}

Measured memory_bytes: 3296
#!/usr/bin/env python3
import sys


def solve(W: int, a: int, b: int):
    if a < b:
        if a+W >= b:
            return 0
        else:
            return b-(a+W)
    else:
        if b+W >= a:
            return 0
        else:
            return a-(b+W)

# 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    print(solve(W, a, b))

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g,  l, m, n, p, q, r,  t,  y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;
double w,h, x;
int s;
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);

    while(cin>>s>>ch>>w>>ch>>h)
    {
          if(w/(h*h)>=25.00)
          {
              printf("%d\n", s);
          }
    }

    return 0;
}




Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    ll N; cin >> N;
    string ans;
    
    while(N){
        N--;
        ans += ('a' + N%26);
        N /= 26;
    }
    

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


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

int main() {
    int K;
    string S;
    cin >> K;
    cin >> S;
    if(S.size() <= K){
        cout << S << endl;
    }
    else{
        for(int i = 0; i < K; i++){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
}


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

int main() {
  
  int N, L;
  cin >> N >> L;
  vector<string> vec(N);
  for (int i = 0; i < N; i++)
    cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  
  string s = vec.at(0);
  for (int i = 1; i < N; i++)
    s = s + vec.at(i);
  
  cout << s << endl;
  
}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        LinkedList<int> list = new LinkedList<int>();
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            var query = Console.ReadLine().Split();
            if (query[0] == "insert")
            {
                list.AddFirst(int.Parse(query[1]));
            }
            else if (query[0] == "delete")
            {
                list.Remove(int.Parse(query[1]));
            }
            else if (query[0] == "deleteFirst")
            {
                list.RemoveFirst();
            }
            else if (query[0] == "deleteLast")
            {
                list.RemoveLast();
            }
        }

        Console.WriteLine(string.Join(" ", list));
    }
}


Measured memory_bytes: 71576
import java.util.*;
import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(in);
        int N;
        N = scanner.nextInt();
        HashMap<String, Boolean> seen = new HashMap<>();
        String[] words = new String[N+1];
        for(int i = 0; i < N; ++i) {
            words[i] = scanner.next();
        }
        String ans = "Yes";
        for(int i = 1; i < N; ++i) {
            seen.put(words[i-1], true);
            if(words[i].charAt(0) != words[i-1].charAt(words[i-1].length()-1))
                ans = "No";
            if(seen.containsKey(words[i]))
                ans = "No";
        }
        System.out.println(ans);
    }
}

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

int main (){
  int N;
  cin>>N;
  map<string, int> seqLen;
  rep(i,N){
    string S;
    cin>>S;
    seqLen[S] = 1;
  }
    cout << seqLen.size() <<endl;
}


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

bool isSquare(int N){
    int square = sqrt((double)N);//平方数の判定
    if (square * square == N){
        return true;
    }
    else {
        return false;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    for (int i = N; i > 0; --i){
        if (isSquare(i)){
            cout << i << endl; break;
        }
    }

    return 0;
}



Measured memory_bytes: 256
def main():
    N = int(input())
    N1 = N % 10
    hon = [2, 4, 5, 7, 9]
    pon = [0, 1, 6, 8]
    bon = [3]

    if N1 in hon:
        print('hon')
    elif N1 in pon:
        print('pon')
    else:
        print('bon')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
listS = list(input())
listS.sort()

index=0
beforeC=""
while index < len(listS):
    if index ==0:
        beforeC=listS[index]
    else:
        if listS[index] == beforeC:
            print("no")
            break
        else:
            beforeC = listS[index]
    index+=1

if index== len(listS):
    print("yes")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;
llong g[205][205];
const llong INF = 1ll << 60ll;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%1lld", &g[i][j]);
        }
    }

    llong ans = -1;
    for (int i = 0; i < n; i++) {
        queue<llong> que;
        llong d[205] = {};
        for (int j = 0; j < n; j++) d[j] = -1;

        bool f = true;

        d[i] = 0;
        que.push(i);
        while (!que.empty()) {
            llong pos = que.front();
            que.pop();

            for (int j = 0; j < n; j++) {
                if (g[pos][j] == 1) {
                    if (d[j] == -1) {
                        d[j] = d[pos] + 1;
                        que.push(j);
                    }
                    else if (abs(d[j] - d[pos]) != 1) {
                        f = false;
                    }
                }
            }
        }

        if (f) {
            for (int j = 0; j < n; j++) {
                ans = max(ans, d[j] + 1);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
  long long int N,M;
  cin >> N >> M;
  if(N==1&&M==1){
    cout << 1 << endl;
    return 0;
  }
  else if(N==1){
    cout << M-2 << endl;
    return 0;
  }
  else if(M==1){
    cout << N-2 << endl;
    return 0;
  }
  else{
    cout << (M-2)*(N-2) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import statistics
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
  B.append(A[i]-(i+1))
#print(B)
b = statistics.median(B)

s = 0
for i in range(N):
  s += abs(A[i] - (b+i+1))
print(int(s))


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

using namespace std;

int main()
{
   int n;
   cin>>n;
   vector<long long> v;
   long long   xos=0;
   
  for(int i=0;i<n;i++)
  {
      int j;
      cin>>j;
     v.push_back(j);
     
      xos^=j;
      
      
  }
  
 for(int i=0;i<n;i++)
 {
     
     long long val = xos^v[i];
     cout<<val<<" ";
 }
   

   return 0;
}

Measured memory_bytes: 5296
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 5100000;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


//UF木
struct UnionFind {
private:
	vector<int> par, ran, sz;
public:
	UnionFind(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		sz.resize(n, 1);
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y; sz[y] += sz[x];
		}
		else {
			par[y] = x; sz[x] += sz[y];
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int num(int x) { return sz[find(x)]; }
};

int n, k, l;


int main() {

	cin >> n >> k >> l;

	UnionFind uf1(n), uf2(n);

	rep(i, k) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf1.unite(a, b);
	}
	rep(i, l) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		uf2.unite(c, d);
	}

	map<PII, int> mp;

	rep(i, n) {
		PII p = dmp(uf1.find(i), uf2.find(i));
		mp[p]++;
	}

	rep(i, n) {
		PII p = dmp(uf1.find(i), uf2.find(i));
		cout << mp[p] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 16640