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

using namespace std;

int main()
{
   long long a,b;
   cin>>a>>b;
   if ((a-b)>=(a*b)&&(a-b)>=(a+b))

    cout<<a-b;

    else if ((a*b)>=(a-b)&&(a*b)>=(a+b))

       cout<<a*b;

     else if ((a+b)>=(a*b)&&(a+b)>=(a-b))

       cout<<a+b;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string>grid(h);
	REP(i, h) {
		cin >> grid[i];
	}
	vector<vector<int>>dist(h, vector<int>(w, -1));      //h行w列の二次元配列の要素を-1とする
	vector<pair<int, int>>q;
	REP(i, h) {
		REP(j, w) {
			if (grid[i][j] == '#') {
				q.emplace_back(i, j);     //黒マスの座標をqの末尾に追加
				dist[i][j] = 0;           //黒マスの座標の要素を0とする
			}
		}
	}
	REP(i, q.size()) {                    //黒マスの数の回数
		for (int dx = -1; dx <= 1; dx++) {
			for (int dy = -1; dy <= 1; dy++) {
				if (dx*dx + dy * dy == 1) {           //(dx,dy)=(1,0)(-1,0)(0,1)(0,-1)のとき(上下左右四方向)
					int x = q[i].first + dx;
					int y = q[i].second + dy;
					if (x >= 0 && y >= 0 && x < h&&y < w&&dist[x][y] == -1) {        //用意したマス目上かつ白マスのとき
						q.emplace_back(x, y);               //白マスの座標をqの末尾に追加
						dist[x][y] = dist[q[i].first][q[i].second] + 1;          //黒マスからのマンハッタン距離
					}
				}
			}
		}
	}
	cout << dist[q.back().first][q.back().second] << endl;
	return 0;
}

Measured memory_bytes: 14572
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int a, b, c;

void input() { cin >> a >> b >> c; }
void solve() {
  cout << ((b - a) == (c - b) ? "YES" : "NO") << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
input = $stdin.read.split("\n")
X = input[0].split(' ')[2].to_i
Y = input[0].split(' ')[3].to_i
if X > Y
  puts 'War'
  exit
end
x = input[1].split(' ').map(&:to_i).sort!
y = input[2].split(' ').map(&:to_i).sort!
if x.last < y.first && (x.last > X && y.first <= Y)
  puts 'No War'
else
  puts 'War'
end

Measured memory_bytes: 1788
/*	[]__________[][][][]____[][][][][]__{}__[][][][]____[][][][][]__[][][][]
    []__________[]______________[]__________[]__________[]__________[]____[]
    []__________[][][][]________[]__________[][][][]____[]__________[]____[]
    []__________[]______________[]________________[]____[]__[][][]__[]____[]
    []__________[]______________[]________________[]____[]______[]__[]____[]
    [][][][]____[][][][]________[]__________[][][][]____[][][][][]__[][][][]
*/
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define endl '\n'
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define decimal(x) cout<<fixed<<setprecision(x);
vector<int>adj[200005];
bool vis[200005];
int n;
vector<int>temp;
int c;
void dfs(int x)
{
    vis[x]=true;
    c++;
    for(auto i:adj[x])
    {
        if(!vis[i])
        dfs(i); 
    }
}
void helper()
{
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==false)
        {
            dfs(i);
            ans=max(ans,c);
            c=0;
        }
    }
    cout<<ans<<endl;
}
void solve()
{
    int  m;
    cin>>n>>m;
    while(m--)
    {
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    helper();
}	
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
       //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 20924
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, m, q;
vector <vector <int> > a, g, l, u;

int calc(vector <vector <int> > &c, int x1, int y1, int x2, int y2){
    if(x2 < x1 || y2 < y1) return 0;
    return c[x2][y2] - c[x2][y1 - 1] - c[x1 - 1][y2] + c[x1 - 1][y1 - 1];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> q;
    a.resize(n + 1, vector <int>(m + 1));
    g.resize(n + 1, vector <int>(m + 1));
    l.resize(n + 1, vector <int>(m + 1));
    u.resize(n + 1, vector <int>(m + 1));
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            char c;
            cin >> c;
            a[i][j] = c - '0';
            l[i][j] = a[i][j] == 1 && a[i][j - 1] == 0;
            u[i][j] = a[i][j] == 1 && a[i - 1][j] == 1;
        }
    }
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            g[i][j] = g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1] + a[i][j];
            l[i][j] += l[i - 1][j] + l[i][j - 1] - l[i - 1][j - 1];
            u[i][j] += u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1];
        }
    }
    while(q--){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int ans = 0;
        if(a[x1][y1]) ans++;
        ans += calc(l, x1, y1 + 1, x1, y2);
        ans += calc(g, x1 + 1, y1, x2, y1);
        ans += calc(l, x1 + 1, y1 + 1, x2, y2);
        ans -= calc(u, x1 + 1, y1, x2, y2);
        cout << ans << "\n";
    }
}


