akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll 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;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  int n;
  cin>>n;
  int m=n%100;
  n/=100;
  if((n>12||n==0)&&(12>=m&&0<m)){
    cout<<"YYMM"<<endl;
    return 0;
  }
  if((m>12||m==0)&&(12>=n&&0<n)){
    cout<<"MMYY"<<endl;
    return 0;
  }
  if((m>12||m==0)&&(n>12||n==0)){
    cout<<"NA"<<endl;
    return 0;
  }
  if((12>=n&&0<n)&&(12>=m&&0<m)){
    cout<<"AMBIGUOUS"<<endl;
    return 0;
  }
}


Measured memory_bytes: 3636
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
	  #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
	   ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
		   # #  # # #                   # #      ###### #    # #    # #      #####
	  #    # #   #  #              #    # #      #    # #    # #    # #      #   #
	   ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LL i = 0; i < (n); i++)
#define FOR(in) for(LL i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 
 
LL concate(LL a, LL b)
{
	ostringstream os;
	os <<a <<b;
	istringstream is(os.str());
	LL c;
	is>> c;
	return c;
}
 
 
LL check(char c)
{
	return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
}
LL mod = 1e9+7;
 
 
int main()
{
	LL q,t;
	//cin>>t;
	//while(t--)
	//{
	   LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
		LL aa[1000];
		LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
		LL ma=0, mi=100000000;
		LL mid=0, temp=0, stop=0, start=0;
		double pi= 3.141592653589793;
		double d1=0.0, d2, d3, d4;
		VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
		VS vs, vs1, vs2, vs3, vs4;
		VP vp, vp1,vp2;
		char ch, ch1, ch2[1001];
		string str, str1, str2, str3, str4, str5;
		pair<LL, LL> pa;
		list<LL> li, li1;
		map<LL, LL> mp, mp1;
		set<LL> st;
		map<LL ,LL> :: iterator imll;
		VLL :: iterator ivll;
		set<LL> :: iterator isll;
		VP :: iterator ivp;
 
		
		cin>>str>>str1;
		a = str.size()+str1.size();
		for(i=0; i<a; i++)
		{
			if(i==0)
			{
				cout<<str[0];
				str.erase(str.begin());
				con
			}
			if(i%2!=0)
			{
				cout<<str1[0];
				str1.erase(str1.begin());

			}
			else
			{
				cout<<str[0];
 				str.erase(str.begin());

			 }
		}
		cout<<endl;
	exit()
 
 
}


Measured memory_bytes: 3616
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		HashMap<String,Integer> hm = new HashMap<>();
		for(int i = 0; i < n; i++){
		String s = sc.nextLine();
		char[] chr = s.toCharArray();
		Arrays.sort(chr);
		String str = String.valueOf(chr);
		hm.put(str, 1 + hm.getOrDefault(str,0));
		}
		long count = 0;
		for(long cur : hm.values()){
			count += (cur * (cur - 1)/2);
		}
		System.out.println(count);
	}
		
		
	}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    ll a;
    long double b;
    cin >> a >> b;
    cout << (ll)(a * b) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

typedef long long ll;

