akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct UnionFind
{
  vector<int> data;
  UnionFind(){}
  UnionFind(int sz):data(sz, -1){};
  int size(int x) { return -data[find(x)]; }
  int find(int x) { return data[x] < 0 ? x : data[x] = find(data[x]); }
  bool same(int x, int y) { return find(x) == find(y); }
  int unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] < data[y]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return -data[x];
  }
  void init(int sz) {
    data.clear();
    data.resize(sz, -1);
  }
};

UnionFind uf;

int N, M;
vector<string> lang;
map<string, int> mp;
map<string, int> group;
vector<int> vec;
vector<string> ans;

bool input() {
  cin >> N >> M;
  if(!N && !M) return false;

  lang.clear();
  mp.clear();
  rep(i, N) {
    string l;
    cin >> l;
    lang.push_back(l);
    mp[l] = i;
  }

  vec.clear();
  group.clear();
  rep(i, M) {
    int k; cin >> k;
    int bit = 0;
    rep(j, k) {
      string l; cin >> l;
      bit |= 1<<mp[l];
      group[l] |= 1<<i;
    }
    vec.push_back(bit);
  }

  return true;
}

void solve(int idx, int bit) {
  if(__builtin_popcount(bit) > 5) return;
  if(uf.size(N) == __builtin_popcount(bit)+M) {
    if(ans.empty() || __builtin_popcountll(bit) < ans.size()) {
      ans.clear();
      rep(i, N) if((bit>>i)&1) ans.push_back(lang[i]);
    }
  }

  reps(i, idx, N) {
    if((bit>>i)&1) continue;
    UnionFind tmp = uf;
    rep(j, M) if((vec[j]>>i)&1) uf.unite(i, N+j);
    solve(i+1, bit|(1<<i));
    uf = tmp;
  }
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  bool flag = false;
  while(input()) {
    if(flag) cout << endl;
    flag = true;

    ans.clear();
    uf.init(N+M);
    solve(0, 0);
    if(ans.size()) {
      cout << ans.size() << endl;
      for(string l : ans) cout << l << endl;
    } else {
      cout << "Impossible" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3044
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var min = 10000
    var max = 0
    for (i in 1..n) {
      val t = sc.nextInt()
      min = Math.min(t,min)
      max = Math.max(t,max)
    }
    println(max-min)
}




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

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i,n) cin >> v[i];
  
  sort(v.begin(), v.end());
  
  double ans;
  rep(i,n-1) {
    ans = ( v[i] + v[i+1] ) / 2.0;
    v[i+1] = ans;
  }
  
  cout << fixed << setprecision(5) << ans << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "hihi" ].parse.expand.solve == "Yes" );
	assert( [ "hi" ].parse.expand.solve == "Yes" );
	assert( [ "ha" ].parse.expand.solve == "No" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	while( !s.empty )
	{
		if( s.length < 2 || s[ 0 .. 2 ] != "hi" ) return "No";
		s.popFrontN( 2 );
	}
	return "Yes";
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <queue>

using namespace std;
using P = pair<int,int>;

enum dir{
  RIGHT = 1,
  DOWN = 2,
  LEFT = 4,
  UP = 8
};

int map[30][30];
int visited[30][30];
int dist[30][30];

int main(){
  int w,h;
  while(cin >> w >> h&&w>0&&h>0){
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
        map[i][j] = 0;
        visited[i][j] = 0;
        dist[i][j] = 0;
      }
    }

    for(int i=0;i<h;++i){
      map[i][0] |= LEFT;
      map[i][w-1] |= RIGHT;
    }

    for(int j=0;j<w;++j){
      map[0][j] |= UP;
      map[h-1][j] |= DOWN;
    }

    for(int i=0;i<2*h-1;++i){
      for(int j=0;j<w-1+i%2;++j){
        int wall;
        cin >> wall;
        if(wall){
          if(i%2){
            map[i/2][j] |= DOWN;
            map[i/2+1][j] |= UP;
          }else{
            map[i/2][j] |= RIGHT;
            map[i/2][j+1] |= LEFT;
          }
        }
      }
    }
    
    queue<P> q;
    q.push(P(0,0));
    visited[0][0] = 1;
    dist[0][0] = 1;
    while(!q.empty()){
      auto p = q.front();q.pop();
      int y = p.first , x = p.second;
      if(!((map[y][x]&RIGHT)||visited[y][x+1])){
        q.push(P(y,x+1));
        dist[y][x+1] = dist[y][x]+1;
        visited[y][x+1] = 1;
      }
      if(!((map[y][x]&DOWN)||visited[y+1][x])){
        q.push(P(y+1,x));
        dist[y+1][x] = dist[y][x]+1;
        visited[y+1][x] = 1;
      }
      if(!((map[y][x]&LEFT)||visited[y][x-1])){
        q.push(P(y,x-1));
        dist[y][x-1] = dist[y][x]+1;
        visited[y][x-1] = 1;
      }
      if(!((map[y][x]&UP)||visited[y-1][x])){
        q.push(P(y-1,x));
        dist[y-1][x] = dist[y][x]+1;
        visited[y-1][x] = 1;
      }

    }
/*
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
        cout << setw(4) << map[i][j];
      }
      cout << endl;
    }
   
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
        cout << setw(4) << dist[i][j];
      }
      cout << endl;
    }*/
    cout << dist[h-1][w-1] << endl;

  }

}

