akhauriyash/Code-Regression huggingface dataset:
from operator import itemgetter


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        if self.parents[y] < self.parents[x]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    N = int(input())
    xy = [list(map(lambda x: int(x) - 1, input().split())) + [i] for i in range(N)]
    
    sorted_x = sorted(xy, key=itemgetter(0, 1))
    sorted_y = sorted(xy, key=itemgetter(1, 0))
    edges = []
    for i in range(N - 1):
        cost = min(abs(sorted_x[i][0] - sorted_x[i + 1][0]), abs(sorted_x[i][1] - sorted_x[i + 1][1]))
        edges.append([cost, sorted_x[i][2], sorted_x[i + 1][2]])
        cost = min(abs(sorted_y[i][0] - sorted_y[i + 1][0]), abs(sorted_y[i][1] - sorted_y[i + 1][1]))
        edges.append([cost, sorted_y[i][2], sorted_y[i + 1][2]])
    edges.sort(key=itemgetter(0))
    
    ans = 0
    uf_tree = UnionFind(N)
    for cost, u, v in edges:
        if not uf_tree.same(u, v):
            ans += cost
            uf_tree.union(u, v)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 55412
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <stdio.h>

int main()
{
    int input = 0;
    scanf("%d", &input);
    
    int hour  = input / (60 * 60);    // 時にする
    int min   = (input - (hour * 60 * 60)) / 60;
    int sec   = input % 60;    
    
    printf("%d:%d:%d\n", hour, min , sec);
    
    return 0;
}



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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n;
    cin >> n;

    vector<int> sticks;

    for(int i = 0; i < n; i++){
        int stick;
        cin >> stick;
        sticks.push_back(stick);
    }

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

    int total = 0;

    for(int largest = sticks.size()-1; largest >= 0; largest--){
        int largestlength = sticks[largest];

        int left = 0;
        int right = largest - 1;
        while(left < right){
            int cur = sticks[left] + sticks[right];
            if(cur <= largestlength){
                left++;
            } else {
                total += right - left;
                right--;
            }
        }
    }

    cout << total;

}

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

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

using namespace std;

typedef long long int lli;

int main () {
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> b(M);
    REP (i, 0, M) cin >> a[i] >> b[i];
    vector<int> nlist(N, 0);
    REP (i, 0, M) {
        nlist[a[i] - 1]++;
        nlist[b[i] - 1]++;
    }
    bool run = true;
    REP (i, 0, N) {
        if (nlist[i] % 2) run = false;
    }
    cout << (run ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstring>
#include <iomanip>
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;

double dp[310][310][310];
double rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;
    if (i > 0) res += rec(i-1, j, k) * i;
    if (j > 0) res += rec(i+1, j-1, k) * j;
    if (k > 0) res += rec(i, j+1, k-1) * k;
    res += N;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

int main() {
    cin >> N;
    int one = 0, two = 0, three = 0;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        if (a == 1) ++one;
        else if (a == 2) ++two;
        else ++three;
    }

    memset(dp, -1, sizeof(dp));

    cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}

Measured memory_bytes: 233088
#include<iostream>
#include<cstdio>
using namespace std;
//fangan[i][j][k]表示前i个公司得到j台机器第k个公司得到的机器数 
int f[105][105],a[105][105],fangan[30][30][30];
int main() {
	/*int n,m;
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			cin>>a[i][j];
		}
	}
	for(int i=1; i<=n; i++) {
		for(int j=0; j<=m; j++) {
			for(int k=0; k<=j; k++) {
				if(f[i-1][j-k]+a[i][k]>=f[i][j]){
					f[i][j]=f[i-1][j-k]+a[i][k];
					fangan[i][j][i]=k;
					for(int l=1;l<i;l++)fangan[i][j][l]=fangan[i-1][j-k][l];
				}
			}
		}
	}
	cout<<f[n][m]<<endl;
	for(int i=1;i<=n;i++)cout<<i<<' '<<fangan[n][m][i]<<endl;
	return 0;*/
	int n;
	cin>>n;
	cout<<n*(n+1)/2;
}

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

typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;

void solve()
{
  int x, n;
  cin >> x >> n;
  set<int> s;
  for (int i = 0; i < n; i++)
  {
    int p;
    cin >> p;
    s.insert(p);
  }
  int ans;
  int min = 10000;
  for (int i = x; i < 200; i++)
  {
    if (s.count(i) == 0)
    {
      ans = i;
      min = i - x;
      break;
    }
  }
  for (int i = x; i >= -200; i--)
  {
    if (s.count(i) == 0)
    {
      if (x - i <= min)
        ans = i;
      break;
    }
  }
  cout << ans << endl;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++)
  // {
  //   solve();
  // }
  solve();
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void) {
    char text[1200];
    fgets(text, 1200, stdin);
    int i = 0;
    while(text[i] != '\0') {
        if(0x41 <= text[i] && text[i] <= 0x5a) {
            printf("%c",text[i] + 32);
        }
        else if(0x61 <= text[i] && text[i] <= 0x7a) {
            printf("%c", text[i] - 32);
        }
        else printf("%c", text[i]);
        i++;
    }

    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, Y;
  cin >> N ;
 
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    if(S=="Y")
      Y++;
  }
  if(Y>0)
    cout<<"Four"<<endl;
  else
    cout<<"Three"<<endl;
}

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int K, P;
    cin >> K >> P;
    int ans = K % P;
    cout << (ans == 0 ? P : ans) << endl;
  }

  return 0;
}