int main() {
  int A, B;
  std::cin >> A >> B;
  int ans;
  if(A <= 5) ans = 0;
  else if(A <= 12) ans = B / 2;
  else ans = B;

  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import numpy as np
N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
    buf=list(map(int,input().split()))
    C.append(buf[0])
    A.append(buf[1:])

MinmalCost=1e30

MaxInter=2**N-1
LenOfBin=len(bin(MaxInter)[2:])
for i in range(MaxInter+1):
    binary=bin(i)[2:].rjust(LenOfBin,"0")
    Cost=0
    Learning=np.zeros(M,)
    for j,Switch in enumerate(binary):
        if Switch=="1":
            Cost+=C[j]
            Learning+=A[j]
    if np.all(Learning>=X) and Cost<MinmalCost:
        MinmalCost=Cost
if MinmalCost==1e30:
    print(-1)
else:
    print(MinmalCost)
    

Measured memory_bytes: 27140
#include<stdio.h>
#include<string.h>
int main() {
    int n;
    long long k;scanf("%d %llu",&n,&k);
    int a[n];for(int i=0;i<n;i++)scanf("%d",&a[i]);
    
    int next=0;
    int cnt=0;
    int table[600000]={};
    static int proc[600000]={};
    proc[0]=1;
    table[0]++;
    int flg;
    for(int i=0;i<2*n;i++){
        int next = a[next] - 1;
        proc[i+1]=next+1;
        if(table[next]>=1){flg=next+1;break;}
        
        table[next]++;
    }
    fprintf(stderr,"flg:%d\n", flg);
    int start=-1,end=-1;
    for(int i=0;i<2*n;i++){
        fprintf(stderr,"%d ",proc[i]);
        if(proc[i]==flg){
            if(start==-1)start=i;
            else if(end==-1)end=i;
        }
        if(end!=-1)break;
    }
    fprintf(stderr,"\n");
    int range = end-start;
    fprintf(stderr, "%d %d %d\n",start,end,range);

    int c=0;
    if(flg==1){
        c=0;
    }else{
        for(int i=1;i<n;i++){
            if(proc[i]==flg){
                c=i;
                break;
            }
        }
    }
    fprintf(stderr,":%d\n",c);
    fprintf(stderr,"::%lld\n",(k-c));
    if(k-c<0)printf("%d\n",proc[k]);
    else printf("%d\n",proc[c+(k-c)%range]);
}

Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
  int N;
  cin >> N;
  int ans = 0;
  int sum = 0;
  vector<int> list;
  for(int t=0;t<N;t++)
  {
    int n;
    cin >> n;
    sum += n;
    list.push_back(sum);
  }
  
  int part = 999999;
  for(int x = 0; x < N; x++)
  {
     int tmp = abs(list[x]  - (sum - list[x]));
    if(tmp < part)
    {
      part = tmp;
    }
    else{
      break;
    }
  }
  
  cout << part << endl;
  return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll LINF=(1LL<<60);
const int INF=1<<29;
const int MOD=1e9+7;

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

vi num;

void make_num(int n){
    int i=1, val;
    while(1){
        val=i*(i+1)*(i+2)/6;
        if(val > n) break;
        num.push_back(val);
        i++;
    }
}

int main(){
    int n;
    make_num(1000000);
    vi dp1(1000001, INF);
    dp1[0]=0;
    for(int i=1; i<=1000000; i++){
        for(auto &m : num){
            if(m <= i){
                chmin(dp1[i], dp1[i-m]+1);
            }
        }
    }
    vi dp2(1000001, INF);
    dp2[0]=0;
    for(int i=1; i<=1000000; i++){
        for(auto &m : num){
            if(m <= i && m%2 == 1){
                chmin(dp2[i], dp2[i-m]+1);
            }
        }
    }
    while(cin >> n){
        if(n == 0) break;
        printf("%d %d\n", dp1[n], dp2[n]);
    }
    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int h,w;
  cin >> h >> w;
  int a,b;
  cin >> a >> b;
  cout << (h-a)*(w-b) << endl;
  return 0;
}


Measured memory_bytes: 256
S = list(input())

for i in range(len(S)-2):
  tmp = int(S[i]+S[i+1]+S[i+2])
  if(i == 0):
    min = abs(753 - tmp)
  else:
    if(min > abs(753 - tmp) ):
      min = abs(753 - tmp)
      
print(min)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
    int n, ans, ans2;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if(a.size() == 2){
        ans = a[1];
        ans2 = a[0];
    }else{
        ans = a[n - 1];
        int t = ans / 2;
        auto itr = lower_bound(a.begin(), a.end() - 1, t);
        if(abs(t - *itr) > abs(t - *(itr - 1))) ans2 = *(itr - 1);
        else ans2 = *itr;
    }
    cout << ans << " " << ans2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int h,w;
  while(cin >> h>>w,h||w) {
    char ba[h][w];
    int ax,ay, bx,by;
    REP(i,h) {
      REP(j,w) {
        cin >> ba[i][j];
        if (ba[i][j]=='A') {
          ax = j;
          ay = i;
        }else if (ba[i][j]=='B') {
          bx = j;
          by = i;
        }
      }
    }
    
    const int dx[] = {0,-1,1,0};
    const int dy[] = {1,0,0,-1};

    int dis[h][w];
    REP(i,h) REP(j,w) dis[i][j] = INF;
    typedef pair<int,int> pii;
    queue<pair<int,pii> > Q;
    Q.push(make_pair(0, pii(ax,ay)));
    int maxd = 0;
    while(!Q.empty()) {
      int x = Q.front().second.first;
      int y = Q.front().second.second;
      int d = Q.front().first;
      Q.pop();

      if (dis[y][x] != INF) continue;
      dis[y][x] = d;
      maxd = max(maxd,d);
      REP(k,4) {
        int xx = x+dx[k];
        int yy = y+dy[k];

        if (xx<0||xx>=w||yy<0||yy>=h) continue;
        if (ba[yy][xx]=='#') continue;
        if (dis[yy][xx] != INF) continue;
        
        Q.push(make_pair(d+1, pii(xx,yy)));
      }
    }
    // REP(y,h) {
    //   REP(x,w) {
    //     if (dis[y][x] == INF) cout << -1 << " ";
    //     else
    //       printf("%2d ", dis[y][x]);
    //   }
    //   cout << endl;
    // }
    string s;
    cin >> s;
    int m = s.size();
    int memo[h][w][m];
    memset(memo,0,sizeof(memo));

    int cnt = 0;
    int res = INF;
    int ansx,ansy;
    while(1) {
//      printf("(%d,%d) ",bx,by);
      if (dis[by][bx] <= cnt) {
        if(cnt<res) {
          res = cnt;
          ansx = bx;
          ansy = by;
        }
      }
      if (cnt >= maxd) {
        if (memo[by][bx][cnt%m]) {
          break;
        }
        memo[by][bx][cnt%m] = 1;
      }


      if (s[cnt%m]-'0' != 5) {
        int dir = (s[cnt%m]-'0')/2-1;
        bx += dx[dir];
        by += dy[dir];
        if (bx<0||bx>=w||by<0||by>=h) {
          bx -= dx[dir];
          by -= dy[dir];
        }
      }
      
      cnt++;
    }

    if (res == INF) {
      cout << "impossible" << endl;
    } else
      printf("%d %d %d\n", res, ansy, ansx);
  }
}

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