Measured memory_bytes: 65280
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n, h, w,sum =0;cin >> n >> h >> w;
	vector<int> a(n), b(n);
	rep(i, n) {
		cin >> a[i] >> b[i];
		if (a[i] >= h && b[i] >= w) sum++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int h,w,i,j;
        while(true){
        h = s.nextInt();
        w = s.nextInt();
        if(h==0&&w==0)break;
        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                if(i % 2 == 1 && j % 2 == 1)System.out.print("#");
                else if (i % 2 == 0 && j % 2 == 0){System.out.print("#");}
                else {System.out.print(".");
                    
                }
            }
            System.out.println();
        }
        System.out.println();
    }
    }
}


Measured memory_bytes: 34828
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		
		InputStreamReader isr= new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		
		String strNum = br.readLine();
		String[] strNumList = strNum.split(" ");
		
		int intNumA = Integer.parseInt(strNumList[0]);
		int intNumB = Integer.parseInt(strNumList[1]);
		int intNumC = Integer.parseInt(strNumList[2]);
		
		String strResult = "";
		
		if(intNumA < intNumB) {
			if(intNumB < intNumC) {
				strResult = "Yes";
			}else {
				strResult = "No";
			}
		}else {
			strResult = "No";
		}
		System.out.println(strResult);
	}
}


Measured memory_bytes: 24460
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)

using namespace std;

void dfs(vector<vector<int>> &tree,vector<int> &res, vector<int> &vis,int fir,int depth)
{
//    printf("%d %d\n",fir,depth);
    res[fir]=depth;
    forn(i,(int)tree[fir].size())
    {
//        printf("%d\n",tree[fir][i]);
        if(vis[tree[fir][i]]==0)
        {
           vis[tree[fir][i]]=1;
           dfs(tree,res,vis,tree[fir][i],depth+1);
        }
    }
}

int lastdfs(vector<vector<int>> &tree,vector<int> &fi,vector<int> &se, vector<int> &vis,int fir)
{
//    res[fir]=depth;
//    printf("%d %d %d\n",fir,fi[fir],se[fir]);
    int maxx=(fi[fir]-se[fir])%2==0?fi[fir]-1:fi[fir]-1;
    bool flag=false;
    forn(i,(int)tree[fir].size())
    {
        if(fi[tree[fir][i]]>se[tree[fir][i]])
        {
            flag=true;
            break;
        }
    }
    if(!flag)
    {
        return maxx;
    }
    forn(i,(int)tree[fir].size())
    {
//        printf("%d %d %d %d\n",tree[fir][i],fi[tree[fir][i]],se[tree[fir][i]],vis[tree[fir][i]]);
        if(vis[tree[fir][i]]==0&&fi[tree[fir][i]]>se[tree[fir][i]])
        {
//            printf("42\n");
           vis[tree[fir][i]]=1;
           maxx=max(maxx,lastdfs(tree,fi,se,vis,tree[fir][i]));
        }
    }
    return maxx;
}
int main()
{
    int n,v,u;
    scanf("%d%d%d",&n,&u,&v);
    u--;
    v--;
    vector<vector<int>> tree(n);
    forn(i,n-1)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        tree[x-1].pb(y-1);
        tree[y-1].pb(x-1);
    }
    vector<int>fir(n),sec(n);
    vector<int>vis(n);
    vis[v]=1;
    dfs(tree,fir,vis,v,0);
    forn(i,n)vis[i]=0;
    vis[u]=1;
    dfs(tree,sec,vis,u,0);
    forn(i,n)vis[i]=0;
    vis[u]=1;
    printf("%d\n",max(0,lastdfs(tree,fir,sec,vis,u)));
    return 0;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int num;
    while(cin>>num)
    {
        set<string> s;
        for(int i=0;i<num;i++)
        {
            string temp;
            cin>>temp;
            s.insert(temp);
        }
        cout<<s.size()<<endl;
    }
}


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

int main() {
	ll n;
	string s;
	cin >> n >> s;
	ll hi = 0;
	ll to = 0;
	for (char c : s) {
		if (c == '(') {
			++to;
		}
		else {
			if (to > 0)--to;
			else ++hi;
		}
	}
	string ans;
	for (ll i = 0; i < hi; ++i)ans += "(";
	ans += s;
	for (ll i = 0; i < to; ++i)ans += ")";
	cout << ans << endl;
}


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

int H, W;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};

bool inside(int x, int y) {
  return (x >= 0 && y >= 0 && x < H && y < W);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> H >> W;
  vector<vector<ll>> cells(H, vector<ll>(W, 0));
  for (int i = 0; i < H; i++) {
    string S; cin >> S;
    for (int j = 0; j < W; j++) {
      if (S[j] == '#') cells[i][j] = 1;
    }
  }

  ll ans = 0;
  vector<vector<bool>> used(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (used[i][j]) continue;
      used[i][j] = true;

      set<pair<int, int>> b, w;
      if (cells[i][j] == 1) b.insert(make_pair(i, j));
      else w.insert(make_pair(i, j));

      queue<pair<int, int>> q;
      q.push(make_pair(i, j));

      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        int px = p.first, py = p.second;
        if (cells[px][py] == 1) b.insert(p);
        else w.insert(p);

        for (int k = 0; k < 4; k++) {
          int nx = px + dx[k];
          int ny = py + dy[k];
          if (inside(nx, ny) && !used[nx][ny] && cells[px][py] != cells[nx][ny]) {
            used[nx][ny] = true;
            
            pair<int, int> n = make_pair(nx, ny);
            if (cells[nx][ny] == 1) b.insert(n);
            else w.insert(n);
            q.push(n);
          }
        }
      }
      ans += b.size() * w.size();
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  cin >> s;
  int a,i,j,cnt = 0;
  a = s.length();
  i = 0;
  j = a - 1;
  while(i <= (a / 2 - 1)){
    if(s.at(i) != s.at(j)){
      cnt++;
    }
    i++;
    j--;
  }
  cout << cnt;
}



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

