akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, a[110];
int arr[] = {399, 799, 1199, 1599, 1999, 2399, 2799, 3199};

signed main() {
    cin >> N;
    int cnt[10] = {};
    int v = 0;
    rep(i,0,N) {
        cin >> a[i];
        if(a[i] >= 3200) v++;
        else {
            int val = a[i];
            int idx = lower_bound(arr, arr+8, val) - arr;
            cnt[idx]++;
        }
    }

    int ret = 0, retb = 0;
    rep(i,0,8) if(cnt[i] != 0) ret++;
    retb = ret + v;
    if(ret == 0) ret = 1;
    printf("%lld %lld\n", ret, retb);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    
    boolean primes[] = new boolean [50022];
    for(int n = 2; n < primes.length; n++){
      if (primes[n]) continue;
      for (int m = 2 * n; m < primes.length; m += n) {
        primes[m] = true;
      }
    }
               
    while (in.hasNext()) {
      int num = in.nextInt();
      int pre =  num - 1;
      int post = num + 1;
      for (int i = pre;  primes[i]; i--) pre  = i - 1;
      for (int i = post; primes[i]; i++) post = i + 1;
      System.out.println(pre + " " + post);
    }
  }
}

Measured memory_bytes: 19248
#include <vector>
#include <iostream>
using namespace std;
class ModPerm {
    long long *fact, *facti;
    const int mod;
public:
    explicit ModPerm(int n, int m) : mod(m) {
        fact = new long long[n+1];
        facti = new long long[n+1];
        fact[0] = 1; facti[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % m;
        // calc 1/n!
        long long &inv = facti[n], pw = fact[n];
        inv = 1;
        for (int e = mod-2; e > 0; e /= 2) {
            if (e&1) inv = inv * pw % mod;
            pw = pw * pw % mod;
        }
        for (int i = n-1; i > 0; i--) facti[i] = (facti[i+1] * (i+1)) % m;
    }

    ~ModPerm() {
        if (fact) delete[] fact;
        if (facti) delete[] facti;
    }

    long long get(int n, int k) const {
        if (n < 0 || k < 0 || k > n) return 0;
        return fact[n] * facti[n-k] % mod;
    }
};

vector<int> adj[100100];
int n, k;
constexpr int M = 1000000007;
ModPerm mc(100100, M);

long long calc(int i, int p) {
    long long ans;
    if (p >= 0) ans = mc.get(k - 2, adj[i].size() - 1);
    else ans = mc.get(k - 1, adj[i].size());
    for (int j : adj[i]) {
        if (j == p) continue;
        ans = ans * calc(j, i) % M;
    }
    return ans;
}

int main() {
    cin >> n >> k;
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b; a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cout << k * calc(0, -1) % M << endl;
}


Measured memory_bytes: 12032
//  s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま
//  s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll kansuu(ll n){
  ll keta = 0;
  while(n>0){
    keta++;
    n/=10;
  }
  return keta;
}
ll kansuu2(ll n){
  ll kyu = 0;
  while(n>0){
    ll a = n%10;
    if(a==9)kyu++;
    n/=10;
  }
  return kyu;
}
ll kansuu3(ll n){
  ll wa = 0;
  while(n>0){
    wa += n%10;
    n/=10;
  }
  return wa;
}
ll kansuu4(ll keta){
  ll k=1;
  for(int i=1;i<=keta;i++){
    k = k * 10;
  }
  return k;
}

int main() {
  ll n;
  cin >> n;
  ll keta = kansuu(n);
  ll kyu = kansuu2(n);
  ll num = n/kansuu4(keta-1);
//  cout << keta<< endl;
//  cout << kyu << endl;
  if(n<=9){
      cout << n << endl;
      return 0;
  }
  else if(keta == kyu){
    cout << kansuu3(n)<<endl;
    return 0;
  }
  else if(keta-1 == kyu){
    ll num2 = n + 1;
    ll num3 = kansuu4(keta-1);
//    cout << num2 << endl;
//    cout << num3 << endl;
    if(num2 % num3 == 0){
      cout << num2/num3 -1 + 9*(keta-1) << endl;
//      cout <<"fda"<<endl;
      return 0;
    }
    else{
      cout << num-1+9*(keta-1)<<endl;
      return 0;
    }
  }
  else if(num == 1){
      cout <<9*(keta-1)<<endl;
      return 0;
      }
  else{
      cout << num-1+9*(keta-1)<<endl;
      return 0;
    }
}


