akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long A,B,N;
    cin>>A>>B>>N;
long long t=min(B,N);
long long s=1;
long long u=max(s,t-1000000);
long long v=0;
for(long long i=u;i<=t; i++){
    long long w=abs((A*i)/B)-A*abs(i/B);
    v=max(v,w);
    
}
cout<<v<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll x, y;
 	cin >> x >> y;
 	ll temp = __gcd(x, y);
	ll ans = (x * y) / temp;
	cout << ans << endl;   
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int n;
	vector < pair < string, pair<int, int>>>list;

	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		int num;
		cin >> s >> num;
		list.push_back(make_pair( s, make_pair ( -num, i + 1)));
	}

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

	for (int i = 0; i < n; i++) {
		cout << list[i].second.second << endl;
	}





	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair < int , int > T;

inline void read(int &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}


inline void read(long long  &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}

long long  a[100];
long long  n;


int main() {
    for (int i=1;i<=4;i++)
        read(a[i]);
    read(n);
    n=n*4;
    for (int i=1;i<4;i++)
        if ( a[i]*2<a[i+1])
         a[i+1]=a[i]*2;
    long long ans=0;
    ans = n/8*a[4] + ( n % 8 )/4*a[3] +  ( n % 4 )/2 * a[2] + n%2*a[1];
    cout<<ans<< endl;
    return 0;
}


Measured memory_bytes: 256
K=int(input())

if K%7==0:
    L=9*K//7
else:
    L=9*K

if L%2==0 or L%5==0:
    print('-1')
    exit()

rem=1
for i in range(1,L+1):
    rem*=10
    rem=rem%L
    if rem==1:
        break
