akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 200005
#define INF 1000005
#define endl "\n"
int arr[MAX];
int f[INF];
bool p[INF];
bool flag[MAX];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(lli i = 2; i<=INF; i++){
		if(!p[i]){
			for(lli j = i*i; j<=INF; j+=i){
				p[j] = true;
 			}
		}
	}
	int n;
	cin>>n;
	for(int i = 0; i<n; i++){
		cin>>arr[i];
		f[arr[i]]++;
	}
	int c = 0;
	bool flag = false;
	for(lli i = 0; i<n; i++){
		flag = false;
		f[arr[i]]--;
		if(!p[arr[i]]){
			if(f[1] || f[arr[i]]){
			}
			else{
				c++;
			}
			f[arr[i]]++;
			continue;
		}
		for(lli j = 1; j*j <= arr[i]; j++){
			if(arr[i]%j == 0){
				if(f[j] || f[arr[i]/j]){
					flag = true;
					break;
				}
			}
		}
		if(!flag){
			c++;
		}
		f[arr[i]]++;
	}
	cout<<c<<endl;
	
}

Measured memory_bytes: 9188
al=["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"]

N=int(input())
S=list(input())
ans=[]
for i in S:
  ans.append(al[(al.index(i)+N)%26])
  
print("".join(ans))

Measured memory_bytes: 3188
n = int(input())
P = list(map(int, input().split()))
count = 0
for i in range(1,n-1):
    a,b,c = P[i-1],P[i],P[i+1]   
    if b != min(a,b,c) and b!= max(a,b,c):
        count+=1
print(count)

Measured memory_bytes: 3064
#ifndef ___Rank_Union_Find
#define ___Rank_Union_Find

#include <vector>

// ------ Class ------ //
class UnionFind {
private:
	unsigned size_; std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

#endif

#include <map>
#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int N, K, L, p, q;
int main() {
	scanf("%d%d%d", &N, &K, &L);
	UnionFind uf1(N), uf2(N);
	for (int i = 0; i < K; i++) {
		scanf("%d%d", &p, &q); p--, q--;
		uf1.unite(p, q);
	}
	for (int i = 0; i < L; i++) {
		scanf("%d%d", &p, &q); p--, q--;
		uf2.unite(p, q);
	}
	map<pair<int, int>, int> cnt;
	for (int i = 0; i < N; i++) {
		cnt[make_pair(uf1.root(i), uf2.root(i))]++;
	}
	for (int i = 0; i < N; i++) {
		printf("%d\n", cnt[make_pair(uf1.root(i), uf2.root(i))]);
	}
	return 0;
}

Measured memory_bytes: 15104
w,h,n=[int(i) for i in input().split(' ')]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=[int(i) for i in input().split(' ')]
  if a==1:
    x1=max(x1,x)
  if a==2:
    x2=min(x2,x)
  if a==3:
    y1=max(y1,y)
  if a==4:
    y2=min(y2,y)
    
if y2<=y1 or x2 <= x1:
  print(0)
else:
  print(max(0,(y2-y1)*(x2-x1)))

Measured memory_bytes: 3064
int main(){
	int h,w,hi,wi;
	while (1){
		scanf("%d %d",&h,&w);
		if (h == 0) break;
		for (hi=0; hi<h; hi++){
			for (wi=0; wi<w; wi++)
				printf((hi%(h-1)==0||wi%(w-1)==0) ? "#":".");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;


int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    int ans=0;
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){
                if(A[i]==A[j] || A[j]==A[k] || A[k]==A[i]) continue;
                if((A[i]+A[j]>A[k]) && (A[j]+A[k]>A[i]) && (A[k]+A[i]>A[j])) ans++;
            }
        }
    }

    cout << ans << endl;




    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef complex<double> CD;
typedef long long LL;
const double PI = acos(-1);

struct FFT {
    int N;
    vector<int> perm;

    void precalculate() {
        perm.resize(N);
        perm[0] = 0;

        for (int k=1; k<N; k<<=1) {
            for (int i=0; i<k; i++) {
                perm[i] <<= 1;
                perm[i+k] = 1 + perm[i];
            }
        }
    }

    void fft(vector<CD> &v, bool invert = false) {
        if (v.size() != perm.size()) {
            N = v.size();
            assert(N && (N&(N-1)) == 0);
            precalculate();
        }

        for (int i=0; i<N; i++)
            if (i < perm[i])
                swap(v[i], v[perm[i]]);

        for (int len = 2; len <= N; len <<= 1) {
            double angle = 2 * PI / len;
            if (invert) angle = -angle;
            CD factor = polar(1.0, angle);

            for (int i=0; i<N; i+=len) {
                CD w(1);
                for (int j=0; j<len/2; j++) {
                    CD x = v[i+j], y = w * v[i+j+len/2];
                    v[i+j] = x+y;
                    v[i+j+len/2] = x-y;
                    w *= factor;
                }
            }
        }
        if (invert)
            for (CD &x : v) x/=N;
    }

