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

vector<int> g[100000];
int d[100000][3];

typedef tuple<int ,int, int> ti;
int main() {
  int n, m;
  cin>>n>>m;

  for (int i=0; i<m; i++) {
    int u, v;
    cin>>u>>v;
    --u; --v;
    g[u].push_back(v);
  }

  int s, t;
  cin>>s>>t;
  --s; --t;

  int inf = 1e9;
  for (int i=0; i<n; i++) {
    for (int j=0; j<3; j++) {
      d[i][j] = inf;
    }
  }
  d[s][0] = 0;

  priority_queue<ti, vector<ti>, greater<ti> > pq;
  pq.push(make_tuple(0, s, 0));

  while (!pq.empty()) {
    auto t = pq.top();
    pq.pop();
    int from = get<1>(t);
    int mod = get<2>(t);
    for (int to: g[from]) {
      int cost = d[from][mod] + 1;
      if (d[to][(mod+1)%3] > cost) {
        d[to][(mod+1)%3] = cost;
        pq.push(make_tuple(cost, to, (mod+1)%3));
      }
    }
  }

  if (d[t][0] != inf) {
    cout<<d[t][0]/3<<endl;
  } else {
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 6912
n, t = map(int, input().split())
t_list = list(map(int, input().split()))

total_seconds = 0
prev_timing = t_list[0]

for timing in t_list[1:]:
  if timing - prev_timing < t:
    total_seconds += timing - prev_timing
  else:
    total_seconds += t
  prev_timing = timing
total_seconds += t

print(total_seconds)


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

int main(){
	int n,x;
  	int sum,bnum;
  	cin >> n;
  	cin >> bnum;
  	sum = bnum;
  	for(int i=0;i<n-2;i++){
      cin >> x;
      sum += min(x,bnum);
      bnum=x;
    }
  	sum += bnum;
  	cout << sum << endl;
	return 0;
}

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

using namespace std;

const int maxn = 2e5 + 9;
int m,n;
struct data
{
    int64_t gt, sl;
};
data a[maxn];

void Enter()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].gt;
        a[i].sl = 1;
    }
    for (int i = 1, sl, gt; i <= m; i++)
    {
        cin >> sl >> gt;
        a[i + n].gt = gt;
        a[i + n].sl = sl;
    }
}

bool cmp(data x, data y)
{
    if (x.gt < y.gt) return true;
    return false;
}

void Solve()
{
    sort(a + 1, a + m + n + 1, cmp);
    int i = m + n;
    int64_t s = 0;
    while (n > 0)
    {
        if (a[i].sl > n)
            s += a[i].gt * n;
        else
            s += a[i].gt * a[i].sl;
         n -= a[i].sl, i--;
    }
    cout << s;

}

int main()
{
    Enter();
    Solve();
    return 0;
}


Measured memory_bytes: 3328
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	odd, four, two int
)

