akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    double pi = 3.14159265358979323846;
    double a, b, h, m; std::cin >> a >> b >> h >> m;
    double u = a*std::cos((60 * h + m) / (60 * 12) * 2 * pi);
    double v = a*std::sin((60 * h + m) / (60 * 12) * 2 * pi);
    double x = b*std::cos(m / 60 * 2 * pi);
    double y = b*std::sin(m / 60 * 2 * pi);
    printf("%.12f\n", std::hypot(u - x, v - y));
    return 0;
}

Measured memory_bytes: 4164
#include <iostream>
#include <vector>
#include <set>

#include <algorithm>
#include<iostream>

using namespace std;


int main(){
          
    int l, n=0, a[210];
    while(cin>>l){
        a[n] = l;
       
        n++;
    }
         
     int i;
  
   
   int k;
   int sum = 0;
  int max = 0;
    for(i = 1; i < a[0]+1; i++){
      
      
        sum = sum + a[i];
      
        int temp = sum;
      
        for(k = a[0]+i; k < a[0]*2+1; k++){
          
           sum = sum + a[k];
          
           if (max < sum){
            
           
              max = sum;
             
            
            }
          
          
        }
      
     
      sum = temp;
      
    }
          
   cout << max;
  
     return 0;     
          
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] l = new int[n];
    for (int i = 0;i<n ;i++ ) {
      l[i] = sc.nextInt();
    }
    Arrays.sort(l);
    int count = 0;
    for(int i = n-1;i>1;i--){
      for(int j = i-1;j>0;j--){
        int a = BinarySearch(l,l[i]-l[j]+1);
        if(a < j){
          count += j - a;
        }
      }
    }
    System.out.println(count);
  }

  public static int BinarySearch(int a[] , int target){
    int left = -1;
    int right = a.length;
    while(right - left > 1){
      int mid = left + (right - left) / 2;
      if(a[mid] >= target){
        right = mid;
      }else{
        left = mid;
      }
    }
    return right;
  }

}


Measured memory_bytes: 39876
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX_H = 80; 
const int MAX_W = 80;
const int MAX_D = (MAX_H + MAX_W) * 80;

vector<vector<int> > diff(MAX_H, vector<int>(MAX_W));
vector<vector<vector<bool> > > searched(MAX_H, vector<vector<bool> >(MAX_W, vector<bool>(MAX_D + 1, false)));
vector<vector<vector<bool> > > memo(MAX_H, vector<vector<bool> >(MAX_W, vector<bool>(MAX_D + 1, false)));

bool dp(int i, int j, int k) {
    if (!searched[i][j][k]) {
        if (i == 0 && j == 0) {
            if (k == diff[i][j]) {
                memo[i][j][k] = 1;
            } else {
                memo[i][j][k] = 0;
            }
        } else if (i == 0) {
            if (dp(i, j - 1, abs(k - diff[i][j]))) memo[i][j][k] = true;
            if (k + diff[i][j] <= MAX_D) {
                if (dp(i, j - 1, k + diff[i][j])) memo[i][j][k] = true;
            }
        } else if (j == 0) {
            if (dp(i - 1, j, abs(k - diff[i][j]))) memo[i][j][k] = true;
            if (k + diff[i][j] <= MAX_D) {
                if (dp(i - 1, j, k + diff[i][j])) memo[i][j][k] = true;
            }

        } else {
            if (dp(i - 1, j, abs(k - diff[i][j])) || dp(i, j - 1, abs(k - diff[i][j]))) memo[i][j][k] = true; 
            if (k + diff[i][j] <= MAX_D) {
                if (dp(i - 1, j, k + diff[i][j]) || dp(i, j - 1, k + diff[i][j])) memo[i][j][k] = true;
            }
        }
        searched[i][j][k] = true;
    }
    return memo[i][j][k];
}