    vector<LL> multiply(const vector<LL> &a, const vector<LL> &b) {
        vector<CD> fa(a.begin(), a.end()), fb(b.begin(), b.end());

        int n = 1;
        while (n < a.size()+ b.size())  n<<=1;
        fa.resize(n);
        fb.resize(n);

        fft(fa);
        fft(fb);
        for (int i=0; i<n; i++) fa[i] *= fb[i];
        fft(fa, true);

        vector<LL> ans(n);
        for (int i=0; i<n; i++)
            ans[i] = round(fa[i].real());
        return ans;
    }
};

const LL p = 200003;
int found[p];
LL ghat[p];

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

//    LL x = generator(p);
    LL x = 2;
//    cout << x << endl;

    memset(found, -1, sizeof found);
    LL y = 1;
    for (int k = 0; k < p-1; k++) {
        ghat[k] = y;
        assert(found[y]==-1);
        found[y] = k;
        y = (y*x)%p;
    }

    LL singles = 0;

    int n;
    cin >> n;
    vector< LL >v(p-1, 0);
    for (int i = 0; i < n; i++) {
        LL x;
        cin >> x;
        if (x==0) continue;
        singles += (x*x)%p;
        v[found[x]]++;
    }

    FFT fft;
    vector< LL >w = fft.multiply(v, v);

    LL ans = 0;
    for (int i = 0; i < w.size(); i++) {
        ans += ghat[i%(p-1)]*w[i];
    }

    ans = (ans-singles)/2;

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 30288
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    if(a<=8&&b<=8){
        cout<<"Yay!"<<endl;
    }else{
        cout<<":("<<endl;
    }

	return 0;
}


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

int gcd(int a,int b){
  return b?gcd(b,a%b):a;
}

int main(){
  int n,ans;cin>>n;
  vector<int> x(n+1,0);
  REP(i,n+1) cin>>x.at(i);
  sort(x.begin(),x.end());
  ans=x.at(1)-x.at(0);
  REP(i,n) ans=gcd(ans,x.at(i+1)-x.at(i));
  cout<<ans;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    set<ll> st;
    REP(i, N){
    	ll tmp;
    	cin >> tmp;
    	st.insert(tmp);
    }

    cout << ((ll)st.size() == N ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 9600
sx,sy,tx,ty=[int(x) for x in input().split()]
dx=tx-sx
dy=ty-sy
print("R"*dx+"U"*dy+"L"*dx+"D"*(dy+1)+"R"*(dx+1)+"U"*(dy+1)+"LU"+"L"*(dx+1)+"D"*(dy+1)+"R")


Measured memory_bytes: 38256
#include<iostream>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

li gcd(li a,li b){
  return b?gcd(b,a%b):a;
}

int main(){
  li n; cin >>n;
  repa(i,n/4+1,3510){
    li num=4*i-n,den=n*i;
    li d=gcd(num,den);
    num/=d; den/=d;
    repa(j,1,num/2+1){
      if((den%j==0) and (den%(num-j)==0)){
        print(i,den/j,den/(num-j));
        return 0;
      }
    }
  }
  while(1) print("err");
}


Measured memory_bytes: 3588
#include<stdio.h>
int gcd(int a, int b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main()
{
	int a;
    scanf("%d", &a);
    int b = a;
    int c = a;
    long long int sum = 0;
    for(int i=1;i<=a;i++)
    {
        for(int j=1;j<=b;j++)
        {
            for(int k=1;k<=c;k++)
            {
              int x = gcd(j,k);
                x = gcd(x, i);
                sum += x;
            }
        }
    }
    printf("%lld", sum);
	return 0;
}


Measured memory_bytes: 1732
#include<stdio.h>

int main(void)
{
	int id, rank,a,n;
	int card[4][14];
	char c,d;
	char ids[4] = { 'S','H','C','D' };

	//初期化
	for (id = 0; id < 4; id++)
	{
		for (rank = 0; rank < 14; rank++)
		{
			card[id][rank] = 0;
		}
	}
	scanf("%d", &a);
	for (int i = 0; i < a; i++)
	{
		scanf("%c", &c); //絵柄文字
		scanf("%c %d", &d, &n); //絵柄+数字
		if (d == 'S')
		{
			card[0][n] = 1;
		}
		else if (d == 'H')
		{
			card[1][n] = 1;
		}
		else if (d == 'C')
		{
			card[2][n] = 1;
		}
		else if (d == 'D')
		{
			card[3][n] = 1;
		}
	}
	for (int j = 1; j < 14; j++) //S
	{
		if (card[0][j] != 1)
		{
			printf("S %d\n", j);
		}
	}
	for (int j = 1; j < 14; j++) //H
	{
		if (card[1][j] != 1)
		{
			printf("H %d\n", j);
		}
	}
	for (int j = 1; j < 14; j++) //C
	{
		if (card[2][j] != 1)
		{
			printf("C %d\n", j);
		}
	}
	for (int j = 1; j < 14; j++) //D
	{
		if (card[3][j] != 1)
		{
			printf("D %d\n", j);
		}
	}
}


Measured memory_bytes: 2040
#include "iostream"
#include "algorithm"
using namespace std;

int bubbleSort(int A[], int n){
    int sw = 0;
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i+1; j--){
            if(A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                sw++;
            }

        }
    }
    return sw;
}
int main(){
    int A[100], n, sw;
    cin >> n;
    for(int i=0; i<n; i++) cin >> A[i];
    sw = bubbleSort(A, n);
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

const int dy[8] = {-1,-1,0,1,1,1,0,-1}, dx[8] = {0,1,1,1,0,-1,-1,-1};

int main(){
	int M;
	while(cin>>M,M){
		int dp[1001] = {}; dp[0] = 1;
		for(int k=0;k<M;k++){
			int A,B; cin>>A>>B;
			for(int i=1000;i>=0;i--){
				for(int j=1;j<=B && i+A*j<=1000;j++){
					dp[i+A*j] += dp[i];
				}
			}
		}
		int G; cin>>G;
			for(int i=0;i<G;i++){
				int N; cin>>N;
				printf("%d\n",dp[N]);
			}
	}
	return 0;
}

Measured memory_bytes: 1148
N, M = map(int, input().split())

pylst = []
py = [[] for _ in range(N+1)]

for i in range(M):
    p, y = map(int, input().split())
    pylst.append([y, p, i])

sorted_pylst = sorted(pylst)

for y, p, i in sorted_pylst:
    py[p].append([y, i])

ans = [0]*M

for i, lst in enumerate(py):
    cnt = 1
    for j, k in lst:
        ans[k] = '{0:06d}{1:06d}'.format(i, cnt)
        cnt += 1
for i in ans:
    print(i)

Measured memory_bytes: 53240
// 5/9 過去問ガリガリ
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int N;
    cin >> N;
    // vector<int> A(N);

    bool approved = true;

    // rep(i, N) cin >> A[i];

    rep(i, N) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0) {
                approved = false;
            }
        }
    }

    if (approved) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import defaultdict