print(i)

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
    }
    int ans = 0;
    rep(i,N){
        rep(j,N){
            int ze = abs(A[i]-A[j]);
            ans = max(ans, ze);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e6 + 3)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
int exp(int a, int b){
    LL res = 1;
    LL sum = a;
    for(int i=0;i<30;++i){
        if(BIT(i)&b){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    LL ans = 0;
    int bn = 0;
    REP(i, N){
        int a;
        cin >> a;
        int d = min(bn, a);
        ans += d;
        a -= d;
        ans += a>>1;
        bn = a & 1;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  ll n;
  ll sum=0;
  cin>>n;
  for(ll i=1;i<=n;i++)
  {
      if(i%3!=0&&i%5!=0)
      sum+=i;
  }
  cout<<sum;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void)
{
	int k;
	cin >> k;
	int ans;
	if (k % 2 == 0)  cout << (k / 2) * (k / 2) << endl;
	else cout << (k / 2) * (k / 2 + 1) << endl;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	vector<int> ans(n);
	rep(ri,2){
		int cnt = 0;
		rep(i,n){
			if(s[i] == 'R') cnt++;
			else{
				ans[i] += cnt/2;
				ans[i-1] += (cnt+1)/2;
				cnt = 0;
			}
		}
		reverse(ans.begin(), ans.end());
		reverse(s.begin(), s.end());
		rep(i,n){
			if(s[i] == 'L') s[i] = 'R';
			else s[i] = 'L';
		}
	}
	rep(i,n){
		cout << ans[i];
		if(i < n-1) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1104
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,k,i,j=0,count[105];
  cin>>a>>b>>k;
  for(i=1;i<=a;i++){
    if(a%i==0&&b%i==0){
      count[j]=i;
      j++;
    }
  }
  cout<<count[j-k]<<"\n";
  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++)
using ll = long long;
 
/* vector<int> A(N); 
    vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
　tie(b, a) = p.at(i); #pairを分割
    tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
　xの二乗:  pow(x, 2.0) 
    小さい順: sort(v.begin(), v.end());
    大きい順: reverse(v.begin(), v.end());
    int: -2,147,483,648 ～ 2,147,483,647
    ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
    // int型の2次元配列(3×4要素の)の宣言
    vector<vector<int>> data(3, vector<int>(4));
*/
 
int main() {
  ll N,n,l=0;
  ll ans=0;
  cin >> N;
  
  if(N%2==0)n=N/2-1;
  else n= N/2;
  
  vector<ll> rgb(3); 
  string D;
  cin >> D;
  rgb.at(0)=0;
  rgb.at(1)=0;
  rgb.at(2)=0;
  
  rep(i,N){
  	if(D.at(i)=='R') rgb.at(0)++;
    else if (D.at(i)=='G') rgb.at(1)++;
    else rgb.at(2)++;
  }
  
  ans = rgb.at(0)*rgb.at(1)*rgb.at(2);
  
  rep(i,n+1){
    l=0;
    ll spa = i+1;
    
    while( l + spa + spa < N ){
  		if( ( D.at(l)!=D.at(l+spa) ) 
           && ( D.at(l)!=D.at(l+spa+spa) )
           && ( D.at(l+spa)!=D.at(l+spa + spa) ) ){
    		ans--;
          	l++;
    	}
      	else{
          l++;
        }
    }
    
  }
  
  if(N<3) ans=0;
  if(ans<0) ans=0;
  
  cout << ans << endl;
}
 

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

int main(){
    int n;
    cin >> n;
    ve<ll> a(n);
    ll b=0;
    rep(i,n){
        cin >> a[i];
        b ^= a[i];
    }
    rep(i,n) cout << (b^a[i]) << " ";
    return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	sort(s.begin(), s.end());
	if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
const int MAX=1e5+5;

int N,M;

//隣接リスト
vi nb[MAX];
vi pa[MAX];
//入次数の管理
int id[MAX];
//トポロジカルソートをvectorで管理
//ts は頂点のソート、ordは頂点iが何番目かを表す。
vi ts;
int ord[MAX];

void top_sort(){
	//入次数0の箱
	stack<int> st;
	rep(i,N)if(id[i]==0)st.push(i);
	while(!st.empty()){
		int i=st.top();st.pop();
		ts.push_back(i);
		rep(j,(int)nb[i].size()){
			id[nb[i][j]]--;
			if(id[nb[i][j]]==0)st.push(nb[i][j]);
		}
	}
	rep(i,N)ord[ts[i]]=i;
}

int main(){
	cin>>N>>M;
	rep(i,N-1+M){
		int a,b;
		cin>>a>>b;
		nb[a].push_back(b);
      	pa[b].push_back(a);
		id[b]++;
	}
	top_sort();
	rep1(i,N){
      	int l=pa[i].size();
    	if(l==0)cout<<0<<endl;
        else if(l==1)cout<<pa[i][0]<<endl;
      	else{
          int mxi=pa[i][0];
          rep1(j,l-1){
          	int w=pa[i][j];
            if(ord[mxi]<ord[w])mxi=w;
          }
          cout<<mxi<<endl;
        }
    }
}

Measured memory_bytes: 13052
class Node():
    def __init__(self, node_id, left, right):
        self.node_id    =   node_id
        self.parent     =   -1
        self.sibling    =   -1
        self.left       =   left
        self.right      =   right
        self.degree     =   0
        self.depth      =   0
        self.height     =   0
        self.typ        =   "leaf"

    def set_prop(self, node_id, parent, sibling, depth):
        if node_id == -1:
            return -1
        self.parent     =   parent
        self.sibling    =   sibling
        self.depth      =   depth
        self.degree     =   (self.left != -1) + (self.right != -1)
        if self.degree:
            self.typ    =   "internal node"
        if self.parent == -1:
            self.typ    =   "root"
        self.height     =   max(tree[self.left].set_prop(self.left, self.node_id, self.right, self.depth + 1), 
                                tree[self.right].set_prop(self.right, self.node_id, self.left, self.depth + 1)) + 1
        return self.height

n = int(input())
tree = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    node_id, left, right = map(int, input().split())
    tree[node_id] = Node(node_id, left, right)
    root -= set([left, right])
r = root.pop()
tree[r].set_prop(r, -1, -1, 0)

for i in range(n):
    a = tree[i]
    print("node ", a.node_id, ": parent = ", a.parent, ", sibling = ", a.sibling,
          ", degree = ", a.degree, ", depth = ", a.depth, ", height = ", a.height, ", ", a.typ, sep="")

Measured memory_bytes: 7872
from collections import deque
N = int(input())
node_branch = [[] for _ in range(N+1)]
branch = [0] * (N)
link = [0] * (N+1)
checked = [False] * (N+1)

for num in range(N - 1):
    a, b = map(int, input().split())
    node_branch[a].append((b, num+1))
    node_branch[b].append((a, num+1))

maxlen = 0
for i, node in enumerate(node_branch):
    if maxlen < len(node):
        maxlen = len(node)
        maxnode = i

print(maxlen)

d = deque()
d.append(maxnode)
link[1] = 0
checked[maxnode] = True

while len(d)>0:
    now = d.popleft()
    color = 1
    for n, b in node_branch[now]:
        if checked[n]:
            continue
        if color == link[now]:
            color += 1
        branch[b] = color
        link[n] = color
        color += 1
        checked[n] = True
        d.append(n)

for i in range(1, N):
    print(branch[i])

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

using namespace std;

bool check(vector<pair<int, int>> s) {
    int h = 0;
    for(auto p: s) {
        if(h + p.first < 0) return false;
        h += p.second;
    }
    return true;
}

int main() {
    int n = 0;
    cin >> n;
    vector<pair<int, int>> ls, rs;

    int total = 0;
    for(int i=0; i<n; i++) {
        string s;
        cin >> s;
        int h = 0, b = 0;
        for(char c: s) {
            if(c == '(') h++; else h--;
            b = min(b, h);
        }
        if(h > 0) ls.push_back({b, h});
        else rs.push_back({b-h, -h});
        total += h;
    }

    sort(ls.rbegin(), ls.rend());
    sort(rs.rbegin(), rs.rend());
    if(check(ls) && check(rs) && total ==0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }



    return 0;
}


Measured memory_bytes: 18988
#include<bits/stdc++.h>
typedef long long ll;
#define sz(x) int(x.size())
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define MOD 1000000007
using namespace std;
 
 
int main(){
    int N; cin >> N;
    int dp[100001]; rep(i,100001) dp[i] = N+1;
    dp[0] = 0;
    for (int i = 0; i <= N; i++)
    {
        for (int six = 1; i + six <= 100000; six *= 6)
        {
            dp[i + six] = min(dp[i + six],dp[i] + 1);
        }
        for (int nine = 9; i + nine <= 100000; nine *= 9)
        {
            dp[i + nine] = min(dp[i + nine],dp[i] + 1);
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 640
#include<iostream>
 
using namespace std;
 
int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x2 - x1;
    int b = y2 - y1;
    cout << x2 - b<<' ' << y2 + a <<' '<< x2 - b - a <<' '<< y2 + a - b;
    return 0;
}

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

int main(){
  while(1){
    int flag=0;
    int h,w;
    cin>>h>>w;
    if(h==0&&w==0)break;
    int n=h*h+w*w;
    int ans=1e9+7;
    for(int i=1;i<151;i++){
      for(int j=i+1;j<151;j++){
        int x=i*i+j*j;
        if(n==x&&i>h){
          cout<<i<<" "<<j<<endl;
          flag=1;
          break;
        }
        if(flag==1)break;
        if(n<x){
          ans=min(ans,x);
        }
        if(flag==1)break;
      }
      if(flag==1)break;
    }

    for(int i=1;i<151;i++){
      if(flag==1)break;
      for(int j=i+1;j<151;j++){
        int x=i*i+j*j;
        if(x==ans){
          cout<<i<<" "<<j<<endl;
          flag=1;
        }
        if(flag==1)break;
      }
      if(flag==1)break;
    }
  }
  return 0;
}

Measured memory_bytes: 3096
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

constexpr int Offset = 10;
struct Pos {short y, x;};
constexpr Pos adjacent[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
char grid[1024][1024];
int group[1024][1024];
Pos q[1024 * 1024];

void flood(Pos p, int g) {
    if (grid[p.y][p.x] != '.') return;

    int push = 0, pop = 0;
    q[push++] = p;
    grid[p.y][p.x] = '*';
    group[p.y][p.x] = g;
    while (pop < push) {
        p = q[pop++];
        for (auto [dy, dx] : adjacent) {
            auto ny = p.y + dy;
            auto nx = p.x + dx;
            if (grid[ny][nx] != '.') continue;
            grid[ny][nx] = '*';
            group[ny][nx] = g;
            auto np = Pos{};
            np.y = ny;
            np.x = nx;
            q[push++] = np;
        }
    }
}

vector<set<int>> link_by_warps(const int h, const int w) {
    auto sets = vector<set<int>>(1024 * 1024);
    for (int y = Offset; y < h + Offset; ++y) {
        for (int x = Offset; x < w + Offset; ++x) {
            auto g = group[y][x];
            if (g == 0) continue;
            auto& gs = sets[g];

            for (int i = y - 2; i <= y + 2; ++i) {
                for (int j = x - 2; j <= x + 2; ++j) {
                    auto g2 = group[i][j];
                    if (g2 == 0) continue;
                    gs.insert(g2);
                }
            }
        }
    }
    return sets;
}

long long solve(const vector<set<int>>& sets, const int s, const int g) {
    auto q = vector<pair<int,int>>(1024 * 1024);
    auto visited = vector<char>(1024 * 1024);
    auto push = 0, pop = 0;
    q[push++] = make_pair(s, 0);
    visited[s] = true;
    while (pop < push) {
        auto [curr, d] = q[pop++];
        if (curr == g) return d;

        for (auto n : sets[curr]) {
            if (visited[n]) continue;
            visited[n] = true;
            q[push++] = make_pair(n, d + 1);
        }
    }
    return -1;
}

int main()
{
    int h, w; // 1000x1000
    cin >> h >> w;
    Pos start, goal;
    cin >> start.y >> start.x >> goal.y >> goal.x;
    start.y--, start.x--;
    goal.y--, goal.x--;

    for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
            cin >> grid[y + Offset][x + Offset];
        }
    }
    start.y += Offset;
    start.x += Offset;
    goal.y += Offset;
    goal.x += Offset;

    int g_last = 1;
    for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
            auto p = Pos{};
            p.x = x + Offset;
            p.y = y + Offset;
            flood(p, ++g_last);
        }
    }


    auto jumps = link_by_warps(h, w);
    cout << solve(jumps, group[start.y][start.x], group[goal.y][goal.x]) << endl;
    return 0;
}


Measured memory_bytes: 90748
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
	int n, m, y;
	vector <int> t, p, x;
	int i;
	int ans = 0;
	int sum = 0;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> y;
		t.push_back(y);
	}
	cin >> m;
	for (i = 0; i < m; i++) {
		cin >> y;
		p.push_back(y);
		cin >> y;
		x.push_back(y);
	}
	
    for(i = 0; i < n; i++){
        sum += t[i];
    }
    
    for(i = 0; i < m; i++){
        ans = sum - t[p[i]-1] + x[i];
        cout << ans << endl;
    }

	return 0;
}

Measured memory_bytes: 256
import std.array;
import std.conv;
import std.string;
import std.algorithm;
import std.stdio;

void main() {
	auto length = readln.chomp.to!uint;
	auto a = readln.chomp.split(" ").map!(to!uint).array;
	assert(length >= 1);
	assert(a.length == length);

	a.sort;

	if (a[0] == 1) {
		if (a.length >= 2 && a[1] == 1) {
			writeln("0");
			return;
		} else {
			writeln("1");
			return;
		}
	}

	auto sieve = new bool[1000008];

	foreach (e;a) {
		for (uint i = e + e;i < sieve.length;i += e) {
			sieve[i] = true;
		}
	}
	for (size_t i = 1;i < a.length;++i) {
		if (a[i - 1] == a[i]) {
			sieve[a[i]] = true;
		}
	}

	uint answer;
	foreach (e;a) {
		if (!sieve[e]) {
			++answer;
		}
	}
	writeln(answer);
}


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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL


int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin >> h >> w;
	bool table[100][100];
	memset(table,false,sizeof(table));
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			char ch;
			cin >> ch;
			table[i][j] = (ch == '#');
		}
	}
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			if(table[i][j]) {
				cout << "#";
			} else {
				int sum = 0;
				sum+= table[i-1][j-1];
				sum+= table[i-1][j];
				sum+= table[i-1][j+1];
				sum+= table[i][j-1];
				sum+= table[i][j+1];
				sum+= table[i+1][j-1];
				sum+= table[i+1][j];
				sum+= table[i+1][j+1];
				cout << sum;
			}
 		}
		cout << "\n";
	}
	return 0;
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc114/tasks/abc114_c