Measured memory_bytes: 3072
#include<iostream>

using namespace std;

int main(){
    int a,b, c;
    cin >> a >> b >> c ;
    if ( a==b && a != c) cout << "Yes" << endl;
    else if ( b==c && a != c) cout << "Yes" << endl;
    else if (a==c && b != c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    static void solve(Scanner in) {
        int W = in.nextInt();
        int H = in.nextInt();
        int N = in.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = in.nextInt();
            y[i] = in.nextInt();
            a[i] = in.nextInt();
        }
        int left = 0;
        int right = W;
        int bottom = 0;
        int top = H;
        for (int i = 0; i < N; i++) {
            switch (a[i]) {
            case 1:
                left = Math.max(left, x[i]);
                break;
            case 2:
                right = Math.min(right, x[i]);
                break;
            case 3:
                bottom = Math.max(bottom, y[i]);
                break;
            case 4:
                top = Math.min(top, y[i]);
                break;
            default:
                throw new IllegalArgumentException("a " + a[i]);
            }
        }
        int menseki = 0;
        if (top > bottom && right > left)
            menseki = (top - bottom) * (right - left);
        System.out.println(menseki);
    }
}

Measured memory_bytes: 10452
#include <stdio.h>

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if (a > b) 
    {
        printf("a > b\n");
        return 0;
    }
    if (a < b) 
    {
        printf("a < b\n");
        return 0;
    }
    if (a == b) 
    {
        printf("a == b\n");
        return 0;
    }
}


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





int main(){
    unsigned long long H,W;
    cin >> H >> W;
    if(H ==1 || W ==1){
        cout << "1" <<endl;
        return 0;
    }
    if(H%2==0 ||W%2 ==0){
        cout << (H*W)/2 <<endl;
        return 0;
    }
    else{
        cout << ((W*H)+1)/2 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner input=new Scanner(System.in);
	String str;
	String res="";
	while(input.hasNext()){
	    str=input.next();
	    for(int i=0;i<str.length()-4;i++){
		if((str.substring(i,i+5)).equals("apple"))
		    str=str.replaceAll("apple","peach");
		else if((str.substring(i,i+5)).equals("peach"))
		    str=str.replaceAll("peach","apple");
	    }
	    res=res.concat(str+" ");
	}
	System.out.println(res.trim());
	input.close();
    }
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    vector<int> g[n];
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      g[a].push_back(b);
      g[b].push_back(a);
    }

    const int N = 1e5 + 5;
    const int D = 10 + 3;
    int dp[N][D];
    fill(&dp[0][0], &dp[N - 1][D - 1] + 1, -1);

    map<int, int> color;

    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
      int v, d, c;
      cin >> v >> d >> c;
      color[i + 1] = c;
      --v;
      dp[v][d] = i + 1;
    }

      for (int i = D - 1; 0 <= i - 1; --i) {
        for (int curr = 0; curr < n; ++curr) {
        each (next, g[curr]) {
          setmax(dp[next][i - 1], dp[curr][i]);
        }
      }
    }

    map<int, int> mx;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < D; ++j) {
        setmax(mx[i], dp[i][j]);
      }
    }

    for (int i = 0; i < n; ++i) {
      cout << color[mx[i]] << endl;
    }
    cout << endl;
  }

  return 0;
}


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

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


int N,T;
int dp[3010][3010] = {0};
int prev_a[3010][3010] = {0};

/*ll rec(int i,int t){
    if(dp[i][t] >= 0){
        return dp[i][t];
    }
    int res;
    if(i == N){
        res = 0;
    }else if(t < a[i]){
        res = rec(i+1,t);
    }else{
        res = max(rec(i+1,t),rec(i+1,t-a[i])+b[i]);
    }
    return dp[i][t] = res;
}*/


int main(){
    cin >> N >> T;
    vector<int> a(N);
    vector<int> b(N);
    REP(i,N) cin >> a[i] >> b[i];
    
    for(int i = 0;i < N;i++){
        for(int j = 0;j <= T;j++){
            if(j >= a[i]){
                if(dp[i+1][j] < dp[i][j-a[i]] + b[i]){
                    dp[i+1][j] = dp[i][j-a[i]] + b[i];
                    prev_a[i+1][j] = j - a[i];
                }
            }
            if(dp[i+1][j] < dp[i][j]){
                dp[i+1][j] = dp[i][j];
                prev_a[i+1][j] = j;
            }
        }
    }
    int ans;
    ans = dp[N][T-1];
    int res = dp[N][T];
    int cur_a = T-1;
    for(int i = N-1;i >= 0;i--){
        if(prev_a[i+1][cur_a] == cur_a - a[i]){
            b[i] = 0;
        }
        cur_a = prev_a[i+1][cur_a];
    }
    sort(b.begin(),b.end(),greater<int>());
    cout << ans + b[0] << endl;
    //cin >> N;
}