ll getnum(ll b,int s){
  ll r=0,x=1;
  for(int i=0;i<=s;i++){
    if((b&(1<<i)))r+=x;
    x*=2;
  }
  return r;
}

ll stoll(string s){
  ll r=0,x=16;
  for(int i=0;i<s.size();i++){
    if('0'<=s[i]&&s[i]<='9')r=r*x+s[i]-'0';
    else r=r*x+s[i]-'a'+10;
  }
  return r;
}

int main(){
  int d,f;
  string s;
  ll b[9],ans;
  cin>>d;
  while(d--){
    for(int i=0;i<9;i++)cin>>s,b[i]=stoll(s);
    ans=0;
    for(int i=0;i<32;i++){
      ll sum=0;
      for(int j=0;j<8;j++)sum+=getnum(b[j],i);
      f=0;
      for(int j=0;j<=i;j++)
	if((sum&(1LL<<j))!=(b[8]&(1LL<<j)))f=1;
      if(f){
	ans|=(1LL<<i);
	for(int j=0;j<9;j++)b[j]^=(1LL<<i);
      }
    }
    printf("%llx\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1212
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    cout << (a - b) * ((k & 1) ? -1 : 1) << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin>>n;
	ll a[n],sum=0, mx=0;
	for(ll i=0; i<n; i++){
		cin>>a[i];
		if(mx<a[i]){
			mx=a[i];
		}
		else
			sum+=mx-a[i];

	}
	cout<<sum;
}

Measured memory_bytes: 5192
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int i;
  for(i=0;i<N;i++)cin >> A[i];
  sort(A.begin(),A.end(),greater<int>());
  long long ans = 0;
  for(i=1;i<N;i++) {
    ans += A[i/2];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4044
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
//#define int long long
int mas[2002][2002];
int mass[2002][2002];
int masss[2002][2002];
int ps[2002][2002];
int inter1[2002][2002];
int inter2[2002][2002];
int get_sum(int i, int j, int ii, int jj) {
	return ps[ii][jj] - ps[ii][j - 1] - ps[i - 1][jj] + ps[i - 1][j - 1];
}
int get_inter1(int i, int j, int ii, int jj) {
	if (ii < i) return 0;
	return inter1[ii][jj] - inter1[ii][j - 1] - inter1[i - 1][jj] + inter1[i - 1][j - 1];
}
int get_inter2(int i, int j, int ii, int jj) {
	if (jj < j) return 0;
	return inter2[ii][jj] - inter2[ii][j - 1] - inter2[i - 1][jj] + inter2[i - 1][j - 1];
}
signed main() {
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			char c;
			cin >> c;
			if (c == '1') mas[i][j] = 1;
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			mass[i][j] = (mas[i][j] * mas[i + 1][j] == 1);
			masss[i][j] = (mas[i][j] * mas[i][j + 1] == 1);
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			ps[i][j] = ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + mas[i][j];
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			inter1[i][j] = inter1[i - 1][j] + inter1[i][j - 1] - inter1[i - 1][j - 1] + mass[i][j];
			inter2[i][j] = inter2[i - 1][j] + inter2[i][j - 1] - inter2[i - 1][j - 1] + masss[i][j];
		}
	}
	while (q--) {
		int i, j, ii, jj;
		scanf("%d %d %d %d", &i, &j, &ii, &jj);
		int f = get_sum(i, j, ii, jj);
		int s = get_inter1(i, j, ii - 1, jj) + get_inter2(i, j, ii, jj - 1);
		printf("%d\n", f - s);
	}
}

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

int main() {

	int n; cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector<int> ans(n + 1, 0);
	for (int i = n; i >= 1 ; i--) {
		int tmpSum = 0;
		for (int j = i + i; j <= n; j += i) {
			tmpSum += ans[j];
		}
		if (tmpSum % 2 != a[i]) {
			ans[i] = 1;
		}
	}
	vector<int> b;
	for (int i = 1; i <= n; i++) {
		if (ans[i]) b.push_back(i);
	}
	cout << b.size() << endl;
	for (int i = 0; i < b.size(); i++) {
		cout << b[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 5296
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, Q; cin >> N >> Q;
	vector<int>a(N + 1, 0);
	rep(i, 1, N + 1)cin >> a[i];
	rep(i, 1, N + 1)a[i] += a[i - 1];
	rep(i, 0, Q) {
		int x; cin >> x;
		int ans(0);
		rep(j, 1, N + 1) {
			ans += j-distance(a.begin(), lower_bound(all(a), a[j] - x));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>
#include <math.h>

int main(void)
{
	int n;
	int k;
	int total;
	double ave;
	int s;
	
	total = 0; s = 0; ave = 0;
	while (scanf("%d,%d", &n, &k) != EOF){
		total += n * k;
		s++;
		ave += k;
	}
	ave /= s;
	ave = floor(ave + 0.5);
	printf("%d\n%.0lf\n", total, ave);
	
	return (0);
}

Measured memory_bytes: 1056
#include<stdio.h>
long long MAX(long long a,long long b){return a<b?b:a;}
long long MIN(long long a,long long b){return a<b?a:b;}
long long n,w,a,i,j,k,max=0,m[110][2],d[110][110][410]={1};
int main(){
  scanf("%lld %lld",&n,&w);
  for(i=0;i<n;i++)scanf("%lld %lld",&m[i][0],&m[i][1]);
  a=m[0][0];
  for(i=0;i<n;i++)m[i][0]-=a;
  for(i=0;i<n;i++){
    for(j=i;j>-1;j--){
      for(k=0;k<=400;k++){
	if(d[i][j][k]==0)continue;
	d[i+1][j][k]=d[i][j][k];
	d[i+1][j+1][k+m[i][0]]=MAX(d[i+1][j+1][k+m[i][0]],d[i][j][k]+m[i][1]);
      }
    }
  }
  for(i=0;i<=n;i++){
    for(j=0;j<400;j++){
      if(i*a+j<=w)max=MAX(max,d[n][i][j]);
    }
  }
  printf("%lld\n",max-1);
  return 0;
}


Measured memory_bytes: 16768
#include"stdio.h"
#include"stdlib.h"
int main()
{
  int num;
  int *A;
  int i,j,k;
  int v;
  scanf("%d",&num);
  if(0<=num&&num<=1000)
    {
      A=(int*)malloc(sizeof(int)*num);
    }
  for(k=0;k<num;k++)
    {
      scanf("%d",&A[k]);
    }
  printf("%d",A[0]);
  for(k=1;k<num;k++)
    {
      printf(" %d",A[k]);
    }
  printf("\n");
  for(i=1;i<num;i++)
    {
      if(A[i-1]>A[i])
	{
	  v=A[i];
	  j=i-1;
	  while(j>=0&&A[j]>v)
	    {
	      A[j+1]=A[j];
	      j--;
	    }
	  A[j+1]=v;
	}
      printf("%d",A[0]);
      for(k=1;k<num;k++)
	{
	  printf(" %d",A[k]);
	}
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2064
#include <cstdio>
using namespace std ;
const int MAXN = 1e5 + 10 ;
int n , a[MAXN] , cnt[MAXN] , sum[1 << 16] , f[1 << 16] , ans , t ;
int min (int a , int b) {
	return a < b ? a : b ;
}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i < n ; i++) {
		int u , v , w ;
		scanf ("%d %d %d" , &u , &v , &w) ;
		a[u] ^= w ; a[v] ^= w ;
	}
	for (int i = 0 ; i < n ; i++) cnt[a[i]]++ ;
	for (int i = 1 ; i < 16 ; i++) {
		ans += (cnt[i] >> 1) ;
		if (cnt[i] & 1) t |= (1 << (i - 1)) ;
	}
	for (int i = 1 ; i < (1 << 15) ; i++)
		f[i] = f[i >> 1] + (i & 1) ;
	for (int i = 1 ; i < (1 << 15) ; i++) f[i]-- ;
	for (int i = 1 ; i < (1 << 15) ; i++)
		for (int j = 0 ; j < 15 ; j++)
			if (i & (1 << j)) 
				sum[i] ^= (j + 1) ;
	for (int i = 1 ; i < (1 << 15) ; i++)
		if (!sum[i])
			for (int j = (i - 1) & i ; j ; j = (j - 1) & i)
				if (!sum[j])
					f[i] = min (f[i] , f[j] + f[i ^ j]) ;
	printf ("%d\n" , ans + f[t]) ;
	return 0 ;
}

Measured memory_bytes: 2364
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String a = sc.next();
 
   if(a.equals("a")||a.equals("u")||a.equals("o")||a.equals("i")||a.equals("e"))System.out.println("vowel");
   else System.out.println("consonant");
 }
}

Measured memory_bytes: 21588
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 500010

int C[SIZE];
ll D[SIZE];

int main(){
  int N, P, Q;

  ll sum = 0;

  scanf("%d%d%d", &N, &P, &Q);

  for (int i=0; i<N; i++) {
    scanf("%d", C+i);
    sum += C[i];
    D[i] = (ll)P * i + C[i];
    debug(D[i]);
  }

  sort(D, D+N);

  ll ans = sum;

  for (int i=0; i<N; i++) {
    ll E = (ll)P * (Q + 2 * i);
    sum += E - D[i];
    ans = max(ans, sum);
  }

  printf("%lld\n", ans);

  return 0;
}



Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int dp[100001];
int power(int x,int y)
{ int temp;
    if(y==0)
        return 1;
    temp=power(x,y/2)%mod;
    if(y%2==0)
        return (temp%mod*temp%mod)%mod;
    else
        return ((x%mod)*((temp%mod*temp%mod)%mod))%mod;
}
int check(vector<int>&v,int i,int n,int k)
{ if(i>=n)
   {
    return 0;
   }
   if(dp[i]!=-1)
    return dp[i];
   int m=INT_MAX;
  for(int j=i+1;(j<=(i+k)&&j<=n);j++)
  {
   m=min(m,abs(v[i]-v[j])+check(v,j,n,k));
  }
  
  return dp[i]=m;

}

void solve()
{ int n,k;
  cin>>n>>k;
  vector<int>v(n+1);
  for(int i=0;i<100001;i++)
    dp[i]=-1;
  for(int i=1;i<=n;i++)
    cin>>v[i];
  int ans=check(v,1,n,k);
  cout<<ans<<endl;

}
signed main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
            #ifndef ONLINE_JUDGE
        freopen("input1.txt","r",stdin);
        freopen("output1.txt","w",stdout);
         #endif

    int t;
    //cin>>t;
    t=1;
    for(int i=1;i<=t;i++)
        {solve();
        }



        return 0;     

    }

Measured memory_bytes: 14164
//Bismillahir Rahmanir Rahim
#include<iostream>
#include<cstdio>
#include<string.h>

int main()
{
    /*freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);*/
    int a,b,c;
    char str[100];
    scanf("%s",str);
    int ln=strlen(str);
    printf("2018");
    for(int i=4;i<ln;i++){
        printf("%c",str[i]);
    }
    printf("\n");





    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

bool is_con(char S){
if (S =='A'||S =='G'||S =='C'||S =='T'){return true;}
return false;
}
int main() {
int cnt =0;
int MAX=0;
string S;
cin>>S;
for (int i = 0; i < S.size(); ++i)//スタートの決め方
{
	cnt = 0;
	if (is_con(S[i]))
	{
		cnt++;
		MAX=max(cnt,MAX);
		for (int j = i+1; j < S.size(); ++j)
		{
			if (is_con(S[j])){cnt++;MAX=max(cnt,MAX);}
			else break;
		}
	}
	else continue;	
}
cout<< MAX<<endl;
return 0;
}



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

typedef struct{
  
  int parent , bro , degree , depth , type, height;
  int r,l;

}node_t;

vector<node_t> tree;

void Preorder(int);
void Inorder(int);
void Postorder(int);

int Depth(int num , int d){

  int lowest=0;
  int work=0;

  tree[num].depth = d;

  if(tree[num].degree == 0){
    tree[num].height = 0;
    return 1;
  }

  if(tree[num].l!=-1)
    lowest = Depth(tree[num].l , d+1);
  if(tree[num].r!=-1)
    work = Depth(tree[num].r , d+1);

  lowest = (lowest < work)? work : lowest;
  tree[num].height = lowest;
  
  return lowest+1;

}


int main(){

  int n,num,root;


  cin >> n;
  tree.resize(n);
  for(int i=0; i<n; i++){
    tree[i].parent = tree[i].bro = -1;
    tree[i].degree = 0;
    tree[i].type = 2;
  }


  for(int i=0; i<n; i++){
    cin >> num;
    cin >> tree[num].l >> tree[num].r;
    if(tree[num].l != -1){
      tree[num].type = 1;
      tree[ tree[num].l ].parent = num;
      tree[ tree[num].l ].bro = tree[num].r;
      tree[num].degree++;    
    }
    if(tree[num].r!=-1){
      tree[num].type = 1;
      tree[ tree[num].r ].parent = num;
      tree[ tree[num].r ].bro = tree[num].l;    
      tree[num].degree++; 
    }
  }    


  for(int i=0; i<n; i++){
    if(tree[i].parent == -1){
      tree[i].type = 0;
      tree[i].depth = 0;
      Depth(i,0);
      root = i;
      break;
    }
  }




  /*Output*/
  cout << "Preorder" << endl;
  Preorder(root);
  cout << endl;

  cout << "Inorder" << endl;
  Inorder(root);
  cout << endl;

  cout << "Postorder" << endl;
  Postorder(root);
  cout << endl;



  return 0;
}



void Inorder(int num){

  if(tree[num].l != -1)
    Inorder(tree[num].l);
  
  cout << ' ' << num;

  if(tree[num].r != -1)
    Inorder(tree[num].r);

}

void Preorder(int num){

  cout << ' ' << num;

  //if(tree[num].l != -1)cout << ' ' << tree[num].l;
  if(tree[num].l != -1)Preorder(tree[num].l);

  //if(tree[num].r != -1)cout << ' ' << tree[num].r;
  if(tree[num].r != -1)Preorder(tree[num].r);

}


void Postorder(int num){

  if(tree[num].l != -1)Postorder(tree[num].l);
  if(tree[num].r != -1)Postorder(tree[num].r);

  cout << ' ' << num;

}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
 
int main() {
    int a,b,c;
    scan3Int(a,b,c);
    if (a + b + c > 21) printf("bust\n");
    else printf("win\n");
    return 0;
}

Measured memory_bytes: 3716
import math
import sys
import os

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


a = I()
ans = 0
if a==0:
    ans = 1
print(ans)

Measured memory_bytes: 9140
N=int(input())
ans=0
A=[int(i) for i in input().split()]
flag=True
while True:
    for i in range(N):
        if A[i]%2==0:
            A[i]/=2

        else:
            flag=False
            break
    if flag==False:
        break  
    else:
        ans+=1
            
print(ans)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll A, B, C; cin >> A >> B >> C;
  string ans = "NO";
  REP(i, 100000) {
    if((i * A) % B == C) ans = "YES";
  }
  cout << ans << endl;
}

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

int main(){

    long long int l,r;
    cin >> l >> r;
    long long int ans = 2019;

    for(long long int i = l; i < r; ++i){
        for(long long int j = i+1; j<= r && j < l + 2019; ++j){
            ans = min((i*j)%2019, ans);
            if(ans == 0)break;
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n_=1<<11;
class segtree{
public:
	short dp[1<<12];
	segtree(){
		memset(dp,0,sizeof(dp));
	}
	void update(int k,int v){
		k+=n_-1;
		dp[k]+=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=dp[k*2+1]+dp[k*2+2];
		}
	}

	short query(int a,int b,int k=0,int l=0,int r=n_){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		short vl=query(a,b,k*2+1,l,mid);
		short vr=query(a,b,k*2+2,mid,r);
		return vl+vr;
	}
};

segtree seg[2001][2];
segtree seg2[2001][2];

int H,W,T,q;
int B=50;
int data[2001][2001];
int cnt[45][45];
int cnt2[45][45];


int main(void){
	scanf("%d%d%d%d",&H,&W,&T,&q);
	memset(data,-1,sizeof(data));
	queue<PP> que;
	for(int i=0;i<q;i++){
		int t,c,h,w;
		scanf("%d%d%d%d",&t,&c,&h,&w);
		while(que.size()){
			PP p=que.front();
			if(p.first<=t){
				int hh=p.second.first;
				int ww=p.second.second;
				seg[hh][0].update(ww,-1);
				seg[hh][1].update(ww,1);
				seg2[ww][0].update(hh,-1);
				seg2[ww][1].update(hh,1);
				cnt[hh/B][ww/B]--;
				cnt2[hh/B][ww/B]++;
			}else break;
			que.pop();
		}
		h--;
		w--;
		if(c==0){
			if(data[h][w]==-1){
				cnt[h/B][w/B]++;
				data[h][w]=t+T;
				seg[h][0].update(w,1);
				seg2[w][0].update(h,1);
				que.push(PP(t+T,P(h,w)));
			}
		}
		if(c==1){
			if(data[h][w]!=-1 && data[h][w]<=t){
				cnt2[h/B][w/B]--;
				data[h][w]=-1;
				seg[h][1].update(w,-1);
				seg2[w][1].update(h,-1);
			}	
		}
		if(c==2){
			int h2,w2;
			scanf("%d%d",&h2,&w2);
			int res=0;
			int res2=0;
			int nh=h;
			int nh2=h2;
			while(nh<nh2 && nh%B!=0){
				res+=seg[nh][0].query(w,w2);
				res2+=seg[nh][1].query(w,w2);
				nh++;
			}
			while(nh<nh2 && nh2%B!=0){
				res+=seg[nh2-1][0].query(w,w2);
				res2+=seg[nh2-1][1].query(w,w2);
				nh2--;
			}
			int nw=w;
			int nw2=w2;
			while(nw<nw2 && nw%B!=0){
				res+=seg2[nw][0].query(nh,nh2);
				res2+=seg2[nw][1].query(nh,nh2);
				nw++;
			}
			while(nw<nw2 && nw2%B!=0){
				res+=seg2[nw2-1][0].query(nh,nh2);
				res2+=seg2[nw2-1][1].query(nh,nh2);
				nw2--;
			}
			for(int j=nh/B;j<nh2/B;j++){
				for(int k=nw/B;k<nw2/B;k++){
					res+=cnt[j][k];
					res2+=cnt2[j][k];
				}
			}
			printf("%d %d\n",res2,res);
		}
	}
	return 0;
}

Measured memory_bytes: 83564
#include <stdio.h>

/* 選択ソート（0オリジン） */
int selectionSort(int A[], int N)
{
    int i, j, t, sw = 0, minj;
    for( i = 0; i < N - 1; i++ ){
        minj = i;
        for( j = i; j < N; j++ ){
            if( A[j] < A[minj] ) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if( i != minj ) sw++;
    }
    return sw ;
}

int main()
{
    int A[100], N, i, sw;

    scanf("%d", &N);
    for( i = 0; i < N; i++ ) scanf("%d", &A[i]);

    sw = selectionSort(A, N);

    for( i = 0; i < N; i ++ ){
        if( i > 0 ) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);

    return 0;
}

Measured memory_bytes: 604
import math
a=list(map(int,input().split(" ")))
N=a[0]
K=a[1]

upbd=min(N,K)
s=0
for i in range(1,upbd+1):
    t=math.ceil(math.log(K/i)/math.log(2))
    s+=(1/2)**t


print((s+(N-upbd))/N)


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

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

const long long MOD = 1000000007;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  if(s.at(n-1)!='s') s=s+"s";
  else s=s+"es";
  
  cout << s << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;

struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for(int i = 0; i < N; ++i) {
      par[i] = i;
    }
  }
  int root(int x) {
    if(par[x] == x) {
      return x;
    }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    auto rx = root(x);
    auto ry = root(y);
    if(rx == ry) {
      return;
    }
    par[rx] = ry;
  }
  bool isSame(int x, int y) { return root(x) == root(y); }
};

int main() {
  int N, K, L;
  cin >> N >> K >> L;
  auto road = UnionFind(N);
  auto train = UnionFind(N);
  int a, b;
  for(int i = 0; i < K; ++i) {
    cin >> a >> b;
    road.unite(a - 1, b - 1);
  }
  for(int i = 0; i < L; ++i) {
    cin >> a >> b;
    train.unite(a - 1, b - 1);
  }
  map<pair<int, int>, int> cs;
  for(int i = 0; i < N; ++i) {
    auto p = make_pair(road.root(i), train.root(i));
    cs[p]++;
  }
  for(int i = 0; i < N; ++i) {
    auto p = make_pair(road.root(i), train.root(i));
    cout << cs[p] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int n;
  cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  int sum=0;
  rep(i,n-1){
    sum+=abs(a[i+1]-a[i]);
  }
  sum+=abs(a[0])+abs(a[n-1]);
  rep(i,n){
    if(i==0){
      cout<<sum-abs(a[0])-abs(a[0]-a[1])+abs(a[1])<<endl;
      continue;
    }
    if(i==n-1){
      cout<<sum-abs(a[n-1])-abs(a[n-2]-a[n-1])+abs(a[n-2])<<endl;
      return 0;;
    }
    cout<<sum-abs(a[i]-a[i+1])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1])<<endl;
  }
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long N)
{
}

signed main()
{
  string S;
  cin >> S;
  for (auto s : S)
  {
    if (s == '7')
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

int n,m,ans=0;
int graph[110][110];
int degree[100];

const int inf=1<<29;
using state=tuple<int,int>; 

void dfs(int v,int d,vector<state> &ary){
	if(v==n) return;
	if(ary.size()>=d+1) return;

	dfs(v+1,d,ary);

	if(int(ary.size())<=degree[v]){
		vector<state> backup=ary;
		
		bool ok=true;
		int cmin=inf,sum=0;
		for(auto &v2:ary){
			if(graph[v][get<0>(v2)]==0) ok=false;
			chmin(get<1>(v2),graph[v][get<0>(v2)]);
			chmin(cmin,graph[v][get<0>(v2)]);
			sum+=get<1>(v2);
		}

		if(ok){
			ary.push_back(state(v,cmin));
			sum+=cmin;
			if(int(ary.size())>=2) chmax(ans,sum);
			dfs(v+1,min(d,degree[v]),ary);
		}

		ary=backup;
	}

	return;
}

int main(void){
	cin >> n >> m;
	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		graph[a-1][b-1]=graph[b-1][a-1]=c;
		degree[a-1]++,degree[b-1]++;
	}

	vector<state> ary;
	dfs(0,n,ary);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3184
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

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

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();

		String[] n = line.split(" ");
		int a = Integer.parseInt(n[0]);
		int b = Integer.parseInt(n[1]);
		int c = Integer.parseInt(n[2]);

		if (a <= b && a <= c && b <= c) {
			System.out.println(a + " " + b + " " + c);
		} else if (b <= a && b <= c && a <= c) {
			System.out.println(b + " " + a + " " + c);
		} else if (a <= b && a <= c && c <= b) {
			System.out.println(a + " " + c + " " + b);
		} else if (b <= a && b <= c && c <= a) {
			System.out.println(b + " " + c + " " + a);
		} else if (c <= a && c <= b && a <= b) {
			System.out.println(c + " " + a + " " + b);
		} else if (c < a && c < b && b < a) {
			System.out.println(c + " " + b + " " + a);
		}

	}

}



Measured memory_bytes: 26108
import heapq
N = int(input())

a = list(map(int, input().split()))
left = []
for i in a[:N]:
    heapq.heappush(left, i)
right = []
for i in a[(2 * N):(3 * N)]:
    heapq.heappush(right, -i)

left_sum = [sum(left)]
right_sum = [-sum(right)]
for k in range(N, 2 * N):

    heapq.heappush(left, a[k])
    v = heapq.heappop(left)
    left_sum.append(left_sum[-1] + a[k] - v)

for k in range(2 * N - 1, N - 1, -1):
    heapq.heappush(right, -a[k])
    v = heapq.heappop(right)
    right_sum.append(right_sum[-1] + a[k] + v)

print(max([a - b for (a, b) in zip(left_sum, right_sum[::-1])]))

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n,m; cin >> n >> m;
  vector<pair<int,int>> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(),v.end());

  int ans = 0;
  for(int i = 0; i < n; i++){
    if(m <= 0) continue;
    ans += v[i].first * min(v[i].second, m);
    m -= v[i].second;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
n=int(input())
def f(x,y):
  ret=0
  for i in range(1,n+1):
    if i%10!=y:
      continue
    else:
      if x==int(str(i)[0]):
        ret+=1
  return ret
ans=0
T=[[0]*10 for _ in range(10)]
for i in range(1,10):
  for j in range(1,10):
    T[i][j]=f(i,j)

for i in range(1,10):
  for j in range(1,10):
    ans+=T[i][j]*T[j][i]
print(ans)


Measured memory_bytes: 3188
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

struct State
{
    int x, y, dist;
};

bool operator<(const State &e, const State &f)
{
    return e.dist > f.dist;
}

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

    int r, c;
    cin >> r >> c;
    vector<string> s(r);
    int sx, sy, gx, gy;
    for (int i = 0; i < r; i++)
    {
        cin >> s[i];
        for (int j = 0; j < c; j++)
        {
            if (s[i][j] == 'S')
            {
                sx = i;
                sy = j;
                s[i][j] = '.';
            }
            if (s[i][j] == 'G')
            {
                gx = i;
                gy = j;
                s[i][j] = '.';
            }
        }
    }
    vector<vector<int>> d(r, vector<int>(c, INF));
    int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    priority_queue<State> que;
    d[sx][sy] = 0;
    que.push(State{sx, sy, 0});
    while (!que.empty())
    {
        auto t = que.top();
        que.pop();
        int x = t.x, y = t.y, dist = t.dist;
        if (d[x][y] < dist)
            continue;
        // 通常移動
        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || r <= nx || ny < 0 || c <= ny)
                continue;
            if (s[nx][ny] == '#')
                continue;
            if (s[nx][ny] == 'x')
                continue;
            int cost = (s[nx][ny] == 'o' ? 1 : 2);
            if (d[nx][ny] <= d[x][y] + cost)
                continue;
            d[nx][ny] = d[x][y] + cost;
            que.push(State{nx, ny, d[nx][ny]});
        }
        // 塗り+移動
        for (int i = 0; i < 4; i++)
        {
            for (int j = 1; j <= 3; j++)
            {
                int nx = x + j * dx[i], ny = y + j * dy[i];
                if (nx < 0 || r <= nx || ny < 0 || c <= ny)
                    continue;
                if (s[nx][ny] == '#')
                    break;
                int cost = 2 + j;
                if (d[nx][ny] <= d[x][y] + cost)
                    continue;
                d[nx][ny] = d[x][y] + cost;
                que.push(State{nx, ny, d[nx][ny]});
            }
        }
    }
    cout << d[gx][gy] << endl;
}