# 7,5,3がそれぞれ1回以上現れる数
# 3進数を自分で作ってしまうのは？→3,5,7の順にiterateするのは十分間に合う
# 10進数で10**9は3進数だけ考慮するなら10**4.5ぐらいですむ


from itertools import product
N = int(input())
number = ['0'] * 9
nums = ['0', '3', '5', '7']
arg = [nums] * 9


ans = 0
for iters in product(*arg):  # 頭がわるいので
    tmp = int(''.join(iters))
    if tmp > N:
        break
    tmp = str(tmp)
    if tmp.count('0') > 0 or tmp.count('3') == 0 or tmp.count('5') == 0 or tmp.count('7') == 0:
        continue
    else:
        ans += 1


print(ans)


Measured memory_bytes: 41836
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint N, K;
set<lint> SET;
vector<lint> ans;


void dfs(lint num){
  if(num >= N) {
    ans.push_back(num);
    return;
  }
  if(num == 0){
    for(auto value : SET){
      if(value != 0) dfs(value);
    }
  }
  else{
    for(auto value : SET){
      dfs(10 * num + value);
    }
  }
}

signed main(){
  cin >> N >> K;
  for(lint i = 0; i < 10; i++) SET.insert(i);
  for(lint i = 0; i < K; i++){
    lint x; cin >> x; SET.erase(x);
  }
  dfs(0);
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int> ans(n,0);
    for(int i=1; i<100; i++){
        for(int j=1; j<100; j++){
            for(int k=1; k<100; k++){
                if(i*i +j*j +k*k +i*j +j*k +k*i <= n){
                    ans[i*i +j*j +k*k +i*j +j*k +k*i-1] ++;
                }
            }
        }
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
struct Debug{
    int cnt = 0;
    bool on = false;
    char debug[10] = "debug";
    template<class T>
    Debug & operator<<(const T & v) {
        if(on && cnt++ == 0) cerr << "debug: ";
        if(on) cerr << v << ' ';
        return *this;
    }
    Debug & operator<<(ostream&(*pManip)(ostream&)) {
        if(on) cerr << (*pManip);
        cnt = 0;
        return *this;
    }
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}
 

typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;


const int MAXN = 1e6 + 20;


int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

    int n, m, a, b;
    cin >> n >> m >> a >> b;
    for(int i = 0; i < n; i++) {
    	for(int j = 0; j < m; j++) {
    		if((i < b && j < a) || (i >= b && j >= a))
    			cout << 0;
    		else
    			cout << 1;
    	}
    	cout << endl;
    }


    return 0;
}






















Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    int T;
    string s,S;
    cin>>s;
    string a,b;
    a.assign(s,0,s.length()/2);
    b.assign(s,(s.length()+1)/2,s.length()/2);
    string c,d;
    c=a;
    d=b;
    S=s;
     reverse(s.begin(),s.end());
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    /*cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;*/
    if(S==s&&a==c&&b==d)
        printf("Yes\n");
    else
        printf("No\n");


    return 0;
}


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()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> P;
constexpr auto INF = INT_MAX/2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];

	multiset<int> cc;

	rep(i, n) {
		auto k = cc.lower_bound(a[i]);
		if (k != cc.begin()) {
			k--; cc.erase(k);
		}
		cc.insert(a[i]);
	}

	cout << cc.size() << endl;
}