#define MAX_1 37
#define MAX_2 2

main()
{
  int i, j, n, a, c, x;
  char b, d, mini;
  char card[MAX_1][MAX_2], cardX[MAX_1][MAX_2], cardS[MAX_1][MAX_2], str[3];  
  
  scanf("%d",&n);
  
  for(i=1; i<=n; i++){
    scanf("%s",str);
    card[i][0]=cardS[i][0]=cardX[i][0]=str[0];
    card[i][1]=cardS[i][1]=cardX[i][1]=atoi(&str[1]);
  }
  
  for(i=1; i<=n; i++){
    for(j=n; j>i; j--){
      if(cardX[j-1][1] > cardX[j][1]){
	a=cardX[j][0];
	b=cardX[j][1];
	cardX[j][0]=cardX[j-1][0];
	cardX[j][1]=cardX[j-1][1];
	cardX[j-1][0]=a;
	cardX[j-1][1]=b;
      }
    }
  }
  
  for(i=1; i<n; i++){
    mini=i;
    for(j=i; j<=n; j++){
      if(cardS[j][1] < cardS[mini][1]){
	mini=j;
      }
    }
    if(cardS[i][1] > cardS[mini][1]){
      c=cardS[i][0];
      d=cardS[i][1];
      cardS[i][0]=cardS[mini][0];
      cardS[i][1]=cardS[mini][1];
      cardS[mini][0]=c;
      cardS[mini][1]=d;
    }
  }
  
  x=1;
  
  for(i=1; i<n; i++){
    printf("%c%d ",cardX[i][0],cardX[i][1]);
    if(x==1 && i<0 && cardX[i-1][1]==cardX[i][1]){
      for(j=1; j<=n; j++){
	if(card[j][0]==cardX[i-1][0] && cardX[i-1][1]==card[j][1]){
	  break;
	}
	if(card[j][1]==cardX[i][1] && card[i][0]==cardX[j][0]){
	  x=0;
	  break;
	}
      }
    }
  }
  
  if(i==n){ 
    printf("%c%d",cardX[i][0],cardX[i][1]);
  }
  
  printf("\n");
  
  if(x==1){
    printf("Stable\n");
  }
  
  else printf("Not stable\n");
  
  x=1;
  
  for(i=1; i<n; i++){
    printf("%c%d ",cardS[i][0],cardS[i][1]);
    if(x==1 && i>0 && cardS[i-1][1]==cardS[i][1]){
      for(j=1; j<=n; j++){
	if(card[j][0]==cardS[i-1][0] && cardS[i-1][1]==card[j][1]){
	  break;
	}
	if(card[j][1]==cardS[i][1] && cardS[i][0]==card[j][0]){
	  x=0;
	  break;
	}
      }
    }
  }
  if(i==n){ 
    printf("%c%d",cardS[i][0],cardS[i][1]);
  }
  
  printf("\n");
  
  if(x==1){
    printf("Stable\n");
  }
  
  else printf("Not stable\n");
  
  return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p;
string s, t;
ld w;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	ll mn = INF,mx = 0;
	for(ll i=0;i<n;i++) {
		cin>>x;
		mn = min(x,mn);
		mx = max(x,mx);
	}
	cout<<mx-mn;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i=0; i<(int)c; i++)