Measured memory_bytes: 70912
#include<stdio.h>

int main(){
    int i,j=0, rate = 400, x;
    scanf("%d",&x);
    for(i=8;i>=1;i--){
        if(rate+200*j<=x && rate+200*(j+1)>x){
            break;
        }
        j++;
    }
    printf("%d",i);
    return 0;
}

Measured memory_bytes: 1736
from collections import deque

n,k=map(int,input().split())
visited=[False]*n
visited[0]=True
color=[0]*n
color[0]=k
mod=10**9+7

graph=[[] for i in range(n)]

for i in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)


Q=deque()
Q.append((0))
ans=k

while Q:
  p=Q.pop()
  cnt=0
  for i in graph[p]:
    if visited[i]==False:
        cnt+=1
        Q.append((i))
        visited[i]=True

  if p==0:
      for i in range(cnt):
          ans*=k-i-1
          ans%=mod

  else:
      for i in range(cnt):
          ans*=k-i-2
          ans%=mod


print(ans%mod)

Measured memory_bytes: 94316
from collections import deque
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append([a, b])
    g[b].append([b, a])
res = [-1 for _ in range(n+1)]
res[1] = 0
q = deque(g[1])
while q:
    q_ = q.popleft()
    if res[q_[1]] == -1:
        for gi in g[q_[1]]: q.append(gi)
        res[q_[1]] = q_[0]
print("Yes")
for i in res[2:]: print(i)

Measured memory_bytes: 66812
#include <assert.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define F first
#define S second
#define qq queue
#define dq deque
#define vc vector
#define INF ((int)(2e9))
#define LINF ((int)(1e18))
#define out cout <<
#define ln  << endl
#define pb push_back
#define mp make_pair
#define _tp template
#define _tyn typename
#define pf push_front
#define itor iterator
#define mp make_pair
#define sint short int
#define ull unsigned long long
#define pq priority_queue
#define pii pair<int,int>
#define uint unsigned int
#define ll long long
#define B out "BreakPoint\n";
#define read(_nowans) scanf("%d",&_nowans)
#define ms(_data) memset(_data,0,sizeof(_data))
#define fin(_filename) freopen(_filename,"r",stdin)
#define fout(_filename) freopen(_filename,"w",stdout)
#define read2(_nowans1,_nowans2) scanf("%d %d",&_nowans1,&_nowans2)
#define msn(_data,_nowans) memset(_data,_nowans,sizeof(_data))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define read3(_nowans1,_nowans2,_nowans3) scanf("%d %d %d",&_nowans1,&_nowans2,&_nowans3)
#define lb( _x , _y ) ( lower_bound( _x.begin() , _x.end() , _y ) - _x.begin() + 1 )
using namespace std;
_tp<_tyn T>void mymax( T &_a , T _b ){ if( _a < _b ) _a = _b; }
_tp<_tyn T>void mymin( T &_a , T _b ){ if( _a > _b ) _a = _b; }
void print( int _x ){ printf("%d\n",_x); }
_tp<_tyn T>void print( T _data[] , int _size ){
	for( int i = 1 ; i <= _size ; i++ )
		cout << _data[i] << " ";
	cout << endl;
}
#define MAXN 200100

char s[MAXN];
ll n;