func main() {
	count()

	if four+1 >= odd {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

func count() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()

	tmp := 0
	for sc.Scan() {
		tmp, _ = strconv.Atoi(sc.Text())

		if tmp%2 == 1 {
			odd++
		} else if tmp%4 == 0 {
			four++
		} else if tmp%2 == 0 {
			two++
		}
	}

	if two > 0 {
		odd++
	}
}

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


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int A[20];
int B[20];
int a_min, a_max;
int b_min, b_max;

int memo[20][20][2];

int dfs(int left, int right, int turn) {

	if (memo[left][right][turn] >= 0)
	{
		return memo[left][right][turn];
	}

	if (turn == 0)
	{
		if (left <= a_min && a_max <= right)
		{
			//先手の勝ち
			return memo[left][right][turn] = 1;
		}
	}
	else
	{
		if (left <= b_min && b_max <= right)
		{
			//後手の勝ち
			return memo[left][right][turn] = 0;
		}
	}

	//以下次の再起部分

	if (turn == 0)
	{
		//先手の手番
		if (A[left] == 1 || A[right] == 1)
		{
			if (A[left] == 1)
			{
				//左に置けるカードがある
				
				if (dfs(left - 1, right, 1 - turn) == 1)
				{
					return memo[left][right][turn] = 1;
				}
			}

			if (A[right] == 1)
			{
				//右に置けるカードがある
				if (dfs(left, right + 1, 1 - turn) == 1)
				{
					return memo[left][right][turn] = 1;
				}
			}

		}
		else
		{
			//パスするケース
			if (dfs(left, right, 1 - turn) == 1)
			{
				return memo[left][right][turn] = 1;
			}
		}
		
		//勝てない場合
		return memo[left][right][turn] = 0;
	}
	else
	{
		//後手の手番
		if (B[left] == 1 || B[right] == 1)
		{
			if (B[left] == 1)
			{
				//左に置けるカードがある
				if (dfs(left - 1, right, 1 - turn) == 0)
				{
					//後手が勝つ
					return memo[left][right][turn] = 0;
				}
			}

			if (B[right] == 1)
			{
				//右に置けるカードがある
				if (dfs(left, right + 1, 1 - turn) == 0)
				{
					return memo[left][right][turn] = 0;
				}
			}
		}
		else
		{
			//パスするケース
			if (dfs(left, right, 1 - turn) == 0)
			{
				return memo[left][right][turn] = 0;
			}
		}
		
		//後手が勝てない場合（先手が勝つ）
		return memo[left][right][turn] = 1;

	}
}

int main() {

	int n;
	cin >> n;
	for (int _ = 0; _ < n; _++)
	{
		//初期化
		a_min = b_min = 100;
		a_max = b_max = 0;
		for (int i = 0; i < 20; i++)
		{
			for (int j = 0; j < 20; j++)
			{
				for (int k = 0; k < 2; k++)
				{
					memo[i][j][k] = -1;
				}
			}
		}
		for (int i = 0; i < 20; i++)
		{
			A[i] = B[i] = 0;
		}
		
		for (int i = 0; i < 6; i++)
		{
			int tmp;
			cin >> tmp;
			A[tmp] = 1;
			a_max = max(a_max, tmp);
			a_min = min(a_min, tmp);
		}

		for (int i = 1; i <= 13; i++)
		{
			if (i == 7)
			{
				continue;
			}
			if (A[i] == 0)
			{
				B[i] = 1;
				b_max = max(b_max, i);
				b_min = min(b_min, i);
			}
		}

		if (dfs(6, 8, 0))
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<int> A(N);
	rep(i,N){
		cin >> A[i];
	}
	int gcd1 = A[0];
	rep(i,N){
		if(i==0) continue;
		gcd1 = __gcd(gcd1, A[i]);
	}
	if(gcd1 != 1) cout << "not coprime" << endl;
	else{
		sort(A.begin(), A.end());
		bool prime[1000010]{};
		for(int i=2;i<1000005;i++){
			prime[i] = true;
		}
		for(int i=2;i<=1000000;i++){
			if(prime[i]){
				int ans = 0;
				for(int j=i;j<=1000000;j+=i){
					prime[j] = false;
					if(j == (*lower_bound(A.begin(), A.end(), j))) ++ans;
				}
				if(ans >= 2){
					cout << "setwise coprime" << endl;
					return 0;
				}
			}
		}
		cout << "pairwise coprime" << endl;
	}
}

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

int main() {
  int h;
  int w;
  cin >> h >> w;
  
  vector<string> table(h);
  for (int i = 0; i < h; i++) {
    cin >> table.at(i);
  }
  
  vector<bool> row(h, false);
  vector<bool> col(w, false);
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if(table.at(i).at(j) == '#') {
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  
  for (int i = 0; i < h; i++) {
    if(row.at(i)) {
      for (int j = 0; j < w; j++) {
        if (col.at(j)) {
          cout << table.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}
  

Measured memory_bytes: 256
n,m=map(int,input().split())
g = [[] for _ in range(n)]

for _ in range(m):
  a,b = map(int,input().split())
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]

from collections import deque
q=deque([0])
s=[0]*n
while q:
  p=q.popleft()
  for v in g[p]:
    if s[v] < 1:
      s[v]=p+1
      q.append(v)
if 0 in q:print('No')
else:
  print('Yes')
  for v in s[1:]:
    print(v)

Measured memory_bytes: 37608
//============================================================================
// Name        : AOJ.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	auto i=0;
	int m,f,b;
	cin>>m>>f>>b;
	if(m>=b){
		i=0;
		cout <<i<< endl;
	}else if((m+f)-b<0){
		cout <<"NA"<< endl;
	}else {
		cout <<b-m<< endl;

	}
	return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , i;

int main()
{
    _FastIO;
    cin >> n >> i;
    cout << n - i + 1 << endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 1e9;
const LL LLINF = 1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve()
{
    vector<int> S_histo(256);
    vector<int> T_histo(256);
    string S,T; cin >> S >> T;
    
    REP0(i, S.length())
    {
        S_histo[ (int)(unsigned char)S[i] ]++;
        T_histo[ (int)(unsigned char)T[i] ]++;
    }

    SORT(S_histo); REVERSE(S_histo);
    SORT(T_histo); REVERSE(T_histo);

    bool possible = true;

    REP0(i, 256) if (S_histo[i] != T_histo[i]) possible = false;

    cout << ( possible ? "Yes" : "No" ) << endl;

}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 916
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<set>
#include<iomanip>
using namespace std;
using ll=long long int ;

int main() {

	int n;
	cin >> n;
	int l[15];
	for (int i = 0; i < n; i++)cin >> l[i];

	sort(l, l + n);

	int sum = 0;
	for (int i = 0; i < n - 1; i++)sum += l[i];

	if (sum > l[n - 1])cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

typedef struct {
	double x;
	double y;
}point;

double len(point p1, point p2) {
	double dx = p1.x - p2.x;
	double dy = p1.y - p2.y;
	double res = (dx * dx) + (dy * dy);
	return sqrt(res);
}

int main() {
	int n;
	point p[8];
	double sum = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> p[i].x >> p[i].y;

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

	printf("%.10f\n", sum / n);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll n;
    cin>>n;
    ll r = n%10;
    if(r == 3) cout<<"bon";
    else if(r==0 || r==1 || r==6 || r==8) cout<<"pon";
    else cout<<"hon";
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,d,x;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    cin>>d>>x;
    for(int i=1;i<=n;i++){
        int a;cin>>a;
        x+= (d-1)/a + 1;
    }
    cout<<x<<newl;
}


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

const int INF = 1<<28;

int main(){
    int n;
    while(cin >> n, n){
        int t[n][n+1];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n+1; j++){
                cin >> t[i][j];
            }
        }
        
        int dp[1<<n];
        for(int i = 0; i < 1<<n; i++)   dp[i] = INF;
        dp[0] = 0;

        for(int s = 0; s < 1<<n; s++){
            for(int i = 0; i < n; i++){
                if(1<<i & s) continue;
                int cost = t[i][0];
                for(int j = 0; j < n; j++){
                    if(1<<j & s)    cost = min(cost, t[i][j+1]);
                }
                dp[s|(1<<i)] = min(dp[s|(1<<i)], dp[s] + cost);
            }
        }

        cout << dp[(1<<n)-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3356
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
typedef  long long ll;
using namespace std;

int main(void) {
	int n;
	string a, b;
	ll taro = 0, hanako = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (a == b)
		{
			taro++;
			hanako++;
		}
		else if (a > b)
		{
			taro += 3;
		}
		else
		{
			hanako += 3;
		}
	}

	cout << taro << " " << hanako << endl;

	return 0;
}


Measured memory_bytes: 3204
#include<iostream>
using namespace std;
int n,t[4];
int num[10000],h[10000],b[10000];
int ans[1000][4],ans_cnt;
int u[4];
int hcnt,bcnt;
int used[10];
void check(){
  //if(t[0]==0&&t[1]==1&&t[2]==3&&t[3]==2)cout<<'A'<<endl;
  int i;
  for(i=0;i<n;i++){
    u[3]=num[i]%10;
    u[2]=(num[i]/10)%10;
    u[1]=(num[i]/100)%10;
    u[0]=num[i]/1000;

    hcnt=bcnt=0;

    for(int j=0;j<4;j++){
      if(t[j]==u[j])hcnt++;
      else{
	for(int k=0;k<4;k++){
	  if(t[j]==u[k]){
	    bcnt++;
	    break;
	  }
	}
      }
    }
    if(!(hcnt==h[i]&&bcnt==b[i]))break;
  }
  if(i==n){
    
    for(int j=0;j<4;j++){
      ans[ans_cnt][j]=t[j];
      
    }
    ans_cnt++;

  }

}

void compute(int x){
  //cout<<x<<'A'<<endl;
  if(x==4)check();
  else{
    for(int i=0;i<10;i++){
      if(used[i]==1)continue;
      used[i]=1;
      t[x]=i;
      compute(x+1);
      used[i]=0;
    }
  }
}

int FLG;
int flg[5][5],v[4];
void check2(){
  // cout<<t[0]<<t[1]<<t[2]<<t[3]<<endl;
  for(int i=0;i<5;i++)for(int j=0;j<5;j++)flg[i][j]=0;
  for(int i=0;i<ans_cnt;i++){
    hcnt=bcnt=0;
    for(int j=0;j<4;j++){
      if(t[j]==ans[i][j])hcnt++;
      else{
	for(int k=0;k<4;k++){
	  if(t[j]==ans[i][k]){
	    bcnt++;
	    break;
	  }
	}
      }
    }
    if(flg[hcnt][bcnt]==1)return;
    else flg[hcnt][bcnt]=1;
  }
  if(FLG==0){
    for(int i=0;i<4;i++)v[i]=t[i];
    FLG=1;
  }
}

void compute2(int x){
  //cout<<x<<'A'<<endl;
  if(x==4)check2();
  else{
    for(int i=0;i<10;i++){
      if(used[i]==1)continue;
      used[i]=1;
      t[x]=i;
      compute2(x+1);
      used[i]=0;
    }
  }
}

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>num[i]>>h[i]>>b[i];
    for(int i=0;i<10;i++)used[i]=0;
    ans_cnt=0;
    compute(0);
    if(ans_cnt==1){
      cout<<ans[0][0]<<ans[0][1]<<ans[0][2]<<ans[0][3]<<endl;
      continue;
    }
    for(int i=0;i<10;i++)used[i]=0;
    FLG=0;
    compute2(0);
    
    if(FLG==0)cout<<"????"<<endl;
    else cout<<v[0]<<v[1]<<v[2]<<v[3]<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int P, Q, R;
	cin >> P >> Q >> R;
	cout << (P + Q + R) - max({ P,Q,R }) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <cmath>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<pair<int,int> > event(n);
    rip(i,n,0){
        cin >> event[i].second >> event[i].first;
    }
    sort(all(event));
    int now=-1;
    int ans=0;
    rip(i,n,0){
        if(now<event[i].second){
            ans++;
            now=event[i].first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int K,X;cin>>K>>X;
    for(int i=X-K+1;i<=X+K-1;i++){
        cout<<i;
        if(i<X+K-1)cout<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 3600
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; m],
    }
    let a_sum = a.iter().sum::<usize>();

    if a_sum <= n {
        println!("{}", n - a_sum);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 2248
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	cin >> str;
	int ans = 0;
	for (int i = 0; i + 1 < str.length(); i++)
	{
		ans += str[i] != str[i + 1];
	}
	cout << ans << endl;
	return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

string s;
int D;
const int N=1e5+5,mod=1e9+7;
ll dp[N][105][2];

ll dfs(int i,int sum,bool strict){
    if(i==sz(s)) return sum==0;
    if(dp[i][sum][strict]!=-1) return dp[i][sum][strict];
    ll ret=0;
    int mx=9;
    if(strict) mx=s[i]-'0';
    for(int j=0;j<=mx;j++){
        (ret+=dfs(i+1,(sum+j)%D,j==mx&&strict))%=mod;
    }
    return dp[i][sum][strict]=ret;
}
    
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>s>>D;
    memset(dp,-1,sizeof(dp));
    cout<<(dfs(0,0,1)-1+mod)%mod;
    return 0;
}



Measured memory_bytes: 168672
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll f(ll x,ll c,ll d){
    ll res =x;
    res -=x/c;
    res -=x/d;
    res+= x/lcm(c,d);
    return res;
}

vector<int> to[100005];
const ll inf =100000000;

vector<ll>a,b,c,d;
ll n,m,q;
ll ans=0;
void bfs(vector<ll> v){
   if(v.size()==n+1) {
       ll sum=0;
       rep(i,q){
           if(v[b[i]]-v[a[i]]==c[i])sum+=d[i];
       }
       ans=max(ans,sum);
       return;
   }
   v.push_back(v.back());
   bfs(v);
   while(v.back()<m){
       v.back()++;
       bfs(v);
   }
}

int main(){
 int n,x,y;
 cin>>n>>x>>y;
 x--;y--;
 vector<int>ans(n);
 rep(sv,n){
     vector<int> dist(n,inf);
     queue<int>q;
     auto push =[&](int v,int d){
         if(dist[v]!=inf)return;
         dist[v]=d;
         q.push(v);
     };
  push(sv,0);
  while(!q.empty()){
    int v=q.front();q.pop();
    int d=dist[v];
    if(v-1>=0)push(v-1,d+1);
    if(v+1<n)push(v+1,d+1);
    if(v==x)push(y,d+1);
    if(v==y)push(x,d+1);
  }
  rep(i,n) ans[dist[i]]++;
 }
 rep(i,n)ans[i]/=2;
 for(int i=1;i<=n-1;i++){
     cout<<ans[i]<<endl;
 }
 return 0;
}


Measured memory_bytes: 5992
n,m=map(int,input().split())
a,M,d=1,10**9+7,[1]
for i in range(1,n+1):
  d.append(((m-n+i-1)*d[i-1]+(i-1)*d[i-2])%M)
  a=a*(m-i+1)%M
print(a*d[-1]%M)

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

#define ll long long

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ll> an(n+1);
    for(int i=1; i<n+1; i++) cin >> an[i];
    if(n%2==0) {
        for(int i=n; i>=2;) {
            cout << an[i] << " ";
            i -= 2;
        }
        for(int i=1; i<=n-1;) {
            cout << an[i] << " ";
            i += 2;
        }
        cout << endl;
    } else {
        for(int i=n; i>=1;) {
            cout << an[i] << " ";
            i -= 2;
        }
        for(int i=2; i<=n-1;) {
            cout << an[i] << " ";
            i += 2;
        }
        cout << endl;
    }
    return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var t = Console.ReadLine().Trim();

        var cs = new char[26];
        var ds = new char[26];
        for (int i = 0; i < s.Length; i++)
        {
            var ord_t = t[i] - 'a';
            if (cs[ord_t] == default(char))
            {
                cs[ord_t] = s[i];
            }
            else if (cs[ord_t] != s[i])
            {
                Console.WriteLine("No");
                return;
            }
            
            var ord_s = s[i] - 'a';
            if (ds[ord_s] == default(char))
            {
                ds[ord_s] = t[i];
            }
            else if (ds[ord_s] != t[i])
            {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 12512
#include <cstdio>
#include <string>
using namespace std;

char s[1010];
string t, b;
long long int a[1010][1010];
int mod = 1e9+7;

int main(){
	scanf("%s", s);
	t = s;
	scanf("%s", s);
	b = s;

	if(t[0] == b[0]) a[0][0] = 1;
	for(int i=1; i<b.size(); ++i) a[0][i] = 0;
	for(int i=1; i<t.size(); ++i){
		a[i][0] += a[i-1][0];
		if(t[i] == b[0]) ++a[i][0];
	}
	for(int i=1; i<t.size(); ++i)
		for(int j=1; j<b.size(); ++j){
			a[i][j] += a[i-1][j];
			if(t[i] == b[j]) a[i][j] += a[i-1][j-1];
			a[i][j] %= mod;
		}

	printf("%lld\n", a[t.size()-1][b.size()-1]);
}

Measured memory_bytes: 10724
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<unordered_map>
#include<map>
using namespace std;

vector<int>c[100000];
vector<int>rinsetu[100000];
bool used[100000];
void DFS(int a) {
	used[a] = true;
	for (int i : rinsetu[a]) {
		if (!used[i]) {
			DFS(i);
		}
	}
}
signed main() {
	int a, b; cin >> a >> b;
	for (int d = 0; d < a; d++) {
		int e; scanf("%d", &e);
		for (int f = 0; f < e; f++) {
			int g; scanf("%d", &g); g--;
			c[g].push_back(d);
		}
	}
	for (int d = 0; d < b; d++) {
		for (int e = 1; e < c[d].size(); e++) {
			rinsetu[c[d][e - 1]].push_back(c[d][e]);
			rinsetu[c[d][e]].push_back(c[d][e - 1]);
		}
	}
	DFS(0);
	bool S = true;
	for (int i = 0; i < a; i++) {
		if (!used[i])S = false;
	}
	if (S)puts("YES");
	else puts("NO");
}

Measured memory_bytes: 11640
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])


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

int main(void){
    ll n,k;
    cin>>n>>k;
    vector<ll> m(n+1,0);
    
    
    for(ll i=0;i<n;++i){
        ll t;
        cin>>t;
        m[t]++;
    }
    sort(m.begin(),m.end(),greater<ll>());
    ll cnt=0;
    for(ll i=k;i<n;++i){
        cnt+=m[i];
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 4840
#include <stdio.h>

int main()
{
    int n, a, b;
    int x, y, z;
    scanf("%d%d%d", &n, &a, &b);
    x = (a < b) ? a : b;
    y = (a + b - n < 0) ? 0 : a + b - n;
    printf("%d %d\n", x, y);
}

Measured memory_bytes: 128
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>

using namespace std;

int main( void ) {

    string s;
    cin >> s;

    for ( int i = 0; i < s.size(); i += 2 ) {
        cout << s[i];
    }

    cout << endl;
 
    return 0;
}

Measured memory_bytes: 512
n, s = map(int, input().split())
a = list(map(int, input().split()))

dp = [[0]*(s+1) for i in range(n+1)]

dp[0][0] = 1

mod = 998244353
ans = 0
for i in range(n):
    for j in range(s+1):
        if j+a[i] <= s:
            dp[i+1][j+a[i]] += dp[i][j]

        dp[i+1][j] += dp[i][j]*2
        dp[i+1][j] %= mod



print(dp[n][s])


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

// リーダーのいる方向を向く

int main() {
    int n;
    string s;
    cin >> n >> s;
    int sol = 1e9;
    int ct = 0;
    for (int i = 1; i < n; i++) {
        ct += (s[i] == 'E');
    }
    for (int i = 0; i < n; i++) {
        sol = min(sol, ct);
        if (i + 1 < n) {
            ct += (s[i] == 'W');
            ct -= (s[i + 1] == 'E');
        }
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 900
#include<iostream>
#include<vector>
#include <stdlib.h>
using namespace std;

int main(){
    int n;
    string str;
    cin>>n;
    cin>>str;
    int I=0,J=0,O=0,JO=0,IOI=0,JOI=0;
    for(int i=0;i<n;i++){
        if(str[i]=='O') {
            if(I-IOI+J>O) O++;
            if(J>JO) JO++;
        }else if(str[i]=='I'){
            I++;
            if(O*J*JO)J--,JO--,O--,JOI++;
            else if(O*I)O--,IOI++;
        } else {
            J++;
        }
    }
    cout<<JOI+min(IOI,(I-JOI)/2)<<endl;
}

Measured memory_bytes: 2068
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,k,a[200009],i;
cin>>n>>k;
  for(i=0;i<n;i++)
cin>>a[i];

long long int count=0;

for(i=0;i<n;i++)
{
   if(a[i]>=k)
    count++;


}
cout<<count;
return 0;
}


Measured memory_bytes: 1024
def bubbleSort(n,A):
    flag = True
    cnt = 0
    while flag:
        flag = False
        for j in range(n-1, 0, -1):
            if A[j-1] > A[j]:
                A[j-1],A[j] = A[j],A[j-1]
                cnt += 1
                flag = True
    print(*A)
    print(cnt)

if __name__ == '__main__':
    N = int(input())
    A = list(map(int,input().split()))
    bubbleSort(N, A)

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

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

int main() {
    int n, k;
    cin >> n>> k;
    ll ans = k;
    for (int i = 1; i < n; i++) {
        ans *= (k - 1);
    }
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define vi vector<int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int a,b,c;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> a >> b >> c;
    if (c<=b) rc(b+c);
    else rc(2*b+min(a+1,c-b));
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

vector<vector<int>> g;
vector<int> color, sz, used;


void dfs(int v, int clr) {
	color[v] = clr;
	sz[clr]++;
	for (auto u : g[v]) {
		if (!color[u]) {
			dfs(u, clr);
		}
	}
}


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	g.resize(n);
	color.resize(n +1);
	sz.resize(n + 1);
	used.resize(n + 1);
	for (int i = 0; i < m; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		g[from].push_back(to);
		g[to].push_back(from);
	}
	int cnt = 1;
	for (int i = 0; i < n; i++) {
		if (!color[i]) {
			dfs(i, cnt);
			cnt++;
		}
	}
	for (int i = 0; i < k; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		if (color[from] == color[to]) {
			used[from]++;
			used[to]++;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << sz[color[i]] - g[i].size() - 1 - used[i] << " ";
	}
}

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

int main(void)
{
  int i,j;
  int ac=0;
  int tle =0;
  int wa =0;
  int re =0;
  cin >> i;
 
  string d[i];
  
  for(j=0; j<i;j++){
   cin >> d[j];
  }
  for(int k=0;k<i;k++){
    if(d[k] == "AC"){ 
     ac++;
    }
    else if(d[k] == "WA"){
     wa++;
    }
    else if(d[k] == "TLE"){
     tle++;
    }
    else if(d[k] == "RE"){
     re++;
    }
  }
  
    cout << "AC x "<< ac <<endl;
    cout << "WA x "<< wa <<endl;
    cout << "TLE x "<< tle <<endl;
    cout << "RE x "<< re <<endl;
  

}



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

inline int read() {
  int ret, cc, sign = 1;
  while (!isdigit(cc = getchar()))
    sign = cc == '-' ? -1 : sign;
  ret = cc - 48;
  while (isdigit(cc = getchar()))
    ret = cc - 48 + ret * 10;
  return ret * sign;
}

const int MAXN = 100010;
std::vector<int> pos[MAXN];
int pa[MAXN];
int size[MAXN];
int tag[MAXN];
inline int Find(int x) { return x == pa[x] ? x : pa[x] = Find(pa[x]); }
inline void Union(int x, int y) { 
  int px = Find(x), py = Find(y);
  if (px != py) pa[px] = py, size[py] += size[px];
}
int main() {
  int n = read(), m = 100000;
  for (int i = 1; i <= n; ++i) {
    int x = read(), y = read();
    pos[x].push_back(y);
  }
  for (int i = 1; i <= m; ++i) pa[i] = i;
  std::map<int, int> mp;
  for (int i = 1; i <= m; ++i) {
    if (pos[i].size() > 1) {
      for (auto x : pos[i]) {
        if (mp.count(x))
          Union(mp[x], i);
        else mp[x] = i, size[Find(i)]++;
      }
    }
  }
  //for (auto x : mp)
  //  printf("%d %d\n", x.first, x.second);
  //for(int i=1;i<=6;i++)
  //  std::cerr<<"size["<<i<<"]="<<size[i]<<"\n";
  long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    for (auto x : pos[i]) {
      if (mp.count(x)) {
        --ans;
        if (tag[Find(mp[x])] != i) {
          tag[Find(mp[x])] = i;
          ans += size[Find(mp[x])];
        }
      }
    }
  }
  printf("%lld\n", ans);
}


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

int main(){
    int N;cin>>N;
    string str="";
    while(N!=0){
        int r=N%2;
        if(r<0)r+=2;
        N=(N-r)/(-2);
        str+=(char)('0'+r);

    }
    reverse(str.begin(),str.end());
    if(str=="")str="0";
    cout<<str<<endl;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(long long*)a>*(long long *)b)return 1;
    return -1;
}
int main()
{   int n,r,g,b,cnt=0;
    scanf("%d%d%d%d",&r,&g,&b,&n);
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
                if((n-i*r-j*g)%b==0&&n-i*r-j*g>=0){
                    cnt++;
            }
        }
    }
    printf("%d",cnt);
    
    return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
mul_A = 1
for a in A:
    mul_A *= a
#print(mul_A)

parts_mul_A = list(map(lambda x: int(mul_A/x),A))
#print(parts_mul_A)
ans = mul_A/sum(parts_mul_A)
print(ans)

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A.begin(), A.end());
  ll ans = 0;
  ll mid = A[N/2];
  REP(i, N){
    ans += abs(A[i] - mid);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main{
    public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();//D
	int r = sc.nextInt();//Jbgñ

	while(n!=0 && r!=0){
	    int[] fuda = new int[n+1];
	    int[] ans = new int[n+1];
	    //DÌú»
	    for(int i=1; i<n+1; i++) fuda[i] = i;
	    
	    for(int j=0; j<r; j++){
		int p = sc.nextInt();//ã©çpÔÚ
		int c = sc.nextInt();//c²«æé
		solve(fuda,ans,p,c);
	    }

	    System.out.println(ans[n]);

	    n = sc.nextInt();
	    r = sc.nextInt();
	}
    }
    
    public static void solve(int[] fuda, int[] ans, int p, int c){
	int count = 1;
	for(int k=1; k<fuda.length; k++){	 
	    //Jbg·éÍÍÉÜÜêÄ¢é©Ç¤©   
	    if(k<=fuda.length-p && k>=fuda.length-p-c+1) ans[k+p-1] = fuda[k];
	    else ans[count++] = fuda[k];	
	}
	//1ñÌJbgìªIíé½ÑÉAzñðRs[
	for(int i=0; i<ans.length; i++)	fuda[i] = ans[i];
    }

}

Measured memory_bytes: 12000
n, m = gets.chomp.split.map(&:to_i)
graph = Array.new(n) { [] }
 
m.times do
  a, b = gets.split.map(&:to_i)
  graph[a - 1] << b - 1
  graph[b - 1] << a - 1
end
 
queue = [0]
answer = [0]
 
until queue.empty?
  current = queue.shift
  graph[current].each do |to|
    next if answer[to]
    answer[to] = current + 1
    queue << to
  end
end

puts "Yes"
puts answer[1...n]

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n;
	vll a(n);  rep(i,n) cin >> a[i];
	cin >> m;
	vll b(m);  rep(i,m) cin >> b[i];
	cout << (a<b?1:0) << endl;
	return 0;
}


Measured memory_bytes: 3132
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
count = n
ans = 1
while count != 0:
    count = (count + n) % 360
    ans += 1
print(ans)

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

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define fast() ios::base::sync_with_stdio(false); cin.tie(NULL);
typedef long long int ll;

using namespace std;

int main(){
    char huruf; cin >> huruf;
    huruf += 1;
    cout << huruf << '\n';
    return 0;
}

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

using ::std::cin;
using ::std::cout;
using ::std::endl;
using ::std::vector;

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int d2 = 0;
      for (int k = 0; k < d; k++) {
        int diff = points[i][k] - points[j][k];
        d2 += diff * diff;
      }

      int r = 0;
      for (int r = 0; r * r <= d2; r++) {
        if (r * r == d2) {
          ans++;
          break;
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    string s; cin>>s;
    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]=='1'){
            ans++;
        }
    }
    cout<<ans<<endl;
    
}


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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007

typedef long long ll;

int main() {
  ll first, second;
  cin >> first >> second;
  ll count = 1;
  ll c = __gcd(first, second);
  if(c % 2 == 0) {
    count++;
    while(c % 2 == 0) {
      c = c / 2;
    }
  }
  for(ll i = 3; i*i <= c; i+=2) {
    if(c%i != 0) continue;
    count++;
    while(c % i == 0) {
      c = c / i;
    }
  }
  if(c!=1) count++;

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    vector<int> dp(3);
    for(int i=0;i<n;i++)
    {
        vector<int>new_dp(3,0),c(3);
        for(int j=0;j<3;j++)
        cin >> c[j];
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j!=k)
                {
                    new_dp[k]=max(new_dp[k],dp[j]+c[k]);
                }
            }
        }
        dp=new_dp;
    }
    cout << max(dp[0],max(dp[1],dp[2]));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin(),(c).end())
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

string s;

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

  cin >> s;
  int pos = -1;
  REP(i, s.size()) if (s[i] == '*') {
    pos = i;
  }
  int ans = 0;
  stack<int> st;
  REP(i, s.size()) if (s[i] != '*') {
    if (s[i] == '(') {
      st.push(i);
    } else {
      int l = st.top(); st.pop();
      ans += (l < pos && pos < i);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
string s;
//int a,b,c,d;
char a[10][10];
int sum;
int ans;
int main()
{
	int h,w,k;cin>>h>>w>>k;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=='#')
			{
				sum++;
			}
		}
	}
	int cnt=0;
	for(int i=0;i<(1<<h);i++)
	{
		for(int j=0;j<(1<<w);j++)
		{
			cnt=0;
			for(int x=0;x<h;x++)
			{
				for(int y=0;y<w;y++)
				{
					if(((i&(1<<x))||(j&(1<<y)))&&a[x][y]=='#')cnt++;
				}
			}
			if(cnt==sum-k)
			{
				ans++;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int a,b,k;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(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;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}	    
int q[100000],w,sum=0;
signed main(){
// __builtin_ctz(N);      Nを２で何回割り切れるかを返す
//(n+1)*n/2;              １からNまでの総和を求める式
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,z;
    cin>>a>>b>>c;
    for(int i=0;i<b;i++) cin>>q[i];
    for(int i=0;i<a;i++){
	w=0;
	for(int j=0;j<b;j++){
	    cin>>z;
	    w=w+z*q[j];
	}
	w=w+c;
	if(w>0) sum++;
    }
    cout<<sum<<"\n";
    
}
    
	    


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a[1000],i,total,N,l,ans;
  
  scanf("%d",&N);
  for(i = 0;i < N;i++){
    scanf("%d",&a[i]);
  }
  for(i = N;i>=0;i--){
    for(l = 0;l < i;l++){
      ans = ans + a[l] * a[i];
    }
  }
printf("%d",ans);
return 0;
}

 
      

Measured memory_bytes: 128
// D - 756
#include <bits/stdc++.h>
using namespace std;

map<int,int>P{
{ 2,0},{ 3,0},{ 5,0},{ 7,0},{11,0},
{13,0},{17,0},{19,0},{23,0},{29,0},
{31,0},{37,0},{41,0},{43,0},{47,0},
{53,0},{59,0},{61,0},{67,0},{71,0},
{73,0},{79,0},{83,0},{89,0},{97,0},
};

int f(int x){
	x--;
	int c = 0;
	for(auto e:P) if(e.second>=x) c++;
	return c;
}

int main(){
	int N; cin>>N;

	for(int i=2; i<=N; ++i)
		for(auto e:P){
			int p = e.first;
			if(p > i) break;
			for(int n=i; n%p==0; n/=p) P[p]++;
		}

	int ans = f(75); // {f(75)}_C_{1}
	ans += f(25) * (f(3)-1); // {f(25)}_C_{1} * {f(3)-1}_C_{1}
	ans += f(15) * (f(5)-1); // {f(15)}_C_{1} * {f(5)-1}_C_{1}
	ans += f(5)*(f(5)-1)/2 * (f(3)-2); // {f(5)}_C_{2} * {f(3)-2}_C_{1}
	cout << ans <<endl;
}

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

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

  std::vector<int> cnt(N);
  for (int i = 0; i < M; ++i) {
    ++cnt[a[i] - 1];
    ++cnt[b[i] - 1];
  }
  for (int i = 0; i < N; ++i) {
    std::cout << cnt[i] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256