Measured memory_bytes: 3144
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    //約数カウント
    ll C[1001];
    FOR(i, 0, 1001){
        C[i] = 0;
    }

    FOR(i, 2, N+1){
        ll a = i;
        // iを素因数分解
        FOR(d, 2, a+1){
            while(a % d == 0){
                C[d]++;
                a /= d;
            }
        }
    }

    ll answer = 1;
    FOR(i, 0, 1001){
        answer *= (C[i]+1);
        answer %= mod;
    }

    p(answer);

    return 0;
}

Measured memory_bytes: 256
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int k, n;
        cin >> k >> n;
        int a[n];
        int sum = 0;
        loop(0, n) {
            cin >> a[i];
            sum += a[i];
        }
        cout << max(k - sum, (int) - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 3536
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>
#include <list>

using namespace std; 

typedef long long int ll;


int main()
{
    ll n,i,j,k,W;
    cin>>n>>W;
    ll wt[n+1];
    ll value[n+1];
    for(i=0;i<n;i++)
    {
    	cin>>wt[i]>>value[i];
    }
    ll sum[n+1][W+1];
    for (i = 0; i <= n; i++) 
   	{ 
       for (ll w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               sum[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 sum[i][w] = max(value[i-1] + sum[i-1][w-wt[i-1]], sum[i-1][w]); 
           else
                 sum[i][w] = sum[i-1][w]; 
       } 
   	} 
   	cout<<sum[n][W];
    return 0;
}

Measured memory_bytes: 79104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n;
        int k;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        k = scanner.nextInt();
        int[] a = new int[n];

        for(int i=0; i<n; i++) {
            a[i] = scanner.nextInt();
        }

        if(n==1)
            System.out.println(0);

        int dp[] = new int[n];

        dp[0] = 0;
        //dp[1] = Math.abs(a[0]-a[1]);

        for(int i=1; i<n; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j=i-k; j<i; j++) {
                if (j>=0 && (dp[i] > dp[j] + Math.abs(a[j]-a[i]))) {
                    dp[i] = dp[j] + Math.abs(a[j]-a[i]);
                }
            }
        }
        System.out.println(dp[n-1]);
    }

}


Measured memory_bytes: 51024
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
using lint = long long;
using P = pair<int, int>;
using V = vector<int>;
constexpr int MOD = 1e9 + 7;

