akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int N;
long long h[100010];
long long dp[100010];

long long rec(int i) {
  if (dp[i] < INF) return dp[i];
  if (i==0) return 0;
  long long res = INF;
  chmin(res, rec(i-1) + abs(h[i]-h[i-1]));
  if (i > 1) chmin(res, rec(i-2)+abs(h[i] - h[i-2]));
  return dp[i] = res;
}

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

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 答え
    cout << rec(N-1) << endl;
}


Measured memory_bytes: 9860
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int d[111][111];
int n;
int main(void){
  cin >> n;

  for(int i = 0; i < n; i++){
    fill(d[i],d[i]+n,1 << 20);
    d[i][i] = 0;
  }


  for(int i = 0; i < n; i++){
    int r,k;
    cin >> r >> k;
    for(int j = 0; j < k; j++){
      int t;
      cin >> t;
      d[r - 1][t - 1] = 1;
    }
  }


  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int p;
  cin >> p;
  for(int i = 0; i < p; i++){
    int s,g,v;
    cin >> s >> g >> v;
    if(d[s-1][g-1] + 1 <= v){
      cout << d[s-1][g-1] + 1 << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

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


vector<int> ar[200001];

int main()
{
    int n;
    cin>>n;
    for(int i=2;i<=n;i++){
        int a;
        cin>>a;
        ar[a].push_back(i);
    }
    for(int i=1;i<=n;i++){
            int sum = 0;
         for(auto it = ar[i].begin();it!=ar[i].end();it++){
            sum++;
         }
        cout<<sum <<endl;
    }


}


Measured memory_bytes: 14520
s = input()
K = int(input())

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)<K:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define MODD 1000000007
#define ll long long
using namespace std;

int T[111111];
int A[111111];

int main() {
    int N;
    cin>>N;
    T[0]=0;
    for(int i=1;i<=N;i++) {
        cin>>T[i];
    }
    
    for(int i=1;i<=N;i++)
        cin>>A[i];
    A[N+1]=0;
    
    ll ans = 1;
    for(int i=1;i<=N;i++) {
        if (T[i]>T[i-1] || A[i]>A[i+1]) {
            int x = (T[i]>T[i-1] ? T[i] : A[i]);
            
            if (x > T[i] || x > A[i])
                ans = 0;
            
        } else {
            ans = (ans * min(A[i], T[i]))%MODD;
        }
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
int main()
{
  int n;
  int ans=0;
  char s[10];
  cin >> s;
  
  sort(s,s+4);
  
  if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip() # ignore trailing spaces 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

def sumitrust2019_d(a,b,c,s):
    abc = list(map(str,[a,b,c]))
    now = 0
    for i in range(len(s)):
        if s[i] == abc[now]:
            now += 1
            if now == 3:
            	return True
    return False

def main():
    n = ni()
    s = ns()
    ans = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                if sumitrust2019_d(a,b,c,s):
                    ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back


int main() {
  int s; cin>>s;
  vi dp(2020);
  dp[0]=1,dp[1]=dp[2]=0;
  ll ans;
  const int MOD=1e9+7;
  int sum=0;

  for(int i=3;i<=s;i++) {
    sum+=dp[i-3];
    sum%=MOD;
    dp[i]=sum;
  }
  cout<<dp[s]<<endl;
}


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

using namespace std;

int n;
int c[500];
int s[500];
int f[500];

int time(int k) {
	int ans=0;

	for (int i = k; i < n-1; i++)
	{
		if (ans<s[i]) {
			ans = s[i] + c[i];
		}
		else {
			int temp = ans - s[i];
			if (temp%f[i] != 0) {
				ans = ans + f[i] - temp%f[i];
			}
			ans += c[i];
		}

	}
	return ans;
	
}



int main() {

	cin >> n;

	for (int i = 0; i < n-1; i++)
	{
		cin >> c[i] >> s[i] >> f[i];
	}

	for (int i = 0; i < n; i++)
	{
		cout << time(i) << endl;
	}


	return 0;
}



Measured memory_bytes: 256
n = int(input())
N = []
for i in range(n):
    N.append(input())
Nn = [sorted(j) for j in N]
Nn.sort()
Nh = []
for let in Nn:
    Nh.append(('').join(let))
c_dict = {}
for letters in Nh:
    if letters not in c_dict:
        c_dict[letters] = 1
    elif letters in c_dict:
        c_dict[letters] += 1
ans_list = []
for letter, num in c_dict.items():
    ans_list.append((num * (num-1))//2)
print(sum(ans_list))


Measured memory_bytes: 48584
from itertools import permutations
import math

N = int(input())
xy = []
for _ in range(N):
    xy.append(list(map(int, input().split())))

    
n_root = 0
dist = []
for r in permutations(range(N)):
    # print(r)
    curr_dist = []
    for i in range(1,N):
        curr_dist.append(math.sqrt(\
           (xy[r[i]][0] - xy[r[i-1]][0])**2 +\
           (xy[r[i]][1] - xy[r[i-1]][1])**2
           ))
    dist.append(sum(curr_dist))
    n_root += 1
    # break
    
print(sum(dist)/n_root)


Measured memory_bytes: 4400
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
template <class ForwardIterator, class T>
bool All_of(ForwardIterator first, ForwardIterator last, const T& value) {
	for (; first < last; ++first) if (*first != value) return false; return true;
}
// all_of

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#include "Geometry.h"
#include "Matrix.h"
#include "Segment_Tree.h"
#include "Rational.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
template <class T>
auto Is(const T& value) { return [value](const auto& comparand) -> bool { return comparand == value; }; }
#endif

int N;
set<char> c;
int main() {
	cin >> N;
	REP(i, 0, N) {
		char a;
		cin >> a;
		c.insert(a);

	}
	cout << (c.size() == 3 ? "Three" : "Four" )<< endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;string s;cin>>n>>s;
  int ans=0;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A' and s[i+1]=='B' && s[i+2]=='C')ans++;
  }
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	while(n--){
		vector<int> v(3);
		for (int i = 0; i < 3; ++i){
			cin>>v[i];
		}
		sort(v.begin(), v.end());
		if (v[2]*v[2] == v[0]*v[0] + v[1]*v[1])
			cout<<"YES";
		else
			cout<<"NO";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[100], D[100];
	constexpr shuturyoku_unko() : C(), D() {
		for (int i = 10; i < 100; i++) {
			C[i] = '0' + i / 10;
			D[i] = '0' + i % 10;
		}
	}
} f;

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X < 10) {
		*di++ = '0' + X;
		*di++ = '\n';
		return;
	}
	*di++ = '0' + f.C[X];
	*di++ = '0' + f.D[X];
	*di++ = '\n';
}

char S[200010];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	fread(S, 1, 200000, stdin);
	

	int cnt = 0;
	rep(i, N) cnt += S[i] - '0';

	int mod1 = cnt + 1;
	int mod2 = cnt - 1;

	if (cnt == 0) {
		rep(i, N) putint(1);
		fwrite(dn, 1, di - dn, stdout);
		Would you please return 0;
	}
	if (cnt == 1) {
		rep(i, N - 1) putint('1' - S[i]);
		putint(('1' - S[N - 1]) * 2);
		fwrite(dn, 1, di - dn, stdout);
		Would you please return 0;
	}

	ll kazu1 = 0;
	ll kazu2 = 0;
	const ll ma = (1ll << 5) - 1;
	rep(i, N) {
		kazu1 = kazu1 * 2 + (S[i] - '0');
		kazu2 = kazu2 * 2 + (S[i] - '0');
		if (!(i & ma)) {
			kazu1 %= mod1;
			kazu2 %= mod2;
		}
	}
	int k1 = kazu1 % mod1;
	int k2 = kazu2 % mod2;

	int are1 = 1;
	int are2 = 1;
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '0') {
			int tmp = k1 + are1;
			if (tmp >= mod1) tmp -= mod1;
			int kotae = 1;
			while (tmp) {
				int k = __builtin_popcount(tmp);
				tmp = tmp % k;
				kotae++;
			}
			S[i] = kotae;
		}
		else {
			int tmp = k2 - are2 + mod2;
			if (tmp >= mod2) tmp -= mod2;
			int kotae = 1;
			while (tmp) {
				int k = __builtin_popcount(tmp);
				tmp = tmp % k;
				kotae++;
			}
			S[i] = kotae;
		}
		are1 *= 2;
		if (are1 >= mod1) are1 -= mod1;
		are2 *= 2;
		if (are2 >= mod2) are2 -= mod2;
	}

	rep(i, N) putint(S[i]);

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 4168
#include<bits/stdc++.h>
using namespace std;
int a[5000000],n,ans,z,now,pl,ru[6000000];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        ans+=abs(now-a[i]);
        now=a[i];
    }ans+=abs(now);

    for(int i=0;i<n;i++){
        int ah=0,b=a[i],c=0;
        if(i!=0)ah=a[i-1];
        if(i!=n-1)c=a[i+1];
        cout<<ans-(abs(ah-b))-(abs(b-c))+(abs(ah-c))<<endl;
    }

}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, m;
int main() {
    cin >> n >> m;
    vector<int> k(m, 0);
    vector<vector<int>> s(m, vector<int>());
    for(int i = 0; i < m; ++i) {
        cin >> k.at(i);
        for(int j = 0; j < k.at(i); ++j) {
            int ins;
            cin >> ins;
            s.at(i).push_back(ins);
        }
    }
    vector<int> p(m, 0);
    for(int i = 0; i < m; ++i) cin >> p.at(i);

    int ans = 0;
    for(int bit = 0; bit < (1<<n); ++bit) {
        vector<int> ccsw(n, 0);
        for(int i = 0; i < n; ++i) {
            if(bit & (1<<i)) {
                ccsw.at(i) = 1;
            }
        }
        int alllc = 0;
        for(int l = 0; l < m; ++l) {
            int lcnt = 0;
            for(int j = 0; j < k.at(l); ++j) {
                int chno = s.at(l).at(j) - 1;
                if(ccsw.at(chno) != 0) lcnt++;
            }
            if(lcnt % 2 == p.at(l)) alllc++;
        }
        if(alllc == m) ans++;
    }
    cout << ans << endl;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int sub = a;
    while(sub <= a * b){
        if (sub % b == c){
            cout << "YES" << endl;
            return 0;
        }
        sub += a;
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000000007
#define MOD 1000000007
#define ARRAY_MAX 405

int h,w;
char mp[ARRAY_MAX][ARRAY_MAX];
bool check[ARRAY_MAX][ARRAY_MAX];
int white = 0;
int black = 0;

void bfs(int y,int x){

    queue<P> que;
    que.push(P(y,x));
    check[y][x] = true;

    while(que.size()){
        P p = que.front();
        que.pop();
        for(int i = 0;i < 4;i++){
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(mp[p.first][p.second] == '.'){
                if(0 <= nx && nx < w && 0 <= ny && ny < h && mp[ny][nx] == '#' && check[ny][nx] == false){
                    que.push(P(ny,nx));
                    check[ny][nx] = true;
                    black++;
                }
            }else{
                //#の場合
                if(0 <= nx && nx < w && 0 <= ny && ny < h && mp[ny][nx] == '.' && check[ny][nx] == false){
                    que.push(P(ny,nx));
                    check[ny][nx] = true;
                    white++;
                }
            }
        }
    }





}

int main(){

    cin >> h >> w;
    REP(i,h){
        REP(j,w){
            cin >> mp[i][j];
        }
    }

    //(i,j)から始める経路の本数
    ll ans = 0;
    REP(i,h){
        REP(j,w){
            if(check[i][j] == false){
                if(mp[i][j] == '.'){
                    white++;
                }else{
                    black++;
                }
                bfs(i,j);
                ans += ll(white)*ll(black);
                white = black = 0;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
int main() 
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    printf("%s\n", c % __gcd(a, b) == 0 ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <climits>
using namespace std;

//static const long long INFTY = (1LL<<32);

#define MAX 105
#define NMAX 10005

int h, w, n;
int A[NMAX];
int G[MAX][MAX];

int main() {
    cin >> h >> w >> n;
    
    for ( int i = 1; i <= n; i++ ) {
        cin >> A[i];
    }
    
    int s, t;
    s = t = 0;
    
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= A[i]; j++ ) {
            G[s][t] = i;
            t++;
            if ( t == w ) {
                t = 0;
                s++;
            }
        }
    }
    
    for ( int i = 0; i < h; i++ ) {
        if ( i % 2 == 1 ) {
            for ( int j = w - 1; j >= 0; j-- ) {
                if ( j != w - 1 ) cout << " ";
                cout << G[i][j];
            }

        } else {
            for ( int j = 0; j < w; j++ ) {
                if ( j != 0 ) cout << " ";
                cout << G[i][j];
            }
        }
        cout << endl;
    }
    
    return 0;
}

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

using namespace std;

int main()
{
    int x, n, p, answer;
    cin >> x >> n;

    map<int, int> array;

    for (int i = 0; i < n; i++)
    {
        cin >> p;
        array[p]++;
    }

    for (int i = 0; i < 100; i++)
    {
        if (array[x - i] == 0)
        {
            answer = x - i;
            break;
        }
        else if (array[x + i] == 0)
        {
            answer = x + i;
            break;
        }
    }
    cout << answer << endl;

    return 0;
}


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

int main() {
	char v[100][100];
	int h, w;
	cin >> h >> w;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> v[i][j];
		}
	}
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++)cout << v[i][j];
		cout << endl;
		for (int j = 0;j < w;j++)cout << v[i][j];
		cout << endl;
	}
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
  string s = scan, t = scan;
  int n = s.length.to!int, m = t.length.to!int;
  int ans = n;
  foreach(i; 0 .. n){
    if(i + m > n) continue;
    int tmpans;
    foreach(j; 0 .. m){
      if(s[i + j] != t[j]) tmpans += 1;
    }
    ans.lowerTo(tmpans);
  }
  ans.writeln;
}


Measured memory_bytes: 3268
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int n, t; cin >> n >> t;
	VI l(n), r(n); rep(i, n)cin >> l[i] >> r[i];

	VI a(t + 3);

	rep(i, n) {
		++a[l[i]];
		--a[r[i]];
	}
	FOR(i, 1, t)a[i] += a[i - 1];
	Cout(*max_element(all(a)));
}


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

ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  ll A,B,C,D; cin>>A>>B>>C>>D;
  ll num_all = B-A+1;
  ll num_cmul = B/C - (A-1)/C;
  ll num_dmul = B/D - (A-1)/D;
  ll E = lcm(C,D);
  ll num_cdmul = B/E - (A-1)/E;
  cout << num_all - (num_cmul + num_dmul - num_cdmul) << "\n";
}


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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  vector<int> B(N);
  for(int i = 0; i < N; i++) {
    if(i != N - 1) {
      B.at(i) = A.at(i + 1) - A.at(i);
      if(B.at(i) > K / 2) {
        B.at(i) = K - B.at(i);
      }
    }
    else if(i == N - 1) {
      B.at(i) = A.at(i) - A.at(0);
      if(B.at(i) > K / 2) {
        B.at(i) = K - B.at(i);
      }
    }
  }
  sort(B.begin(), B.end());
  int ans = 0;
  for(int i = 0; i < B.size() - 1; i++) {
    ans += B.at(i);
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less   
using namespace __gnu_pbds;  
using namespace std;  
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> set1;
int main()
{  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   ll n;
   cin>>n;
   ll a[n+1];
   for(ll i=0;i<=n;i++)
   cin>>a[i];

ll dp[n+1][2];
ll cnt=0;
ll ans=1;
if(a[0]>1)
{
    ans=0;
}
if(a[0]==1)
{
  dp[0][0]=0;
  dp[0][1]=1;

}
if(a[0]==0)
{
    dp[0][0]=1;
    dp[0][1]=0;
}
ll res=1e16;
if(ans==1)
{
    for(ll i=1;i<=n;i++)
    {
        ll mm=2*dp[i-1][0];
        dp[i][1]=a[i];
        dp[i][0]=min(res,mm-a[i]);
        if(dp[i][0]<0)
        {
            ans=0;
            break;
        }
        
    }
}
if(ans==0)
cout<<-1<<endl;
else
{
    dp[n][0]=0;
    for(ll i=n-1;i>=0;i--)
    {
        ll z=dp[i+1][0]+dp[i+1][1];
        ll nn=min(dp[i][0],z);
        dp[i][0]=nn;
    }
    for(ll i=0;i<=n;i++)
    {
        cnt=cnt+dp[i][0]+dp[i][1];
    }
    cout<<cnt<<endl;
}
return 0;
}


Measured memory_bytes: 6000
import numpy as np

N, W = map(int, input().split())
w, v = [], []
for i in range(N):
    a, b = map(int, input().split())
    w += [a]
    v += [b]

DP = np.zeros(W + 1,dtype=int)

for i in range(N):
    # print(DP[w[i]:])
    # print(DP[:-w[i]])
    # print(DP[:-w[i]] + v[i])
    DP[w[i]:] = np.maximum(DP[:-w[i]] + v[i], DP[w[i]:])
    # print(DP)
print(DP[-1])

Measured memory_bytes: 15480
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
ll max(ll a,ll b){
	if(a>b) return a;
	else return b;
}
ll min(ll a,ll b){
	if(a<=b) return a;
	else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll arr[n+1];
    for(int i=1; i<=n; i++) cin>>arr[i];
    //for(int i=1; i<=n; i++) cout<<arr[i]<<" ";
    vector<int> visit(n+1,0);
    int curr=1;
    int icycle=0;
    while(visit[curr]==0){
    	visit[curr]=1;
    	//cout<<curr<<endl;
    	curr=arr[curr];
    	//cout<<curr<<endl;
    	icycle++;
	}
	int tr=arr[curr];
	int cycle=1;
	while(tr!=curr){
		tr=arr[tr];
		cycle++;
	}
	//cout<<icycle<<" "<<cycle<<" "<<endl;
	if(k>icycle){
	k=k-(icycle-cycle);
	//cout<<k<<endl;
	k=k%cycle;
	//cout<<k<<endl;
	cycle=1;
	tr=arr[curr];}
	else curr=1,tr=arr[curr],cycle=1;
	while(tr!=curr && cycle<k){
		tr=arr[tr];
		cycle++;
		if(cycle==k) break;
	}
	if(k==0) cout<<curr<<endl;
	else
	cout<<tr<<endl;
	return 0;
}

Measured memory_bytes: 5576
import sys

N = int(input())
CSF = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N - 1)]