Measured memory_bytes: 3224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
            int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
            int sum = vs[0] + vs[1];
            if (sum % 2 == 0) {
                Console.WriteLine(sum/2);
            } else {
                Console.WriteLine("IMPOSSIBLE");
            }
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;

int main()
{
	string a,b;
	cin >>a;
	cin>>b;
	string ans[3]={"GREATER","LESS","EQUAL"};
	int flag = a.size() - b.size();
	int D;
	if(flag==0){
		flag=2;
		for(int i=0;i<a.size() and flag==2;i++){
			D=a[i] -b[i];
			if(D >0){
				flag=0;
			}else if(D <0){
				flag=1;
			}
		}
	}else if(flag >0){
		flag=0;
	}else{
		flag=1;
	}
	cout <<ans[flag]<<endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>n;--i)
#define mset(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mod 1000000007
#define inf 1e18
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define bye return

int main()
{
    ll n,k,ans=0,i;
    cin>>n>>k;

    ll A[n];

    for(i=0;i<n;i++)
    {
        cin>>A[i];
    }

    sort(A,A+n);
    for(i=0;i<n-k;i++)
    {
        ans+=A[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            
            if((a+b+c)<= 21){
                System.out.println("win");
            }
            else if((a+b+c)>=22){
                System.out.println("bust");
            }
    }
}


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

Measured memory_bytes: 596
def calc_sum(num):
    ans = 0
    for i in range(len(str(num))):
        target = num % 10
        num //= 10
        ans += target
    return ans

def main():

    n, a, b = map(int, input().split())
    ans = 0
    for i in range(1, n + 1):
        num = calc_sum(i)
        if a <= num <= b:
            ans += i
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>



using namespace std;


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

	int Nketa=0;

	if (N < 10) { Nketa = 1; }
	else if (N < 100) { Nketa = 2; }
	else if (N < 1000) { Nketa = 3; }
	else if (N < 10000) { Nketa = 4; }
	else if (N < 100000) { Nketa = 5; }
	else if (N < 1000000) { Nketa = 6; }

	int ans=0;
	if (Nketa == 1) {
		ans = N;
	}
	if (Nketa == 2) {
		ans = 9;
	}
	if (Nketa == 3) {
		ans = N - 90;
	}
	if (Nketa == 4) {
		ans = 909;
	}
	if (Nketa == 5) {
		ans = N - 90 - 9000;
	}
	if (Nketa == 6) {
		ans = 90909;
	}

	cout << ans << endl;

}


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

int	main(void)
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a + b) == (c + d))
    cout << "Balanced" << endl;
  else if ((a + b) > (c + d))
    cout << "Left" << endl;
  else
    cout << "Right" << endl; 
}

Measured memory_bytes: 256