int main() {
	vector<string>a;
	string ans,s,c;

	cin >>s;

	for(int i=0;i<s.length();i++){
		c=s.substr(i,1);
		if (c!="B"){
			ans+=c;
		}
		else{
			if (!ans.empty()){
				ans.erase(ans.length()-1);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    long long n, i, a, b, min = 1000000, max = -1000000, sum, tem, t;
    scanf("%lld", &n);
    sum = 0;
    for (i = 0; i < n; i++)
    {
        scanf("%lld", &a);
        sum = sum + a;
        if (a > max)
        {
            max = a;
        }
        if (a < min)
        {
            min = a;
        }
    }
    printf("%lld %lld %lld\n", min, max, sum);

    return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>
int main(){
  int a,b,c,flag;
  scanf("%d%d%d",&a,&b,&c);
  for(int i=b;b<=c;b++){
    if(b%a==0)
      flag++;
  }
  if (flag)
    printf("OK");
  else printf("NG");
  return 0;
}

Measured memory_bytes: 1728
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

int main() {
  //
  int n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll cnt = 0;
  rep(i, n) {
    int tmp = a[i];
    while ((tmp & 1) == 0) {
      tmp = tmp >> 1;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

ll N;
vector<ll> edges[300000];

// 頂点 cur から最も遠い点に対して {vへの距離、v} を調べる
PLL f(ll cur, ll par = -1, ll d = 0) {
  if (edges[cur].size() == 1 && edges[cur][0] == par)
    return {d, cur};
  PLL res(-1, -1);
  for (auto nxt : edges[cur]) {
    if (nxt == par) continue;
    chmax(res, f(nxt, cur, d+1));
  }
  return res;
}

signed main() {
  cin >> N;
  rep(i, N-1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  if (N == 1) {
    cout << "First" << endl;
    return 0;
  }
  ll u, r, _, __;
  tie (_, u) = f(0);
  tie (r, __) = f(u);
  cout << (r % 3 != 1 ? "First" : "Second") << endl;
  return 0;
}


Measured memory_bytes: 32256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
using namespace std;

double thirdRoot(double x, double q){
	double next_x;
	if (fabs(x*x*x - q) < 0.00001*q) {
		return x;
	}else {
		next_x = x - ((x*x*x-q) / (3.0*x*x));
		return thirdRoot(next_x, q);
	}
}

int main(){
	double n;

	while (cin >> n) {
		if (n == -1) {
			break;
		}
		cout << fixed << setprecision(6)<< thirdRoot(n/2.0, n) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long n,a,b,ans;
  cin >> n >> a >> b;
  if(a>b||(n==1&&a!=b)) {
    cout << 0 << endl;
  }
  else {
    cout << (b-a)*(n-2)+1 << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
const int N = 100009;
LL g[N], cnt, v, vn;
LL n;
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n;
	for(LL i = 1; i <= n; i++)
		cin >> g[i], cnt += g[i];
	vn = n * (n + 1) / 2;
	if(cnt % vn)
	{
		puts("NO");
		return 0;
	}
	LL p = g[1];
	for(LL i = 1; i < n; i++)
		g[i] = g[i+1] - g[i];
	g[n] = p - g[n];
	LL d = cnt / vn;
	for(LL i = 1; i <= n; i++)
	{
		g[i] -= d;
		if(g[i] % n || g[i] > 0)
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll T[2], A[2], B[2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i,2) cin >> T[i];
    rep(i,2) cin >> A[i];
    rep(i,2) cin >> B[i];
    pl a = pl(A[0]*T[0], A[1]*T[1]), b = pl(B[0]*T[0], B[1]*T[1]);
    if (a.first > b.first) swap(a, b);
    if (a.first+a.second == b.first+b.second) {
        cout << "infinity" << endl;
        return 0;
    }
    if (a.second < b.second) {
        cout << 0 << endl;
        return 0;
    }
    if (a.first+a.second > b.first+b.second) {
        ll d = a.first+a.second-b.first-b.second;
        ll ans = 1+2*((b.first-a.first)/d);
        if ((b.first-a.first)%d == 0) ans--;
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
def runlength(S):
    cnt = 1
    d = []
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            d.append(cnt)
            cnt = 1
    else:
        d.append(cnt)

    return d



def main():
    N = int(input())
    S = input()
    d = runlength(S)
    print(len(d))

  

if __name__ == "__main__":
    main()

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

#define endl "\n"
#define MOD 1000000007

#define forn(i, a, n) for (int i = a; i < n; i++)
#define forns(i, a, n, step) for (int i = a; i < n; i += step)
#define fornr(i, a, n) for (int i = n; i > a; --i)
#define fornrs(i, a, n, step) for (int i = n; i > a; i -= step)
#define forlimits(i, l, r) for (int i = l; i <= r; i++)

// Choose auto x when you want to work with copies.
#define foritc(i, v) for (auto i = v)
// Choose auto &x when you want to work with original items and may modify them.
#define foritm(i, v) for (auto &i = v)
// Choose auto const &x when you want to work with original items and will not modify them.
#define forit(i, v) for (auto const &i = v)

#define all(v) (v).begin(), (v).end()

#define fill(arr, n, k) \
    forn(i, 0, n) { arr[i] = k; }

#define print(arr, n)                        \
    forn(i, 0, n) { cout << arr[i] << " "; } \
    cout << endl;

#define intersection(a, b, out) set_intersection(all(a), all(b), out.begin())

#define sum_n(n) ((n) * (n + 1) / 2)
typedef long long ll;
void solve();

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
    // return 0;
}

void solve() {
    ll n, a, b, c;
    cin >> n;
    ll ans[n][3];
    forn(i, 0, n) {
        cin >> a >> b >> c;
        if (i == 0) {
            ans[i][0] = a;
            ans[i][1] = b;
            ans[i][2] = c;
        } else {
            ans[i][0] = a + max(ans[i - 1][1], ans[i - 1][2]);
            ans[i][1] = b + max(ans[i - 1][0], ans[i - 1][2]);
            ans[i][2] = c + max(ans[i - 1][0], ans[i - 1][1]);
        }
    }

    cout << max(ans[n - 1][0], (ll)max(ans[n - 1][1], ans[n - 1][2])) << endl;
}

Measured memory_bytes: 5968
N,A,B,C=map(int,input().split())
L=[int(input()) for _ in range(N)]


ans=[]

def getmagic(a,b,c):
    return abs(sum(a)-A)+abs(sum(b)-B)+abs(sum(c)-C)+(len(a)-1)*10+(len(b)-1)*10+(len(c)-1)*10

def dfs(a,b,c,depth):
    if depth==N:
        if len(a)>=1 and len(b)>=1 and len(c)>=1:
            ans.append(getmagic(a,b,c))
    else:
        tmp=a[:]
        tmp.append(L[depth])
        dfs(tmp, b, c, depth + 1)
        tmp=b[:]
        tmp.append(L[depth])
        dfs(a, tmp, c, depth + 1)
        tmp=c[:]
        tmp.append(L[depth])
        dfs(a, b, tmp, depth + 1)
        dfs(a, b, c, depth + 1)


dfs([],[],[],0)

print(min(ans))

Measured memory_bytes: 4956
init = int(input())

m = 1000000


def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


ls = [init]
s = init
flag = 1
while 1:
    ls.append(f(s))
    s = f(s)
    # print(s)
    if s == 1 and flag == 1:
        flag = 0
    elif s == 1 and flag == 0:
        break

if init == 2:
    print(4)
elif init == 1:
    print(4)
else:
    # print(ls)
    print(len(ls)-2)


Measured memory_bytes: 38256
// glory be to the sky
#include<bits/stdc++.h> 


using namespace std;
	
typedef long long ll; 



int main(){

	ios::sync_with_stdio(false);
	cin.tie(0);

	int a, b ,c;
	cin >> a >> b  >> c;
	if (c >= a && c <= b) cout << "Yes";
	else cout << "No";
	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
const int MOD=1e9+7;
using pii=std::pair<int,int>;
using namespace std;

const int maxh = 10, maxw = 1005;

int h, w, k, grid[maxh][maxw], dp[1 << maxh][maxw] = {0};
string s;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++)
    {
        cin >> s;
        for(int j = 0; j < w; j++)
            grid[i][j] = s[j] - '0';
    }
    int cnt[1 << maxh][h] = {0}, bad[1 << maxh] = {0};
    for(int i = 0; i < w; i++)
        for(int j = 0; j < (1 << (h - 1)); j++)
            if(!bad[j])
            {
                int curcnt = 0;
                for(int l = 0; l < h; l++)
                {
                    if(grid[l][i])
                        curcnt++;
                    if(l == h - 1 || (j & (1 << l)))
                    {
                        if(curcnt > k)
                            bad[j] = 1;
                        cnt[j][l] += curcnt;
                        if(cnt[j][l] > k)
                            dp[j][i] = 1;
                        curcnt = 0;
                    }
                }
                curcnt = 0;
                if(dp[j][i])
                    for(int l = 0; l < h; l++)
                    {
                        if(grid[l][i])
                            curcnt++;
                        if(l == h - 1 || (j & (1 << l)))
                        {
                            cnt[j][l] = curcnt;
                            curcnt = 0;
                        }
                    }
                if(i > 0)
                    dp[j][i] += dp[j][i - 1];
            }
    int ans = (int) 2e9;
    for(int j = 0; j < (1 << (h - 1)); j++)
        if(!bad[j])
            ans = min(ans, dp[j][w - 1] + __builtin_popcount(j));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4480
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let L: Vec<usize> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let R = {
        let mut R = L.clone();
        R.sort();
        R
    };
    let ans = (0..N).map(|i| R[2 * i]).sum::<usize>();

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b;
	c=a*b;
	if(c%2==0)
	{
		cout<<"Even";
	}
	else
	{
		cout<<"Odd";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}
    int32_t main()
    {
        std::ios::sync_with_stdio(false);
        int n;
        cin>>n;
        int res;
        for(int i=1;;i++)
        {

            if((n*i)%360==0)
            {
                res=i;
                break;
            }
        }
        cout<<res<<endl;
        return 0;
    }


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
    int n; cin >> n;
    map<string, int> m;
    int mx = -1;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        m[s] += 1;
    }
    for(auto it = m.begin(); it != m.end(); it++){
        if(it->second > mx) mx = it->second;
    }

    for(auto it = m.begin(); it != m.end(); it++){
        if(it->second == mx) cout << it->first<<endl;
    }

    return 0;
}

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

using ll =  long long;
using pint =  pair<int,int>;

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}

signed main(void){
  int n,y;cin>>n>>y;
  rep(i,n+1){
    rep(j,n+1-i){
      if(y==i*10000+j*5000+(n-i-j)*1000){
        printf("%d %d %d\n",i, j, n-i-j);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 998244353;

ll lpow(int p, int q) {
	ll ans = 1;
	ll pp = p;
	while (q) {
		if (q % 2) {
			ans *= pp;
			ans %= MOD;
		}
		q /= 2;
		pp *= pp;
		pp %= MOD;
	}
	return ans;
}
V<ll> fac, invfac;
void precom(int n) {
	fac.resize(0);invfac.resize(0);
	rep(i, n + 1) {
		if (i == 0)fac.push_back(1);
		else fac.push_back((fac[i - 1] * i) % MOD);
		invfac.push_back(lpow(fac[i], MOD - 2));
	}
	return;
}
ll com(int n, int r) {
	if (n < r || n < 0 || r < 0)return 0;
	int k = n - r;
	ll ans = fac[n];
	ans *= invfac[r];
	ans %= MOD;
	ans *= invfac[k];
	ans %= MOD;

	return ans;
}

int main() {

	int n, m, k;
	cin >> n >> m >> k;

	if (n == 1) {
		cout << m << endl;
		return 0;
	}

	precom(202000);

	ll ans = 0;

	rep(i, k + 1) {
		ll pt = m;
		pt *= lpow(m - 1, n - 1 - i);
		pt %= MOD;
		pt *= com(n - 1, i);
		pt %= MOD;
		ans += pt;
		ans %= MOD;
	}

	cout << ans << endl;

}

Measured memory_bytes: 6632
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
c = [0,2,5,5,4,5,6,3,7,6]

dp = [-1]*(N+1)
dp[0] = ''
for a in A:
    if c[a] <= N:
        dp[c[a]] = str(a)

for i in range(N+1):
    for a in A:
        if i-c[a]>=0 and dp[i-c[a]]!=-1:
            if dp[i]==-1 or len(dp[i]) <= len(dp[i-c[a]])+1:
                dp[i] = str(a)+dp[i-c[a]]

ans = sorted(dp[N])
ans = ans[::-1]
ans = ''.join(ans)
print(ans)

Measured memory_bytes: 134876
import java.util.Scanner;

public class Main {

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

			int num = sc.nextInt();

			int [] nums = new int[num];
			int sum =0;

			for(int i=0;i<nums.length;i++) {
				nums[i] = sc.nextInt();
			}


			for(int i=0;i<nums.length-1;i++) {
				for(int j=i+1;j<nums.length;j++) {
					sum += nums[i]*nums[j];
				}

			}

			System.out.println(sum);

	}


}




Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int INF=999999;
int ans;
int main(){
 long long a,b,c,k[100005],l[10005];
cin>>a>>b>>c;
for(int i=0;i<a;++i){
  cin>>k[i]>>l[i];
if(k[i]>=b&&l[i]>=c)++ans;
}
cout<<ans<<endl;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};

int dist[1005][1005];
bool visited[1005][1005];
string grid[1005];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    for (int i=0; i<h; i++)
        cin >> grid[i];

    auto ok = [&] (int r, int c) {
        return 0 <= r && r < h && 0 <= c && c < w && grid[r][c] == '.';
    };

    memset(dist, 127, sizeof(dist));
    int INF = dist[0][0];
    deque<pair<int, int>> dq;
    dist[ch][cw] = 0;
    dq.push_back({ch, cw});
    while (!dq.empty()) {
        int r = dq.front().first, c = dq.front().second;
        dq.pop_front();
        if (visited[r][c])
            continue;
        visited[r][c] = true;
        for (int i=0; i<4; i++) {
            int nr = r + dr[i], nc = c + dc[i];
            if (ok(nr, nc) && dist[r][c] < dist[nr][nc]) {
                dist[nr][nc] = dist[r][c];
                dq.push_front({nr, nc});
            }
        }
        for (int nr=r-2; nr<=r+2; nr++)
            for (int nc=c-2; nc<=c+2; nc++)
                if (ok(nr, nc) && dist[r][c] + 1 < dist[nr][nc]) {
                    dist[nr][nc] = dist[r][c] + 1;
                    dq.push_back({nr, nc});
                }
    }

    cout << (dist[dh][dw] >= INF ? -1 : dist[dh][dw]) << "\n";

    return 0;
}


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

using ll = long long;

void solve(long long N, long long X, long long M){
    vector<ll> ans;
    ll A = X;
    set<ll> se;
    map<ll, int> mp;
    while(1){
        if(se.find(A) != se.end() || N == ans.size()){
            break;
        }
       // cout<<A<<endl;
        mp[A] = ans.size();
        ans.push_back(A);
        se.insert(A);
        A = (A * A) % M;
    }
    if(ans.size() == N){
        cout<<accumulate(ans.begin(), ans.end(), 0LL)<<endl;
        return;
    }
    ll s = mp[A];

    ll qqq = 0;
    for(int i = 0;i < min(s, N);i++){
        qqq += ans[i];
    }
    N -= min(s, N);
    ll mid = 0;
    int cnt = 0;
    for(int i = s;i < ans.size();i++){
        mid += ans[i];
        cnt++;
    }
    qqq += (N / cnt) * mid;
    for(int i = 0;i < N%(cnt);i++){
        qqq += ans[i + s];
    }
    cout<<qqq<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long M;
    scanf("%lld",&M);
    solve(N, X, M);
    return 0;
}


Measured memory_bytes: 9132
n = gets.to_i

edges = []
g = Array.new(n+1){ [] }
(n-1).times do |i|
  a, b = gets.split.map(&:to_i)
  a, b = b, a if a > b # 辺は頂点 i < j の形で入れる。
  g[a] << b # 隣接リストに
  g[b] << a # 反対向きにも隣接リストに.無向グラフなので
  # gに隣接頂点だけでなく、何番目の辺の情報をいれることもある。
  edges << [a,b] # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n+1){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [1] # 頂点1から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。なければnilを返す
  k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    next if used[w] #trueで、探索済みの頂点なら見ない。
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

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

#define rep(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 reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0) return b;
    else return gcd(b, a%b);
}

int main(void){
    ll K;
    cin>>K;
    ll ans=0;
    rep1(i, K) rep1(j, K) rep1(k, K){
        ans+=gcd(gcd(i, j), k);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
N, Q = map(int, input().split())
S = input()
t=[0]*(N+1) 
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0) 
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])


Measured memory_bytes: 9156
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{s:String};
    println!("{}", if s.contains("9") {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#define FIN freopen("inputs.txt", "r", stdin)
using namespace std;
typedef pair<int, int> P;
int H, n;
int main(){
//FIN;
    cin>>H>>n;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        int tmp ; cin>>tmp;
        sum += tmp;
    }
    if(sum >= H) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int eatNum = scan.nextInt();
		int eatFee = eatNum * 800;
		int waribiki = (eatNum / 15) * 200;
		System.out.println(eatFee - waribiki);
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                    \
  for (int i = 0; i < (int)(n); i++) \
    ;
 
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
 
int main() {
  long n;
  cin >> n;
 
  vector<long> a(n);
  for (long &x : a) {
    cin >> x;
  }
 
  bool plus;
  long sum = 0;
  long count_plus = 0;
 
  plus = false;
 
  for (long i = 0; i < n; i++) {
    plus = !plus;
    sum += a.at(i);
    if (plus) {
      if (sum > 0) {
        continue;
      } else {
        count_plus += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum < 0) {
        continue;
      } else {
        count_plus += 1 + sum;
        sum = -1;
      }
    }
  }
  long count_minus = 0;
  plus = true;
  sum = 0;
 
  for (long i = 0; i < n; i++) {
    plus = !plus;
    sum += a.at(i);
    if (plus) {
      if (sum > 0) {
        continue;
      } else {
        count_minus += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum < 0) {
        continue;
      } else {
        count_minus += 1 + sum;
        sum = -1;
      }
    }
  }
  cout << min(count_plus, count_minus) << endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;

int cut(int a, int b) {//切り捨て
    return (a - a % b) / b;
}
int up(int a, int b) {
    return (a + a % b) / b;
}


int main() {
    ll x;
    cin >> x;
    ll h1 = x / 500;
    ll h2 = (x - h1 * 500)/5;
    cout << h1*1000 + h2*5 << endl;
    return 0;
}

Measured memory_bytes: 384
def solve():
    N = int(input())
    A = [int(x) for x in input().split()]
    right = 0
    sum = 0
    res = 0
    for left in range(N):
        while right < N and (right <= left or sum^A[right] == sum + A[right]):
            sum += A[right]
            right += 1
        res += (right - left)
        if right == left: right += 1
        else:
            sum -= A[left]
    return res

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 23560
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, D;
    cin >> N >> D;
    int X[10][10];
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> X[i][j];
        }
    }
    
    int ans = 0;
    double d;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            d = 0;
            for(int k=0;k<D;k++){
                d += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
            }
            d = sqrt(d);
            if(ceil(d) == floor(d))
                ans++;
        }
    }
        
    cout << ans << endl;

}

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

int main() {

	//int a, b, c, d;
	//std::cin >> a >> b >> c >> d;

	std::string s;
	std::cin >> s;

	int a = s[0] - '0';
	int b = s[1] - '0';
	int c = s[2] - '0';
	int d = s[3] - '0';

	int flag = 0;
	int op1 = -1;
	int op2 = -1;
	int op3 = -1;

	for (int i = 0; i < 2; i++) {
		op1 *= -1;
		for (int j = 0; j < 2; j++) {
			op2 *= -1;
			for (int k = 0; k < 2; k++) {
				op3 *= -1;
				int res = a + b * op1 + c * op2 + d * op3;
				if (res == 7) {
					flag = 1;
					break;
				}
			}
			if (flag)break;
		}
		if (flag)break;
	}
	std::cout << a << (op1 == 1 ? '+' : '-') << b << (op2 == 1 ? '+' : '-') << c << (op3 == 1 ? '+' : '-') << d << "=7" << std::endl;

}

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

using namespace std;

int main(int argc, const char *argv[]) {
  using ll = long long;
  int x, y, z, k;
  cin >> x >> y >> z >> k;

  vector<ll> va(x), vb(y), vc(z);
  for (auto &a : va) {
    cin >> a;
  }

  for (auto &b : vb) {
    cin >> b;
  }

  for (auto &c : vc) {
    cin >> c;
  }

  vector<ll> sum_bc;
  for (auto &b : vb) {
    for (auto &c : vc) {
      sum_bc.push_back(b + c);
    }
  }

  sort(sum_bc.begin(), sum_bc.end(), greater<ll>());
  sort(va.begin(), va.end(), greater<ll>());
  vector<ll> ans;
  for (int i = 0; i < min(static_cast<int>(sum_bc.size()), k); ++i) {
    for (int j = 0; j < min(static_cast<int>(va.size()), k); ++j) {
      ans.push_back(sum_bc[i] + va[j]);
    }
  }

  sort(ans.begin(), ans.end(), greater<ll>());
  for (int i = 0; i < k; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

Measured memory_bytes: 43240
import heapq as hq

n=int(input())
da=[[] for i in range(n)]
for i in range(n):
    li=list(map(int,input().split()))
    for i in range(li[1]):
        da[li[0]].append([li[i*2+3],li[i*2+2]])
q=[]
ans=[-1 for i in range(n)]
ans[0]=0
for i in da[0]:
    hq.heappush(q,i)
while len(q)!=0:
    no=hq.heappop(q)
    if ans[no[1]] < 0:
        ans[no[1]]=no[0]
        for i in da[no[1]]:
            hq.heappush(q,[no[0]+i[0],i[1]])
for i in range(n):
    print("{} {}".format(i,ans[i]))





Measured memory_bytes: 133032