int A, B, C, F, H, I, J, K, L, M, N, S, T, U, W;
// lint A, B, F, H, I, J, K, L, M, N, S, T, U, W;
// string A, B;
int ans = 0;
// string ans;
vector<V> cnt(10, V(10, 0));

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

	cin >> N;

	rep1(i, N) {
		int f = to_string(i)[0] - '0';
		int l = i % 10;
		cnt[f][l]++;
	}

	rep1(i, 9) {
		rep1(j, 9) {
			ans += cnt[i][j] * cnt[j][i];
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
 
template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL N=1e6+5;
struct NODE{
	LL i,r,c,num;
}tt,ss;
LL t,n,m,q,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;
int a[33];
char s[111];
 
int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v,tmp;
	cin>>s;
	l=strlen(s);
	rep(i,0,l)a[s[i]-'a'+1]^=1;
	repu(i,1,26)ans+=a[i];
	cout<<(ans?"No":"Yes")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

signed main(){
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	vector<pair<int,int>> C(N);
	for(int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i];
		C[i] = make_pair(A[i] + B[i], i);
	}
	sort(ALL(C));
	reverse(ALL(C));
	vector<int> D(2);
	for(int i = 0; i < N; ++i) {
		if(i % 2 == 0) {
			D[0] += A[C[i].second];
		} else {
			D[1] += B[C[i].second];
		}
	}
	cout << D[0] - D[1] << endl;
	return 0;
}


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

using namespace std;

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

	string a, b, c;
	cin >> a >> b >> c;

	int len_a = (int) a.size();
	int len_b = (int) b.size();

	if (a[len_a - 1] == b[0] && b[len_b - 1] == c[0])
		cout << "YES" << '\n';
	else
		cout << "NO" << '\n';
	
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
const int N=605;
const int mod=1e9+7;
int n,m,cnt,vis[N],f[2][N][N],ans;
inline void add(int &x,int y){x+=y;x>=mod?x-=mod:x;}
int main(){
	n=gi();
	for(int i=1;i<=n;++i){
		int x=gi(),y=gi();
		if(x!=-1&&y!=-1)vis[x]=vis[y]=2;
		else if(x!=-1||y!=-1)vis[x!=-1?x:y]=1;
		else ++cnt;
	}
	for(int i=1;i<=n<<1;++i)if(vis[i]!=2)vis[++m]=vis[i];
	f[0][0][0]=1;
	for(int i=m,nxt=1,lst=0;i;--i,lst=nxt,nxt^=1){
		memset(f[nxt],0,sizeof(f[nxt]));
		for(int j=0;j<=m;++j)
			for(int k=0;k<=m;++k)
				if(f[lst][j][k])
					if(vis[i]){
						add(f[nxt][j+1][k],f[lst][j][k]);
						if(k)add(f[nxt][j][k-1],f[lst][j][k]);
					}else{
						add(f[nxt][j][k+1],f[lst][j][k]);
						if(j)add(f[nxt][j-1][k],1ll*f[lst][j][k]*j%mod);
						if(k)add(f[nxt][j][k-1],f[lst][j][k]);
					}
	}
	ans=f[m&1][0][0];
	for(int i=1;i<=cnt;++i)ans=1ll*ans*i%mod;
	printf("%d\n",ans);return 0;
}


Measured memory_bytes: 3072
D = int(input())
C = list(map(int,input().split())) #C[i]AiCを実施しないと下がる満足度
S = [] #S[i][j] i日目にAjcというコンテストを実施した場合に上がる満足度
for i in range(D): #コンテストは0index
    temp = list(map(int,input().split()))
    S.append(temp)

since = [0 for _ in range(26)] #最後に開催されてから何日経ったか。
for i in range(26):
    since[i] += C[i]
for i in range(D):
    delta = [0]*26
    for j in range(26):
        delta[j] = S[i][j] - since[j]
    value = max(delta)
    contest = delta.index(value)
    print(contest+1) #1indexに直す。
    for j in range(26):
        if j != contest:
            since[j] += C[j]
        else:
            since[j] = C[j]


Measured memory_bytes: 69048
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
#define bit(mask,i) ((mask)>>(i)&1)
using namespace std;
using ll = long long;


const int MD=int(1e9)+7;

inline int madd(int x,int y) {
	if (x+y<MD) return x+y; else return x+y-MD;
}
inline int msub(int x,int y) {
	if (x-y>=0) return x-y; else return x-y+MD;
}
inline int mmul(int x,int y) {
	return int(ll(x)*y % MD);
}

int const MAXN=16;
int N,M;
int a[MAXN];
int dp[1<<MAXN];

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

	cin>>N>>M;
	rep(i,0,M) {
		int x,y;
		cin>>x>>y;
		x--,y--;
		a[x]|=1<<y;
	}
	
	rep(S,1,1<<N) if (bit(S,0)==bit(S,1)) {
		dp[S]=1;
		for (int T=S&(S-1); T>0; T=S&(T-1)) {
			if (bit(T,0)!=bit(T,1)) continue;
			int U=S^T;
			assert(U!=0);
			
			int ways=1;
			rep(v,0,N) {
				if (bit(T,v)) {
					int k=__builtin_popcount(a[v]&U);
					ways=mmul(ways,(1<<k)-1);
				} else if (bit(U,v)) {
					int k=__builtin_popcount(a[v]&T);
					ways=mmul(ways,1<<k);
				}
			}
			
			dp[S]=madd(dp[S],mmul(dp[T],ways));
		}
	}
	
	int res=1;
	rep(i,0,M) res=madd(res,res);
	res=msub(res,dp[(1<<N)-1]);
	
	cout<<res<<"\n";
}


Measured memory_bytes: 384
N, M, Q = gets.chomp.split.map(&:to_i)

array = Q.times.map do
  gets.chomp.split.map(&:to_i)
end

max_point = 0

(1..M).to_a.repeated_combination(N) do |combi|
  point = 0
  combi.sort!
  # p combi
  array.each do |a, b, c, d|
    point += d if (combi[b - 1] - combi[a - 1]) == c
  end
  # p point
  max_point = point if max_point < point
end

puts max_point


Measured memory_bytes: 14940
# dp[i] := i 項目以降を見たときの場合の数
#       = dp[i+1] + (Σ_{3<=d<=N-1} dp[i+d]) + (n-1)**2

# i 項目と i+1 項目について、
#   (1) i 項目が 1 の場合
#   (2) i 項目が 1 で無く、i+1 項目が 1 の場合
#   (3) i 項目も i+1 項目も 1 で無い場合
# で場合分けしてそれぞれを足している
# これを累積和で高速化する

# 初期化がややこしい

