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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r.begin()); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

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

int main()
{
  int n, p;
  while (n = in(), p = in(), n || p){
    int id = 0;
    int stone[64] = {};
    int cnt = p;
    int have_user = 0;
    while (1){
      if (cnt == 1 &&
          ((stone[id] && have_user == 1) ||
          (!stone[id] && have_user == 0))){
        break;
      }
      if (cnt == 0){
        if (stone[id]) have_user--;
        cnt = stone[id];
        stone[id] = 0;
      }
      else {
        if (stone[id] == 0) have_user++;
        cnt--;
        stone[id]++;
      }
      id = (id + 1) % n;
    }
    printf("%d\n", id);
  }
  return (0);
}

Measured memory_bytes: 1188
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int N, K;
    cin >> N >> K;
    if (K > (N - 1)*(N - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }
    int reduce = (N - 1) * (N - 2) / 2 - K;
    cout << (N - 1 + reduce) << endl;
    for (int i = 2; i <= N; i++) {
        cout << 1 << " " << i << endl;
    }
    for (int i = 2; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (reduce != 0) {
                cout << i << " " << j << endl;
                reduce -= 1;
            } else {
                break;
            }
        }
        if (reduce == 0) break;
    }
    return 0;
}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():

    def walk(p, c):
        if visited[p]:
            return
        visited[p] = True
        cnt[p] += c
        for n in tree[p]:
            walk(n, cnt[p])

    setrecursionlimit(2000001)

    n, q = [int(x) for x in stdin.readline().split()]

    tree = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        a, b = [int(x) for x in stdin.readline().split()]
        tree[a].append(b)
        tree[b].append(a)

    cnt = [0] * (n + 1)
    for _ in range(q):
        p, x = [int(x) for x in stdin.readline().split()]
        cnt[p] += x

    visited = [False] * (n + 1)
    walk(1, 0)

    print(*cnt[1:])


main()


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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll h, w, k;  cin >> h >> w >> k;
    string g[h + h];

    for (ll i = 0; i < h; i++) {
        cin >> g[i];
    }

    ll ans = 0;
    for(ll r = 0; r < (1 << h); r++) {
        for (ll c = 0; c < (1 << w); c++) {
            ll d = 0;
            for (ll i = 0; i < h; i++) {
                if(r & (1 << i)) continue;
                for (ll j = 0; j < w; j++) {
                    if(c & (1 << j)) continue;
                    if(g[i][j] == '#') d++;
                }
            }
            if(d ==  k)
                ans++;
        }
    }

    cout << ans << endl;
    return 0;
}


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

typedef pair<int, int> P;

int main(){
    int n;
    cin >> n;
    int m_a , m_v = 0, a, v;
    for(int i = 0; i < n; i++){
        cin >> a >> v;
        if( v > m_v || (v == m_v && a < m_a )){
            m_v = v;
            m_a = a;
        }
    }
    cout << m_a << ' ' << m_v << endl;
    return 0;
}

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

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

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const int INF = 1e9;
const llint llINF = 1e18;

int main () {
    int n; cin >> n;
    vint h(n);
    rep(i, n) cin >> h[i];
    int lmax = h[0], ans = 0;
    for (int i = 0; i < n; i++) {
        lmax = max(lmax, h[i]);
        if (h[i] >= lmax) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define emb emplace_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define N  99999
#define f first 
#define em emplace
#define s second
using lint=long long int;

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

 
#define fori(n) for(int i=0; i<int(n); i++)
 
#define cins(s) string s; cin>>s;
#define cini(i) lint i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }
#define z 1000000007 


void solve(){
  
  cini(n);
  vector<int>dp(3);


  for(int i=0;i<n;i++){
     vector<int>v(3);

     for(int j=0;j<3;j++){
           cin>>v[j];
            int m=0;
           for(int k=0;k<3;k++){

              if(j!=k){
                m=max(dp[k],m);
              }
           }
           v[j]+=m;
     }
    
    v.swap(dp);
  }
     
     int a=*max_element(dp.begin(),dp.end());
     cout<<a<<endl;




}
 
 
int main()
{ 
  fast;
 
  



  solve();
 }

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main()
{
	int n;
	double x1,x2,x3,y1,y2,y3,x,y,r;
	double a,b,c;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
	    x=(y1-y3)*(y1*y1-y2*y2+x1*x1-x2*x2)-(y1-y2)*(y1*y1-y3*y3+x1*x1-x3*x3);
	    x/=(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));

	    y=(x1-x3)*(x1*x1-x2*x2+y1*y1-y2*y2)-(x1-x2)*(x1*x1-x3*x3+y1*y1-y3*y3);
	    y/=(2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));

	    a=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
	    b=(x3-x2)*(x3-x2)+(y3-y2)*(y3-y2);
	    c=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
	    a=sqrt(a);
	    b=sqrt(b);
	    c=sqrt(c);
	    r=a*b*c/sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c));

		printf("%.3f %.3f %.3f\n",x,y,r);
	}
	return 0;
}
/*?????\???*/