for i in range(N - 1):
    res = 0
    for c, s, f in CSF[i:]:
        if res < s:
            res = s + c
        elif res % f == 0:
            res += c
        else:
            res += f - (res % f) + c
    print(res)
print(0)


Measured memory_bytes: 9212
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

ll A, B, H, M;

const double PI=3.14159265358979323846;

int main()
{
    cin >> A >> B >> H >> M;

    double hu = 360.0/12.0;
    double hu2 = hu/60.0;
    double mu = 360.0/60.0;

    double hk = hu*H + hu2*M;
    double mk = mu * M;

    double k = abs(hk-mk);
    k = k <= 180 ? k : 360-k;
    double rad = (PI/180.0)*k;

    double ans = sqrt(A*A+B*B-2*A*B*cos(rad));
    cout << std::fixed << std::setprecision(10) << ans << endl;

    return 0;
}

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

int main(){
	int N ;
	scanf("%d",&N);
	if( N == 1 ) puts("Hello World");
	else{
		int A , B ;
		scanf("%d%d",&A,&B);
		printf("%d\n",A+B);
	}

	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
constexpr ll mod = 1000000007;
ll f[5010][2] = {},g[5010][2] = {},dp[5010][2] = {};
int main(){
    int i,j,n,a,b;
    cin >> n >> a >> b;
    if(a<b) swap(a,b);
    for(i=0;i<b;i++) f[i][0] = 1;
    for(i=b;i<=n;i++){
        f[i][0] += (f[i - 1][0] + f[i - 1][1])%mod;
        for(j=i - b;j>=0;j--){
            (f[i][1] += f[j][0]) %= mod;
        }
    }
    for(i=0;i<=n;i++){
        for(j=max(a,i - b + 1);j<=i - 1;j++) (g[i][1] += f[j - 1][0]) %= mod;
        for(j=max(1,i - b + 1);j<=min(i - 1,a - 1);j++) (g[i][0] += f[j - 1][0]) %= mod;
    }
    dp[0][0] = 1;
    for(i=1;i<=n;i++){
        for(j=i - 1;j>=1;j--){
            (dp[i][1] += (g[i - j][1]*dp[j][0] + (g[i - j][1] + g[i - j][0])*dp[j][1])%mod) %= mod;
            (dp[i][0] += (g[i - j][0]*dp[j][0])%mod) %= mod;
        }
        for(j=1;j<b;j++){
            if(j<=i && i - j>=a) (dp[i][1] += f[i - j][0]) %= mod;
            if(j<=i && i - j<a) (dp[i][0] += f[i - j][0]) %= mod;
        }
    }
    ll ans = 0;
    (ans += dp[n][1] + f[n][0] + f[n][1]) %= mod;
    for(i=1;i<n;i++){
        (ans += (f[n - i - 1][0] + f[n - i - 1][1])*dp[i][1]%mod) %= mod;
        if(n - i>=a) (ans += (f[n - i - 1][0] + f[n - i - 1][1])*dp[i][0]%mod) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3856
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long LL;
int main()
{
    LL n,k,s;
    scanf("%lld%lld%lld",&n,&k,&s);
    LL t;
    if(s==1e9) t=s-1;
    else t=s+1;
    if(k==0){
        for(int i=1;i<n;i++) printf("%d ",t);
        printf("%d",t);
        return 0;
    }
    for(int i=1;i<=k-1;i++)
        printf("%lld ",s);
    printf("%lld",s);
    for(int i=k+1;i<=n;i++)
        printf(" %lld",t);
    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <algorithm>
using namespace std;

int N,L,Q,X[100006],J[100006][17];

int main()
{
	scanf ("%d",&N);
	for (int i=0;i<N;i++) scanf ("%d",&X[i]);
	scanf ("%d %d",&L,&Q);

	for (int i=0;i<N-1;i++) J[i][0] = upper_bound(X,X+N,X[i]+L) - X - 1;
	J[N-1][0] = N;
	for (int j=0;j<17;j++) J[N][j] = N;
	for (int i=N-1;i>=0;i--){
		for (int j=1;j<17;j++) J[i][j] = J[J[i][j-1]][j-1];
	}

	while (Q--){
		int a,b; scanf ("%d %d",&a,&b); a--; b--;
		if (a > b) swap(a,b);
		int s = 0;
		for (int i=16;i>=0;i--){
			if (J[a][i] < b) a = J[a][i], s += (1 << i);
		}
		s++;
		printf ("%d\n",s);
	}

	return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    int64_t r = 0;
    for (int i = n - 1; i >= 0; i--) {
        int64_t t = (r + a[i]) % b[i];
        if (t != 0) r += b[i] - t;
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 1024
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>

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

#define int long long

using namespace std;



signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int N, x;
    int a[100010];

    cin >> N >> x;
    rep(i,N) cin >> a[i];

    int ans = 0;
    if (a[0] > x) {
        ans += a[0] - x;
        a[0] = x;
    }
    for (int i=1; i<N; i++) {
        if (a[i - 1] + a[i] > x) {
            int temp = a[i] - (x - a[i - 1]);
            ans += temp;
            a[i] = x - a[i - 1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
N = gets.to_i
A = N.times.map { gets.to_i }

o_pos = Hash.new

A.each_with_index do |a, i|
  o_pos[a] = i
end

s_pos = Hash.new

A.sort.each_with_index do |a, i|
  s_pos[a] = i
end

ans = 0

A.each do |a|
  if (o_pos[a].even? && s_pos[a].odd?) || (o_pos[a].odd? && s_pos[a].even?)
    ans += 1
  end
end

puts ans / 2


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

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

int main() {
    int N;
    string S;

    cin >> N;
    cin >> S;

    int ans = 1;
    for (int i = 1; i < S.size(); i++) {
        if (S.at(i - 1) != S.at(i))
            ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!

        Scanner sc = new Scanner (System.in);
        
        int a = sc.nextInt();
        int b=a;
        int c =0;
        //6900
        while(true){
            if(a-1000>0){
                c++;
                a-=1000;
                
            }else if (a==0){
                System.out.println(c*1000);
                break;
            }//elseif
            else if(a-1000<=0){
          
                System.out.println((((++c)*1000))-b);
                break;
            }//elseif
        }//while
        
    }
}


Measured memory_bytes: 35712
#include <iostream>
#include <vector>
#include <tuple>
#include <limits>
using namespace std;

int main(){
	vector<pair<int, int>> v;
	int N, T;
	scanf("%d %d", &N, &T);
	for(int i=0; i<N; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		if( b > T ) {
			continue;
		}
		v.push_back({a, b});
	}

	int minCost = numeric_limits<int>::max();
	for( auto &iter : v ) {
		if( minCost > std::get<0>(iter) ) {
			minCost = std::get<0>(iter);
		}
	}

	if( minCost == numeric_limits<int>::max() ) {
		printf("TLE\n");
	}else{
		printf("%d\n", minCost);
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int N;
  cin>>N;
  int A[100];
    int r=0;
  for (int i=1; i<10; i++){
    for (int j=1; j<10; j++){
     
      A[r]=i*j;
      r++;
    }}
           bool t=false;
 for (int i=0; i<81; i++)
           {
             if (A[i]==N) {t=true;}
           }
           if (t) cout<<"Yes"<<endl;
           else cout<<"No"<<endl;
           }
      

Measured memory_bytes: 256
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)

#dp[i][j]: iまでからj枚えらんで和がkになるのは何通り
def main():
	s = input()
	if(s[0] == s[1] or s[1] == s[2]  or s[2]== s[3]):
		print('Bad')
	else:
		print('Good')

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Measured memory_bytes: 63212
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
string s;
ll mod13[100010];
ll dp[100010][13];
int main(){
    cin>>s;
    ll tmp=1;
    mod13[0]=1;
    mod13[1]=10;
    for(int i=2;i<s.length();i++){
        mod13[i]=(mod13[i-2]*9)%13;
    }
    for(int i=0;i<=s.length();i++){
        for(int j=0;j<13;j++){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(int i=1;i<=s.length();i++){
        for(int j=0;j<13;j++){
            if(s[i-1]=='?'){
                for(int k=0;k<10;k++){
                    int next=(j+mod13[s.length()-i]*k)%13;
                    dp[i][next]+=dp[i-1][j];
                    dp[i][next]%=MOD;
                }
            }else{
                int next=(j+mod13[s.length()-i]*(s[i-1]-'0'))%13;
                dp[i][next]+=dp[i-1][j];
                dp[i][next]%=MOD;
            }

        }
    }/*
    for(int i=0;i<=s.length();i++){
        for(int j=0;j<13;j++){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    cout<<dp[s.length()][5]<<endl;
    return 0;
}

Measured memory_bytes: 11392
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for( int i=0; i<N; i++ ) cin >> d.at(i);
  
  sort( d.begin(), d.end() );
  int ans = - d.at( N/2-1 ) + d.at( N/2 );
  
  cout << ans;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 char s;
 cin >> s;
 int n=s;
 if(n<=95)cout << 'A' << endl;
 else cout << 'a' << endl;

}

Measured memory_bytes: 3620
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
char in[110000];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	int ret=0;
	int cur=0;
	for(int i=0;i<n;i++){
		if(in[i]=='A'||in[i]=='T'||in[i]=='G'||in[i]=='C')cur++;
		else cur=0;
		ret=max(ret,cur);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s;
		while(null != (s = in.readLine())){
			String[] arr = s.split(" ",0);
			double[] iarr = toDoubleArray(arr);
			calc(iarr);
		}
	}
	private static double[] toDoubleArray(String[] arr){
		double[] result = new double[arr.length];
		for(int i=0;i<arr.length;i++)
			result[i] = Integer.parseInt(arr[i]);
		return result;
	}
	private static void calc(double[] arr){
		double det = arr[0]*arr[4]-arr[1]*arr[3];
		double x = (arr[2]*arr[4]-arr[1]*arr[5])/det;
		double y = (-arr[2]*arr[3]+arr[0]*arr[5])/det;
		if(x==-0)x=0.0;
		if(y==-0)y=0.0;
		System.out.printf("%.3f %.3f\n",x,y);
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N){
    int a;
    cin >> a;
    A[i] = a;
  }
  // 最大値と二番目に大きい値を求めるためにvectorをコピー
  vector<int> B(N);
  B = A;
  // コピーしたものをソート
  sort(B.begin(), B.end());
  // 一番目に大きい値と二番目に大きい値
  int max_value1, max_value2;
  max_value1 = B[N-1];
  max_value2 = B[N-2];
  // もし二番目に大きい値が指定されれば最大値を出力する
  // もし最大値が指定されれば二番目に大きい値を出力する
  rep(i, N){
    if (A[i]!=max_value1) cout << max_value1 << endl;
    else cout << max_value2 << endl;
  }
}

Measured memory_bytes: 4764
def diameter(N, E):#diamete of a tree
    from collections import deque
    V = [-1]*N
    V[0] = 0
    q = deque([0])
    while q:
        v = q.popleft()
        for w in E[v]:
            if V[w] == -1:
                V[w] = V[v] + 1
                q.append(w)
    s = V.index( max(V))
    p = deque([s])
    W = [-1]*N
    W[s] = 0
    while p:
        v = p.popleft()
        for w in E[v]:
            if W[w] == -1:
                W[w] = W[v] + 1
                p.append(w)
    return max(W)

N = int( input())
E = [ [] for _ in range(N)]
for _ in range(N-1):
    a, b = map( int, input().split())
    a, b = a-1, b-1
    E[a].append(b)
    E[b].append(a)
ans = "First"
if diameter(N, E)%3 == 1:
    ans = "Second"
print( ans)

Measured memory_bytes: 55464
//https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_c
#include<bits/stdc++.h>
using namespace std;

const int N = 303;
int H, W, K;
int a[N][N];
char cake[N][N];
bool mark[N];

void init() {
	scanf("%d %d %d", &H, &W, &K);
	for (int i = 0; i < H; i++) {
		scanf("%s", cake[i]);
		mark[i] = false;
		for (int j = 0; j < W; j++) {
			a[i][j] = 0;
		}
	}
}

void solve() {
	int cur = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (cake[i][j] == '#') {
				mark[i] = true;
				a[i][j] = cur++;
			}
		}
		for (int j = 1; j < W; j++) {
			if (!a[i][j] and a[i][j - 1]) {
				a[i][j] = a[i][j - 1];
			}
		}
		for (int j = W - 2; j >= 0; j--) {
			if (!a[i][j]) {
				a[i][j] = a[i][j + 1];
			}
		}
	}
	for (int i = 1; i < H; i++) {
		if (!mark[i] and mark[i - 1]) {
			mark[i] = true;
			for (int j = 0; j < W; j++) {
				a[i][j] = a[i - 1][j];
			}
		}
	}
	for (int i = H - 2; i >= 0; i--) {
		if (!mark[i]) {
			for (int j = 0; j < W; j++) {
				a[i][j] = a[i + 1][j];
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			printf("%d ", a[i][j]);
		}
		printf("\n");
	}
}

int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

signed main(){

	int N, a[123456], b[123456];

	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> a[i] >> b[i];

	int ans = 0;
	for (int i = N - 1; i >= 0; i--){
		if ((a[i] + ans) % b[i] == 0) continue;
		else
			ans += b[i] - (a[i] + ans) % b[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int n;
vector<vector<ll>> dp;
ll inf = 1000000000000000;
vector<ll> a;

ll rec(int l = 0, int r = n) {
  if (l == r) return 0;

  if (dp[l][r] != inf) return dp[l][r];

  if ((n - (r - l)) % 2 == 0) {
    dp[l][r] = max(rec(l,r-1) + a[r-1], rec(l+1,r) + a[l]);
  } else {
    dp[l][r] = min(rec(l,r-1) - a[r-1], rec(l+1,r) - a[l]);
  }

  return dp[l][r];
}

int main() {
  cin >> n;
  a.resize(n);
  rep(i,0,n) cin >> a[i];
  dp.assign(n+2, vector<ll>(n+2,inf));
  rep(i,0,n) dp[i][i] = 0;
  cout << rec() << endl;
  return 0;
}


Measured memory_bytes: 74008
#include <atcoder/all>
#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 998244353;

struct S {
    atcoder::modint value;
    atcoder::modint size;
};

using F = atcoder::modint;
S op(S a, S b) { return {a.value + b.value, a.size + b.size}; }
S e() { return {0, 0}; }

S mapping(F f, S x) {
    if (f == -1) {
        return x;
    } else {
        return {x.size * f, x.size};
    }
}

F composition(F f, F g) {
    if (f == -1) {
        return g;
    }
    return f;
}

F id() { return -1; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> lazy(n);

    atcoder::modint base = 1;
    repb(i, n) {
        lazy.set(i, {base, base});
        base *= 10;
    }

    vector<atcoder::modint> ans(m);
    rep(i, m) {
        int l, r, d;
        cin >> l >> r >> d;
        lazy.apply(l - 1, r, d);
        ans[i] = lazy.all_prod().value;
    }

    rep(i, m) { cout << ans[i].val() << endl; }
    return 0;
}



Measured memory_bytes: 9832
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    sort(ALL(a));
    bool flag = true;
    REP(i,n-1){
        if(a[i] == a[i+1]){
            flag=false;
            break;
        }
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3960
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

string board[30][30];

int main() {
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> board[i][j];
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (board[i][j] == "snuke") {
				cout << (char)('A'+j) << i+1 << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
const int INF = 1 << 30;

class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> H(N); cin >> H;

        vector<int> dp(N, INF);
        dp[0] = 0;
        rep(i, N) {
            if(i + 1 < N) set_min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]));
            if(i + 2 < N) set_min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]));
        }
        cout << dp[N - 1] << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long LL;

const int MOD = 1e9+7;
void solve(){
    int m,n;
    cin>>m>>n;
    int k;
    cin>>k;
    int t = max(m,n);
    int res = k/t;
    if(k%t) res++;
    cout<<res<<endl;
}

int main(){
    int T = 1;
    // cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include <iostream>

using namespace std;
char arr[4][4];

int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	if (n >= 2 && m >= 2)
	{
		printf("%lld", (n - 2)*(m - 2));
	}
	else
		printf("%lld", n*m - 2 < 0 ? 1 : n * m - 2);
	
}

Measured memory_bytes: 256