int main(){
	//fin( "B.txt" );

	while( scanf("%s",s) != EOF ){
		n = strlen(s);
		//在第i个字符上
		ll ans = (n) * (n-1) / 2 + 1;
		ll app[27];
		ms( app );
		for( int i = 0 ; i < n ; i++ )
			app[ s[i]-'a' ]++;
		for( int i = 0 ; i < 26 ; i++ ){
			ans -= app[i] * (app[i]-1) / 2;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 384
q = int(input())

def eratosthenes(n):
    l = [True] * (n+1)
    l[2] = True
    for i in range(2, n+1):
        if l[i]:
            for j in range(i*i, n+1, i):
                l[j] = False
    return l

l = eratosthenes(10**5)
r = [0] * (10**5 + 1)
r[1] = r[2] = 0
for i in range(3,10**5):
    if i % 2 == 0:
        r[i] = r[i-1]
    elif l[i] and l[(i+1) // 2]:
        r[i] = r[i-1] + 1
    else:
        r[i] = r[i-1]
for i in range(q):
    a, b = map(int, input().split())
    print(r[b] - r[a-1])


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> A(M); REP(i, M) cin >> A[i];
  ll ans = accumulate(all(A), 0LL);
  if(ans <= N) cout << N - ans << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n, x;
	cin >> n >> x;
	int d = 0;
	int ans = 1;
	for(int i=0; i<n; ++i){
		int k;
		cin >> k;
		d+=k;
		if(d<=x) ++ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#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>
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)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int n, total;
int b[101];

int main(){
	
	cin >> n;
	rep(i, n - 1)cin >> b[i];

	total = b[0] + b[n - 2];
	REP(i, 1, n - 1){
		total += min(b[i], b[i - 1]);
	}

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 256
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
#include <climits>
namespace orliv {
namespace graph {
struct Edge {
  typedef int weight_type;
  static constexpr weight_type INF =
      std::numeric_limits<weight_type>::max() - 100;

  int from, to;
  weight_type w;
  Edge(int from, int to, weight_type w = 1) : from(from), to(to), w(w) {}
  bool operator<(const Edge& rhs) const {
    if (w != rhs.w) return w > rhs.w;
    if (from != rhs.from) return from < rhs.from;
    return to < rhs.to;
  }
};

typedef Edge::weight_type Weight;
typedef std::vector<Edge> Edges;
typedef std::vector<Weight> Weights;
typedef std::vector<int> Path;
}
typedef std::vector<graph::Edges> Graph;
}
#endif
//}}}
//{{{ articulation.cc
#ifndef INCLUDE_GRAPH_HPP
#include "graph.hpp"
#endif

namespace orliv {
namespace graph {
namespace articulation_internal {
struct ArticulationImpl {
  const Graph& G;
  int k;
  std::vector<int> ord, low;
  std::vector<int> articulations;
  ArticulationImpl(const Graph& g)
      : G(g), k(0), ord(g.size(), -1), low(g.size()) {}
  void dfs(int v, int p = -1) {
    low[v] = ord[v] = k++;
    int degree = 0;
    bool articulation = false;
    for (const auto& e : G[v]) {
      int u = e.to;
      if (u == p) continue;
      if (ord[u] >= 0) {
        low[v] = std::min(low[v], ord[u]);
      } else {
        dfs(u, v);
        degree++;
        low[v] = std::min(low[v], low[u]);
        if (p >= 0 && ord[v] <= low[u]) articulation = true;
      }
    }
    if ((p == -1 && degree > 1) || articulation) articulations.emplace_back(v);
  }
  std::vector<int> get() {
    dfs(0);
    return std::move(articulations);
  }
};
}

std::vector<int> articulations(const Graph& g) {
  return std::move(articulation_internal::ArticulationImpl(g).get());
}
}
}
//}}}

using namespace std;

typedef long long ll;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int V = in(), E = in();
  orliv::Graph g(V);
  for (int i = 0; i < E; i++) {
    int s = in(), t = in();
    g[s].emplace_back(s, t);
    g[t].emplace_back(t, s);
  }
  auto articulations = orliv::graph::articulations(g);
  sort(articulations.begin(), articulations.end());
  for (int v : articulations) {
    cout << v << endl;
  }
  return 0;
}

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

using namespace std;

#define rep0(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repU(i,bottom,ceiling) for(int (i)=(bottom);(i)<=(ceiling);(i)++)
#define repD(i,ceiling,bottom) for(int (i)=(ceiling);(i)>=(bottom);(i)--)
#define V vector
#define Vi vector<int>
#define VVi vector<vector<int>>
#define pub push_back
#define pob pop_back
#define pf printf
#define sf scanf
#define ci(a) cin>>a
#define lco(a) cout<<a<<endl
#define co(a) cout<<a
#define Vci(v) for(int i=0;i<v.size();i++) cin>>v[i]
#define Vco(v) for(int i=0;i<v.size();i++){ cout<<v[i]<<' '; } cout<<endl
#define P pair
#define Pii pair<int,int>
#define Mp(a,b) make_pair(a,b)
#define fir first
#define sec second
#define Re return 

typedef long long ll;
typedef double db;

const string alphabet("abcdefghijklmnopqrstuvwxyz");
const vector<vector<int>> Dir={{0,0},{1,0},{1,1},{0,1},{-1,1},{0,-1},{-1,-1},{0,-1},{1,-1}};
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const int Inf=(int)2e9+1e8;
const int Mod=(int)1e9+7;

template <typename T,typename U>                                                   
pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir+r.fir,l.sec+r.sec};                                    
} 

template <typename T,typename U> 
pair<T,U> operator-(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir-r.fir,l.sec-r.sec};                                    
} 

template <typename T,typename U>                                                   
pair<T,U> operator*(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir*r.fir,l.sec*r.sec};                                    
}

template <typename T,typename U>                                                   
pair<T,U> operator/(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir/r.fir,l.sec/r.sec};                                    
}

ll rem(ll n,ll m){
	if(!m) Re -1;
	Re (n<0?n%m+m:n%m);
}
             
/*The main code follows below*/
 
int ParSet(int start,int *par){
	if(start!=par[start]) return par[start]=ParSet(par[start],par);
	return start;
}
 