Measured memory_bytes: 3632
import java.util.Scanner;
public class Main { 
	public static void main(String[] args){
	//	int count=0;
		int a=0;
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()) {
			int count=0;
			int n = sc.nextInt();
			for (int i = 0;i<10;i++) {
				for(int j = 0;j<10;j++) {
					for(int k =0;k<10;k++) {
						for(int l = 0;l<10;l++) {
							
							a = i + j + k + l;
							if(a==n) count++;
						}
					}
				}

			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 26204
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 202020;
constexpr long long INF = 1LL << 60;
long long dp[N][5][2];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i <= n; i++) for (int j = 0; j < 5; j++) {
    dp[i][j][0] = dp[i][j][1] = -INF;
  }
  dp[0][2][0] = 0;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    //use;
    for (int j = 0; j < 5; j++) {
      int num = (i - 1) / 2 + (j - 2);
      for (int k = 0; k < 5; k++) {
        int num_nxt = i / 2 + (k - 2);
        if (num + 1 != num_nxt) continue;
        dp[i][k][1] = max(dp[i][k][1], dp[i - 1][j][0] + a);
      }
    }
    //not use;
    for (int j = 0; j < 5; j++) {
      int num = (i - 1) / 2 + (j - 2);
      for (int k = 0; k < 5; k++) {
        int num_nxt = i / 2 + (k - 2);
        if (num != num_nxt) continue;
        dp[i][k][0] = max({dp[i][k][0], dp[i - 1][j][1], dp[i - 1][j][0]});
      }
    }
  }
  cout << max(dp[n][2][0], dp[n][2][1]) << endl;
  return 0;
}

Measured memory_bytes: 19224
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;

#define all(x) x.begin(), x.end()
#define all_r(x) x.rbegin(), x.rend()
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, n) for(int i = n; i >= 0; --i)
#define f first
#define s second

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int X, Y;
	cin >> X >> Y;
	for(int i = 0; i <= X; ++i) {
		if(2 * i + (X - i) * 4 == Y) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
 	return 0;
}

Measured memory_bytes: 3616
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()

if s == 'RRR':
    print(3)
elif s[:2]=='RR' or s[1:] == 'RR':
    print(2)
elif s == 'SSS':
    print(0)
else:
    print(1)

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

int main() {
    int h, a;
    cin >> h >> a;
    int ans = (h+(a-h%a)%a) / a; 
    cout << ans << endl;
    return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S;

int main(){
  cin >> S;
  int N = S.length(), turn;
  if (S[0] == S[N - 1]) turn = N - 3;
  else turn = N - 2;

  if (turn % 2 == 0) cout << "Second" << endl;
  else cout << "First" << endl;
  

  return 0;
}


Measured memory_bytes: 3728
#include<iostream>
using namespace std;
static const long long INF = -9223372036854775807;

int main(){
  long long a, b, c, d;
  long long p = INF;
  cin >> a >> b >> c >> d;
  if(a*c > p) p = a*c;
  if(a*d > p) p = a*d;
  if(b*c > p) p = b*c;
  if(b*d > p) p = b*d;
  cout << p << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int i,j,x;
	for(i=1;i<=9;i++)	{
		for(j=1;j<=9;j++)	{
			x=i*j;
			printf("%dx%d=%d\n",i,j,x);
		}
	}
	return 0;
}


Measured memory_bytes: 924
using System;
using System.Text;

namespace ALDS1_11_A_Graph
{
	class Program
	{
		static void Main ( string[] args )
		{
			int vertexCount = int.Parse (Console.ReadLine ());

			Graph graph = new Graph (vertexCount);

			for (int lp = 0; lp < vertexCount; lp++)
			{
				int[] inputNum = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);

				for (int lp2 = 0; lp2 < inputNum[1]; lp2++)
				{
					graph.GetData (inputNum[0], inputNum[2 + lp2]);
				}
			}

			Console.Write (graph);
		}
	}

	class Graph
	{
		public Graph ( int size )
		{
			this.Map = new int[size + 1, size + 1];
		}

		public int[,] Map { private set; get; }

		private const int Exist = 1;

		public void GetData ( int vertexNumber, int adjacencyNumber )
		{
			if (0 <= vertexNumber && vertexNumber < Map.GetLength (0) &&
				0 <= adjacencyNumber && adjacencyNumber < Map.GetLength (1))
			{

				Map[adjacencyNumber, vertexNumber] = Exist;
			}
		}

		public override string ToString ()
		{
			StringBuilder output = new StringBuilder (Map.Length * 2);

			for (int col = 1; col < Map.GetLength (0); col++)
			{
				for (int row = 1; row < Map.GetLength (1) - 1; row++)
				{
					output.Append (Map[row, col]);
					output.Append (" ");
				}

				output.Append (Map[Map.GetLength (0) - 1, col]);
				output.AppendLine ();
			}

			return output.ToString ();
		}
	}
}