Measured memory_bytes: 2596
using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        class Room
        {
            // 英語として正しいのは何だろう
            public int count = 0;
        }
        class Floor
        {
            public Room[] rooms = new Room[10];
            public Floor()
            {
                for (int i = 0; i < rooms.Length; ++i)
                {
                    rooms[i] = new Room();
                }
            }
        }
        class Building
        {
            public Floor[] floors = new Floor[3];
            public Building()
            {
                for (int i = 0; i < floors.Length; ++i)
                {
                    floors[i] = new Floor();
                }
            }
        }
        static void Main(string[] args)
        {
            var buildings = new Building[4];
            for (int i = 0; i < buildings.Length; ++i)
            {
                buildings[i] = new Building();
            }

            var inputFirstLine = Console.In.ReadLine();
            var dataCount = int.Parse(inputFirstLine);

            for (int idata = 0; idata < dataCount; ++idata)
            {
                var inputLine = Console.In.ReadLine();
                var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });

                var ibuilding = int.Parse(inputs[0]) - 1;
                var ifloor = int.Parse(inputs[1]) - 1;
                var iroom = int.Parse(inputs[2]) - 1;
                var count = int.Parse(inputs[3]);
                buildings[ibuilding].floors[ifloor].rooms[iroom].count += count;
            }

            bool firstBuilding = true;
            var border = new string('#', buildings[0].floors[0].rooms.Length * 2);
            foreach (var building in buildings)
            {
                if (firstBuilding == false)
                {
                    Console.WriteLine(border);
                }
                firstBuilding = false;

                foreach (var floor in building.floors)
                {
                    foreach (var room in floor.rooms)
                    {
                        Console.Write(" {0}", room.count);
                    }
                    Console.WriteLine();
                }
            }
        }
    }
}



Measured memory_bytes: 18068
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, M = read_values()
    A = read_list()
    B = read_list()
    P = [[-1, -1] for _ in range(N * M + 1)]
    C = 0
    HC = 0
    WC = 0
   
    for i, a in enumerate(A):
        if P[a][0] != -1:
            print(0)
            return
        P[a][0] = i
    for j, b in enumerate(B):
        if P[b][1] != -1:
            print(0)
            return
        P[b][1] = j

    res = 1
    for k in range(N * M, 0, -1):
        h, w = P[k]
        if h != -1 and w != -1:
            HC += 1
            WC += 1
            C += HC - 1
            C += WC - 1
        elif h != -1:
            res *= WC
            res %= mod
            C += WC - 1
            HC += 1
        elif w != -1:
            res *= HC
            res %= mod
            C += HC - 1
            WC += 1
        else:
            res *= C
            res %= mod
            C -= 1
        #print(f"k: {k}, HC: {HC}, WC: {WC}, C: {C}, res: {res}")
        if res == 0:
            break
    print(res)


if __name__ == "__main__":
    main()


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

int main(){
    using namespace std;
    long N;
    cin >> N;
    vector<long> v(5);
    for(auto& i : v)cin >> i;
    cout << 5 + (N - 1) / *min_element(v.begin(), v.end()) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#else
#define VS_ENDPAUSE()
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;

#if 0
#define INT8_MIN	(-127)
#define INT8_MAX	( 128)
#define UINT8_MAX	( 255)
#define INT16_MIN	(-32768)
#define INT16_MAX	( 32767)
#define UINT16_MAX	( 65535)
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18

void func(void);
#pragma endregion

int main(void)
{
	func();
	VS_ENDPAUSE();
	return 0;
}



void func(void)
{
	char s[100];
	int a[26] = {0};
	scanf("%s", s);
	int len = strlen(s);

	for(int i=0; i<len; i++){
		a[ s[i]-'a' ] += 1;
	}
	for(int i=0; i<26; i++){
		if(a[i] > 1){
			printf("no\n");
			return;
		}
	}
	printf("yes\n");

	return;
}




Measured memory_bytes: 256
#include <cstdio>
int min(int a,int b){
	return a<b?a:b;
}
const int Maxn=1000;
char s[Maxn+5],t[Maxn+5];
int n,m;
int calc(int x){
	int ans=0;
	for(int i=1;i<=m;i++){
		if(s[i+x]!=t[i]){
			ans++;
		}
	}
	return ans;
}
int main(){
	scanf("%s",s+1);
	scanf("%s",t+1);
	while(s[++n]!='\0');
	n--;
	while(t[++m]!='\0');
	m--;
	int ans=m;
	for(int i=1;i<=n-m+1;i++){
		ans=min(ans,calc(i-1));
	}
	printf("%d\n",ans);
	return 0;
}


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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define ll long long
#define vi vector < int >
#define si set <int>
#define mii map <int, int>
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code
int n, m;
const int N = 1e5 + 5;
vector<int> v[N];
int dp[N];

int solve(int x) {

	if (dp[x] != -1) return dp[x];

	int leaf = 1, best = 0;

	for (auto i : v[x]) {
		leaf = 0;
		best = max(best, solve(i));
	}
	return dp[x] = 1 + best;
}

int32_t main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast;
	memset(dp , -1, sizeof dp);
	int x, y;
	cin >> n >> m;
	while (m--) {
		cin >> x >> y;
		v[x].push_back(y);
	}
	int ans = 0;
	f(i, 1, n + 1) ans = max(ans, solve(i));
	cout << ans - 1 << nl;
}

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