int main() {
    int H, W; cin >> H >> W;
    vector<vector<int> > As(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> As[i][j];
        }
    }
    vector<vector<int> > Bs(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> Bs[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            diff[i][j] = abs(As[i][j] - Bs[i][j]);
        }
    }
    for (int i = 0; i < MAX_D; i++) {
        if (dp(H-1, W-1, i)) {
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 21120
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int h;
    int a;
    int ans=0;
    cin >> h >> a;
    while(h>0){
        h-=a;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int r, d, x;
	cin >> r >> d >> x;
	vector <int> v(12);
	v[0] = x;
	for (int i = 0; i < 11; ++i){
		v[i+1] = r*v[i]-d; 		
	} 
	v.erase(v.begin());
	v.erase(v.end() - 1);	
	for (auto x : v){
		cout << x << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
bridge = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    bridge[a - 1].append(b - 1)
    bridge[b - 1].append(a - 1)
queue = deque([0])
ans = [[] for i in range(n)]
ans[0].append('god')
while queue:
    now = queue.popleft()
    for factor in bridge[now]:
        if not (ans[factor]):
            ans[factor].append(now)
            queue.append(factor)
print('Yes')
for i in range(1, len(ans)):
    print(ans[i][0]+1)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

class UnionFindTree{
  public:
    vector<ll> rank,p,count;

    UnionFindTree() {}

    UnionFindTree(ll size){
      rank.assign(size, 0);
      p.assign(size, 0);
      count.assign(size,1);
      REP(i,size)makeSet(i);
    }

    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }

    bool same(int x, int y){
      return findSet(x) == findSet(y);
    }

    void unite(int x, int y){
      if(findSet(x) == findSet(y))return;

      x = findSet(x);
      y = findSet(y);
      
      if(rank[x] > rank[y]){
        p[y] = x;
      }else{
        p[x] = y;
        if(rank[x] == rank[y]){
          rank[y]++;
        }
      }

      ll tmp = count[x] + count[y];
      count[x] = tmp;
      count[y] = tmp;
    }

    int findSet(int x){
      if(x != p[x]){
        p[x] = findSet(p[x]);
      }
      return p[x];
    }

    ll getCount(int x){
      return count[findSet(x)];
    }

    void print(){
      REP(i,p.size()){
        cout << p[i] << " ";
      }
      cout << endl;
      REP(i,p.size()){
        cout << rank[i] << " ";
      }
      cout << endl;
    }

};



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

  VI a(m),b(m);
  REP(i,m){
    cin>>a[i];
    cin>>b[i];
    a[i]--; b[i]--;
  }

  UnionFindTree tree(n);
  vector<ll> ans;
  ll now = n * (n-1) / 2;
  for(int i = m-1; i >= 0; i--){
    ans.emplace_back(now);
    if(tree.same(a[i], b[i]) == false){
      now -= tree.getCount(a[i]) * tree.getCount(b[i]);
      tree.unite(a[i], b[i]);
    }
  }
  for(int i = m-1; i >= 0; i--){
    cout << ans[i] << endl;
  }
}



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

int gcd(int x,int y){
    if (y==0) return x;
    return gcd(y,x%y);
}

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int d=gcd(a,b);
  if(c%d==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
# 078-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
h,w=IL()
c=[IL() for i in range(10)]
a=[IL() for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
    
ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:
            continue
        ans+=c[a[i][j]][1]
print(ans)

Measured memory_bytes: 3444
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var k int
	fmt.Scanf("%d", &k)

	sum := big.NewInt(0)
	for x := 1; x <= k; x++ {
		bx := big.NewInt(int64(x))
		for y := 1; y <= k; y++ {
			by := big.NewInt(int64(y))
			t := big.NewInt(1)
			t.GCD(nil, nil, bx, by)
			for z := 1; z <= k; z++ {
				bz := big.NewInt(int64(z))
				s := big.NewInt(1)
				s.GCD(nil, nil, t, bz)
				sum.Add(sum, s)
			}
		}
	}

	fmt.Printf("%s\n", sum.String())
}


Measured memory_bytes: 6664
#include <bits/stdc++.h>
using namespace std;
// nichijou
#define REP(i,a,b) for (int i(a), _B(b); i < _B; ++i)
#define RP(i,n) REP(i,0,n)
#define PER(i,a,b) for(int i((a)-1), _B(b); i >= _B; --i)
#define PR(i,n) PER(i,n,0)
#define REP1(i,a,b) REP(i,a,(b)+1)
#define RP1(i,n) REP1(i,1,n)
#define PER1(i,a,b) PER(i,(a)+1,b)
#define PR1(i,n) PER1(i,n,1)
#define DO(n) REP(__i,0,n)
template<typename T>
void cmax(T & a, T b) {a = max(a, b);}
template<typename T>
void cmin(T & a, T b) {a = min(a, b);}

// data type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second

// STL container
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define CLR(a) a.clear()
#define BK(a) (a.back())
#define FT(a) (a.front())
#define DB(a) a.pop_back()
#define DF(a) a.pop_front()
#define PB push_back
#define EB emplace_back

/* I gave you my heart and then you turned around. */
void _BG(const char * s) {}
template<typename T, typename ... TT>
void _BG(const char * s,T a, TT...b)
{
	for (int c = 0; *s && (c || *s != ','); ++s) {
		cerr<<*s;
		switch (*s) {
		case '(':
		case '[':
		case '{':
			++c;
			break;
		case ')':
		case ']':
		case '}':
			--c;
			break;
		}
	}
	cerr<<" = "<<a;
	if (*s) {
		cerr<<", ";
		_BG(++s,b...);
	} else
		cerr<<endl;
}
#define BG(...) do { \
	cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
	_BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)

/* Reading input is now 20% cooler! */
bool RD(void) {return true;}
bool RD(char & a) {return scanf(" %c", &a) == 1;}
bool RD(char * a) {return scanf("%s", a) == 1;}
bool RD(double & a) {return scanf("%lf", &a) == 1;}
bool RD(int & a) {return scanf("%d", &a) == 1;}
bool RD(ll & a) {return scanf("%lld", &a) == 1;}

template<typename T, typename ... TT>
bool RD(T & a, TT & ...  b) {return RD(a) && RD(b...);}

/* Do princesses dream of magic sheep? */
#define RI(a) int a; RD(a)
#define RII(a,b) RI(a); RI(b)
#define RIII(a,b,c) RI(a); RII(b,c)
#define RIIII(a,b,c,d) RI(a); RIII(b,c,d)

/* For it's time for you to fulfill your output. */
void PT(const char a) {putchar(a);}
void PT(const char * a) {fputs(a, stdout);}
void PT(char * a) {fputs(a, stdout);}
void PT(const double a) {printf("%.16f", a);}
void PT(const int a) {printf("%d", a);}
void PT(const ll a) {printf("%lld", a);}

/* The line will last forever! */
template<char sep = ' ',char end = '\n'>
void PL(void) {if (end) PT(end);}
template<char sep = ' ',char end = '\n',typename T, typename ... TT>
void PL(const T a, const TT ...  b) {PT(a); if (sizeof...(b) && sep) PT(sep); PL<sep,end>(b...);}

/* Good Luck && Have Fun ! */
int main()
{
	RI(n);
	int b,c;
	b=c=0;
	DO(n) {
		RI(x);
		if (x%4 == 0)
			++c;
		else if (x%2 == 0)
			++b;
	}
	int a=n-b-c;
	if (c >= a || (c == a - 1 && c + a == n))
		PL("Yes");
	else
		PL("No");
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>
#include<list>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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




const int INF = 1e9+7;


/******************************************************************************************/

int L[500005];
int R[500005];
int cnt = 0;

void merge(vector<int>& a, int n, int left, int mid, int right) {

	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++)
	{
		L[i] = a[left + i];
	}
	for (int i = 0; i < n2; i++)
	{
		R[i] = a[mid + i];
	}
	L[n1] = R[n2] = INF;

	int i = 0, j = 0;
	for (int k = left; k < right; k++)
	{
		cnt++;
		if (L[i] <= R[j]) {
			a[k] = L[i++];
		}
		else
		{
			a[k] = R[j++];
		}
	}
}



void mergeSort(vector<int>& a, int n, int left, int right) {

	if (left + 1 < right) {

		int mid = (right + left) / 2;
		mergeSort(a, n, left, mid);
		mergeSort(a, n, mid, right);
		merge(a, n, left, mid, right);

	}

}




int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n;
	cin >> n;

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

	for (int i = 0; i < n; i++)
	{
		if (i)cout << " ";
		cout << a[i];
	}
	cout << endl;
	

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 6672
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
h = ni()
w = ni()
print((n-h+1)*(n-w+1))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#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; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, m; cin >> n >> m;
    vpint sc(m); vpin(sc);

    repi(i, 0, (int)pow(10, n)) {
        if(to_string(i).length() != n) continue;
        bool p = true;
        rfor(pair, sc) {
            int k = n - pair.first, c = pair.second;
            int t = i;
            rep(i, k) t /=10;
            t %= 10;
            p &= c == t;
        }
        if(p) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


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

using namespace std;

const int MAXN = 1e5 + 10;

long long dp[MAXN];

int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif

    int n;
    cin >> n;
    int w;
    cin >> w;

    for(int i = 0; i < MAXN; ++i) dp[i] = 1e18;

    dp[0] = 0;
    for(int i = 1; i <= n; ++i) {
    	int a, b;
    	cin >> a >> b;

    	for(int j = MAXN - b - 1; j >= 0; --j) {
    		dp[j + b] = min(dp[j + b], dp[j] + a);
    	}
    }

    for(int i = MAXN - 1; i >= 0; --i) {
    	if(dp[i] <= w) {
    		cout << i;
    		return 0;
    	}
    }
}  

Measured memory_bytes: 1024
from operator import itemgetter
N,M = list(map(int, input().split()))

A = list(map(int, input().split()))
A.sort(reverse=True)

X = [[0]*2 for i in range(M)]

for i in range(M):
  x,y = list(map(int, input().split()))
  X[i] = [y,x]
  
X.sort(reverse=True,key=itemgetter(0))

idA, idX = 0,0
ans=0
#print(A)
#print(X)
while N > 0:
  if idX >= M or A[idA] >= X[idX][0]:
    ans += A[idA]
    idA += 1
    N -= 1
  else:
    cnt = min(N, X[idX][1])
    ans += X[idX][0] * cnt
    idX += 1
    N -= cnt
  #print(N,ans,idA,idX)
print(ans)

Measured memory_bytes: 25592
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
	
	int R[MAX], n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for(int i = 1; i < n; i++){
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 1940
k = int(input())

lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def generate_lunlun(p):
    last = p % 10
    if last - 1 >= 0:
        yield p * 10 + last - 1
    yield p * 10 + last
    if last + 1 <= 9:
        yield p * 10 + last + 1


p = 0
while len(lunlun) < k:
    for new_lunlun in generate_lunlun(lunlun[p]):
        lunlun.append(new_lunlun)
    p += 1

print(lunlun[k-1])


Measured memory_bytes: 7140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;


int main(){
    vector<string> top(50,""),down(50,"");
    rep(i,0,50)rep(j,0,100){
        top[i]+='#';
        down[i]+='.';
    }
    int a,b;
    cin>>a>>b;
    rep(i,0,a-1){
        int x = i/25*2;
        int y = i%25*2;
        top[x][y]='.';
    }
    rep(i,0,b-1){
        int x = i/25*2+1;
        int y = i%25*2;
        down[x][y]='#';
    }
    printf("%d %d\n",100,100);
    rep(i,0,50)cout<<top[i]<<endl;
    rep(i,0,50)cout<<down[i]<<endl;
	return 0;
}



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

int main(){
  int N;
  string S,T;
  cin >> N >> S >> T;
  for(int i=0;i<N;i++){
    bool ok=true;
    for(int j=0;j<N-i;j++){
      if(S[i+j]!=T[j]){
        ok=false;
        break;
      }
    }
    if(ok){
      cout << N+i << endl;
      return 0;
    }
  }
  cout << 2*N << endl;
}

Measured memory_bytes: 256
Sd=input()
T=input()

for i in range(len(Sd)-len(T)+1):
    for j in range(len(T)):
        if Sd[len(Sd)-i-j-1] not in (T[len(T)-j-1],'?'):
            break
    else:
        print((Sd[:len(Sd)-i-len(T)]+T+Sd[len(Sd)-i:]).replace('?','a'))
        exit()
print('UNRESTORABLE')

Measured memory_bytes: 3060
main :: IO ()
main = do
  n <- readLn
  print $ ans n

ans :: Int -> Int
ans n
  | n < 10 = n
  | n < 100 = 9
  | n < 1000 = 9 + n - 99
  | n < 10000 = 9 + 900
  | n < 100000 = 9 + 900 + n - 9999
  | otherwise = 9 + 900 + 90000

Measured memory_bytes: 508
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        k: usize,
    }

    let mut ans = 0;

    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                let tmp = num::integer::gcd(a, b);
                ans += num::integer::gcd(tmp, c);
            }
        }
    }

    echo!(ans);
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
// #include <cmath>
// #include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


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