N = int(input())
mod = 10**9+7
dp = [0] * N
dp[N-1] = N
dp[N-2] = N*N
c = N * (N+1) + N-1
const = (N-1)**2
for i in range(N-3, -1, -1):
    ans = c - dp[i+2] + const
    dp[i] = ans
    c = (c + ans - 1) % mod
print(dp[0]%mod)


Measured memory_bytes: 45780
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	//static String eikomoji[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
	
	
	public static void main(String[] args) {
	int n =sc.nextInt();
	int a =sc.nextInt();
	int b =sc.nextInt();
	if(n==a&&n!=b) {
		p("Yes");
	}else if(n==b&&n!=a) {
		p("Yes");
	}else if(a==b&&a!=n) {
		p("Yes");
	}else {
		p("No");
	}
	
	
	
	}
}

Measured memory_bytes: 22612
#
# abc106 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """105"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7"""
        output = """0"""
        self.assertIO(input, output)


def resolve():
    N = int(input())

    ans = 0
    for i in range(1, N+1):
        if i % 2 == 0:
            continue
        t = 0
        for j in range(1, N+1):
            if i % j == 0:
                t += 1
        if t == 8:
            ans += 1
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    cout<<180*(n-2)<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b string
	fmt.Scan(&a, &b)
	a += b
	v, _ := strconv.Atoi(a)
	for i := 1; i*i <= v; i++ {
		if i*i == v {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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

int main(){
	string s;
	getline(cin,s);
	int l=s.length(),ans=0,i=0;
	int tmp=0;
	while(i<l){
		switch(s[i]){
			case 'A':
			case 'C':
			case 'G':
			case 'T':++tmp;break;
			default:ans=max(ans,tmp);tmp=0;
		}
		++i;
	}
	cout<<max(ans,tmp)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

    if((a == "H" && b == "H") || (a == "D" && b == "D")){
        cout << "H" << endl;
    }else {
        cout << "D" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int a[12] = {1,3,5,7,9,11,15,17,19,21,23,25};
 
void solve(){
   string str;
   getline(cin,str);
 
   int A,B;
   A = B = 0;
    
   for(int i = 0 ; i < 12 ; i++){
      for(int j = 0 ; j < 26 ; j++){
     string tmp = "this";
     for(int k = 0 ; k < 4 ; k++){
        tmp[k] = (a[i]*(tmp[k]-'a')+j)%26 + 'a';
     }
     if(str.find(tmp) != -1){
        A = a[i]; B = j;
        i = 11;j = 26;
        break;
     }
 
     tmp = "that";
     for(int k = 0 ; k < 4 ; k++){
        tmp[k] = (a[i]*(tmp[k]-'a')+j)%26 + 'a';
     }
     if(str.find(tmp) != -1){
        A = a[i]; B = j;
        i = 11;j = 26;
        break;
     }
 
      }
   }
   for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == ' '){
     cout << ' ';
     continue;
      }
      for(int j = 0 ; j < 26 ; j++){
     if(str[i]-'a' == (A*j + B)%26){
        cout << (char)(j + 'a');
        break;
     }
      }
   }
   cout << endl;
}
 
int main(){
   int n;
   cin >> n;
   string tmp;
   getline(cin,tmp);
   for(int i = 0 ; i < n ; i++){
      solve();
   }
   return 0;
}

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

int main() {
	int n,i,k,ans=0;
	cin >> n;
	if(n<=9) k=1;
	else if(n<=99) k=2;
	else if(n<=999) k=3;
	else if(n<=9999) k=4;
	else if(n<=99999) k=5;
	else k=6;
	if(k==1) ans=n;
	if(k==2) ans=9;
	if(k==3) ans=9+n-99;
	if(k==4) ans=9+900;
	if(k==5) ans=9+900+n-9999;
	if(k==6) ans=9+900+90000;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//In The Name Of GOD
 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

const int mod = 1000000007;
const int inf = 2000000000;
const int maxn = 500*1000+500*1000+15;
const int MLOG = 18;

#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())

vector<char> vec;

void faz1(vector<char> &vec){
	if ( vec.back() == 'd' ){
		if( sz(vec) >= 5 ){
		 	if( vec[sz(vec) - 2] == 'r' && vec[sz(vec) - 3] == 'e' && vec[sz(vec) - 4] == 'a' && vec[sz(vec) - 5] == 'm'){
				for(int i = 0;i < 5 ; i++)
					vec.pp();
			}else{
				cout << "NO";
				exit(0);
			}
		}else{
			cout << "NO";
			exit(0);
		}
	}else if( vec.back() == 'e' ){
		if( sz(vec) >= 5 ){
		 	if( vec[sz(vec) - 2] == 'r' && vec[sz(vec) - 3] == 'a' && vec[sz(vec) - 4] == 's' && vec[sz(vec) - 5] == 'e'){
				for(int i = 0;i < 5 ; i++)
					vec.pp();
			}else{
				cout << "NO";
				exit(0);
			}
		}else{
			cout << "NO";
			exit(0);
		}
	}else{
		cout<< "NO";
		exit(0);
	}
}

void faz3(vector<char> &vec){
	if( sz(vec) == 0 )
		return ;
	if ( vec[sz(vec)-1] == 'r'){
		vec.pp();	
	}else{
		return ;
	}
}


void faz2(vector<char> &vec){
	if( sz(vec) == 0 )
		return ;
	if( sz(vec) == 1 ){
		cout << "NO";
		exit(0);
		return ;
	}
	if ( vec.back() == 'e' && vec[sz(vec)-2] == 'r'){
		
	}else{
		cout<<"NO";
		exit(0);
	}
	if(sz(vec) == 2){vec.pp();vec.pp();return ;}
	if(vec[sz(vec) - 3] == 'a'){
		return;
	}
	vec.pp();
	vec.pp();
	return ;
}
int main(){
	string s;
    cin >> s;
    reverse(s.begin(),  s.end());
    int i=0;
    string ss[4]={"dream","dreamer","erase","eraser"};
    for(int i = 0; i < 4; i++){ 
        reverse(ss[i].begin(), ss[i].end());
    }
    string t = "";
    while(i < (int)s.size()){
        t += s[i];
        for(int i = 0; i < 4; i++){
            if(ss[i] == t){
                t="";
            }
        }
        i++;
    }
    if(t==""){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

int main() {
    std::string s, t;
    int cnt = 0;
    
    std::cin >> s >> t;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            cnt++;
        }
    }

    std::cout << cnt << std::endl;
}

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

const int maxn=1e5+10;
const int maxnd=5e6+10;
const LL INF=1e16;

int n,b[maxn];
LL k,a[maxn];

namespace SegTree{
	LL mn[maxnd],_mn[maxnd],mem[maxnd];
	int totnd,root,lc[maxnd],rc[maxnd];
#define mid ((s+t)>>1)

	void init()
	{
		totnd=root=1;
		memset(mem,-1,sizeof(mem));
	}

	inline void pushdown(int nd,int s,int t)
	{
		if (!lc[nd]) lc[nd]=++totnd;
		if (!rc[nd]) rc[nd]=++totnd;
		mn[lc[nd]]=mn[rc[nd]]=mem[nd];
		_mn[lc[nd]]=mem[nd]-mid;
		_mn[rc[nd]]=mem[nd]-t;
		mem[lc[nd]]=mem[rc[nd]]=mem[nd];
		mem[nd]=-1;
	}

	LL query(int &nd,int s,int t,int l,int r)
	{
		if (!nd) nd=++totnd;
		if (l<=s&&t<=r) return _mn[nd];
		if (mem[nd]!=-1) pushdown(nd,s,t);
		LL Ans=INF;
		if (l<=mid) Ans=min(Ans,query(lc[nd],s,mid,l,r));
		if (r> mid) Ans=min(Ans,query(rc[nd],mid+1,t,l,r));
		mn[nd]=min(mn[lc[nd]],mn[rc[nd]]);
		_mn[nd]=min(_mn[lc[nd]],_mn[rc[nd]]);
		return Ans;
	}

	void checkmin(int &nd,int s,int t,int id,LL val)
	{
		if (!nd) nd=++totnd;
		if (s==t)
		{
			mn[nd]=min(mn[nd],val);
			_mn[nd]=mn[nd]-s;
			return;
		}
		if (mem[nd]!=-1) pushdown(nd,s,t);
		if (id<=mid)
			checkmin(lc[nd],s,mid,id,val);
		else
			checkmin(rc[nd],mid+1,t,id,val);
		mn[nd]=min(mn[lc[nd]],mn[rc[nd]]);
		_mn[nd]=min(_mn[lc[nd]],_mn[rc[nd]]);
	}

	void memset(int &nd,int s,int t,int l,int r,LL val)
	{
		if (!nd) nd=++totnd;
		if (l<=s&&t<=r)
		{
			mn[nd]=val;
			_mn[nd]=mn[nd]-t;
			mem[nd]=val;
			return;
		}
		if (mem[nd]!=-1) pushdown(nd,s,t);
		if (l<=mid) memset(lc[nd],s,mid,l,r,val);
		if (r> mid) memset(rc[nd],mid+1,t,l,r,val);
		mn[nd]=min(mn[lc[nd]],mn[rc[nd]]);
		_mn[nd]=min(_mn[lc[nd]],_mn[rc[nd]]);
	}
};

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i;
	scanf("%d%lld",&n,&k);
	for (i=1;i<=n;i++)
	{
		scanf("%lld%d",&a[i],&b[i]);
		if (b[i]==1&&2*a[i]>k) {puts("-1"); return 0;}
		a[i]+=a[i-1];
	}
	SegTree::init();
	SegTree::memset(SegTree::root,0,k-1,0,k-1,0);
	for (i=1;i<=n;i++)
		if (b[i]==1)
		{
			int L=k-2ll*a[i-1]%k,R=k-2ll*a[i]%k;
			L%=k; R%=k;
			LL Ans=SegTree::query(SegTree::root,0,k-1,0,L)+L;
			Ans=min(Ans,SegTree::query(SegTree::root,0,k-1,L,k-1)+k+L);
			SegTree::checkmin(SegTree::root,0,k-1,L,Ans);
			if (L<=R)
			{
				if (0<L) SegTree::memset(SegTree::root,0,k-1,0,L-1,INF);
				if (R<k-1) SegTree::memset(SegTree::root,0,k-1,R+1,k-1,INF);
			}
			else if (R+1<=L-1) SegTree::memset(SegTree::root,0,k-1,R+1,L-1,INF);
		}
	printf("%lld\n",a[n]+a[n]+SegTree::mn[SegTree::root]);
}


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

using namespace std;

typedef unsigned long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 18) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 666;

int n;
char s[MAXN][MAXN];
int a[MAXN][MAXN];

int main()
{
	
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i)
	{
		scanf("%s", s[i]+1);
		for (int j = 1; j <= n; ++ j)
			s[i+n][j+n] = s[i+n][j] = s[i][j+n] = s[i][j];
	}
	
	for (int i = 1; i <= 2*n; ++ i)
		for (int j = 1; j <= 2*n; ++ j)
		{
			int k = 0;
			while (i-k >= 1 && j-k >= 1 && s[i-k][j] == s[i][j-k])
				k ++;
			a[i][j] = k;
		}
	
	int ans = 0;
	
	for (int i = n; i < n*2; ++ i)
		for (int j = n; j < n*2; ++ j)
		{
			int flag = 1;
			for (int k = 0; k < n; ++ k)
				if (a[i-k][j-k] < n-k) flag = 0;
			ans += flag;
		}
	
	cout << ans << endl;
	
	return 0;
}


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