int main(){ 
	int ar[100005],p[100005],n,m,ans=0;
	ci(n>>m);
	rep0(i,n){
		ci(ar[i]);
		ar[i]--; 
		p[i]=i;
   }
	rep0(i,m){
		int x,y;
		ci(x>>y);
		x--; y--;
		ParSet(x,p);
		ParSet(y,p);
		p[p[x]]=p[y];
	}
	rep0(j,n) ParSet(j,p);
	rep0(i,n) if(p[i]==p[ar[i]]) ans++; 
	lco(ans);
	return 0;
}

Measured memory_bytes: 1024
using System;

class Atcoder85
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);
        int d = int.Parse(input[3]);

        if (System.Math.Abs(a - c) <= d)
            Console.WriteLine("Yes");
        else if (System.Math.Abs(a - b) <= b && System.Math.Abs(b - c) <= d)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

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

int main() {
  int N;
  int64_t ans=0;
  cin>>N;
  for(int i=1;i<=N;i++){
    if(i%3!=0&&i%5!=0) ans+=i;
  }
  cout<<ans<<endl;
}
 

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

int main(){
    int n;
    cin >> n;
    pair<int, int> p;
    vector<pair<int, int>> v;
    for (int i = 1; i <= n; i++)
    {
        int x; cin >> x;
        v.push_back(make_pair(x, i));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
    {
        cout << v[i].second << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,h;cin>>h>>n;
    rep(i,n){
        ll a;cin>>a;
        h-=a;
    }
    if(h<=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	long long N, M;
	cin >> N >> M;
	for (long long i = M/N; i>=1; --i) {
		if (M % i == 0) {
			cout << i << endl;
			return 0;
		}
	}
;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC056_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            var sum = 0;
            for (var i = 0; i <= 1000000000; i++)
            {
                sum += i;
                if (sum >= x)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;
int next[4][2] = { {1,0}, {-1,0}, {0,1}, {0,-1} };
int main()
{
  int w,h,ax,ay,bx,by;
  cin >> w >> h >> ax >> ay >> bx >> by;
  vector<vector<pair<int,int> > > map(h,vector<pair<int,int> >(w));
  map[ay][ax] = make_pair(0,1);
  queue<pair<int,pair<int,int> > > q;
  q.push(make_pair(0,make_pair(ax,ay)));
  set<pair<int,int> > s;
  s.insert(make_pair(ax,ay));
  while(!q.empty()){
    pair<int,pair<int,int> > p = q.front(); q.pop();
    int d = p.first;
    int x = p.second.first, y = p.second.second;
    for(int i=0; i<4; i++){
      int nx = x + next[i][0];
      if(nx >= w) nx = 0;
      else if(nx < 0) nx = w-1;
      int ny = y + next[i][1];
      if(ny >= h) ny = 0;
      else if(ny < 0) ny = h-1;
      if(map[ny][nx].second == 0){
        if(s.insert(make_pair(nx,ny)).second) {
          q.push(make_pair(d+1,make_pair(nx,ny)));
        }
      }else if(map[ny][nx].first < d){
        map[y][x].second += map[ny][nx].second;
      }
    }
    map[y][x].first = d;
    map[y][x].second %= 100000007;
  }
  cout << map[by][bx].second << endl;
  return 0;
}

Measured memory_bytes: 56444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
#define INF 1000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll unuse = (n % 2) + 1;
  vector<vector<ll>>dp(n+1, vector<ll>(unuse+1));
  dp[1][0] = a[0];
  dp[2][0] = a[0];
  dp[2][1] = a[1];
  if (unuse == 2) {
    dp[3][0] = a[0] + a[2];
    dp[3][1] = 0;
    dp[3][2] = a[2];
  }

  if (unuse == 1) {
    for (int i = unuse + 2; i <= n; i++) {
      dp[i][0] = dp[i-2][0] + a[i-1];
      dp[i][1] = a[i-1] + max(dp[i-2][1], dp[i-3][0]);
    }
    cout << max(dp[n][1], dp[n-1][0]) << endl;
  }
  else {
    for (int i = unuse + 2; i <= n; i++) {
      dp[i][0] = dp[i-2][0] + a[i-1];
      dp[i][1] = a[i-1] + max(dp[i-2][1], dp[i-3][0]);
      dp[i][2] = a[i-1] + max(dp[i-2][2], max(dp[i-3][1], dp[i-4][0]));
    }
    cout << max(dp[n][2], max(dp[n-1][1], dp[n-2][0])) << endl;
  }
}

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

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0;i < n;i++){
        cin >> a[i];
    }

    ll m = 0;
    bool z = false;

    for (ll i = 0; i < n; i++){
        if (a[i] == 0){
            z = true;
        }
        else if (a[i] < 0){
            m++;
        }
    }

    vector<ll> b(n);
    for (ll i = 0; i < n; i++){
        b[i] = abs(a[i]);
    }

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

    ll ans = 0;

    if (z){
        for (ll i = 0; i < n; i++){
            ans += b[i];
        }
    }
    else{
        if (m%2 == 0){
            for (ll i = 0; i < n; i++){
                ans += b[i];
            }
        }
        else{
            for (ll i = 1; i < n; i++){
                ans += b[i];
            }
            ans -= b[0];
        }
    }

    cout << ans << endl;
}

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

int main(){
    string s;
    cin>>s;
    int n = s.size();
    ll ans = 0;
    for(int i=0; i<1<<(n-1); i++){
        int l = 0;
        ll sum = 0;
        for(int j=0; j<n-1; j++){
            if((i>>j)&1){
                sum+=stoll(s.substr(l,j-l+1));
                l = j+1;
            }
        }
        sum+=stoll(s.substr(l,n-l));
        ans+=sum;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        for(int i= a; i <= b; i++){
            if((c%i) == 0) count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 26180
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    vector p(n,0);
    for (int i=0; i<n; i++) cin >> p[i];
    sort(p.begin(), p.end());
    k = min(n,k);
    int ans = accumulate(p.begin(), p.begin()+k, 0);
    cout << ans << endl;
}


Measured memory_bytes: 3192
l, n = (int(i) for i in input().split());
a = [int(i) for i in input().split()];
mx = 0;
for i in range(1, n):
    mx = max(mx, a[i] - a[i - 1]);

mx = max(mx, a[0] + l - a[n - 1]);

print(l - mx);


Measured memory_bytes: 26436
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;

class DoublyLinkedList{

	struct node{
		int data;
		node * next;
		node * prev;
	}typedef Node;

	Node *nil;

public:
	void init(){
		nil = (Node *)malloc(sizeof(Node));
		nil->next = nil;
		nil->prev = nil;
	}

public:
	void insert(int data){
		Node *np = (Node *)malloc(sizeof(Node));
		np->data = data;
		np->next = nil->next;
		np->next->prev = np;
		nil->next = np;
		np->prev = nil;
	}

	Node *listSearch(int data){
		Node* np = nil->next;
		while(np != nil && np->data != data){
			np = np->next;
		}
		return np;
	}

	void deleteNode(Node *np){
		if(np==nil) return;
		np->prev->next = np->next;
		np->next->prev = np->prev;
		free(np);
	}

	void deleteFirst(){
		deleteNode(nil->next);
	}

	void deleteLast(){
		deleteNode(nil->prev);
	}

	void deleteData(int data){
		deleteNode(listSearch(data));
	}

	void printList(){
		Node *np;
		int cnt=0;
		np = nil->next;

		while(np!=nil){
			if(cnt++>0) printf(" ");
			printf("%d",np->data);
			np=np->next;
		}
		puts("");
	}
};

int main(){
	int key,n,i;
	char com[20];
	DoublyLinkedList list;
	list.init();
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",com);
		if(strlen(com)<=6) scanf("%d",&key);
		if(com[0]=='i'){
			list.insert(key);
		}else if(com[0] == 'd'){
			if(strlen(com)>6){
				if(com[6] == 'F') list.deleteFirst();
				else if(com[6] == 'L') list.deleteLast();
			}else{
				list.deleteData(key);
			}
		}

	}
	list.printList();
	return 0;
}

Measured memory_bytes: 32364
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i64 = read();
    let a: i64 = read();
    let b: i64 = read();

    let ans = (b-a)*(n-2)+1;
    if ans < 0 {
        println!("0");
    }else{
        println!("{}",ans);
    }
}


Measured memory_bytes: 2076
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <fstream>
#include <climits>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <memory>
#include <set>
#include <map>
#include <list>
#include <cmath>

using namespace std;

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a+b>=10) cout<<"error"<<endl;
    else cout<<(a+b)<<endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
const int infty = static_cast <int> (pow(256, sizeof(int)) / 2 - 1);

int knapsack(int n, int w, vector<int> &vv, vector<int> &vw)
{
	vector<vector<int>> vvc;
	vvc = vector<vector<int>>(vv.size(),vector<int>(w+1,0));

	for(int i = 0; i <= w; ++i)
	{
		vvc[0][i] = 0;
	}

	for(int i = 0; i <= n; ++i)
	{
		vvc[i][0] = 0;
	}

	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= w; ++j)
		{ 
			if(vw[i] <= j)
			{
				if((vv[i] + vvc[i-1][j-vw[i]]) > vvc[i-1][j])
					vvc[i][j] = vv[i] + vvc[i - 1][j - vw[i]];
				else
					vvc[i][j] = vvc[i - 1][j];
			}
			else
				vvc[i][j] = vvc[i - 1][j];
		}
	}
	return vvc[n][w];
}

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

	int n, w;
	cin >> n >> w;
	cin.ignore();

	int a, b;
	vector<int> vv,vw;

	vv.push_back(0);
	vw.push_back(0);

	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		vv.push_back(a);
		vw.push_back(b);
	}

	cout << knapsack(n,w,vv,vw) << endl;

	return 0;
}