int N; cin >> N;
VI H(N); rep(i, 0, N) cin >> H[i];

int maxi = 0, r = 0, cnt = 0;

while (r < N-1) {
    if (H[r] >= H[r+1]) {
        ++cnt;
        ++r;
    }
    else {
        ++r;
        maxi = max(maxi, cnt);
        cnt = 0;
    }
}
maxi = max(maxi, cnt);


cout << maxi << endl;
}

// 境界，出力文字列 チェック



Measured memory_bytes: 640
# https://www.youtube.com/watch?v=ENSOy8u9K9I&feature=youtu.be
# https://twitter.com/tempura_cpp/status/1259483252919635969

n, k = gets.to_s.split.map{|e|e.to_i}
a = [0] + gets.to_s.split.map{|e|e.to_i}

cur = 1
while k > 0

  cur = a[cur] if k[0] == 1
  
  a = Array.new(n+1){ |i| a[a[i]] }
  
  k >>= 1
end

puts cur

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


int main() {
  string X;

cin >> X;
  
  if(X=="RRR"){
	cout << 3;    
  } 
    if(X=="RRS"){
	cout << 2;    
  }
    if(X=="RSR"){
	cout << 1;    
  }
    if(X=="SRR"){
	cout << 2;    
  }
    if(X=="RSS"){
	cout << 1;    
  }
      if(X=="SRS"){
	cout << 1;    
  }
      if(X=="SSR"){
	cout << 1;    
  }
      if(X=="SSS"){
	cout << 0;    
  }

}

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