Measured memory_bytes: 5376
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

using namespace std;

int main(void) {
  int vs[3];
  REP(i, 3) {
    cin >> vs[i];
  }
  sort(vs, vs + 3);
  cout << vs[0] + vs[1] << endl;
  return 0;
}


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

int n, k;

int main(void){
    cin >> n >> k;
    vector<double> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    double l = 0;
    double r = 1e10;
    double mid;
    bool ok;
    int count = 100;
    while(count--){
        mid = (l+r)/2;
        int c = 0;
        for(int i = 0; i < n; i++){
            c += ceil(A[i]/mid)-1;
        }
        if(c <= k){
            r = mid;
        }else{
            l = mid;
        }
    }
    cout << fixed;
    cout << setprecision(0);
    cout << ceil(mid) << endl;

    return 0;
}


Measured memory_bytes: 4756
(defun tag ()
    (let* ((readA (read))
        (readV (read))
        (readB (read))
        (readW (read))
        (readT (read))
        (nowA (* readV readT))
        (nowB (* readW readT))
        (ans "")
        )

        (if (> readA readB)
            (if (<= (- readA nowA) (- readB nowB))
            (setq ans "YES")
            (setq ans "NO")
            )
            (if (<= (+ readB nowB) (+ readA nowA))
            (setq ans "YES")
            (setq ans "NO")
            )
        )
        ans
    )
    
)
(format t "~A~%" (tag))