def main():
	n=II()
	d=defaultdict(int)

	while n%2==0:
		d[2]+=1
		n//=2

	f=3
	while f*f<=n:
		if n%f==0:
			d[f]+=1
			n//=f
		else:
			f+=2

	if n!=1:
		d[n]+=1

	#print(d)

	ans=0

	for _,v in d.items():
		for i in range(1,10000):
			if (i*(i+1))//2>v:
				ans+=i-1
				break
	print(ans)
















if __name__ == "__main__":
	main()


Measured memory_bytes: 9436
#include<stdio.h>
#define N 8
#define N_FREE 1
#define FREE 0

int Gyo[N],Retu[N],kesa[2*N-1],Gkesa[2*N-1];
int Board[N][N];

void putQueen(int);
void printBoard(){
  int i,j;

  for(i=0;i<N;++i){
    for(j=0;j<N;++j){
      if(Board[i][j]){if(Retu[i] != j) return;}
    }
  }

  for(i=0;i<N;++i){
    for(j=0;j<N;++j){
      if(Retu[i] == j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }

}

void shokika(){
  int i;
  for(i=0;i<N;i++)Retu[i] =  Gyo[i] = FREE;
  for(i=0;i<2*N-1;i++)kesa[i] = Gkesa[i] = FREE;
}


int main(){
  int i,j,n,gyo,retu;

  shokika();
  
   for(i=0;i<N;++i){
     for(j=0;j<N;++j)Board[i][j] = FREE;
  }

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d",&gyo,&retu);
    Board[gyo][retu] = N_FREE;
  }
  
  putQueen(0);

  

  return 0;
}

void putQueen(int i){
  int j;

  if(i == N) {
    printBoard();
    return ;
  }
  for(j=0;j<N;j++){
    if(Gyo[j] == N_FREE || kesa[i+j] == N_FREE || Gkesa[i-j+N-1] == N_FREE) continue;
  
    Retu[i] = j;
    Gyo[j] = kesa[i+j] = Gkesa[i-j+N-1] = N_FREE;
    
    putQueen(i+1);
    
    Gyo[j] = Retu[i] = kesa[i+j] = Gkesa[i-j+N-1] = FREE;
  }
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>

using namespace std;

long long gcd(long long a, long long b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b)
{
    return a * b / gcd(a, b);
}

int main() {
    long long  A, B;
    cin >> A >> B;
    long long  answer = lcm(A,B);
    cout << answer<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input().rstrip())
W = list(map(int, input().split()))

Sa = sum(W)

T = 0
sub_min = max(W)
while T < N:
    S1 = sum(W[0:T])
    S2 = Sa-S1
    sub = abs(S2-S1)
    if sub < sub_min:
        sub_min = sub
    T += 1    
print(sub_min)



Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        sc.close();
        
        System.out.println((n == m) ? "Yes" : "No");
    }
}

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

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h,vector<char>(w));
    vector<int> a(h),b(w);
    int i,j,l,m;

    for(i=0; i<h; i++){
        for(j=0; j<w; j++){
            cin >> c.at(i).at(j);
        }
    }

    int count=0;
    int ans=0;

    for(l=0; l<pow(2,h); l++){
        for(m=0; m<pow(2,w); m++){
            count=0;
            for(i=0; i<h; i++){
                for(j=0; j<w; j++){
                    if(a.at(i)&&b.at(j)){
                        if(c.at(i).at(j)=='#') count++;
                    }
                }
            }
            if(count==k) ans++;
            b.at(0)++;
            for(i=0; i<w-1; i++){
                if(b.at(i)==2){
                    b.at(i)=0;
                    b.at(i+1)++;
                }
            }
        }
        for(j=0; j<w; j++){
            b.at(j)=0;
        }
        a.at(0)++;
        for(i=0; i<h-1; i++){
            if(a.at(i)==2){
                a.at(i)=0;
                a.at(i+1)++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4092
let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let () =
  let h = read_int () in
  let t = Array.make (h + 1) 0 in
  let rec read i =
    if i <= h then (t.(i) <- Scanf.scanf "%d " (fun i -> i); read (i + 1))
  in
  read 1;
  let rec doit i =
    if i <= h then begin
      Printf.printf "node %d: key = %d, " i t.(i);
      if parent i >= 1 then Printf.printf "parent key = %d, " t.(parent i);
      if left i <= h then Printf.printf "left key = %d, " t.(left i);
      if right i <= h then Printf.printf "right key = %d, " t.(right i);
      print_newline ();
      doit (i + 1)
    end
  in
  doit 1

Measured memory_bytes: 2592
import sys


def main():
    input = sys.stdin.buffer.readline
    k = int(input())
    s = set()
    i = 1
    a = 7
    while True:
        a %= k
        if a in s:
            print(-1)
            break
        if a == 0:
            print(i)
            break
        s.add(a)
        i += 1
        a = 10 * a + 7


if __name__ == "__main__":
    main()


Measured memory_bytes: 78000
#include <iostream>
#include <map>
#include <vector>

using namespace std;

struct send
{
	int s;
	int d;
};

int main(void)
{
	int n,m;
	int i1;
	int t;
	int count;

	while(1){
		cin>>n>>m;
		if(n+m==0) break;

		map<int,send> data;
		send sd;
		vector<int> infe(n+1,0);
		infe[1]=1;
		count=1;

		for(i1=0;i1<m;i1++){
			cin>>t>>sd.s>>sd.d;
			data[t]=sd;
		}

		for(map<int,send >::iterator it=data.begin(); it!=data.end();it++){
			if(infe[(*it).second.s]==1 && infe[(*it).second.d]==0) {
				count++;
				infe[(*it).second.d]=1;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 2528
// https://qiita.com/e869120/items/eb50fdaece12be418faa

#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    vector<vector<int>> s(m);
    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int a;
            cin >> a;
            --a;
            s[i].push_back(a);
        }
    }

    vector<int> p(m);
    rep(i, m) {
        cin >> p[i];
    }

    int res = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        bool ok = true;
        for (int i = 0; i < m; i++) {
            int sum = 0;
            for (auto a : s[i]) {
                if ((bit >> a) & 1) sum++;
            }
            if (sum % 2 != p[i]) ok = false;
        }
        if (ok) res++;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,dmax[101010],indeg[101010],a,b;
vector<int>graph[101010];
int visit(int p) {
	if(dmax[p]!=-1)
		return dmax[p];
	dmax[p]=0;
	for(int q:graph[p])
		dmax[p]=max(dmax[p],visit(q)+1);
	return dmax[p];
}
int ans[101010];
void visit2(int p,int rt) {
	if(ans[p]!=-1)
		return;
	ans[p]=rt+1;
	vector<pair<int,int>>c;
	for(int q:graph[p])
		c.push_back({dmax[q],q});
	sort(c.begin(),c.end());
	reverse(c.begin(),c.end());
	for(auto a:c)
		visit2(a.second,p);
}
int main() {
	cin>>n>>m;
	for(int i=0;i<n-1+m;i++) {
		cin>>a>>b;
		graph[a-1].push_back(b-1);
		indeg[b-1]++;
	}
	int o=-1;
	for(int i=0;i<n;i++)
		if(indeg[i]==0)
			o=i;
	for(int i=0;i<n;i++)
		dmax[i]=ans[i]=-1;
	visit(o);
	visit2(o,-1);
	for(int i=0;i<n;i++)
		cout<<ans[i]<<endl;
	return 0;
}

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

int main() {
	int x[5];
	
	for(int i = 0; i < 5; i++)
	{
		cin>>x[i];
	}
	
	for(int i = 0; i < 5; i++)
	{
		if(x[i] == 0)
		{
			cout<<i+1<<endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
/************ Combination wtih MOD ************
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// preprocess for some tables
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// combination
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*******************************************************/
/********** UnionFind ***************
struct UnionFInd {
vector<ll> par;
UnionFInd(ll N) : par(N) {
for (ll i = 0; i < N; i++) {
par[i] = i;
}
}
ll root(ll x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
if (rx == ry) return;
par[rx] = par[ry];
}
bool same(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
*************************************/
int main(int argc, char *argv[]) {
  // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  ll l, r, d;
  cin >> l >> r >> d;

  ll ans = 0;
  for (int i = l; i <= r; i++){
      if(i % d == 0)
          ans += 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

#include<stdlib.h>

#include<string.h>


int main(void)

{

char num_str[1002];

int num;

long long sum = 0;

int i;

char tmp;

while (1)

{

fgets(num_str,sizeof(num_str),stdin);

if(num_str[0] == '0') break;

for (i = 0; i < strlen(num_str)-1; i++)

{

tmp = num_str[i];

num = atoi(&tmp);

sum = sum + num;

}

printf("%lld\n",sum);

sum = 0;

memset(num_str, 1002,0);

}

return 0;

}

Measured memory_bytes: 532
#include<bits/stdc++.h>
using namespace std;
int i,j,k,l;
int dp[1000005];
void bottomupdp(int a[],int n)
{
	dp[0]=0;
	dp[1]=0;
	for(i=2;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i-1]-a[i-2]),dp[i-2]+abs(a[i-1]-a[i-3]));
	}
//	for(i=0;i<=n;i++)
//	{
//		cout<<dp[i]<<" ";
//	}
	cout<<dp[n];
}
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	bottomupdp(a,n);
}

Measured memory_bytes: 4384
#include <stdio.h>

int main() {
    int D;
    scanf("%d", &D);
    switch(D)
   { case 25: printf("Christmas");break;
     case 24: printf("Christmas Eve");break;
     case 23: printf("Christmas Eve Eve"); break;
     case 22 :printf("Christmas Eve Eve Eve");break;
   }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
g = []
for i in range(n):
    a = list(map(int,input().split()))
    g.append(a[2:])
d = [0]*n
f = [0]*n
global t
t = 0

def find(x):
    global t
    if len(g[x-1]) == 0:
        t += 1
        f[x-1] = t
    else:
        for i in g[x-1]:
            if d[i-1] == 0:
                t += 1
                d[i-1] = t
                find(i)
        t += 1
        f[x-1] = t

for i in range(n):
    if d[i] == 0:
        t += 1
        d[i] = t
        find(i+1)
for i in range(n):
    print(i+1, d[i], f[i])



Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int H, W, N, sr, sc;
    string S, T;
    cin >> H >> W >> N >> sr >> sc >> S >> T;

    auto func = [&](char mi, char ma, int pos, int siz) -> bool {
        int posmi = pos, posma = pos;
        for (int i = 0; i < N; ++i) {
            if (S[i] == ma)
                posma++;
            else if (S[i] == mi)
                posmi--;
            if (posma > siz)
                return true;
            if (posmi < 1)
                return true;
            if (T[i] == ma)
                posmi = min(posmi + 1, siz);
            else if (T[i] == mi)
                posma = max(posma - 1, 1);
            if (posma > siz)
                return true;
            if (posmi < 1)
                return true;
        }
        return false;
    };

    bool res = false;
    res |= func('U', 'D', sr, H);
    res |= func('L', 'R', sc, W);

    cout << (res ? "NO" : "YES") << endl;

    return 0;
}


Measured memory_bytes: 920
#include <stdio.h>
#include <stdlib.h>

void swap(int *nx, int *ny)
{
    int temp = *nx;
    *nx = *ny;
    *ny = temp;
}

/*--- *n1≦*n2≦*n3となるように並べ替える ---*/
void sort3(int *n1, int *n2, int *n3)
{
    if (*n1 > *n2) swap(n1, n2);
    if (*n2 > *n3) swap(n2, n3);
    if (*n1 > *n2) swap(n1, n2);
}

int main() {
	int N;
	char *S;
	long long int sum_of_R = 0;
	long long int sum_of_G = 0;
	long long int sum_of_B = 0;
	int *array_of_R;
	int *array_of_G;
	int *array_of_B;
	int i, j, k; int count_R = 0; int count_G = 0;
	int count_B = 0;
	int a, b, c;
	int sum = 0;
	int sum_cont = 0;

	scanf("%d", &N);
	S = (char*)malloc(N * sizeof(char));
	scanf("%s", S);

	for(i = 0; i < N; i++) {
		if(S[i] == 'R') {
			sum_of_R++;
		} else if(S[i] == 'G') {
			sum_of_G++;
		} else if(S[i] == 'B') {
			sum_of_B++;
		}
	}

	for(i = 1; i * 2 < N; i++) {
		//for(j = 0; j < N - i * 2; j++) {
		for(j = 0; j + 2 * i < N; j++) {
			//printf("%d, %d, %d\n", j, j + i, j + 2 * i);
			if(S[j] == S[j + i]
				|| S[j + i] == S[j + 2 * i]
				|| S[j] == S[j + 2 * i]) {
				continue;
			}
			sum++;
		}
	}

	//printf("%d\n", sum_of_R * sum_of_G * sum_of_B);
	printf("%lld\n", sum_of_R * sum_of_G * sum_of_B - sum);
	return 0;
}



Measured memory_bytes: 1736
/*input
10 1000000000000000000
0 0 1 1 0 0 0 1 1 0
0 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 1 0 1
1 1 1 0 1 1 0 1 1 0
0 1 1 1 0 1 0 1 1 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 0 0 1 0 1
1 0 0 0 1 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
1 0 1 1 1 0 1 1 1 0
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 55,mod=1e9+7;
int n;
long  int k;
vector<vector<long int>> g;

class Matrix
{
public:
	vector<vector<long int>> Mat;
	int Row,Col;

	//cont
	Matrix(vector<vector<long int>> mat) : Mat(mat), Row((int)mat.size()) ,Col((int)mat[0].size()) {};

	//Identity Martix
	Matrix(int siz)
	{
		Row=siz;Col=siz;
		vector<vector<long int>> mat(siz,vector<long int> (siz,0));
		for(int i=0;i<siz;i++) mat[i][i]=1;
		Mat=mat;
	}

	//multiple Matrix
	Matrix operator* (const Matrix &oth)
	{
		assert(Col==oth.Row);
		vector<vector<long int>> mat(Row,vector<long int> (oth.Col));
		for(int i=0;i<Row;i++)
		{
			for(int j=0;j<oth.Col;j++)
			{
				mat[i][j]=0;
				for(int k=0;k<Col;k++)
				{
					mat[i][j] += (Mat[i][k]*oth.Mat[k][j])%mod;
					if(mat[i][j]>=mod) mat[i][j]-=mod;
				} 
			}
		}

		return Matrix(mat);
	}

	// matrix power
	Matrix MatrixPower(long int y)
	{
		if(k==0) return Matrix(Row);
		Matrix ans = Matrix(Row);
		Matrix mat = *this;
		while(k>0)
		{
			if(k&1) ans=ans*mat;
			k>>=1;
			mat=mat*mat;
		}

		return ans;
	}

	//print mat
	void Print()
	{
		for(int i=0;i<Row;i++)
		{
			for(int j=0;j<Col;j++) cout<<Mat[i][j]<<" ";
			cout<<"\n";
		}
		return ;
	}
};



int main()
{
	cin>>n>>k;
	g.resize(n,vector<long int> (n));
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>g[i][j];


	Matrix ansMat = (Matrix(g).MatrixPower(k));
	int ans = 0;
	for(int i=0;i<ansMat.Row;i++) for(int j=0;j<ansMat.Col;j++) ans+=ansMat.Mat[i][j],ans%=mod;
	cout<<ans<<"\n";


	// Matrix m1 = Matrix(3);
	// m1.Print();

	// Matrix m2 = Matrix(g);
	// m2.Print();
	// cout<<"\n";

	// m1=m1*m1;
	// m1.Print();

	// Matrix m3=m2*m2;
	// m3.Print();

	// m2 = m2.MatrixPower(2l);
	// m2.Print();

	return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;

namespace
{
	ll GCD(ll a, ll b)
	{
		return a == 0 ? b : GCD(b % a, a);
	}


	ll LCM(ll a, ll b)
	{
		return a / GCD(a, b) * b;
	}
}
void ABC070C()
{
	int N;
	cin >> N;
	vector<ll> Ti(N);
	for (auto& x : Ti)
		cin >> x;
	sort(Ti.begin(), Ti.end());

	ll lcm = 1;
	for (const auto& x : Ti)
	{
		lcm = LCM(lcm, x);
	}
	cout << lcm << endl;
}

int main()
{
	ABC070C();
	return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
ans = 0
X = []
for i in range(N):
    X.append(T[i])
    if i < K: 
        if T[i] == 'r':
            ans += P
        elif T[i] == 's':
            ans += R
        elif T[i] == 'p':
            ans += S
    else:
        if T[i] == X[i-K]:
            X[i] = 'z'
        else:
            if T[i] == 'r':
                ans += P
            elif T[i] == 's':
                ans += R
            elif T[i] == 'p':
                ans += S
print(ans) 

Measured memory_bytes: 4792
require 'pp'

n = gets.chomp!.to_i
a_n = gets.chomp!.split(" ").map(&:to_i).sort!.reverse!

alice = 0
bob = 0
a_n.each_with_index do |a, i|
    if i % 2 == 0
        alice += a
    else
        bob += a
    end
end

puts alice - bob


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<int,int>;
const int MAX=100010;
ll n,sum,m,all;
ll par[MAX];
ll depth[MAX];

ll calc(ll x){
  return ((x+1)*x)/2;
}

void init(ll n){
  for(int i=0;i<n;i++){
    par[i]=i;
    depth[i]=0;
  }
}

ll find(int x){
  if(par[x]==x){
    return x;
  }
  return par[x]=find(par[x]);
}

ll unite(int a,int b){
  int x=find(a),y=find(b);
  if(x==y){
    return sum-all;
  }
  all-=calc(depth[y])+calc(depth[x]);
  if(depth[x]<depth[y]){
    par[x]=y;
    depth[y]=depth[y]+depth[x]+1;
    all+=calc(depth[y]);
  }else{
    par[y]=x;
    depth[x]=depth[y]+depth[x]+1;
    all+=calc(depth[x]);
  }
  return sum-all;
}

int main(){
  all=0;
  cin>>n>>m;
  init(n);
  vector<ll> ans(m);
  sum=calc(n-1);
  ans[m-1]=sum;
  vector<P> num(m);
  for(int i=0;i<m;i++){
    int a,b; cin>>a>>b;
    a--; b--;
    num[i]=P(a,b);
  }
  for(int i=m-1;i>0;i--){
    int x=num[i].first,y=num[i].second;
    ans[i-1]=unite(x,y);
  }
  for(int i=0;i<m;i++){
    if(ans[i]<0){
      cout<<0<<endl;
    }else{
      cout<<ans[i]<<endl;
    }
  }
}

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

bool ope(pair<int,int>a, pair<int, int>b){
    return a.first < b.first;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int,int>> AB(N);
    for(int i=0; i<N; i++){
        int a,b;
        cin >> a >> b;
        AB[i] = make_pair(a,b);
    }
    sort(AB.begin(),AB.end(),ope);

    ll ans=0LL;
    for(int i=0; M>0; i++){
        if(AB[i].second<=M){
            ans += (ll)AB[i].first * (ll)AB[i].second;
            M-=AB[i].second;
        }else{
            ans += (ll)AB[i].first * (ll)M;
            M=0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	char s[200001];
	int a[200000],dp[2][2019],i,j,wk,len,k1,k2;
	long long sum;
	scanf("%s",s);
	len=strlen(s);
	for(i=0;i<len;i++)	a[i]=s[i]-'0';
	sum=0;
	for(j=0;j<2019;j++)	dp[0][j]=0;
	dp[0][a[0]]=1;
	for(i=1;i<len;i++)	{
		k1=i%2;	k2=(k1+1)%2;
		for(j=0;j<2019;j++)	dp[k1][j]=0;
		dp[k1][a[i]]=1;
		for(j=0;j<2019;j++)	{
			wk=(j*10+a[i])%2019;
			dp[k1][wk]+=dp[k2][j];
		}
		sum+=dp[k1][0];
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 2628
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

bool subset(vector<int> &a, vector<int> &b)
{
	if (a.size() > b.size()) return false;
	rep(i, a.size()) 
		if (find(ALL(b), a[i]) == b.end())
			return false;
	return true;
}

int main(void)
{
	int n;
	while (cin >> n, n) {
		vector< vector<int> > people;
		vector<int> data;
		rep(i, n) {
			int t;
			cin >> t;
			vector<int> vs = vector<int>(t);
			rep(j, t)
				cin >> vs[j];
			people.push_back(vs);
		}
		int k;
		cin >> k;
		data = vector<int>(k);
		rep(i, k)
			cin >> data[i];

		int cnt = 0, id;
		rep(i, people.size()) {
			if (subset(data, people[i]))
				cnt++, id = i+1;
		}

		cout << (cnt==1?id:-1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1268
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split(),np.int64)

answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)


Measured memory_bytes: 36624
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  vector<ll> ans(N-1); // すぬけくんがi+1枚のカードをとった時のabs(x-y)の値
  ll sum = accumulate(a.begin(), a.end(), 0LL);
  vector<ll> memo(N); // 累積和
  memo[0] = a[0];
  for (int i=1; i<N; i++) memo[i] = memo[i-1]+a[i];
  for (int i=0; i<N-1; i++) ans[i] = abs(2*memo[i]-sum);
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	while (true) {
		int a[21][21] = {}, X = 10, Y = 10;

		int N, M;
		cin >> N; if (!N)break;
		for (int i = 0; i < N; i++) {
			int x, y;
			cin >> x >> y;
			a[x][y] = 1;
		}
		cin >> M;
		for (int i = 0; i < M; i++) {
			char c;
			int z;
			cin >> c >> z;

			if (c == 'N')for (int j = 1; j <= z; j++) a[X][Y + j] = 0;
			else if (c == 'E')for (int j = 1; j <= z; j++) a[X + j][Y] = 0;
			else if (c == 'S')for (int j = 1; j <= z; j++) a[X][Y - j] = 0;
			else if (c == 'W')for (int j = 1; j <= z; j++) a[X - j][Y] = 0;

			if (c == 'N') { Y += z; }
			else if (c == 'E') { X += z; }
			else if (c == 'S') { Y -= z; }
			else if (c == 'W') { X -= z; }

		}
		bool No = false;
		for (int i = 0; i < 21; i++)
			for (int j = 0; j < 21; j++)
				if (a[i][j])
					No = true;
		if (No)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
integer N
integer,allocatable,dimension(:)::X
integer,allocatable,dimension(:)::ansx,ansy
integer minuscnt,ans
read*,N
allocate(X(N))
allocate(ansx(N-1),ansy(N-1))
read*,X
call heapsort(N,X)

minuscnt=0
do i=1,N
  if(x(i)<0)minuscnt=minuscnt+1
end do

if(minuscnt>=1.and. N-minuscnt>=2)then
  ansx(1)=X(1)
  ansy(1)=X(N-1)
  do i=2,(N-minuscnt)-1
    ansx(i)=ansx(i-1)-ansy(i-1)
    ansy(i)=X(minuscnt+i-1)
  end do
    ansy(N-minuscnt)=ansx(N-minuscnt-1)-ansy(N-minuscnt-1)
    ansx(N-minuscnt)=X(N)
  if(N-minuscnt+1/=N)then
    do i=N-minuscnt+1,N-1
      ansx(i)=ansx(i-1)-ansy(i-1)
      ansy(i)=X(i-N+minuscnt+1)
    end do
  endif
else if(minuscnt==0)then
  ansx(1)=X(1)
  ansy(1)=X(N-1)
  do i=2,N-2
    ansx(i)=ansx(i-1)-ansy(i-1)
    ansy(i)=X(i)
  end do
  ansx(N-1)=X(N)
  ansy(N-1)=ansx(N-2)-ansy(N-2)
else if(minuscnt>0)then
  ansx(1)=X(N)
  ansy(1)=X(1)
  do i=2,N-1
    ansx(i)=ansx(i-1)-ansy(i-1)
    ansy(i)=X(i)
  end do
end if

ans=ansx(N-1)-ansy(N-1)

print"(i0)",ans
do i=1,N-1
  print"(i0,A,i0)",ansx(i)," ",ansy(i)
end do
contains

subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end


Measured memory_bytes: 3584
#include<iostream>
#include<cstring>
using namespace std;
const int BUF = 3005;


int row, col;
int add[BUF][BUF];

void read() {
    int K;
    cin >> row >> col >> K;

    memset(add, 0, sizeof(add));

    for (int i = 0; i < K; ++i) {
        int r, c, v;
        cin >> r >> c >> v;
        --r;
        --c;
        add[r][c] = v;
    }
}


long long rec(int nPick, int r, int c, long long dp[4][BUF][BUF]) {
    if (r == row - 1 && c == col - 1) return 0;
    
    long long &ret = dp[nPick][r][c];
    if (ret != -1) return ret;

    ret = 0;
    
    if (r + 1 < row) {
        ret = max(ret, rec(1, r + 1, c, dp) + add[r + 1][c]);
        ret = max(ret, rec(0, r + 1, c, dp));
    }

    if (c + 1 < col) {
        if (nPick < 3) {
            ret = max(ret, rec(nPick + 1, r, c + 1, dp) + add[r][c + 1]);
        }
        ret = max(ret, rec(nPick, r, c + 1, dp));
    }

    return ret;
}

void work() {
    static long long dp[4][BUF][BUF];
    memset(dp, -1, sizeof(dp));

    cout << max(rec(0, 0, 0, dp), rec(1, 0, 0, dp) + add[0][0]) << endl;
}


int main() {
    read();
    work();
    return 0;
}


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

int main()
{

    int c,n;
  cin >> n >> c;
	string s;
  cin >> s;
  
  for(int i = 0; s[i]; i++)
  {
    if(i==c-1)
      cout << (char)(s[i]+32);
    else
      cout << s[i];
  }
}

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
const Int MAX = 10000;
Int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
Int COM(Int n, Int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
Int dp[3010][3010];
int main() {
    COMinit();
    int N, M; cin >> N >> M;
    string S; cin >> S;
    vector<int> L, R;
    L.push_back(-1), R.push_back(-1);
    for (int i = 0; i < M; i++) {
        int l, r; cin >> l >> r; l--;
        if (L.back() == l) {
            R.back() = max(R.back(), r);
        } else if (R.back() < r) {
            L.push_back(l), R.push_back(r);
        }
    }
    L.push_back(N + 1), R.push_back(N + 1);
    dp[0][0] = 1;
    for (int i = 1; i <= L.size() - 2; i++) {
        int add = 0;
        for (int k = max(R[i - 1], L[i]); k < R[i]; k++) {
            add += S[k] - '0';
        }
        int set = max(0, min(L[i + 1], R[i]) - L[i]);
        for (int j = 0; j <= max(0, R[i - 1] - L[i]); j++) {
            int cnt = j + add;
            for (int k = max(0, cnt - set); k <= min(cnt, max(0, R[i] - L[i + 1])); k++) {
                dp[i][k] += COM(set, cnt - k) * dp[i - 1][j];
                dp[i][k] %= MOD;
            }
        }
    }
    cout << dp[L.size() - 2][0] << '\n';
    return 0;
}


Measured memory_bytes: 29568
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  int r;
  cin >> r;
  cout << r * r << endl;

  return 0;
}


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

using namespace std;


const int N = 1111;

string board[N];
int dp[N][N];


int main(){
	
	while(1){
		int n;
		cin>>n;
		
		if(n==0)break;
		
		
		for(int i=0;i<N;i++)for(int j=0;j<N;j++)dp[i][j]=0;
		
		for(int i=0;i<n;i++){
			cin>>board[i];
		}
		
		int ans = 0;
		
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(board[i-1][j-1]=='*')dp[i][j] = 0;
				if(board[i-1][j-1]=='.')dp[i][j] = min(min(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]) + 1;
				ans = max(ans, dp[i][j]);
			}
		}
		
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 7068
import java.util.*;
import java.io.*;

public class Main {
    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        public long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int ans = (x-y)%z;
        System.out.println(ans);
    }
}


Measured memory_bytes: 32720
var
  s: array[0..100000] of char;
  alpha: array[0..128] of boolean;
  i: integer;
  ok: boolean;
begin
  read(s);
  for i := 0 to length(s) do
  begin
    alpha[ord(s[i])] := True;
  end;
  
  ok := False;
  for i := 97 to 122 do
  begin
    if alpha[i] = False then
    begin
      write(chr(i));
      ok := True;
      break;
    end;
  end;
  
  if ok = False then
  begin
    write('None');
  end;
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);


int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  if(a==0){
    cout<<0<<endl;
    return 0;
  }
  ll ans=0;
  ans+=(n/(a+b))*a;
  n-=(n/(a+b))*(a+b);
  ans+=min(a,n);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256