int a[200005];
int seg[800005];
vector<vector<int> >adj;
int cnt=0;
int dp[200005];
int ini[200005];
int fi[200005];

void upd(int ver,int tl,int tr,int pos,int val)
{
  if(tl>tr)
    return ;
  else if(tl==tr)
    seg[ver]+=val;
  else
  {
    int tm=(tl+tr)/2;
    if(tm>=pos)
      upd(2*ver,tl,tm,pos,val);
    else 
      upd(2*ver+1,tm+1,tr,pos,val);
    seg[ver]=max(seg[2*ver],seg[2*ver+1]);
  }  
}

int get(int ver,int tl,int tr,int l,int r)
{
  if(tl>tr||l>r||tr<l||r<tl)
    return 0;
  else if(tl==l&&tr==r)
    return seg[ver];
  else
  {
    int tm=(tl+tr)/2;
    return max(get(2*ver,tl,tm,l,min(tm,r)),get(2*ver+1,tm+1,tr,max(tm+1,l),r));
  }  
}

void dfs(int ver,int pr)
{
  int z=get(1,1,cnt,1,a[ver]-1);
  dp[ver]=z+1;
  ini[ver]=get(1,1,cnt,a[ver],a[ver]);
  if(dp[ver]>ini[ver])
  {
    upd(1,1,cnt,a[ver],dp[ver]-ini[ver]);
  }
  fi[ver]=seg[1];
  for(auto i:adj[ver])
  {
    if(i!=pr)
      dfs(i,ver);
  }
  if(ini[ver]<dp[ver])
  {
    upd(1,1,cnt,a[ver],ini[ver]-dp[ver]);
  }
}

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(0);   
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

  int n;
  cin>>n;
  adj.resize(n+1);
  set<int>s;
  map<int,int>mm;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    s.insert(a[i]);
  }
  for(auto i:s)
    mm[i]=++cnt;
  for(int i=1;i<=n;i++)
  {
    a[i]=mm[a[i]];
  }
  int x,y;
  for(int i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x); 
  }
  dfs(1,0);
  for(int i=1;i<=n;i++)
    cout<<fi[i]<<'\n';
}