int main()
{

	int n;
	int a[1000];

	cin >> n;
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i];
	}
	for(int i = n ; i > 0; i--)
	{
		cout << a[i-1];
		if(i > 1)
		{
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}


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

using namespace std;

bool arr[110];
vector<int> vec;

void Eratosthenes(){
  
  for(int i = 0; i < 110; i++){ arr[i] = true;}
  
  arr[0] = false; arr[1] = false;
  
  for(int i = 2; i < 110; i++){
    if( !arr[i]){ continue;}
    else{
     for(int j = 2; i* j < 110; j++){
         arr[i*j] = false;}
    }
  }
}

void prime_solusion(int a){
 
  for(int j = 2; j <= a; j++){
    if( !(a % j) &&arr[j]){ 
      //aがjで割り切れ、かつjが素数の時、aが素因数jを何個もつかを数える
        int k = a;
        while( !( k % j)){ k /= j; vec[j]++;}
    }
  }
}
  

long long COM(int a, int b){
 if( b == 1){ return a;}
 if( b == 2){ return ( a * ( a - 1)) / 2;}
 if( b == 3){ return ( a * ( a - 1 ) * ( a - 2)) / 6;}
}

      
      
      
      
int main(){
int N; cin >> N;
 vec= vector<int>( 110 , 0);
  // vec[i]で、N！が　素因数i　を　何個もつかが示される
  Eratosthenes(); //素数列挙
  
  for(int i = 2; i <= N; i++){
    // i　を　素因数分解した結果をvecに収めて、Nまで合算する
    prime_solusion(i);}
  
  int cnt74 = 0; int cnt24 = 0; int cnt14 = 0; 
  int cnt4 = 0; int cnt2 = 0;
  
  for(int i = 0; i < 110; i++){
         if( vec[i] >= 74){ cnt74++;}
    else if( vec[i] >= 24){ cnt24++;}
    else if( vec[i] >= 14){ cnt14++;}
    else if( vec[i] >= 4) { cnt4++;}
    else if( vec[i] >= 2) { cnt2++;}}
    
  long long  ans = 0;
  
  // p^2 * q^4 * r^4 のパターンについて
  
  ans += cnt2 * COM( cnt4 + cnt14 + cnt24 + cnt74, 2);
  ans += COM( cnt4 + cnt14 + cnt24 + cnt74, 3) * 3;
  
  //p^14 * q^4のパターンについて
  
  ans += cnt4 * COM( cnt14 + cnt24 + cnt74,1);
  ans += COM( cnt14 + cnt24 + cnt74,2) * 2;
  
  //p^24 * q^2のパターンについて
  
  ans += (cnt2 + cnt4 + cnt14) * COM( cnt24 + cnt74,1);
  ans += COM( cnt24 + cnt74, 2) * 2;
  
  // p^74のパターンについて
  
  ans += COM( cnt74, 1);
  
  cout << ans << endl; return 0;}
  
  

Measured memory_bytes: 256
a,b=map(int,input().split())
num=0

if a%2==0 and b%2==1 or a%2==1 and b%2==0:
  num=1
  
if a>0 and b>0 or a<0 and b<0 and num==1:
  print("Positive")
  
elif a<0 and b<0 and num==0 or a<0 and b<0:
  print("Negative")
  
else:
  print("Zero")

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;

using namespace std;

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

	vector<int>l(n);
	rep(i, n)cin >> l[i];

	SORT(l);
	reverse(all(l));

	int sum = 0;
	rep(i, k) {
		sum += l[i];
	}
	cout << sum << endl;
}

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

int main()
{
    string s;
    int r=0;
    cin >> s;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]=='o')
            r++;
    }
    if((15-(int)s.size())+r>=8)
        cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