int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) cin >> X[i];
  int ans1 = 0, ans2 = 0;
  int p1 = 0, p2;
  rep(i , N) p1 += X[i];
  p1 = p1 / N;
  p2 = p1 + 1;
  rep (i, N) {
    ans1 += (p1 - X[i]) * (p1 - X[i]);
    ans2 += (p2 - X[i]) * (p2 - X[i]);
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}


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

using namespace std;

int maxi(vector<int> a, int jogai){
	int max = 0;
	int maxi = 0;
	for (int i = 0; i < a.size(); i++){
		if (i == jogai){
			continue;
		}
		if (a[i]>max){
			max = a[i];
			maxi = i;
		}
	}
	if (max == 0){
		if (jogai != -1){
			if (a[jogai] != 0){
				return jogai;
			}
		}
		return -1;
	}
	else return maxi;
}

int main(){
	int K, T;
	cin >> K >> T;
	vector<int> a(T);
	for (int i = 0; i < T; i++){
		cin >> a[i];
	}
	int jogai = -1;
	int count = 0;
	while (maxi(a, jogai) >= 0){
		if (jogai == maxi(a, jogai)){
			count++;
		}
		int tmp = maxi(a, jogai);
		a[maxi(a, jogai)]--;
		jogai = tmp;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n;
string s;

int solve(){
  int i = 0;
  while(s.size() > 1){
    char c[4];
    sprintf(c, "%d", s[0]+s[1]-2*'0');
    s.erase(0, 2);
    s.insert(0, c);
    i++;
  }
  return i;
}

int main(){
  scanf("%d", &n);
  while(n--){
    cin >> s;
    printf("%s wins.\n", (solve()%2)?"Fabre":"Audrey");
  }
  return 0;
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    ll a,b,k;
    cin>>a>>b>>k;
    vector<ll>v;
    ll i;
    for(i=1;i<=max(a,b);i++)
    {
        if(a%i==0 && b%i==0)
        {
            v.pb(i);
        }
    }
    ll ct=0;
    ll ans = v[v.size()-k];
    cout<<ans<<endl;
}


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

#include <ctype.h>

using namespace std;

enum token_type
{
	T_INT,
	T_TAG_S,
	T_TAG_E,
	T_END,
};

struct token
{
	token_type type;
	string tag_name;
	int value;
};

struct panel
{
	string name;
	int bounds[4];
	vector<panel> children;

	bool click(int x, int y)
	{
		bool hit = false;
		for (int i = 0; !hit && i < children.size(); i++)
		{
			hit = children[i].click(x, y);
		}
		if (!hit)
		{
			hit = contains(x, y);
			if (hit) cout << name << " " << children.size() << endl;
		}
		return hit;
	}

	bool contains(int x, int y)
	{
		return bounds[0] <= x && bounds[1] <= y && x <= bounds[2] && y <= bounds[3];
	}
};

string src;
int p;
token cur_tok;

bool end() { return p >= src.length(); }
char peek() { return src[p]; }
void next() { if (!end()) p++; }

token lex_int()
{
	token t;
	t.type = T_INT;
	t.value = 0;
	char c;
	while (isdigit(c = peek()))
	{
		t.value = 10 * t.value + (c - '0');
		next();
	}
	return t;
}

string lex_tag_name()
{
	string name = "";
	char c;
	while ((c = peek()) != '>')
	{
		name += c;
		next();
	}
	return name;
}

token lex_tag()
{
	token t;
	if (peek() == '<') next();
	if (peek() == '/')
	{
		next();
		t.type = T_TAG_E;
		t.tag_name = lex_tag_name();
	}
	else
	{
		t.type = T_TAG_S;
		t.tag_name = lex_tag_name();
	}
	if (peek() == '>') next();
	return t;
}

void lex_next()
{
	if (end()) cur_tok = token();
	char c = peek();
	if (c == '<') cur_tok = lex_tag();
	else if (c == ',') { next(); lex_next(); }
	else if (isdigit(c)) cur_tok = lex_int();
}

panel tag_structure()
{
	panel p;
	if (cur_tok.type == T_TAG_S)
	{
		p.name = cur_tok.tag_name;
		lex_next();

		for (int i = 0; i < 4; i++)
		{
			p.bounds[i] = cur_tok.value;
			lex_next();
		}

		while (cur_tok.type == T_TAG_S)
		{
			p.children.push_back(tag_structure());
		}
		if (cur_tok.type == T_TAG_E) lex_next();
	}
	return p;
}

int main()
{
	int N;
	for(;cin>>N, N;)
	{
		cin >> src;

		p = 0;
		lex_next();
		panel root = tag_structure();

		for (int i = 0; i < N; i++)
		{
			int x, y;
			cin >> x >> y;
			bool hit = root.click(x, y);
			if (!hit) cout << "OUT OF MAIN PANEL 1" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<numeric>
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/(a,b);}
//priority_queue<int, vi, greater<int> > que;//æ˜‡é †

using namespace std;

const int mod=1e9+7;
bool isSosuu(int n);
signed main(){
  SPEED;
  int n;
  while(1){
    int n=0;
    cin >> n;
    if(n==0)return 0;
    for(int i=(n-2);i>1;i--){
      if(isSosuu(i)&&isSosuu(i+2)){
        cout << i << " " << i+2 << endl;
        break;
      }
    }
  }
  return 0;
}
bool isSosuu(int num){
  if (num < 2) return false;
      else if (num == 2) return true;
      else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

      double sqrtNum = sqrt(num);
      for (int i = 3; i <= sqrtNum; i += 2)
      {
          if (num % i == 0)
          {
              // 素数ではない
              return false;
          }
      }

      // 素数である
      return true;
}



Measured memory_bytes: 3184
#include <iostream>
using namespace std;
int main(void){
    int n, train[100]={}, max=0;
    while(cin >> n){
        if(n != 0){
            for(int i=max; i>=0; i--){
                train[i+1]=train[i];
            }
            train[0]=n;
            max++;
        }
        else if(n == 0){
            cout << train[0] << endl;
            for(int i=1; i<=max; i++){
                train[i-1]=train[i];
            }
            max--;
        }
    }
    return 0;
}



Measured memory_bytes: 2988
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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 ll INF=1e18;
const ll mod=1e9+7;

int main(){
    string s;
    cin >> s;
    cout << s.substr(0,3) << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include<string.h>
#define LEN 100005

/*プロセスを表す構造体*/
typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];
int head, tail,n;

void enqueue(P x){
	Q[tail]=x;
	tail=(tail + 1) % LEN;
}

P dequeue(){
	P x = Q[head];
	head = ( head + 1 ) % LEN;
	return x;
}

int min(int a,int b){return a<b? a:b;}/*最小値を返す*/

int main(){
	int elaps =0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);

/*すべてのプロセスをキューに順番に追加する*/
	
	for(i=1; i<=n; i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head =1; tail=n+1;
	
	/*シミュレーション*/
	while(head!=tail){
		u=dequeue();
		c=min(q,u.t); /*qまたは必要な時間u.tだけ処理を行う*/
		u.t -= c; /*残りの必要時間を計算*/
		elaps+=c; /*経過時間を加算*/
		if(u.t>0) enqueue(u); /*処理が完了していなければキューに追加*/
		else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	
	return 0;
}




Measured memory_bytes: 12724
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iterator>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define VE vector<int>
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  LL N,C,K;
  LL T[100000];
  cin>>N>>C>>K;
  FOR(i,0,N){
    cin>>T[i];
  }
  sort(T,T+N);
  LL ans=0;
  LL sum=0;
  LL now=0;
  LL fir=0;
  while(now<N){
    if(sum==0){
      fir=T[now];
      sum++;
    }else if(sum<C){
      if(T[now]-fir<=K){
        sum++;
      }else{
        ans++;
        fir=T[now];
        sum=1;
      }
    }else if(sum==C){
      ans++;
      fir=T[now];
      sum=1;
    }
    now++;
    if(now==N){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*

fun main(A:Array<String>) {
	val s=Scanner(System.`in`)
	val a=s.nextInt()
	val b=s.nextInt()
	val c=s.nextInt()
	val d=s.nextInt()
	val e=s.nextInt()
	val k=s.nextInt()
	println(if(e-a>k) ":(" else "Yay!")
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    string s;cin >> s;
    int n = s.size();
    string s1 = s.substr(0,(n-1)/2);
    string s2 = s.substr((n+3)/2-1);

    for(int i=0;i<n/2;i++){
        if(s[i] != s[n-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    int s1_size = s1.size();
    for(int i=0;i<s1_size/2;i++){
        if(s1[i] != s1[s1_size-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    int s2_size = s2.size();
    for(int i=0;i<s2_size/2;i++){
        if(s2[i] != s2[s2_size-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb emplace_back 
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii; 
typedef vector<int> vi; 
typedef pair<string, int> Psi; 
typedef pair<ll, ll> Pll;

int main(){
	string str;
	cin >> str;
	rep(i,str.size()){
		cout << str[i];
		if(i == 3){
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


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

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

    sort(arr,arr+n);
    ll diff = arr[k-1] - arr[0];
    for(ll i=k;i<n;i++)
        diff = min(diff , arr[i] - arr[i-k+1]);

    cout<<diff;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int S = sc.nextInt();

        int hour = S / 3600;
        int min = (S % 3600) / 60;
        int sec = (S % 3600 % 60);

        System.out.println(String.format("%d:%d:%d", hour, min, sec));
    }
}

Measured memory_bytes: 26384
#include <stdio.h>
    
long long F_0_N(long long n)
{
     long long  pair_num;
     
     if (n <= 0) return 0;             
     pair_num =  (n + 1)/2;
     return  ((pair_num & 0x01) ^ (n*(1 - (n & 0x01))));  
 }
     
long long F_A_B(long long a, long long b)
{
    if (a == b) return a;
    return (F_0_N(a - 1) ^ F_0_N(b));
}
     
//A ～　B までの論理和を求める
int main(int argc, char *argv[])
{
    long long A, B;
    long long xor_v;
  
    scanf("%lld %lld", &A, &B);
    xor_v =  F_A_B(A, B);
  
    printf("%lld\n", xor_v);
     
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Scanner sc=new Scanner(System.in);
		String a=sc.nextLine();
		String b=sc.nextLine();
		if(a.length()>b.length()) {
			System.out.println("GREATER");
		}else if(a.length()<b.length()) {
			System.out.println("LESS");
		}else{
			if(a.compareTo(b)>0) {
				System.out.println("GREATER");
			}else if(a.compareTo(b)<0){
				System.out.println("LESS");
			}else {
				System.out.println("EQUAL");
			}
		}
	}

}


Measured memory_bytes: 23892
#include <iostream>
#include <cstring>

using namespace std;

#define repeat(i,n) for(int i=0;i<(n);i++)
#define N_MAX 50

int n, p;
int cup;
int cur_player;
int player[N_MAX];

bool finished() {
    if (cup != 0) {
        return false;
    }
    repeat(i,n) {
        if (player[i] == p) {
            return true;
        }
    }
    return false;
}

void step() {
    if (cup == 0) {
        cup = player[cur_player];
        player[cur_player] = 0;
    } else {
        cup--;
        player[cur_player]++;
    }
    cur_player++;
    if (cur_player == n) {
        cur_player = 0;
    }
}

int main() {
    while (cin >> n >> p) {
        if (n == 0 && p == 0) break;
        memset(player, 0, sizeof(player));
        cup = p;
        cur_player = 0;
        while (!finished()) {
            step();
        }
        int winner;
        repeat(i, n) {
//            cout << player[i] << ' ';
            if (player[i] == p) winner = i;
        }
        cout << winner << endl;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,a[100010],cur=1,sum[100010],ans=0;

int main()
{
	//freopen("in.txt","r",stdin);
	cin>>n;
	rep(i,n+1) cin>>a[i];
	for(int i=n;i>=0;i--) sum[i]=sum[i+1]+a[i];
	rep(i,n+1)
	{
		ans+=cur;
		cur-=a[i];
		if(cur<0||cur>sum[i+1])
		{
			puts("-1");
			return 0;
		}
		cur=min(cur*2,sum[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5196