Measured memory_bytes: 54212
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 200005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
     string s;
     cin >> s;
     if(s[1]=='B')  s[1] = 'R';
     else           s[1] = 'B';
     cout<<s;
}

int main()
{
     FAST;
     ll t = 1;
  //   cin >> t;
     while(t--)
     {    
          solve();
     }
}

Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    int N;
    string S;
    cin >> N >> S;
    int x = 0;
    int ans = 0;
    for(int i=0; i<N; i++){
        if(S[i] == 'I') x++;
        if(S[i] == 'D') x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[101010];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", A + i);
		--A[i];
	}
	int ret = 0;
	for (int i = 0; i < N; ++i) {
		if (A[A[i]] == i) ++ret;
	}
	printf("%d\n", ret / 2);
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
int main(){
	
	int a,b;
	cin>>a>>b;
	cout<<(a-1)*(b-1)<<endl;
	
	return 0;
}





Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int N; char S[5];
  scanf("%d",&N);

  int AC=0, WA=0, TLE=0, RE=0;
  for(int i=0;i<N;i++){
    scanf("%s",S);
    if(S[0]=='A'){
        AC++;
    }else if(S[0]=='W'){
        WA++;
    }else if(S[0]=='T'){
        TLE++;
    }else if(S[0]=='R'){
        RE++;
    }
  }
  
  printf("AC x %d\n", AC);
  printf("WA x %d\n", WA);
  printf("TLE x %d\n", TLE);
  printf("RE x %d\n", RE);
}


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

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