Measured memory_bytes: 6828
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        scanner.nextInt();
        String s = scanner.next();
        int count = 0;
        for (int i=0;i<s.length()-2;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='B'&&s.charAt(i+2)=='C'){
                count++;
            }
        }
        System.out.println(count);
    }
}

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


int dp[2005][20005];
int res[2005];
int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
   
    int t=1;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        vector<int>nish;
        for(int i=1;i<=b;i++)
        {
            int first;
            cin>>first;
            nish.push_back(first);
        }

        sort(nish.begin(),nish.end());
        vector<int>arr;
        int siz=nish.size();
        arr.push_back(a-nish[siz-1]+nish[0]);
       
        for(int i=1;i<siz;i++)
        {
            arr.push_back(nish[i]-nish[i-1]);
        }
        sort(arr.begin(),arr.end());
        long long int ans=0;
        int siz2=arr.size();
        for(int i=0;i<siz2-1;i++)
            ans+=arr[i];

        cout<<ans<<endl;   


    }

return 0;

}

Measured memory_bytes: 2548
using System;

namespace ABC167A
{
    class Program
    {
        static void Main(string[] args)
        {
            var t1 = Console.ReadLine();
            var t2 = Console.ReadLine();
            if(t1.Length + 1 == t2.Length && t1 == t2.Substring(0,t1.Length))
            Console.WriteLine("Yes"); else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 25888
void main(){
	long n = _scan!long();
	for(int i;; i++){
		if(i*i>n){
			( (i-1)*(i-1) ).writeln();
			break;
		}
	}
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
 
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define FOR0(i,n) for(int i=0;i<n;i++)
#define For(v) for(auto it = v.begin();it!=v.end();it++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORD(i,a,b) for(int i=(a);i>=(int)(b);i--)
#define sf(n) scanf("%d", &n)
#define sfc(x) scanf("%c", &x)
#define pf(x) printf("%d", x)
#define pff(x) printf("%lf", x)
#define pfc(x) printf("%c", x)
#define pfs(x) printf("%s", x)
#define sf2(a,b) scanf("%d %d", &a, &b)
#define sf3(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define sp <<" "<<
//#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()
#define ll long long
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
bool prime[500010];
void SieveOfEratosthenes(ll n)
{
    memset(prime,true, sizeof(prime));
 
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
 
ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}
 
ll mod_power(ll a, ll b){
  ll res=1;
  a%=mod;
  while(b){
    if(b&1){
      res = (res%mod * a%mod)%mod;
    }
    a=(a*a)%mod;
    b>>=1;
  }
  return res;
} 

ll power1(ll a,ll b){
  ll res=1;
  while(b){
    if(b&1){
      res*=a;
    }
    a=a*a;
    b>>=1;
  }
  return res;
}

int main(){
  fast
  ll n;
  cin>>n;
  ll a[n];
  
  priority_queue<ll,vector<ll>, greater<ll> > pq;
  FOR0(i,n){
    cin>>a[i];
    pq.push(a[i]);
  }
  ll x=pq.top();
  while(!pq.empty()){
    pq.pop();
    if(!pq.empty()){
      ll temp=pq.top();
      pq.pop();
      if(temp%x>0)pq.push(temp%x);
      if(x>0)pq.push(x);
    }
    if(pq.top()>0)x=pq.top();
  }
  cout<<x;
}

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

const int N = 3e3 + 5, inf = INT_MAX;

int n;
ld dp[N][N], a[N];

ld solve(int i, int heads)
{
    if (i == n)
        return heads > n / 2? 1: 0;
    if (dp[i][heads] != -1)
        return dp[i][heads];
    return dp[i][heads] = solve(i + 1, heads + 1) * a[i] + solve(i + 1, heads) * (1 - a[i]);
}

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            dp[i][j] = -1;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    cout << fixed << setprecision(10) << solve(0, 0);
    return 0;
}

Measured memory_bytes: 145116
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

a, b, t = nm()
count = 0
aa = a
while(aa <= t + 0.5):
    count += b
    aa += a
print(count)


Measured memory_bytes: 3436
n=int(input())
if(n==0):
    print(0)
    exit()
s=""
c=0
while(n!=0):
    if(abs(n)%2==0):s+='0'
    else:
        s+='1'
        if(c%2==0):n-=1
        else:n+=1
    c+=1
    n/=2
    if(c>=100):break
        
t=reversed(s)
for x in t:print(x,end="")

Measured memory_bytes: 3064
using System;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = double.Parse(Console.ReadLine());
            var area = (r * r * Math.PI).ToString("F8");
            var around = (2 * r * Math.PI).ToString("F8");

            Console.WriteLine($"{area} {around}");

        }
    }
}