Measured memory_bytes: 24256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int S[N-1];
    for (int i = 0;i < N;i++){
      cin >> S[i];
    }
    sort(S, S + N);
    int t = 0;
    for(int c = 0;c < N;c++){
      t = t + S[c];
    }
    if(t%10!=0){
      cout << t <<"\n";
    }else{
      for(int d = 0;d < N;d++){
        if(S[d]%10!=0){
          t = t-S[d];
          cout << t <<"\n";
          break;
        }
      }
    }
    if(t%10==0){
      cout << "0\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

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

int main() {
  int h, w, d, n;
  cin >> h >> w >> d >> n;
  string t[h];
  rep (i, h) cin >> t[i];
  int r[d + 2];
  rep (i, d) cin >> r[i + 1];
  r[0] = -1;
  r[d + 1] = 1e9;
  bool c[h][w];
  rep (i, h) rep (j, w) c[i][j] = true;
  rep (i, h) rep (j, w) if (t[i][j] == '#') c[i][j] = false;
  rep (_, n) {
    int x, y, s;
    cin >> x >> y >> s;
    rep (i, h) rep (j, w) {
      int dx = abs(x - j);
      int dy = abs(y - i);
      if (r[s + 1] < dx || r[s + 1] < dy || (dx <= r[s] && dy <= r[s])) c[i][j] = false;
    }
  }
  bool broken = true;
  rep (i, h) rep (j, w) if (c[i][j]) broken = false;
  if (broken) {
    cout << "Broken" << endl;
    return 0;
  }
  queue<pair<int, int> > que;
  rep (i, h) rep (j, w) if (t[i][j] == 'D') que.push(make_pair(i, j));
  while (!que.empty()) {
    pair<int, int> now = que.front();
    que.pop();
    if (now.first < 0 || h <= now.first || now.second < 0 || w <= now.second) continue;
    if (t[now.first][now.second] == '#') continue;
    t[now.first][now.second] = '#';
    rep (k, 4) que.push(make_pair(now.first + dy[k], now.second + dx[k]));
  }
  bool yes = true;
  bool no = true;
  rep (i, h) rep (j, w) if (c[i][j]) {
    if (t[i][j] == '#') no = false;
    else yes = false;
  }
  if (yes) cout << "Yes" << endl;
  else if (no) cout << "No" << endl;
  else cout << "Unknown" << endl;
}

Measured memory_bytes: 1228
from itertools import permutations

N, M = map(int, input().split())
Hen = [[]for i in range(N)]


for i in range(M):
    a, b = map(int, input().split())
    Hen[a-1].append(b-1)
    Hen[b-1].append(a-1)

T = []
for i in range(1, N):
    T.append(i)

ans = 0
for I in permutations(T):
    flag = True
    S = [0]
    S.extend(I)
    for j in range(N-1):
        if S[j+1] not in Hen[S[j]]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)