int main(){

  ll n;
  cin >> n;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];

  ll ans = 0;
  ll max = 0;

  rep(i,n){
    if(h[i]>=max){
      ans++;
      max = h[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    set<char> st;
    rep(i, 3) {
        char c;
        cin >> c;
        st.insert(c);
    }
    cout << (sz(st) == 2 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 384
a, b, c = list(map(int, input().split()))
y = (a + b - c) ** 2 - 4 * a * b
condition = y < 0
if c - a - b < 0:
    print("No")
elif 4 * a * b - (a + b - c) ** 2 < 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
n = int(input())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.reverse()
b.reverse()

ans = 0
for i in range(n):
    ai = a[i]+ans
    bi = b[i]
    if ai%bi != 0:
       ans += bi-ai%bi
print(ans)


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

#define MOD 1000000007LL;
using namespace std;

int main(void){
    long long N, K;
    cin >> N >> K;
    long long ans = 0;
    for(long long i = K; i <= N + 1; i++){
        long long j = N + 1 - i;
        long long M = N * (N + 1) / 2 - (N - j) * (N - j + 1) / 2;
        long long m = j * (j - 1) / 2;
        ans += M - m + 1;
        ans %= MOD;
        // cout << i << " " << M << " " << m << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX = 2e5;
const int GRIDMAX= 1e9;

int main() {
  int N; cin >> N;
  int x[MAX], y[MAX];
  int lbrt[MAX], rblt[MAX];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    lbrt[i] = x[i] + y[i];
    rblt[i] = GRIDMAX - x[i] + y[i];
  }

  sort(lbrt, lbrt + N);
  sort(rblt, rblt + N);
  cout << max(lbrt[N - 1] - lbrt[0], rblt[N - 1] - rblt[0]);
}

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

int main()
{
    int n, a;
    cin >> n >> a;
    int min, max;
    long sum;
    min = max = sum = a;

    while(cin >> a){
        if(min > a) min = a;
        if(max < a) max = a;
        sum = sum + a;
    }
    cout << min << " " << max << " " << sum << endl;

    return 0;
}

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

using namespace std;

int main(){
int a1,a2,a3;
cin >>a1 >> a2 >> a3;
int a4 = a1+a2+a3;
if (a4 >=22 )
{
	cout << "bust" <<endl;
}
else if(a4 <= 21) cout << "win" <<endl;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
a = 100
ans = 0
for i in range(N):
    if ((A[i]-1) - a ) ==1:
        c = C[a]
    else:
        c = 0
    a = A[i] - 1
    ans += (B[a] + c)
print(ans)


Measured memory_bytes: 38636
N = int(input())
W = [str(input()) for _ in range(N)]

count = 0

for n in range(1,N):
    if W[n-1][-1] != W[n][0] or W[n] in W[:n]:
        break
    else:
        count += 1

if count == N-1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   1000000000
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}



//=============================================ASIFAZAD==============================================//
vector<vi > adj;
int cnod;
vector<bool> vis;
set<int> an;

void dfs(int nod)
{
    cnod++;
    an.insert(nod);
    vis[nod] = 1;
    for(auto x: adj[nod])
        if(vis[x] == 0)
            dfs(x);
}


int32_t main()
{
    io;
    int n, m, k;
    cin>>n>>m>>k;
    adj.resize(n+1);
    vis.resize(n+1);
    while(m--)
    {
        int u, v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    vi blk[n+1];
    while(k--)
    {
        int u, v;
        cin>>u>>v;
        blk[u].pb(v);
        blk[v].pb(u);
    }
    vi ans(n+1);
    for(int i = 1; i<= n;i++)
    {
        if(vis[i] == 0)
        {
            cnod = 0;
            an.clear();
            dfs(i);
            for(auto x: an)
            {
                int outcn = 0;

                for(auto b: blk[x])
                    if(an.count(b) == 0)
                        outcn++;

                ans[x] = cnod - (int)blk[x].size() - (int)adj[x].size() + outcn-1;
            }
        }
    }

    for(int i = 1; i<= n; i++)
        cout<<ans[i] <<" ";
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int x[N];
    for(int i=0; i<N; i++){
        cin >> x[i];
    }
    long physical;
    long physical_min;
    for(int i=1; i<=100; i++){
        physical=0;
        for(int j=0; j<N; j++){
            physical+=pow((i-x[j]),2);
        } 
        if(i==1){
            physical_min=physical;
        }
        if(physical_min>physical){
            physical_min=physical;
        }
    }
    cout << physical_min << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<queue>
#include<vector>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	VgetII(a,b);
	puts(a%3==0||b%3==0||(a+b)%3==0?"Possible":"Impossible");
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
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
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

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

int m[55][55];
int main(){
	while(1){
		int h,w,ret=0;
		cin>>w>>h;
		if(w==0)return 0;
		memset(m, 0, sizeof(m));
		REP(i,w+2){
			m[0][i]=0;
			m[h+1][i]=0;
		}
		REP(i,h+2){
			m[i][0]=0;
			m[i][w+1]=0;
		}
		REP(i,h)REP(j,w)cin>>m[i+1][j+1];
		priority_queue<PII> q;
		FOR(i,1,h+1){
			FOR(j,1,w+1){
				if(m[i][j]==1){
					ret++;
					q.push(MP(i,j));
					while(!q.empty()){
						PII tmp = q.top();
						q.pop();
						if(m[tmp.first][tmp.second]==0)continue;
						m[tmp.first][tmp.second] = 0;
						REP(i,8)q.push(MP(tmp.first+dy[i], tmp.second+dx[i]));
					}
				}
			}
		}
		cout << ret << endl;
	}
}

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

int main() {
  int n; cin>>n;
  REP(i,55000){
    if((int)(i*1.08)==n){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
}

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

int main(void)
{
	int a;					/* input a */
	int b;					/* input b */
	int remainder = 1;		/* amari */
	int divide;
	int loop;
   
    /* get Data" */
    scanf("%d %d", &a, &b);
	
    while(remainder != 0)
    {
    	/* Compare Value */
		if(a < b)
		{
			remainder = b % a; 
			b = remainder;
			divide = a;
		}
		else
		{
			remainder = a % b;
			a = remainder;
			divide = b;
		}   	
    }
	printf("%d\n", divide); /* print greatest Common */
	
    return 0;
}

Measured memory_bytes: 1816
N, x= map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
cnt = 0
for i, a in enumerate(A):
  if i < N - 1:
    cnt += 1 if x >= a else 0
    x -= min(x, a)
  else:
    cnt += 1 if x == a else 0
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  long long count=0;
  for(int i=0;i<n;i++){
    while(a[i]%2==0){
      count++;
      a[i]/=2;
    }
  }
  cout<<count<<endl;
  return 0;
}

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

#include <iostream>
#include <string>
using namespace std;
int main() {
	int A,B;
	int D[5001],E[5001];
	int R=0;
	cin>>A>>B;
	for(int i=0;i<A;i++)cin>>D[i];
	for(int j=0;j<B;j++)cin>>E[j];

	int S=0;
	int k;
	for(int i=0;i<B;i++){
		S=0;
		k=0;
		for(int j=0;j<A;j++){
			if(E[i+k]==D[j]){
				S+=1;
				k++;
			}
		}
		R=max(R,S);
	}
	cout<<R<<endl;
	return 0;
}

Measured memory_bytes: 3128
N,T=map(int,input().split())
L=[]
for i in range(N):
  a,b=map(int,input().split())
  L.append((a,b))
L.sort()

DP=[[0 for i in range(T)] for j in range(N+1)]

for i in range(1,N+1):
  for j in range(T):
    if i>0 and j-L[i-1][0]>=0:
      DP[i][j]=max(DP[i-1][j-L[i-1][0]]+L[i-1][1],DP[i-1][j])
    else:
      DP[i][j]=DP[i-1][j]
ans=0
for i in range(N+1):
  if i!=N:
    ans=max(ans,DP[i][T-1]+L[i][1])
  else:
    ans=max(ans,DP[i][T-1])

print(ans)

Measured memory_bytes: 152420
S = input()

chasms = []
for i in range(len(S) - 1):
    if S[i] + S[i + 1] == "><":
        chasms.append(i + 1)

blocks = []
if len(chasms) == 0:
    blocks.append(S)
else:
    blocks.append(S[:chasms[0]])
    for i in range(len(chasms) - 1):
        blocks.append(S[chasms[i]:chasms[i + 1]])
    blocks.append(S[chasms[-1]:])

answer = 0
for i in blocks:
    a = i.count("<")
    b = i.count(">")
    if a >= b:
        n = a
        m = b - 1
    else:
        n = b
        m = a - 1
    answer += n * (n + 1) // 2
    answer += m * (m + 1) // 2

print(answer)


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


int main()
{
	int n;
	scanf("%d",&n);
	n=n%10;
	if(n==2||n==4||n==5||n==7||n==9) puts("hon");
	else if(n==0||n==1||n==6||n==8) puts("pon");
	else puts("bon");
}

Measured memory_bytes: 3764
package main

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

func main() {
	n, a, b := readI(), readI(), readI()
	g := n / (a + b)
	r := n % (a + b)
	if r > a {
		r = a
	}
	fmt.Println(g*a + r)
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 1784
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end
class UnionFindTree

  class ParArray < Hash
    def [] key
      self[key] = key if super(key).nil?
      super(key)
    end
  end

  class SizeArray < Hash
    def [] key
      self[key] = 1 if super(key).nil?
      super(key)
    end
  end

  def initialize()
    @par = ParArray.new
    @size = SizeArray.new
  end

  private

  def find(x)
    return x if x == @par[x]
    return @par[x] = find(@par[x])
  end

  public

  def unite(x, y)
    x = find(x)
    y = find(y)

    return nil if x == y
    x, y = y, x if @size[x] < @size[y]

    @par[y] = x
    @size[x] += @size[y]
  end

  def same?(x, y)
    return find(x) == find(y)
  end

  def size(x)
    return @size[find(x)]
  end

end

n = gif
x = array n
y = array n
rep n do |i|
  x[i],y[i] = gi.map{|a| [a,i]}
end


cost = x.sort_by{|a,b| a }.each_cons(2).map{|(a1,b1),(a2,b2)| [a2-a1,b1,b2]}+y.sort_by{|a,b| a }.each_cons(2).map{|(a1,b1),(a2,b2)| [a2-a1,b1,b2]}
u = UnionFindTree.new
ans = 0
cost.sort_by{|a,b,c| a }.each{|c|
  if u.size(0) >= n
    puts ans
    break
  end
  if u.same? c[1],c[2]
    next
  else
    u.unite c[1],c[2]
    ans+=c[0]
  end
}


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

using namespace std;

int main()
{
	char S[3];
	char weekdays[7][5] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

	cin >> S;

	for(int i = 0; i < 7; i++)	
	{
		if(strcmp(S, weekdays[i]) == 0)
		{
			cout << 7-i << "\n";
		}
	}
	return 0;
}

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

int main(){
  int slen,tlen;
  string s,t;
  cin>>s;
  slen=s.size();
  char a=s[0];
  t+=a;
  for(int i=1;i<slen;i++)
    if(s[i]!=a)a=s[i],t+=a;
  tlen=t.size();
  if(tlen%2==0){
    if(t[0]=='x')t=t.substr(1,tlen-1);
    if(t[tlen-1]=='x')t=t.substr(0,tlen-1);
    tlen--;
  }
  char c=t[tlen/2];
  int f=0;
  for(int i=1;i<=50;i+=4)
    if(tlen==i)f=1;
  if(f)cout<<c<<endl;
  else{
    if(c=='o')cout<<'x'<<endl;
    else cout<<'o'<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 11;
const int M = 1010;
const int Inf = 1e9;

int n, m, k;
char A[N][M];

int Try(vector <vector <int>> B)
{
    int Res = 0;
    vector <int> Total(B.size());

    for(int j = 0; j < m; j++)
    {
        vector <int> Current(B.size());

        for(int r = 0; r < B.size(); r++)
            for(int i : B[r])
                Current[r] += A[i][j];

        for(int x : Current)
            if(x > k)
                return Inf;

        bool Cut = false;

        for(int r = 0; r < B.size(); r++)
            if(Current[r] + Total[r] > k)
                Cut = true;

        if(Cut)
        {
            Res++;
            Total = Current;
        }

        else
        {
            for(int r = 0; r < B.size(); r++)
                Total[r] += Current[r];
        }
    }

    return Res;
}

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

    for(int i = 0; i < n; i++)  scanf("%s", A[i]);

    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            A[i][j] -= '0';

    int Ans = Inf;

    for(int Mask = 0; Mask < (1 << (n - 1)); Mask++)
    {
        vector <vector <int>> B;

        B.push_back(vector <int> ());

        for(int i = 0; i < n; i++)
        {
            B.back().push_back(i);

            if(Mask & (1 << i))
                B.push_back(vector <int> ());
        }

        Ans = min(Ans, __builtin_popcount(Mask) + Try(B));
    }

    cout << Ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

//0-index 半開区間セグツリー(値の更新or加算 , 最小値or最大値or和) verified AOJ DSL_2_A
template<typename T, typename E>
class segment_tree{
    typedef function<T(T,T)> F;
    typedef function<T(T,E)> G;
private:
    int num_of_elm_;
    vector<T> dat_;
    F f_;
    G g_;
    T ident_;
public:
    segment_tree(int n, F f, G g, T ident):f_(f), g_(g), ident_(ident){
        num_of_elm_ = 1;
        while(num_of_elm_<n)num_of_elm_*=2;
        dat_.resize(2*num_of_elm_,ident);
    }

    void update(int pos,T val){
        int p = num_of_elm_ + pos;
        dat_[p] = g_(dat_[p],val);
        while(p!=1){
            p/=2;
            dat_[p] = f_(dat_[p*2], dat_[p*2+1]);
        }
    }

    T query(int L, int R,int l=0,int r=0, int k=1){
        if(k==1)r = num_of_elm_;
        if(r<=L || R<=l)return ident_;
        else if(L<=l && r<=R){
            return dat_[k];
        }
        else{
            return f_(query(L,R,l,(l+r)/2,k*2), query(L,R,(l+r)/2,r,k*2+1));
        }
    }
};


int main(){
    int n,q;
    cin>>n>>q;
    auto  f = [](int a, int b){ return a+b; };
    auto  g = [](int a, int b){ return a+b; };
    segment_tree<int,int> st(n,f,g,0);

    rep(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0){
            st.update(x-1,y);
        }else{
            cout<<st.query(x-1,y+1-1)<<endl;
        }

    }
}





Measured memory_bytes: 3884