Measured memory_bytes: 15948
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

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

    string s;
    cin >> s;
    ll k;
    cin >> k;
    k--;
    int n = sz(s);
    int ans = 1;
    rep(i, n) {
        if (i > k) break;
        if (s[i] != '1') { ans = s[i] - '0'; break;}
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
ll dy[4] = {1,0,-1,0};
ll dx[4] = {0,1,0,-1};


int main(){
    ll n; cin >> n;
    ll G[n][n];
    rep(i,n){
        string s; cin >> s;
        rep(j,n){
            G[i][j] = s[j]-'0';
        }
    }
    ll ans = 0;
    rep(i,n){
        bool flag = false;
        vl d(n,-1);
        queue<ll> q;
        d[i] = 0;
        q.push(i);
        while(!q.empty()){
            ll u = q.front(); q.pop();
            for(ll v=0; v<n; v++){
                if(G[u][v] == 0) continue;
                if(d[v] == -1){
                    d[v] = d[u] + 1;
                    q.push(v);
                }else{
                    if((d[u]+1-d[v])%2==1){
                        flag = true;
                        break;
                    }
                }
            }
            if(flag) break;
        }
        if(flag) break;
        rep(i,n) ans = max(ans, d[i]+1);
    }
    if(ans==0) puts("-1");
    else cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (1 << 23) + 1;

struct pt
{
	int x, y;
	pt() { }
};

int H[maxn], F[maxn], used[maxn];

struct hash_table
{
	hash_table() { }

	int getpos(int h) const
	{
		int i = h % maxn;
		for (; used[i] && H[i] != h; ++i) if (i == maxn) i = 0;
		return i;
	}

	int& operator[](int h)
	{
		int i = getpos(h);
		H[i] = h;
		used[i] = 1;
		return F[i];
	}
};

struct fenwick
{
	int n;
	hash_table F;

	fenwick() { n = inf; }

	void upd(int i, int x)
	{
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	}

	int get(int i)
	{
		int res = 0;

		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);

		return res;
	}
};

int n;
pt s, f;
pt p[maxn];

bool read()
{
	if (scanf("%d %d %d %d %d", &s.x, &s.y, &f.x, &f.y, &n) != 5)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].x, &p[i].y);

	return true;
}