Measured memory_bytes: 40048
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long MOD = 1000000007;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        if(X==3||X==5||X==7){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23376
#include<iostream>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
bool cmp(pair<int,int> a,pair<int,int> b)
{
	if(a.second!=b.second)
	return a.second<b.second;
	return a.first<b.first;
}
int main()
{
	int n,m;
	cin>>n;
	if(n<=999)
		cout<<"ABC";
	else
		cout<<"ABD";
}

Measured memory_bytes: 256
fun main(args:Array<String>):Unit {
    while (true) {
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        val charactors = Array(n) {
            val arg = readLine()!!.trim().split(' ')
            Charactor(arg.first(), arg.drop(2).map(String::toInt))
        }
        val times = Array(31) { n + 1 }
        charactors.forEach { it.appearTimes().forEach { times[it]-- } }
        val score = charactors.map {
            Pair(it.name, it.appearTimes().sumBy { times[it] })
        }.sortedWith(compareBy(Pair<String, Int>::second, Pair<String, Int>::first)).first()
        println("${score.second} ${score.first}")
    }
}
data class Charactor(val name:String, private val mTimes:Iterable<Int>){
    fun appearTimes():Iterable<Int> = mTimes
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

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

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int x;
    cin >> x;
    cout << 360/__gcd(x,360) << endl;

    time_taken();
    return 0;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==7){
    if(b==5&&c==5){
      cout<<"YES"<<endl;
    }
    else{
    cout<<"NO"<<endl;
  }
  }
  else if(b==7){
    if(a==5&&c==5){
      cout<<"YES"<<endl;
    }
    else{
    cout<<"NO"<<endl;
  }
  }
  else if(c==7){
    if(b==5&&a==5){
      cout<<"YES"<<endl;
    }
    else{
    cout<<"NO"<<endl;
  }
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 200002;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll k,n,ans=0;
	vector<ll> v;
	cin>>n>>k;
	FOR(i,0,n){
		ll r;cin>>r;
		v.pb(r);
	}
	SORT(v);
	vector<ll> kosu;
	FOR(i,0,n){
		ll r=NUM(v,v[i]);
		kosu.pb(r);
		i+=r;
		i--;
	}
	SORT(kosu);
	ll i=0;
	while(1){
		if(kosu.size()<=k+i)break;
		ans+=kosu[i];
		i++;
	}
	pri(ans);
    return 0;
}


Measured memory_bytes: 4848
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {
  vector<int> t(5);
  vector<string> s = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"};
  while( scanf("%d,%d,%d,%d,%d", &t[0], &t[1], &t[2], &t[3], &t[4]) != EOF ){
    sort(t.begin(), t.end());
    vector<int> c(14, 0);
    for(int i=0; i<5; i++) c[ t[i] ]++;
    int two = 0, thr = 0, four = 0;
    for(int i=0; i<14; i++){
      if( c[i] == 2 ) two++;
      if( c[i] == 3 ) thr++;
      if( c[i] == 4 ) four++;
    }

    int ans = 0;
    if( four == 1 ) ans = 6;
    else if( thr == 1 && two == 1 ) ans = 5;
    else if( t[0] + 1 == t[1] && t[1] + 1 == t[2] && t[2] + 1 == t[3] && t[3] + 1 == t[4] ) ans = 4;
    else if( t[0] == 1 && t[1] == 10 && t[2] == 11 && t[3] == 12 && t[4] == 13 ) ans = 4;
    else if( thr == 1 ) ans = 3;
    else if( two == 2 ) ans = 2;
    else if( two == 1 ) ans = 1;

    cout << s[ans] << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define FAST()                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define fill(a, i) memset(a, i, sizeof(a))
#define all(vec) vec.begin(),vec.end()
#define revall(vec) vec.rbegin(),vec.rend()
#define v vector
#define tlll tuple<ll, ll, ll>
#define pb push_back
#define fr(i, a, b) for (int i = a; i < b; ++i) 
const ll maxn=3e3+5;
ll dp[maxn][maxn];
void solve()
{
   ll n;
   cin>>n;
   ll arr[n+1];
   fr(i,0,n)cin>>arr[i+1];
   fr(i,1,n+1)
   dp[i][i]=arr[i];
   ll pref[n+1];
   pref[0]=0;
   fr(i,1,n+1)
   pref[i]=pref[i-1]+arr[i];
   for(int l=2;l<=n;++l)
   {
       for(int i=1;i+l-1<=n;++i)
       {
           ll a,b;
           a=arr[i]+pref[i+l-1]-pref[i]-dp[i+1][i+l-1];
           b=arr[i+l-1]+pref[i+l-2]-pref[i-1]-dp[i][i+l-2];
           dp[i][i+l-1]=max(a,b);
       }
   }
   cout<<dp[1][n]*2-pref[n];

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

Measured memory_bytes: 49764
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()
 
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
 
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];
 
void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}
 
ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}
 
 
int main(void){
  ll N, A, B, W, H, C, D, Q, X, Y;
  string S, T;
  cin >> N;
  char s[N];
  rep(i, N) cin>>s[i];
  rep(i, N) {
    if (s[i] == 'Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout <<"Three" << endl;
  return 0;           
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
const ll INF=1e9+7;
const ll N = 101;

ll n,m;
vector<string> v,s,t;

int main(){
	cin>>n;
	FOR(i,0,n){
		string sa;
		cin>>sa;
		if(NUM(s,sa)==0)v.push_back(sa);
		s.push_back(sa);
		SORT(s);
	}
	cin>>m;
	FOR(i,0,m){
		string ta;
		cin>>ta;
		if(NUM(s,ta)==0&&NUM(t,ta)==0)v.push_back(ta);
		t.push_back(ta);
		SORT(t);
	}
	ll ans=0;
	FOR(i,0,v.size()){
		string a=v[i];
		if(ans<(NUM(s,a)-NUM(t,a)))ans=(NUM(s,a)-NUM(t,a));
	}
	cout<<ans<<endl;
	return 0;
}

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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n,i,a[200000];
	cin>>n;
	for (i=0;i<n;i++){
		cin>>a[i];
	}
	for (i=n-1;i>=0;i-=2){
		cout<<a[i]<<" ";
	} 
	for (i=n%2;i<n;i+=2){
		cout<<a[i]<<" "; 
	}
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
const int MAX_E = 2000;
const int MAX_V = 1000;
const ll INF = -100000000000000;
struct edge {int from, to; ll cost; };

edge es[MAX_E];
ll d[MAX_V];
int V, E;
bool t=false;
void longest_path(int s){
    rep(i, 0, V) d[i] = INF;
    d[s]=0;
    int j=0;
    while (true){
        bool update =false;
        rep(i, 0, E){
            edge e = es[i];
            if (d[e.from] != INF && d[e.to] < d[e.from] + e.cost){
                d[e.to]=d[e.from]+e.cost;
                if(e.to==V-1) update=true;
            }
        }
        j++;
        if(V<=j&&j<=2*V&&update){
            t=true;
            break;
        }
        if(j==2*V+1) break;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>> V>>E;
    rep(i,0,E){
        int a,b;
        ll c;
        cin>>a>>b>>c;
        a--;
        b--;
        es[i]={a,b,c};
    }
    longest_path(0);
    if(t) cout<< "inf"<<"\n";
    else {
        cout << d[V-1]<<"\n";
    }
}


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

using namespace std;

int abs (int a, int b)
{
	int diff = a - b;
	if (diff < 0)
		return -diff;
	else
		return diff;
}

// 差が2以上ある時，非負の整数を返す a:0, b:1, c:2
// 			ない時，-1 を返す．
int diff_2 (int a, int b, int c)
{
	if (2 <= abs(a, b))
	{
		if (a < b)
			return 0;
		else
			return 1;
	}
	else if (2 <= abs(b, c))
	{
		if (b < c)
			return 1;
		else
			return 2;
	}
	else if (2 <= abs(c, a))
	{
		if (c < a)
			return 2;
		else
			return 0;
	}
	return -1;
}

int mmm (int a, int b)
{
	if (a < b)
		return 1;
	else
		return 0;
}

int max (int a, int b, int c)
{
	// aが大きい
	if (!mmm(a, b))
	{
		if (!mmm(a, c))
			return 0;
		else 
			return 2;
	}
	else
	{
		if (!mmm(b, c))
			return 1;
		else
			return 2;
	}
}

int main (void)
{
	int num[3];
	cin >> num[0] >> num[1] >> num[2];
	int count = 0;
	int small = 0;

	while (1)
	{
		if (num[0] == num[1]  && num[1] == num[2])
			break;
		else
		{
			small = diff_2(num[0], num[1], num[2]);
			// 差が2以上あれば
			if (0 <= small)
			{
				num[small]+=2;
				count++;
			}
			else
			{
				int m = max(num[0], num[1], num[2]);
				for (int i = 0; i < 3; i++)
				{
					if (i != m)
						num[i]++;
				}
				count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sortBy, groupBy)
import Data.Tuple (swap)
import Data.Function (on)

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  xls <- sequence . replicate n $ unsafeListToTuple . map unsafeSignedDecimal . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    lrs :: [(Int, Int)]
    lrs = map ((,) <$> maximum . map fst <*> snd . head) . groupBy ((==) `on` snd) . sortBy (compare `on` snd) . map bound $ xls
    step :: (Int, Int) -> (Int, Int) -> (Int, Int)
    step acc@(s, r0) (l, r) | r0 <= l   = (succ s, r)
                            | otherwise = acc
  print . fst . foldl step (0, -(10 ^ 9)) $ lrs

bound :: (Int, Int) -> (Int, Int)
bound (x, l) = (x - l, x + l)

unsafeListToTuple :: [Int] -> (Int, Int)
unsafeListToTuple (x : y : _) = (x, y)

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 54652
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;

int main(){
	int a,b;
	cin >> a>>b;
	int ans = max(a + b, max(a * b, a - b));
	cout<<ans <<endl;
	return 0;
}

Measured memory_bytes: 256
import math
a,b=map(int,input().split())
gcd=math.gcd(a,b)

def prime_factorization(n):
  i=2
  prime=[]
  while i*i<=n:
    if n==1: break
    if n%i:
      i+=1
    else:
      n//=i
      prime.append(i)
      while n%i==0:
        n//=i
  if n>1:
    prime.append(n)
  return prime

print(len(prime_factorization(gcd))+1)
#print(prime_factorization(gcd))

Measured memory_bytes: 9100
n, m, c = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

ans = 0

n.times do
  sum = 0
  as = gets.split.map(&:to_i)
  m.times do |j|
    sum += as[j] * bs[j]
  end

  ans += 1 if sum + c > 0
end

puts ans


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>

#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e12

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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    vector<ll> v;
    v.push_back(0);
    rep(i, n){
        ll tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    reps(i, n){
        ll flag = 1;
        rep(j, i){
            if(v[i]<v[j]) flag*=0;
        }
        if(flag == 1) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto a = new int[](n), b = new bool[](n);
  foreach (i; 0..n) a[i] = readln.chomp.to!int-1;

  auto c = 0, d = 0;
  for (;;) {
    ++d;
    b[c] = true;
    c = a[c];
    if (c == 1) {
      writeln(d);
      break;
    }
    if (b[c]) {
      writeln(-1);
      break;
    }
  }
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  bool isok = false;
  for (int i = 1; i <= 9; i++) isok |= N % i == 0 && N / i <= 9;
  cout << (isok ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3656
import itertools
import math

n = int(input())
cities = []
for _ in range(n):
    x, y = map(int, input().split())
    cities.append([x - 1, y - 1])

ave = 0
count = 0
for path in itertools.permutations(cities):
    length = 0
    for i in range(len(path))[1:]:
        length += math.sqrt((path[i][0] - path[i-1][0]) ** 2 +
                            (path[i][1] - path[i-1][1]) ** 2)
    ave += length
    count += 1

print(ave / count)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <unordered_set>
 
 
int main(void)
{
	int count, value;
	std::cin >> count;

  	std::unordered_set<int> sets;
  
  	for(int i = 0 ; i< count; i++)
    {
		std::cin >> value;
      	if( 0 < sets.count(value) )
        {
	  		std::cout << "NO" << std::endl;
          std::exit(0);
        }
      else
      {
        sets.emplace(value);
      }
    }
  
	std::cout << "YES" << std::endl;
}

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

int main(){
	int N;
	cin >> N;
	vector<string> W(N);
	for (int i = 0;i < N;++i) {
		cin >> W[i];
	}
	for (int i = 0;i < N - 1;++i) {
		if (W[i][W[i].size() - 1] != W[i + 1][0]) {
			puts("No");
			return 0;
		}
	}
	sort(W.begin(), W.end());
	for (int i = 0;i < N - 1;++i) {
		if (W[i] == W[i + 1]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
const int cy=2019, cm=4, cd=30;
int main()
{
	int yy, mm, dd;
	cin >> yy;
	getchar();
	cin >> mm;
	getchar();
	cin >> dd;
	int ans = 1;
	if (yy < cy) {
		ans = 1;
	}
	else if (yy == cy) {
		if (mm < cm) {
			ans = 1;
		}
		else if (mm == cm) {
			if (dd <= cd) {
				ans = 1;
			}
			else ans = 0;
		}
		else ans = 0;
	}
	else ans = 0;
	if (ans) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
	return 0;
}
//_CRT_SECURE_NO_WARNINGS

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long N,M,K,an,bn,ans=0LL;
int main(){
    cin>>N>>M>>K;
    vector<long long>A(N+1,0LL),B(M+1,0LL);
    for(int i=1;i<=N;i++)cin>>A[i];
    for(int i=1;i<=N;i++)A[i]=A[i]+A[i-1];
    for(int i=1;i<=M;i++)cin>>B[i];
    for(int i=1;i<=M;i++)B[i]=B[i]+B[i-1];
    for(bn=0;bn<M&&B[bn+1]<=K;bn++);
    for(an=0;an<N&&A[an+1]+B[bn]<=K;an++);

    ans=max(ans,an+bn);
    for(an=0;bn>=0;bn--){
        while(an<N&&A[an+1]+B[bn]<=K)an++;
        ans=max(ans,an+bn);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6372