int main() {
  int N, R;
  cin >> N >> R;
  
  if (N >= 10) {
    cout << R << endl;
  }
  else {
    cout << R + 100 * (10 - N) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
n = 110000
primes = set(range(3, n+1, 2))|set([2])
for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*3, n+1, i*2))
primes=list(primes)
primes.sort()
x = int(input())
for i in primes:
  if i >=x:
    print(i)
    break

Measured memory_bytes: 8812
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, N;
    cin >> K >> N;
    int A[400010];
    int ans = INF;
    rep(i, N) {
        cin >> A[i];
        A[i + N] = A[i] + K;
    }
    rep(i, N) {
        ans = min(ans, A[N - 1 + i] - A[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
# https://atcoder.jp/contests/abc128/submissions/8312583
# 写経

def solve():
    from heapq import heappush, heappop
    from collections import defaultdict
    from operator import itemgetter
    import sys

    input = sys.stdin.readline

    inf = 1 << 31

    n, q = map(int, input().split())

    S = [0] * n
    T = [0] * n
    X = [0] * n
    for i in range(n):
        S[i], T[i], X[i] = map(int, input().split())

    e = [(t - x, 0, x) for t, x in zip(T, X)]
    e.extend([(s - x, 1, x) for s, x in zip(S, X)])
    e.extend([(int(input()), 2, idx) for idx in range(q)])
    # e = [*((t - x, 0, x) for t, x in zip(T, X)),
    #      *((s - x, 1, x) for s, x in zip(S, X)),
    #      *((int(input()), 2, idx) for idx in range(q))
    #      ]
    e.sort(key=itemgetter(0))
    # 安定ソートなので、0,1,2順になる（はず

    cnt = defaultdict(int)
    cnt[inf] = 1
    h = [inf]
    ret = [-1] * q
    for time, type, x in e:
        if type == 0:
            cnt[x] -= 1
        elif type == 1:
            heappush(h, x)
            cnt[x] += 1
        else:
            while not (cnt[h[0]]):
                heappop(h)
            curr = h[0]
            if curr != inf:
                ret[x] = curr

    print(*ret, sep='\n')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 126168
N = gets.to_i
s = 0
A1 = [0] + gets.split.map(&:to_i).map{ |a| s += a; s }
s = 0
A2 = [0] + gets.split.map(&:to_i).map{ |a| s += a; s }
p (1...A1.size).map{ |i|
  A1[i] + (A2[-1] - A2[i-1])
}.max


Measured memory_bytes: 1788
#include<stdio.h>
#define N 10000
#define TRUE 1
#define FALSE 0

int a[N],n,key;

int search(){
  int i=0;
  a[n]=key;
  while(a[i]!=key){
    i++;
    if(i==n) return FALSE;   
  }
  return TRUE;
}

int main(){
  int q,i,sum=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(search()==TRUE) sum++;
  }
  
  printf("%d\n",sum);
  
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  if((N/10)%111 == 0 ||(N % 1000) %111 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000LL
#define MOD 1000000009
#define EPS 1E-9

typedef ll Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void Dijkstra(const Graph &g, int s, vector<Weight> &dist, vi &prev)
{
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if(prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    vrep(f, g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}

int V, E, r;
int s, t;
Weight d;

int main()
{
  cin >> V >> E >> r;
  Graph g(V);
  vi prev(V);
  vector<Weight> dist;
  rep(i, E){
    cin >> s >> t >> d;
    g[s].pb(Edge(s, t, d));
  }

  Dijkstra(g, r, dist, prev);

  rep(i, V) if(dist[i] >= INF) puts("INF"); else printf("%d\n", dist[i]);

  return 0;
}

Measured memory_bytes: 18016
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,A,maxA;
	long long int ans=0;
	cin>>N>>maxA;
	for(int i=1;i<N;i++){
		cin>>A;
		if(A<maxA)ans+=maxA-A;
		maxA=max(A,maxA);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int k;
	cin >> k;
	int cur = 0, cnt = 0;
	while(true) {
		cur = (cur * 10 + 7) % k;
		cnt++;
		if(cur == 0) {
			cout << cnt << endl;
			break;
		}
		if(cnt > k) {
			cout << -1 << endl;
			break;
		}
	}
	
}





Measured memory_bytes: 3696
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

using namespace std;
struct m_proc {
    char name[11];
    int timeslice;
};

m_proc p[100000];
int head, tail;
void enqueue(m_proc lp) {
    p[tail] = lp;
    tail++;
    tail = tail % 100000;
}

m_proc dequeue() {
    m_proc lp = p[head];
    head++;
    head = head % 100000;
    return lp;
}

int main() {
    head = 0;
    int n, q;
    cin >> n;
    cin >> q;
    //m_proc *p = new m_proc[n];
    for(int i=0; i<n; i++) {
        scanf("%s", &(p[i].name));
        scanf("%d", &p[i].timeslice);
    }
    tail = n;
    int t = 0;
    int c = n;
    while(head != tail) {
        m_proc mp = dequeue();
        mp.timeslice -= q;
        t += q;
        if (mp.timeslice <= 0)
        {
            t += mp.timeslice;
            printf("%s %d\n", mp.name, t);
            continue;
        }
        enqueue(mp);
    }
}


Measured memory_bytes: 4636
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 1'000'000'007;

int main() {

    llint N;
    cin >> N;
    vector<int> cnt(N);
    for(int i = 1; i < N; i++) {
        int a;
        cin >> a;
        cnt[a - 1]++;
    }
    for(auto e: cnt) {
        cout << e << endl;
    }
}

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

int main(){
    double L;
    cin >> L;
    double X = L / 3;
    cout << setprecision(17)<< X * X * X << endl;
}



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

using namespace std;

#define allof(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define exists(s, e) (s.find(e)!=s.end())
#define INF 0x3f3f3f3f
#define f first
#define s second
#define endl '\n'
#define mp make_pair
#define watch(x) cout << (#x) << " is " << (x) << endl;

typedef pair<int, int> pii;
typedef long long ll;

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

void solve() {
    int d; cin >> d;
    if(d==25) cout << "Christmas" << endl;
    else if(d==24) cout << "Christmas Eve" << endl;
    else if(d==23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    solve();
    return 0;
}


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

typedef long long LL;

const int MOD = 2e5 + 3, G = 2, MAXN = 2e5 + 10, MAXM = 1 << 19 | 1;
const double PI = acos(-1.);

int n;
int powG[MAXN], logG[MAXN], cnt[MAXN], rev[MAXM];
struct Complex {
	double x, y;
	Complex(double x = 0, double y = 0): x(x), y(y) {}
	inline friend Complex operator+ (const Complex &a, const Complex &b) { return Complex(a.x + b.x, a.y + b.y); }
	inline friend Complex operator- (const Complex &a, const Complex &b) { return Complex(a.x - b.x, a.y - b.y); }
	inline friend Complex operator* (const Complex &a, const Complex &b) { return Complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
} A[MAXM], B[MAXM];

inline void init() {
	powG[0] = 1, logG[1] = 0;
	for (int i = 1; i <= MOD - 2; ++i) powG[i] = G * powG[i - 1] % MOD, logG[powG[i]] = i;
}

inline void trans(Complex *A, int n, int opt) {
	for (int i = 0; i < n; ++i) if (i < rev[i]) std::swap(A[i], A[rev[i]]);
	for (int i = 2; i <= n; i <<= 1) {
		int mid = i >> 1; Complex Wn(cos(PI / mid), sin(PI / mid));
		for (int j = 0; j < n; j += i) {
			Complex W(1, 0);
			for (int k = 0; k < mid; ++k, W = W * Wn) {
				Complex X = A[j | k], Y = W * A[j | k | mid];
				A[j | k] = X + Y, A[j | k | mid] = X - Y;
			}
		}
	}
	if (opt) {
		std::reverse(A + 1, A + n);
		for (int i = 0; i < n; ++i) A[i].x /= n;
	}
}
inline void DFT(Complex *A, int n) { trans(A, n, 0); }
inline void IDFT(Complex *A, int n) { trans(A, n, 1); }

int main() {
	init();
	scanf("%d", &n);
	for (int i = 1, x; i <= n; ++i) scanf("%d", &x), x && (++cnt[logG[x]]);
	for (int i = 0; i <= MOD; ++i) A[i].x = B[i].x = cnt[i];
	int lim = 1, index = 0;
	for (; lim < MOD << 1; lim <<= 1, ++index);
	for (int i = 1; i < lim; ++i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (index - 1));
	DFT(A, lim), DFT(B, lim);
	for (int i = 0; i < lim; ++i) A[i] = A[i] * B[i];
	IDFT(A, lim);
	LL ans = 0;
	for (int i = 0; i < lim; ++i) ans += llround(A[i].x) * powG[i % (MOD - 1)];
	for (int i = 0; i <= MOD; ++i) ans -= 1LL * cnt[i] * (1LL * powG[i] * powG[i] % MOD);
	printf("%lld\n", ans >> 1);
	return 0;
}

Measured memory_bytes: 24888
n,i=1;main(r){
for(scanf("%d",&n),r=n;i*i<=n;)if(n%++i==0)for(r=1LL*r*(i-1)/i;n%i==0;n/=i);
if(--n)r=1LL*r*n/++n;
n=!printf("%d\n",r);
}

Measured memory_bytes: 592
n = int(input())
s = input()

i = 0
ans = 0
while i < n-2:
	if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
		ans += 1
		i += 3
	else:
		i += 1


print(ans)		


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n;
    map<string, int> s, t;
    rep(i, n){
        string S;
        cin >> S;
        s[S]++;
    }
    cin >> m;
    rep(i, m){
        string T;
        cin >> T;
        t[T]++;
    }

    int ans = 0;
    for(auto i = s.begin(); i != s.end(); i++){
        ans = max(ans, i->second - t[i->first]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC063_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var s = new int[N];
            for (int i = 0; i < s.Length; i++)
            {
                s[i] = int.Parse(Console.ReadLine());
            }

            if (s.Sum() % 10 != 0)
            {
                Console.WriteLine(s.Sum());
                return;
            }
            if (!s.Where(x => x % 10 != 0).Any())
            {
                Console.WriteLine(0);
                return;
            }

            Array.Sort(s);

            foreach (var i in s)
            {
                if (i % 10 == 0) continue;
                Console.WriteLine(s.Sum() - i);
                return;
            }
        }
    }
}


Measured memory_bytes: 13396
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class prog
{
    public static void Main()
    {
       int N = int.Parse(Console.ReadLine());
       
       int ans = 0;
       
       for(int i = 1; i <= N ; i++){
           string s = i.ToString();
           if(s.Length % 2 == 1) ans++;
       }
       Console.WriteLine(ans);
    }
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n, x[100000], l, q;
    cin >> n;
    for(int i=0;i<n;i++) cin >> x[i];
    cin >> l >> q;

    static int r[100000][20];
    for(int j=0;j<20;j++){
        for(int i=0;i<n;i++){
            if(j==0){
                int ok = i, ng = n;
                while(ng-ok > 1){
                    int mid = (ok+ng)/2;
                    if(x[mid] <= x[i] + l) ok = mid;
                    else ng = mid;
                }
                r[i][j] = ok;
            }else{
                r[i][j] = r[r[i][j-1]][j-1];
            }
        }
    }

    for(int i=0;i<q;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(b < a) swap(a, b);

        int ok = n, ng = 0;
        while(ok-ng>1){
            int mid = (ok+ng)/2;
            int pos = a;
            for(int j=20;j>=0;j--){
                if((1<<j) & mid) pos = r[pos][j];
            }
            if(pos >= b) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }

    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;
#define out(i) cout<<(i)<<endl

int main() {
  ll A,B,C,cnt=0;
  bool flag=false;
  cin>>A>>B>>C;
  while(A%2==0&&B%2==0&&C%2==0){
    ll a=A,b=B,c=C;
    if(a==b&&b==c){flag=true; break;}
    a=(C+B)/2; b=(A+C)/2; c=(A+B)/2;
    A=a; B=b; C=c;
    cnt++;
  }
  if(flag){out(-1);}
  else{out(cnt);}
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val dp = Array(m + 1) { 0L }

    for (i in 0 until n) {

        val (s1, s2) = readLine()!!.split(' ')
        val w = s1.toInt()
        val v = s2.toLong()

        for (tw in m downTo 0) {
            if (tw - w >= 0) {
                dp[tw] = Math.max(dp[tw], dp[tw - w] + v)
            }
        }
    }

    println(dp[m])
}


Measured memory_bytes: 123152
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    cin>>a;
    int ans=INF;
    int tmp=0;
    int sum=0;
    REP(f,2) {
        tmp=0;
        sum=0;
        REP(i,n) {
            sum+=a[i];
            if(i%2==f) {
                if(sum<=0) {
                    tmp+=abs(1-sum);
                    sum=1;
                }
            } else {
                if(sum>=0) {
                    tmp+=abs(-1-sum);
                    sum=-1;
                }
            }
        }
        chmin(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int x; scanf("%d", &x);
	
	printf("%d\n", 8 - (x - 400) / 200);
	return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll uni[10005];
ll root(ll u){
    if(uni[u]<0)return u;
    return uni[u]=root(uni[u]);
}

void connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return;
    if(uni[a]<uni[b]){
        a^=b;
        b^=a;
        a^=b;
    }
    uni[a]+=uni[b];
    uni[b]=a;
    return;
}
ll size(ll u){
    return -uni[root(u)];
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    memset(uni,-1,sizeof(uni));
    int n,q;
    cin>>n>>q;
    int a,b,c;
    vector<int> v;
    for(int i=0;i<q;i++){
    	cin>>a>>b>>c;
    	if(a==1){
    		if(root(b)==root(c)){
    			v.pb(1);
    		}else{
    			v.pb(0);
    		}
    	}else{
    		connect(b,c);
    	}
    }
    for(auto& i:v){
    	cout<<i<<endl;
    }
    return 0;
}



Measured memory_bytes: 3416
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long K){
  vector<int> a {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[K-1] << endl;
}

// 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)
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
}


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

long long node,edge,r;
long long dist[500][500];
long long cities[400];

void fw(long long n)
{
    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=n;j++)
        {
            for(long long k=1;k<=n;k++)
            {
                dist[j][k] = min(dist[j][k],dist[j][i]+dist[i][k]);
            }
        }
    }
}

int main()
{
    cin >> node >> edge >> r;
    for(long long i=1;i<=node;i++)
        for(long long j=1;j<=node;j++)
        {
            if(i==j)    dist[i][j]=0;
            else        dist[i][j]=INT_MAX;
        }
    for(long long i=0;i<r;i++)
        cin >> cities[i] ;
    sort(cities,cities+r);



    for(long long i=0;i<edge;i++)
    {
        long long x,y,d;
        cin >> x >> y >> d;
        if(dist[x][y]>d)    dist[x][y]=d;
        if(dist[y][x]>d)    dist[y][x]=d;
    }


     fw(node);

    long long ans=INT_MAX;
    do
    {
        long long res = 0;
        for(long long i=1;i<node;i++)   res+=dist[cities[i-1]][cities[i]];
        ans = min(ans,res);
    }while(next_permutation(cities,cities+r));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1024
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
ind=a.index(m)
m2=-1e10
for i in range(n):
    if i!=ind:
        m2=max(m2,a[i])
for i in range(n):
    if i==ind:
        print(m2)
    else:
        print(m)


Measured memory_bytes: 12520
#include <iostream>
#include <algorithm>
using namespace std;
int N, K, a[100009];
int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> a[i];
	int g = a[0];
	for (int i = 1; i < N; i++) g = gcd(g, a[i]);
	int r = *max_element(a, a + N);
	if (K <= r && K % g == 0) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mp make_pair
 
using namespace std;
 
inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}
 
inline void read(int &x){
  char c=nc();int b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline void read(LL &x){
  char c=nc();LL b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

inline int read(char *s)
{
	char c=nc();int len=1;
	for(;!(c>='a' && c<='z');c=nc()) if (c==EOF) return 0;
	for(;(c>='a' && c<='z');s[len++]=c,c=nc());
	s[len++]='\0';
	return len;
}

inline void read(char &x){
  for (x=nc();!(x>='A' && x<='Z');x=nc());
}

int wt,ss[19];
inline void print(int x){
	if (x<0) x=-x,putchar('-'); 
	if (!x) putchar(48); else {
	for (wt=0;x;ss[++wt]=x%10,x/=10);
	for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
	if (x<0) x=-x,putchar('-');
	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

int n,m,a[200010],b[200010];

int main()
{
	read(n);read(m);
	if (m==1 || m==2*n-1) puts("No");
	else
	{
		puts("Yes");
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		if (m>2)
		{
			a[n-1]=m-1,a[n]=m,a[n+1]=m+1,a[n+2]=m-2;
			b[m-2]=1,b[m-1]=1,b[m]=1,b[m+1]=1;
		}
		else
		{
			a[n-1]=m+1,a[n]=m,a[n+1]=m-1,a[n+2]=m+2;
			b[m-1]=1,b[m]=1,b[m+1]=1,b[m+2]=1;
		}
		int x=1;
		for (int i=1;i<n-1;i++)
		{
			while (b[x]==1) x++;
			a[i]=x;b[x]=1;
		}
		for (int i=n+3;i<=2*n-1;i++)
		{
			while (b[x]==1) x++;
			a[i]=x;b[x]=1;
		}
		for (int i=1;i<=2*n-1;i++)
			print(a[i]),puts("");
	}
	return 0;
}

Measured memory_bytes: 3072
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Created by YuyaKita on 2015/05/18.
 */
public class Main {
    static final int MAX_W = 50, MAX_H = 50;
    static int W, H;
    static int[][] world = new int[MAX_H + 1][MAX_W + 1];
    static int count = 0;
    static int[] dx = {-1, 0, 1, 0};
    static int[] dy = {0, -1, 0, 1};

    public static void main(String args[]) throws FileNotFoundException {

        Scanner sc = new Scanner(System.in);
        while (true) {
            W = sc.nextInt();
            H = sc.nextInt();
            if (W == 0 && H == 0){

                break;
            }
            for (int i = 0; i < H; i++) {
                for(int j = 0;j<W;j++){
                    world[i][j] = sc.nextInt();
                }
            }

            System.out.println(solve(world));
        }

    }

    static int solve(int[][] input) {
        int res = 0;
        for (int i = 0; i < W; i++) {
            for (int j = 0; j < H; j++) {
                if (world[j][i] == 1){
                    dfs(i, j);
                    res++;
                }
            }
        }
        return res;
    }

    static void dfs(int x, int y) {
        count++;
        world[y][x] = 0;
        for (int dx = -1; dx <= 1; dx++) {
            for(int dy=-1; dy<=1;dy++){
            int nx = x + dx;
            int ny = y + dy;
                if (nx >= 0 && nx < W && ny >= 0 && ny < H && world[ny][nx] == 1) {
                    dfs(nx, ny);
                }
            }

        }

    }
}

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

// #define int long long

/* short */
#define pb push_back
#define print(Target) cout << Target << '\n'

/* REPmacro */
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

/* const */
const int INF = INT_MAX;

int dp[31];

int shinobu(int n)
{
  if (dp[n] != -1){
    return (dp[n]);
  }
  if (n == 1) return (1);
  if (n == 2) return (2);
  if (n == 3) return (4);
  return (shinobu(n - 1) + shinobu(n - 2) + shinobu(n - 3));
}

signed main()
{
  ios::sync_with_stdio(false);
  int n;

  while (cin >> n, n){
    fill(dp, dp + 31, -1);
    print(shinobu(n) / 3650 + 1);
  }
  return (0);
}

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

using namespace std;

int main() {

    int P,Q,R;
    cin >> P >> Q >> R;

    vector<int> flightTime;
    flightTime.push_back(P);
    flightTime.push_back(Q);
    flightTime.push_back(R);

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

    cout << flightTime[0] + flightTime[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <vector>

const int MAXN = 5e5;
int n, K, p[MAXN + 5], mn[MAXN << 2], suf[MAXN + 5], d[MAXN + 5];
int buc[MAXN + 5], ans[MAXN + 5];
std::vector<int> dag[MAXN + 5];

inline int rint () {
	int x = 0; char s = getchar ();
	for ( ; s < '0' || '9' < s; s = getchar () );
	for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );
	return x;
}

inline int max_ ( const int a, const int b ) { return a < b ? b : a; }
inline int min_ ( const int a, const int b ) { return a < b ? a : b; }

inline void build ( const int rt, const int l, const int r ) {
	mn[rt] = n + 1;
	if ( l == r ) return ;
	int mid = l + r >> 1;
	build ( rt << 1, l, mid ), build ( rt << 1 | 1, mid + 1, r );
}

inline void update ( const int rt, const int l, const int r, const int x, const int v ) {
	if ( l == r ) return void ( mn[rt] = v );
	int mid = l + r >> 1;
	if ( x <= mid ) update ( rt << 1, l, mid, x, v );
	else update ( rt << 1 | 1, mid + 1, r, x, v );
	mn[rt] = min_ ( mn[rt << 1], mn[rt << 1 | 1] );
}

inline int query ( const int rt, const int l, const int r, const int ql, const int qr ) {
	if ( ql <= l && r <= qr ) return mn[rt];
	int mid = l + r >> 1, ret = n + 1;
	if ( ql <= mid ) ret = min_ ( ret, query ( rt << 1, l, mid, ql, qr ) );
	if ( mid < qr ) ret = min_ ( ret, query ( rt << 1 | 1, mid + 1, r, ql, qr ) );
	return ret;
}

inline void topoSort () {
	std::priority_queue<int, std::vector<int>, std::greater<int> > heap;
	int cnt = 0;
	for ( int i = 1; i <= n; ++ i ) if ( ! d[i] ) heap.push ( i );
	while ( ! heap.empty () ) {
		int u = heap.top (); heap.pop ();
		ans[u] = ++ cnt;
		for ( int v: dag[u] ) if ( !-- d[v] ) heap.push ( v );
	}
}

int main () {
	n = rint (), K = rint ();
	for ( int i = 1; i <= n; ++ i ) p[rint ()] = i;
	build ( 1, 1, n );
	for ( int i = n; i; -- i ) {
		int l = max_ ( p[i] - K + 1, 1 ), r = min_ ( p[i] + K - 1, n ), t;
		if ( ( t = query ( 1, 1, n, l, p[i] ) ) <= n ) {
			dag[p[i]].push_back ( p[t] );
			++ d[p[t]];
		}
		if ( ( t = query ( 1, 1, n, p[i], r ) ) <= n ) {
			dag[p[i]].push_back ( p[t] );
			++ d[p[t]];
		}
		update ( 1, 1, n, p[i], i );
	}
	topoSort ();
	for ( int i = 1; i <= n; ++ i ) printf ( "%d\n", ans[i] );
	return 0;
}

Measured memory_bytes: 41264
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int a, b, x;
    cin >> a >> b >> x;
    if (x <= a * a * b / 2) {
        double t = (double)(a * b * b) / (double)(2 * x);
        double deg = 180 * atan(t) / M_PI;
        printf("%f\n", deg);
    }
    else {
        double t = (double)(2 * (a * a * b - x)) / (double)(a * a * a);
        double deg = 180 * atan(t) / M_PI;
        printf("%f\n", deg);
    }
    return 0;
}


Measured memory_bytes: 384