Measured memory_bytes: 9496
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int main(){
	int A, B, C;
	int seven = 0;
	int five = 0;
	cin >> A >> B >> C;
	if (A==7) seven++;
	if (A==5) five++;
	if (B==7) seven++;
	if (B==5) five++;
	if (C==7) seven++;
	if (C==5) five++;
	
	if (seven==1 && five==2){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	

	return 0;
}

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

int main()
{
  int h, w;
  while (cin >> h >> w) {
    if (h==0 && w==0) continue;
    for (int i=0; i < h; i++) {
      for (int j=0; j < w; j++) {
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    ll a,b;
    cin>>a>>b;
    ll ab=a;
    ll ba=b;
    REP(i,b-1){
        ab*=10;
        ab+=a;
    }
    REP(i,a-1){
        ba*=10;
        ba+=b;
    }
    if(a<b){
        cout<<ab<<endl;
    }else{
        cout<<ba<<endl;
    }
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#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 MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

int itr = 0;
vector<vector<int>> tree;
vector<int>  V,c;
ll ans;
void dfs(int n, int per) {
    for (auto e : tree[n]) {
        if (e != per) {
            dfs(e, n);
        }
    }
    V[n] = c[itr];
    if (n != 0) ans += c[itr];
    itr++;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    V.resize(N);
    c.resize(N);
    tree.resize(N);
    REP(i, N - 1) {
        int a, b; cin >> a >> b;
        a--; b--;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }
    REP(i, N) {
        cin >> c[i];
    }
    sort(ALL(c));
    dfs(0, -1);
    cout << ans << endl;
    REP(i, N) {
        cout << V[i] << " ";
    }
    cout << endl;
    getchar(); getchar();
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void){
	int a,b;
	int kazu[100];
	scanf("%d",&a);
	for(b=0;b<a;b++){
		scanf("%d",&kazu[b]);
	}
	for(b=a-1;b>=0;b--){
		if(b == 0){
			printf("%d\n",kazu[b]);
		}
		else{
			printf("%d ",kazu[b]);
		}
	}
	
	return 0;
}

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

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
  if(A.size()==n+1){
    int now=0;
    for(int i=0; i<q; i++){
      if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
    }

    ans=max(ans,now);

    return;
  }

  A.push_back(A.back());
  while(A.back()<=m){
    dfs(A);
    A.back()++;
  }
}

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

  a = b = c = d = vector<int>(q); 

  for(int i=0; i<q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  dfs(vector<int>(1,1));

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
	return b!=0 ? gcd(b, a%b) : a;
}

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

int main() {
	ll a, b;
	
	while (cin>>a>>b) {
		cout << gcd(a, b) << " " << lcm(a, b) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1156
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def primes(n):
    """ Returns  a list of primes < n """
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]

BIT = Bit(10**5+1)

plist = primes(10**5+1)
# print(plist)
pp = []
for p in plist[1:]:
    if (p+1) //2 in plist:
        pp.append( p )
        BIT.add(p,1)
# print(pp)

Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    if l in pp:
        l-=1
    if r in pp:
        r+=1
    print( BIT.sum(r) - BIT.sum(l) )


Measured memory_bytes: 57432
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> index(n);
    vector<int> dist(n);
    vector<int> num(n);
    for(int i=0; i<n; ++i)
        cin >> index[i] >> dist[i] >> num[i];

    vector<int> weight(1<<n, 0);
    vector<vector<double> > time(1<<n, vector<double>(n, DBL_MAX));
    vector<vector<int> > prev(1<<n, vector<int>(n));
    for(int i=0; i<n; ++i){
        weight[1<<i] = num[i] * 20;
        time[1<<i][i] = 0.0;
    }

    for(int i=0; i<(1<<n); ++i){
        bitset<15> bs(i);
        for(int j=0; j<n; ++j){
            if(!bs[j])
                continue;
            for(int k=0; k<n; ++k){
                if(bs[k])
                    continue;
                bs[k] = true;

                double t = time[i][j] + abs(dist[j] - dist[k]) / (2000.0/(70+weight[i]));
                if(t < time[bs.to_ulong()][k]){
                    weight[bs.to_ulong()] = weight[i] + num[k] * 20;
                    time[bs.to_ulong()][k] = t;
                    prev[bs.to_ulong()][k] = j;
                }
                bs[k] = false;
            }
        }
    }

    vector<int> ret(n);
    bitset<15> bs((1<<n)-1);
    int j = min_element(time.back().begin(), time.back().end()) - time.back().begin();
    ret[n-1] = index[j];
    for(int i=n-2; i>=0; --i){
        int k = prev[bs.to_ulong()][j];
        ret[i] = index[k];
        bs[j] = false;
        j = k;
    }

    cout << ret[0];
    for(int i=1; i<n; ++i)
        cout << ' ' << ret[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 7924
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
   uniform_int_distribution<int> uid(l, r);
   return uid(rng);
}
//shuffle(v.begin(), v.end(), rng);

int dist(int x, int y){
   return (x) * (x) + (y) * (y);
}

int32_t main(){_

   cin>>n;

   vector<P> v;
   
   for (int i = 0; i < n; ++i)
   {
      int x, y;
      cin >> x >> y;
      v.push_back({x, y});
   }

   int ans = 0;
   for (int i = 0; i < N; ++i)
   {
      shuffle(v.begin(), v.end(), rng);      
      int X = 0, Y = 0;
      for (int j = 0; j < sz(v); ++j)
      {
         if(dist(X+v[j].F, Y+v[j].S) > dist(X, Y)){
            X += v[j].F;
            Y += v[j].S;
         }  
      }
      smax(ans, dist(X, Y));
   }

   cout << fixed << setprecision(15);
   cout<<sqrtl(ans);   

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdio>
#include <cstdlib>

#ifndef INT_MAX
#define INT_MAX (0x7FFFFFFF)
#endif

using namespace std;

typedef pair<int,int> ii_t;
struct edge_t {
    int src, dest, cost;
    edge_t(int s,int d,int c):src(s),dest(d),cost(c){}
};

bool dfs(int n, int cur, 
        vector<int> &pos,
        vector<vector<edge_t> > &edges){
    int m = edges[cur].size();
    for (int j=0;j<m;j++) {
        edge_t &e(edges[cur][j]);
        if (pos[e.dest] == INT_MAX) {
            pos[e.dest] = pos[cur] + e.cost;
            bool c = dfs(n, e.dest, pos, edges);
            if (!c) return false;
        } else {
            if (pos[e.dest]-pos[cur] != e.cost) {
                cerr << cur << " " << e.dest << " " << e.cost << endl;
                cerr << pos[cur] << " " << pos[e.dest] << endl;
                return false;
            }
        }
    }
    return true;
}
int main() {
    int n, m, l, r, d;
    cin >> n >> m;
    vector<vector<edge_t> > edges(n);
    vector<int> pos(n, INT_MAX);
    for (int i=0;i<m;i++) {
        cin >> l >> r >> d;
        l--;
        r--;

        edges[l].push_back(edge_t(l,r,d));
        edges[r].push_back(edge_t(r,l,-d));
    }
    string result = "Yes";
    for (int i=0;i<n;i++) 
    if (pos[i] == INT_MAX) {
        pos[i] = 0;
        int ans = dfs(n,i,pos,edges);
        if (!ans) {
            result = "No";
            break;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 16640
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char** argv) {
	int n, k;
	vector<int> h;
	unsigned int cnt = 0;

	cin >> n >> k;
	h.resize(n);
	for (auto &i : h) {
		cin >> i;
		if (i >= k) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<29
#define DEBUG 0
/*
	Ritsumeikan University Programming Contest 2011 , Japan, 2011-10-05

	2285 - Anipero

	Anipero01.cpp
	まずは全探索.

	Anipero02.cpp
	メモ化再帰

	Anipero03.cpp
	DPに書き直す

	Anipero04.cpp
	ループの向きを反対にする

*/
using namespace std;

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

const int MAX_LIMIT = 1000;
const int MAX_N = 100;
const int MAX_M = 100;

int LIMIT, N, M, X;

int sec_e[MAX_N+1], sec_s[MAX_N+1], e[MAX_M+1], s[MAX_M+1];

int dp[MAX_M+1][MAX_LIMIT+1];
/*
int dfs (int depth, int cnt, int cost ){
	if (cost > LIMIT ) return -INF;
	if (depth >= M ){
		return 0;
	} // end if
	if (memo[depth][cnt][cost] != -1 ) return memo[depth][cnt][cost];

	int res = -INF;
	res = max (res, dfs (depth + 1, cnt, cost ) );
	res = max (res, dfs (depth + 1, cnt + 1, cost + e[depth] ) + s[depth] );

	return memo[depth][cnt][cost] = res;
}
*/

int solve (void ){
	rep (j, MAX_M+1 ) rep (k, MAX_LIMIT + 1 ) dp[j][k] = -INF;
	dp[0][0] = 0;

	rep (i, M ){
		for (int j = i; j >= 0; j-- ){
			for (int k = 0; k <= LIMIT; k++ ){
				if (k + e[i] <= LIMIT ){
					dp[j+1][k+e[i]] = max (dp[j+1][k+e[i]], dp[j][k]+s[i] );
					dp[j][k+e[i]] = max (dp[j][k+e[i]], dp[j][k] );
				} // end if
			} // end for
		} // end for
	} // end for

#if DEBUG
	rep (i, M+1 ){
		for (int j = 0; j <= LIMIT; j++ ){
			cerr << (dp[i][j] <= -INF/2 ? -1 : dp[i][j] ) << (j != LIMIT ? ' ' : '\n' );
		} // end for
	} // end rep
#endif

	int res = 0;
	for (int j = X; j <= M; j++ )
	rep (k, LIMIT+1 ){
		if (dp[j][k] >= 0  ){
			int curr = -INF;
			rep (ii, N ){
				if (k + sec_e[ii] <= LIMIT )
					curr = max (curr, sec_s[ii] );
				rep (jj, ii )
					if (k + sec_e[ii] + sec_e[jj] <= LIMIT )
						curr = max (curr, sec_s[ii] + sec_s[jj] );
			} // end rep
			res = max (res, dp[j][k] + curr );
		} // end if
	} // end rep
	
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	while (cin >> LIMIT >> N >> M >> X, LIMIT ){
		memset (sec_e, 0, sizeof (sec_e ) );
		memset (sec_s, 0, sizeof (sec_s ) );
		memset (e, 0, sizeof (e ) );
		memset (s, 0, sizeof (s ) );
		string str;
		rep (i, N ) cin >> str >> sec_e[i] >> sec_s[i];
		rep (j, M ) cin >> str >> e[j] >> s[j];
		int res = solve() ;
		cout << res << endl;
	} // end while	
		
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  map<char,int> m;
  for(int i=0; i<s.size(); i++) m[s[i]]++;
  bool f=1;
  if(m['S']&&!m['N']) f=0;
  if(!m['S']&&m['N']) f=0;
  if(m['E']&&!m['W']) f=0;
  if(!m['E']&&m['W']) f=0;
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  char moji[2];
  int length;

  scanf("%255[^\n]%zn", moji, &length);
  if (length == 3) {
    char k = moji[0];
    moji[0] = moji[2];
    moji[2] = k;
  }
  printf("%s\n", moji);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	int N;
	scanf("%d", &N);
	if (N % 10 == 9 || N / 10 == 9) return !printf("Yes\n");
	return !printf("No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

LL cal(LL x){
    LL num = 0;
    LL fv = 10;
    while(true){
        LL c = x/fv;
        if(c == 0)break;
        num += c;
        fv *= 5;
    }
    return num;
}

int main() {
    LL N;cin >> N;
    if(N % 2 == 1)cout << 0 << endl;
    else cout << cal(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

  for(;;){
 nextq:
  int n,q;
  cin>>n>>q;
  if(!n) break;
  int a[110]={};
  for(int i=0;i<n;i++){
    int m;
    cin>>m;
    for(int j=0;j<m;j++){
      int d;
      cin>>d;
      a[d]++;
    }
  }

  int a_max=0;

  for(int i=0;i<110;i++) a_max=max(a_max,a[i]);
  if(a_max<q){
    cout<<0<<endl;
    goto nextq;
  }

  for(int i=0;i<110;i++){
    if(a_max==a[i]){
      cout<<i<<endl;
      goto nextq;
    }
  }

  }

  return 0;

}



Measured memory_bytes: 2968
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;
typedef std::pair<int,int> P;
const ll SIZE= 100010;

ll N,K,A[SIZE];
ll sa=INF;
int main() {
    std::ios_base::sync_with_stdio(false);
    cin>>N>>K;
    REP(i,N)cin>>A[i];
    std::sort(A,A+N);
    if(A[N-1]<K)cout<<"IMPOSSIBLE";
    else if(A[N-1]==K)cout<<"POSSIBLE";
    else if(A[N-1]>K){
        bool f=false;
        REP(i,N-1){
            if((ll)abs(A[i+1]-A[i])!=0)sa=std::min(sa,(ll)abs(A[i+1]-A[i]));
            if(A[i]==K){cout<<"POSSIBLE"; return 0;}
        }
        if(sa!=1&&abs(sa-A[0])!=0)sa=std::min(sa,(ll)abs(sa-A[0]));
        sa=std::min(sa,A[0]);
        //DEB(sa)END
        if(sa==0){cout<<"IMPOSSIBLE"; return 0;}
        REP(i,N){
            if((A[i]-K)%sa==0)f=true;
        }
        if(f)cout<<"POSSIBLE";
        else cout<<"IMPOSSIBLE";
    }

    return 0;
}


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

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  int a = max(h,w);
  cout << (n+a-1)/a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[2000][2001];
int val[2000][2001];

int main(int argc, char* argv[])
{
    int h,w;
    scanf("%d%d", &h, &w);
    int i,j;
    for(i=0; i<h; i++) {
        scanf("%s", str[i]);
    }
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            int cnt=0;
            int k=j;
            while(k<w) {
                if(str[i][k]=='.') {
                    k++;
                    cnt++;
                }
                else {
                    break;
                }
            }
            k--;
            int p;
            for(p=j; p<=k; p++) {
                val[i][p]+=cnt;
            }
            j=MAX(j,k);
        }
    }

    for(i=0; i<w; i++) {
        for(j=0; j<h; j++) {
            int cnt=0;
            int k=j;
            while(k<h) {
                if(str[k][i]=='.') {
                    k++;
                    cnt++;
                }
                else {
                    break;
                }
            }
            k--;
            int p;
            for(p=j; p<=k; p++) {
                val[p][i]+=cnt;
            }
            j=MAX(j,k);
        }
    }

    int ans=0;
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(str[i][j]=='.') val[i][j]--;

            ans=MAX(ans,val[i][j]);
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << a - (a > b) << endl;   
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]

use std::collections::*;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut a = vec![vec![0 as usize; m]; n];
    for i in 0..n {
        for j in 0..m {
            a[i][j] = sc.read();
            a[i][j] -= 1;
        }
    }
    let ans = solve(&a, vec![true; m], m - 1);
    println!("{}", ans);
}

fn solve(a: &Vec<Vec<usize>>, mut now: Vec<bool>, rep: usize) -> i32 {
    let (n, m) = (a.len(), a[0].len());
    let mut count: Vec<i32> = vec![0; m];
    for i in 0..n {
        for j in 0..m {
            if now[a[i][j]] {
                count[a[i][j]] += 1;
                break;
            }
        }
    }
    let (index, &cand) = count.iter().enumerate().max_by_key(|item| item.1).unwrap();
    if rep == 0 {
        cand
    } else {
        now[index] = false;
        std::cmp::min(cand, solve(a, now, rep - 1))
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 4352
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	ll n;
	cin >> n;
	vector<int> vv;
	int ans = 0;
	while (n) {
		vv.push_back(n % 10);
		ans += n % 10;
		n /= 10;
	}
	int cur = 0;
	for (int i = vv.size() - 1; i >= 0; --i) {
		if (vv[i] > 0) {
			ans = max(ans, cur + vv[i] - 1 + i * 9);
		}
		cur += vv[i];
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int size = n+m, arr[size] = { 1 }, cnt = 0, i, j;
    
    for (i=0; i<n; i++) arr[i] = 2;
    for (i=n; i<size; i++) arr[i] = 1;
    
    //for (i=0; i<size; i++) cout << arr[i] << "\t";
    
    for (i=0; i<size; i++) {
        for (j=i+1; j<size; j++) {
            if (!((arr[i]+arr[j])%2)) {
                //cout << i << " " << arr[i] << "\t" << j << " " << arr[j] << "\n";
                ++cnt;
            }
        }
    }
        
    cout << cnt;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int n;
	cin>>n;
	int k;
	cin>>k;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		
		int w=min(x,n-x+1);
		int h=min(y,n-y+1);
		int ans=min(w,h);
		cout<<(ans-1)%3+1<<endl;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
int dp[3001][3001];
int main(void)
{
	int N,T,S,i,j,max=0,A[3001],B[3001];
	scanf("%d%d%d",&N,&T,&S);
	for(i=1;i<=N;i++){
		scanf("%d%d",&A[i],&B[i]);
	}
	for(i=0;i<=N;i++){
		for(j=0;j<=T;j++){
			dp[i][j]=-1;
		}
	}
	dp[0][0]=0;
	for(i=0;i<N;i++){
		for(j=0;j<=T;j++){
			if(dp[i+1][j]<dp[i][j]){
				dp[i+1][j]=dp[i][j];
			}
			if(dp[i][j]!=-1){
				if(j<S&&S<j+B[i+1]){
						if(S+B[i+1]<=T&&dp[i+1][S+B[i+1]]<dp[i][j]+A[i+1]){
							dp[i+1][S+B[i+1]]=dp[i][j]+A[i+1];
						}
				}
				else if(j>=S||S>=j+B[i+1]){
					if(j+B[i+1]<=T&&dp[i+1][j+B[i+1]]<dp[i][j]+A[i+1]){
							dp[i+1][j+B[i+1]]=dp[i][j]+A[i+1];
					}
				}
			}
		}
	}
	/*for(i=0;i<=N;i++){
		for(j=0;j<=T;j++){
			printf("%d ",dp[i][j]);
		}
		printf("\n");
	}*/
	for(i=0;i<=T;i++){
		if(max<dp[N][i]){
			max=dp[N][i];
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 37932
import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int ni = 2;
	int max = 0;
	if(N == 1){
		System.out.println(1);
	}else{
	while(true){
		if(ni <= N){
			max = ni;
		}else{
			System.out.println(max);
			break;
		}
		ni *= 2;
	}
	}
	}
}	
	



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

int x[200000];
int maxn, maxh, maxw;

void prime(int p) {
	for (int i = 2; i < p; i++) {
		for (int j = 2; j*j <= i; j++) {
			if (i%j == 0) {
				goto E;
			}
		}
		x[i] = 1;
	E:;
	}
}

int m, a, b, c;

int main() {
	prime(200000);
	while (true) {
		maxn = 0;
		cin >> m >> a >> b;
		if (m + a + b == 0) { break; }
		for (int i = sqrt(m); i >= 0; i--) {
			if (x[i] == 1) {
				c = m / i;
				for (int j = c; j >= 0; j--) {
					if (x[j] == 1) {
						if ((double)(1.0*a / b) <= (double)(1.0*i / j)) {
							if (i*j >= maxn) {
								maxn = i*j;
								maxh = i;
								maxw = j;
							}
						}
					}
				}
			}
		}
		cout << maxh << ' ' << maxw << endl;
	}
}

Measured memory_bytes: 1940
#include <iostream>

using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;

	int c;
	c = a + b;

	if (c < 10) {
		cout << c << endl;
	}
	if (c >= 10) {
		cout << "error" << endl;
	}

	
}

Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
#define req(i,n) for(int i = 1;i <= n;i++)
ll n,m, sum = 0;
const ll MOD = 1000000007;
int main() {
    cin >> n >> m; vector<ll> a(n + 1,0);
    req(i, n) a[i] = a[i - 1] + i;
    for (int i = m; i <= n; i++) {
        sum += (a[n] - a[n - i] - a[i - 1] + 1);
        sum %= MOD;
    }
    cout << sum + 1 << endl;
}

Measured memory_bytes: 4680
row, col = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(row)]
ans   = [[0 for c in range(col+1)] for r in range(row+1)]

for r in range(row):
    for c in range(col+1):
        if c == col:
            ans[r][c] = sum(table[r][:])
        else:
            ans[r][c] = table[r][c]
        ans[row][c] += ans[r][c]
        
    print(*ans[r][:])
print(*ans[row][:])


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n), f(n);
    rep (i, n) cin >> a[i];
    rep (i, n) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<int>());
    ll l = -1, r = 1e12, mid;
    while (l + 1 < r) {
        mid = (l + r) / 2;
        ll x = k;
        rep(i, n) {
            ll t = max((ll)0, (ll)(a[i] - mid / f[i]));
            x -= t;
        }
        if (x >= 0) r = mid;
        else l = mid;
    }
    cout << r << endl;
    
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    string s;cin >> s;
    for(int a = 0;a < s.size();a++){
        if(a%2==0){
            cout<<s.at(a);
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

int main(){
	string s; cin >> s;
	stack<int> sti;
	stack<pair<int, int>> stp;
	int sum = 0;
	for(int i=0; i<s.size(); i++){
		if(s[i] == '\\') sti.push(i);
		else if(s[i] == '/'){
			if(sti.empty()) continue;
			int t = sti.top(); sti.pop();
			pair<int, int> p = make_pair(t, i-t);
			sum += i-t;
			while(!stp.empty() && stp.top().first > t){
				pair<int, int> q = stp.top(); stp.pop();
				p.second += q.second;
			}
			stp.push(p);
		}
	}
	cout << sum << endl;
	int n = stp.size();
	if(!n){
		cout << n << endl;
		return 0;
	}
	cout << n << " ";
	vector<int> l(n);
	for(int i=0; i<n; i++){
		pair<int, int> p = stp.top(); stp.pop();
		l[n-1-i] = p.second;
	}
	for(int i=0; i<n; i++){
		cout << l[i];
		if(i < n-1) cout << " ";
	}
	cout << endl;
}


Measured memory_bytes: 3328
n = gets.to_i
a = gets.strip.split.map(&:to_i).sort.reverse
cnt = 0

(1..n-1).each do |i|
  if i == 1
    cnt += a[i-1]
    next
  end
  i = i + 2
  i = i / 2
  i = i.floor
  cnt += a[i-1]
end

puts cnt

Measured memory_bytes: 33380
n,a,b=map(int,input().split())

c=a+b
if a==0:
    print(0)
if c!=0 and a!=0:
    d=n//c
    num=a*d
    if n%c<=a:
        print(num+n%c)
    elif n%c>a:
        print(num+a)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int a, b, answer;
    char opera;

    while (true)
    {
        cin >> a >> opera >> b;
        if ('?' == opera) break;
        switch (opera)
        {
        case '+':
            answer = a + b;
            break;
        case '-':
            answer = a - b;
            break;
        case '*':
            answer = a * b;
            break;
        case '/':
            answer = a / b;
            break;
        default:
            break;
        }
        cout << answer << endl;
    }

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int A, B, C; cin>> A >> B >> C;
    bool judge = false;

    rep(i, B){
        if(A*(i + 1) % B == C) judge = true;
    }

    if(judge) cout<< "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 3636
object Main extends App {

  import scala.io.StdIn._

  var n = readLine.toInt
  while (n != 0) {
    val vote = readLine.trim.split(' ').map(_.charAt(0)).toList
    val voteCount = Array.tabulate(27){_ ⇒ 0}
    println(
      search(vote, voteCount, ('A' + 26).toChar, ('A' + 26).toChar) match{
        case Some((winner, count)) ⇒ s"$winner $count"
        case None ⇒ "TIE"
      }
    )
    n = readLine.toInt
  }
  def search(vote: List[Char], voteCount: Array[Int], first: Char = 'A', second: Char = 'A', count: Int = 0): Option[(Char, Int)] = {
    if (vote.size + voteCount(second - 'A') < voteCount(first - 'A')) Some(first, count)
    else vote match{
      case Nil ⇒
        if (voteCount(first - 'A') == voteCount(second - 'A')) None
        else Some(first, count)
      case `first`::t ⇒ voteCount(first - 'A') += 1
        search(t, voteCount, first, second, count + 1)
      case `second`::t ⇒ voteCount(second - 'A') += 1
        if (voteCount(first - 'A') > voteCount(second - 'A')) search(t, voteCount, first, second, count + 1)
        else search(t, voteCount, second, first, count + 1)
      case h::t ⇒ voteCount(h - 'A') += 1
        if (voteCount(second - 'A') > voteCount(h - 'A')) search(t, voteCount, first, second, count + 1)
        else if (voteCount(first - 'A') > voteCount(h - 'A')) search(t, voteCount, first, h, count + 1)
        else search(t, voteCount, h, first, count + 1)
    }
  }
}



Measured memory_bytes: 54824
def sousa(a,b)
  if a%2 == 1
    a -= 1
  end
  a /= 2
  b += a
  return [a,b]
end

a,b,k = gets.chomp.split.map(&:to_i)
(k/2).times do
  a,b = sousa(a,b)
  b,a = sousa(b,a)
end
if k%2 == 1
  a,b = sousa(a,b)
end
print("#{a} #{b}")


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b; cin>>a>>b;
	if((a+b)&1)cout<<"IMPOSSIBLE"s;
	else cout<<(a+b)/2;
	cout<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n, ans;
int main() {
    cin >> n;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i == 0){
            ll m = n / i - 1;
            if (m > i)
                ans += m;
        }
    }
    cout << ans << endl;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n, 0);
    for (int i = 1; i < n; i++) {
        int c; cin >> c;
        a[--c]++;
    }
    for (auto &x: a) cout << x << "\n";
    return 0;
}

Measured memory_bytes: 3988
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>

using namespace std;

int getint()
{
    char ch=getchar();
    int f=1,x=0;
    while(!isdigit(ch)){if(ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return f*x;
}

const int N=16;

int n,m;
int map[N][N];
int f[1<<15][N];
int slf[1<<15],ot[1<<15][N];
int tot;

void init()
{
    n=getint(),m=getint();
    for(int i=1; i<=m; i++){
        int u=getint(),v=getint(),w=getint();
        map[u][v]=map[v][u]=w;
        tot+=w;
    }
    for(int s=1; s<(1<<n); s++){
        for(int j=1; j<=n; j++){
            if(s&(1<<(j-1))){
                for(int k=j+1; k<=n; k++){
                    if(!(s&(1<<(k-1)))) continue;
                    slf[s]+=map[j][k];
                }
            }else{
                for(int k=1; k<=n; k++){
                    if(!(s&(1<<(k-1)))) continue;
                    ot[s][j]+=map[j][k];
                }
            }
        }
    }
}

int main()
{
    init();
    memset(f,128,sizeof(f));
    f[1][1]=0;
    for(int s=1; s<(1<<n); s+=2){
        for(int i=1; i<=n; i++){
            if(!(s&(1<<(i-1)))) continue;
            for(int t=s&(s-1); t; t=s&(t-1)){
                if(!(t&1)) continue;
                f[s][i]=max(f[s][i],f[t][i]+slf[s^t]+ot[s^t][i]);
            }
            for(int j=1; j<=n; j++){
                if(i==j || !(s&(1<<(j-1)))) continue;
                if(map[i][j]==0) continue;
                f[s][i]=max(f[s][i],f[s^(1<<(i-1))][j]+map[i][j]);
            }
        }
    }
    printf("%d\n",tot-f[(1<<n)-1][n]);
    return 0;
}


Measured memory_bytes: 4352