bool cmp(pt a, pt b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); }

void solve()
{
	if (s.x > f.x)
		swap(s, f);

	if (s.y > f.y)
	{
		f.y = 2 * s.y - f.y;

		forn (i, n)
			p[i].y = 2 * s.y - p[i].y;
	}

	vector<pt> pp;

	forn (i, n)
		if (s.x <= p[i].x && p[i].x <= f.x && s.y <= p[i].y && p[i].y <= f.y)
			pp.push_back(p[i]);

	sort(pp.begin(), pp.end(), cmp);
	fenwick dp;

	forn (i, size(pp))
		dp.upd(pp[i].y, dp.get(pp[i].y) + 1);

	int lis = dp.get(inf);
	long double ans = 0;

	if (lis != min(f.y - s.y, f.x - s.x) + 1)
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * lis;
	else
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * (lis - 1) + 10 * M_PI;

	printf("%.15f\n", (double) ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 101872
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N;
  cin >> N;
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    int A,B;
    cin >> A >> B;
    if (A == B){
      count++;
    }
    else {
      count = 0;
    }
    if (count > 2){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}
 

  
  

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

int n, x, niz[200000], p[200000];
vector <int> v;

int main(){


    cin >> n >> x;
    if (x == 1 || x == 2*n-1){
        cout << "No";
        return 0;
    }

    cout << "Yes" << endl;

    for (int i=0; i<2*n-1; i++){
        p[i]=i+1;
    }

    niz[(2*n-1)/2] = x;
    p[x-1] = 0;
    if (x==2){
        niz[(2*n-1)/2-1] = x+1;
        niz[(2*n-1)/2+1] = x-1;
        niz[(2*n-1)/2+2] = x + 2;
        p[x]=0;
        p[x-2]=0;
        p[x+1]=0;
    }
    else{
        niz[(2*n-1)/2-1] = x-1;
        niz[(2*n-1)/2+1] = x+1;
        niz[(2*n-1)/2+2] = x - 2;
        p[x-2]=0;
        p[x]=0;
        p[x-3]=0;
    }
    for(int i=0; i<2*n-1; i++){
        if (p[i]!=0)v.push_back(p[i]);
    }

    int br=0;

    for(int i=0; i<2*n-1; i++){
        if (niz[i] == 0){
            niz[i] = v[br];
            br++;
        }
    }

    for (int i=0; i<2*n-1; i++)cout << niz[i] << endl;

    return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll c = 0;
vector<vector<ll>> v;

void dfs(ll node, vector<bool> visited) {
    visited[node] = true;
    bool isok = true;
    rep(i, visited.size()) {
        isok = isok && visited[i];
    }
    if (isok) {
        c++;
        return;
    }
    rep(i, v[node].size()) {
        if (!visited[v[node][i]]) dfs(v[node][i], visited);
    }
}

int main()
{
    ll n, m; cin >> n >> m;
    v.resize(n);
    
    rep(i, m) {
        ll a, b; cin >> a >> b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }

    dfs(0, vector<bool>(n, false));

    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256