akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

import static java.lang.Math.max;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[][] gain = new int[3][n];

        for (int i = 0; i < n; i++) {

            String[] abc = sc.nextLine().split(" ");
            gain[0][i] = Integer.parseInt(abc[0]);
            gain[1][i] = Integer.parseInt(abc[1]);
            gain[2][i] = Integer.parseInt(abc[2]);
        }

        // dp[i][j] := j - 1番目でiを選んだときの最適解
        int[][] dp = new int[3][n + 1];

        dp[0][0] = 0;
        dp[1][0] = 0;
        dp[2][0] = 0;

        for (int j = 1; j <= n; j++) {
            dp[0][j] = max(dp[1][j - 1], dp[2][j - 1]) + gain[0][j - 1];
            dp[1][j] = max(dp[2][j - 1], dp[0][j - 1]) + gain[1][j - 1];
            dp[2][j] = max(dp[0][j - 1], dp[1][j - 1]) + gain[2][j - 1];
        }

        System.out.println(max(max(dp[0][n], dp[1][n]), dp[2][n]));
    }
}

Measured memory_bytes: 123804
n=int(input())
s_list=[input() for i in range(n)]
m=int(input())
t_list=[input() for j in range(m)]

st_list=list(set(s_list)|set(t_list))
ans_list=[]
for k in range(len(st_list)):
    ans_list.append(s_list.count(st_list[k])-t_list.count(st_list[k]))

ans_list.sort()
if ans_list[-1]>=0:
    ans=ans_list[-1]
else:
    ans=0
print(ans)

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

int main(){
    int N;
    cin >> N;
    int W[N];
    int sum=0;
    for(int i=0;i<N;i++){
        cin >> W[i];
        sum += W[i];
    } 
    
    //int s1=0,s2=0;
    int ans=1000000;
    for(int i=0;i<N;i++){
        int s1=0,s2=0;
        for(int j=0;j<N;j++){
            if(j<=i) s1+=W[j];
        }
        s2 = sum-s1;
        ans = min(ans,abs(s1-s2));
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n;
	cin >> n;
	vector<long long int>s;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	vector<long long int> b;
	b.push_back(0);
	for (int i = 0; i < n; i++) {
		b.push_back(b[i] + s[i]);
	}
	long long int sum = 0;
	map<long long int, long long int> c;
	for (int i = 1; i <= n; i++) {
		c[b[i]]++;
	}
	for (auto iter = c.begin(); iter != c.end(); iter++) {
		long long int x = iter->second;
		if (iter->first == 0) {
			sum = sum + x;
		}
		sum = sum + x * (x - 1) / 2;
	}
	cout << sum;
}

Measured memory_bytes: 15856
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

bool is_number(string s) {
    string::iterator it = s.begin();
    while (it != s.end() && isdigit(*it)) ++it;
    return !s.empty() && it == s.end();
}

int main()
{
    ll a, b;
    string s;
    cin >> a >> b >> s;
    if (s.size() == a + b + 1 && 
        s.at(a) == '-' && 
        is_number(s.substr(0, a)) &&
        is_number(s.substr(a + 1, b))
    ) {
        cout << "Yes" << endl;
        return 0;
    } else {
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,m;
ll d;
vector<P> a,b;
vector<P> A,B;
P sum[(1<<15)];

void solve(vector<P> &A,vector<P> &a){
  int n=a.size();
  
  for(int S=1;S<(1<<n);S++){
    sum[S]=P(0,0);
    for(int i=0;i<n;i++){
      if(S>>i&1){
        sum[S].first+=a[i].first;
        sum[S].second+=a[i].second;
      }
    }
  }

  for(int S=0;S<(1<<n);S++){
    int T=S;
    do{
      int s=S-T;
      int t=T;
      P p;
      p.first=sum[s].first-sum[t].first;
      p.second=sum[s].second-sum[t].second;
      A.push_back(p);
      T=(T-1)&S;
    }while(T!=S);
  }
}
  
int main(){
  cin>>n>>d;
  m=n/2;
  n-=m;
  a.resize(n);
  for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
  solve(A,a);
  b.resize(m);
  for(int i=0;i<m;i++)cin>>b[i].first>>b[i].second;
  solve(B,b);

  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  sort(B.begin(),B.end());
  
  /*
  for(int i=0;i<(int)A.size();i++){
    cout<<A[i].first<<' '<<A[i].second<<endl;
  }
  cout<<endl;
  for(int i=0;i<(int)B.size();i++){
    cout<<B[i].first<<' '<<B[i].second<<endl;
  }
  cout<<endl;
  */
  deque<int> deq;
  int l=0,r=0,as=A.size(),bs=B.size();
  ll ans=0;
  for(int i=0;i<as;i++){
    while(r<bs&&A[i].first+B[r].first<=d){
      while(!deq.empty()){
        if(B[r].second<B[deq.back()].second)break;
        deq.pop_back();
      }
      deq.push_back(r);
      r++;
    }
    while(l<bs&&A[i].first+B[l].first<-d){      
      l++;
      if(deq.front()<l)deq.pop_front();
    }
    if(deq.empty()){
      if(abs(A[i].first)<=d)ans=max(ans,A[i].second);
    }else{
      ans=max(ans,A[i].second+B[deq.front()].second);
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int32_t main(){
     int n,k;
     cin>>n>>k;
     int a[n];
     for(int i=0;i<n;++i) cin>>a[i]; 
     int dp[n];
     for(int i=0;i<n;++i) dp[i]=INT_MAX; 
     dp[0]=0;
     dp[1]=abs(a[0]-a[1]);
     
     for(int i=2;i<n;++i){
         for(int j=1;j<=k&& (i-j)>=0; ++j){
             dp[i] = min( dp[i-j]+abs(a[i-j]- a[i]) , dp[i] );
         }
     }

     cout<<dp[n-1];

    return 0;
}

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

void dfs(vector<vector<int>> &graph, int curr, vector<int> &vis, stack<int> &top)
{
	vis[curr] = 1;
	for (auto i : graph[curr])
	{
		if (!vis[i])
			dfs(graph, i, vis, top);
	}
	top.push(curr);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	vector<vector<int>> graph(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
	}

	stack<int> top;
	vector<int> vis(n);

	for (int i = 0; i < n; i++)
	{
		if (!vis[i])
			dfs(graph, i, vis, top);
	}

	vector<int> dp(n);
	while (top.size())
	{
		int x = top.top();
		top.pop();
		for (auto i : graph[x])
		{
			dp[i] = max(dp[i], 1 + dp[x]);
		}
	}
	cout << *max_element(dp.begin(), dp.end()) << "\n";
}

Measured memory_bytes: 9600
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int n, m;
	scanf("%d%d", &n, &m);
	printdb((double)n / m);
	
	Please AC;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,k,a[100000],b[100000],fa[100000],ra[100000],ans,kai[100000];
ll find(ll x){
    if(x==fa[x])return x;
    return fa[x]=find(fa[x]);
}
void uni(ll x,ll y){
    x=find(x),y=find(y);
    if(x==y)return ;
    if(ra[x]<ra[y])swap(x,y);
    fa[y]=x;
    ra[x]+=ra[y]+1;
}
int main(void){
    cin>>k>>n;
    for(int i=0;i<k;i++)fa[i]=i;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
    }
    for(int i=n-1;i>=0;i--){
        ans=0;
        ll x=find(a[i]);
        ll y=find(b[i]);
        if(x!=y){
            ans=(ra[x]+1)*(ra[y]+1);
            uni(x,y);
        }
        kai[i]=ans;
    }
    for(int i=0;i<n;i++){
        if(i!=0)kai[i]+=kai[i-1];
            cout<<kai[i]<<endl;
    }
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;
const ll inf = 1001001001;
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
int main() {
    int n;
    ll k, p;
    cin >> n >> k >> p;
    ll m = p;
    rep(i, 1, n){
        ll q;
        cin >> q;
        p = gcd(p, q);
        m = max(m, q);
    }
    if(k%p == 0 && k <=m) cout << "POSSIBLE" << endl; 
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			int A = input.nextInt();
			int B = input.nextInt();
			int C = input. nextInt();
			int D = input.nextInt();
			
			if(A > D || C > B){
				System.out.println("0");
			} else {
				System.out.println(Math.min(B, D) - Math.max(A, C));
			}
			
		}

	}

}


Measured memory_bytes: 20820
#include <stdio.h>

long N;
long W;
long dp[110][100010];
long w[110];
long v[110];
//dpに格納するのは重さの総和
//価値の総和は配列の要素番号
long V = 100010;
const long INF = 10000000000; 
long min(long a, long b)
{
	if (a > b)
		return b;
	return a;
}

int main(int argc, char const *argv[])
{
	scanf("%ld%ld", &N, &W);
	for (int i = 0; i < N; i++) scanf("%ld%ld", w+i, v+i);
	for (int i = 0; i < 110; i++)
	{
		for (int j = 0; j < V; j++)
		{
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for (long i = 0; i < N; i++)
	{
		for (long j = 0; j < 100010; j++)
		{
			if (j + v[i] < V)
			{
				dp[i+1][j + v[i]] = min(dp[i+1][j + v[i]], dp[i][j] + w[i]);
			}
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
		}
	}
	long res = 0;
	for (long j = 0; j < V; j++){
		if(dp[N][j] <= W) res = j;
	}

	printf("%ld", res);
	return 0;
}


Measured memory_bytes: 86144
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a =scan.nextInt();
        int b = scan.nextInt();

        int i = 1;
        int ans = -1;
        while(true) {
        	int tempA = (i * 8) / 100;
        	int tempB = i / 10;

        	if(tempA == a && tempB ==b) {
        		ans = i;
        		break;
        	}
        	if(tempA > a || tempB > b) {
        		break;
        	}
        	i++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23508
# sys.stdin.readline()
from copy import deepcopy
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
GM = [[False]*N for _ in range(N)]
GL = []
for _ in range(M):
  a, b = list(map(int, input().split()))
  GM[a-1][b-1], GM[b-1][a-1] = True, True
  GL.append([a-1,b-1])
  
def DFS(v,g):
  visited[v] = True
  for i in range(N):
    if g[v][i] and not visited[i]:
      DFS(i,g)

ans = 0

for i in range(M):
  G = deepcopy(GM)
  G[GL[i][0]][GL[i][1]], G[GL[i][1]][GL[i][0]] = False, False
  visited = [False] * N
  DFS(0,G)
  
  flg = False
  for j in range(N):
    if not visited[j]:
      flg = True
      break
      
  if flg:
    ans += 1

print(ans)

Measured memory_bytes: 3572
#include <cstdio>
#include <cstring>
const int INF = 1 << 30;
const int MAX_N = 14;
int N, M, X;
int A[MAX_N][MAX_N];
int C[MAX_N];

int min(int a, int b) {
	return (a > b) ? b : a;
}

int calc(int now, int cost, int lev[]) {
	if (now > N) {
		for (int i = 1; i <= M; i++)
			if (lev[i] < X) return INF;
		return cost;
	}
	for (int i = 1; i <= M; i++) lev[i] += A[now][i];
	int a = calc(now + 1, cost + C[now], lev);
	for (int i = 1; i <= M; i++) lev[i] -= A[now][i];
	int b = calc(now + 1, cost, lev);
	return min(a, b);
}

int main() {
	scanf("%d %d %d", &N, &M, &X);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &C[i]);
		for (int j = 1; j <= M; j++)
			scanf("%d", &A[i][j]);
	}
	int level[MAX_N] = { 0 };
	int ans = calc(1, 0, level);
	if (ans == INF) ans = -1;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std; typedef unsigned int uint; typedef long long ll;
typedef unsigned long long ull; typedef pair<int, int> pii;
typedef pair<ll,ll> pll; typedef long double ld;
void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0);}
template<typename T> T __lcm(T a, T b){return (a*b)/__gcd(a,b);}
template<typename T> T fpow(T a, T b, T p) { a %= p;T res = 1;
while (b > 0) { if (b & 1) res = res * a % p;
a = a * a % p; b >>= 1;} return res;} template<typename T> T binpow(T a, T b) {
T res = 1; while (b > 0) { if (b & 1) res = res * a;
a = a * a; b >>= 1;} return res;}
const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1e5+5;

bool visited[maxn];
int n, m, x, y;
vector<int> vs[maxn], topo;
void dfs(int v){
	visited[v] = true;
	for(auto&e: vs[v]) if(not visited[e]) dfs(e);
	topo.pb(v);
}

int main() {
	rii(n, m);
	forn(i, m){
		rii(x, y);
		vs[--x].pb(--y);
	}
	forn(i, n) if (not visited[i]) dfs(i);
	reverse(all(topo));
	vector<int> dp(n, 0);
	int ans = 0;
	for(auto&v:topo)
		for(auto&e:vs[v]) ans = max(dp[e] = max(dp[e], dp[v]+1), ans);
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 8824
n,m = map(int,input().split())

pl = list(map(int,input().split()))


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(n)

for _ in range(m):
    x,y = map(int,input().split())
    uf.union(x-1, y-1)

ans = 0
for idx, p in enumerate(pl):
    if uf.same(idx, p-1):
        ans += 1

print(ans)

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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


inline li upd(li now, li num) {
	if (now % num == 0)return now;
	return (now / num + 1) * num;
}

int main() {
	li x = 1, y = 1;
	li n;
	cin >> n;
	rin{
		li xx, yy;
		cin >> xx >> yy;
		if (xx < yy) {
			x = upd(x, xx);
			li cand_y = x / xx * yy;
			if (cand_y < y) {
				y = upd(y, yy);
				x = y / yy * xx;
			} else {
				y = cand_y;
			}
		} else {
			y = upd(y, yy);
			li cand_x = y / yy * xx;
			if (cand_x < x) {
				x = upd(x, xx);
				y = x / xx * yy;
			} else{
				x = cand_x;
			}
		}
		//p2(x, y);
	}
	cout << x + y << endl;


	return 0;
}

Measured memory_bytes: 256
'''
while True:
    H,W = [int(i) for i in input().split()]

    if H == 0 and W == 0:
        break

    table = [[0 for i in range(W)] for j in range(H)]
    for i in range(H):
        line = input()
        for j in range(W):
            if line[j] == "*":
                table[i][j] = 1
'''

H,W = [int(i) for i in input().split()]
table = [[0 for i in range(W)] for j in range(H)]

ans = 0

for i in range(H):
    table[i] = [1 - int(j) for j in input().split()]

for i in range(H):
    for j in range(W):
        if table[i][j] == 1:
            ans = 1

for i in range(1,H):
    for j in range(1,W):
        if table[i][j] == 1:
            table[i][j] = min(table[i-1][j-1], table[i][j-1], table[i-1][j]) + 1
            ans = max(table[i][j], ans)

print(ans*ans)



Measured memory_bytes: 44380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()	
{
	int n,m,a,sum=0;
	cin>>n>>m;
	vector<int>v(m),w;
	for(int i=0;i<m;i++)cin>>v[i];
	if(n>=m)
	{
		cout<<0<<endl;
		return 0;
	}
	sort(v.begin(),v.end());
	for(int i=1;i<m;i++)
	{	
		w.push_back(v[i]-v[i-1]);
		sum+=v[i]-v[i-1];
	}	
	sort(w.begin(),w.end());
	for(int i=0;i<n-1;i++)
	{
		sum-=w[m-2-i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1276
# input
N, M = map(int, input().split())
a = []
a_append = a.append

for n in range(M):
    a_append(int(input()))

mod = 1000000007

# check
check = [True] * (N + 1)
for i in a:
    check[i] = False

dp = {0: 1}
if check[1] is True:
    dp[1] = 1
else:
    dp[1] = 0

for n in range(2, N + 1):
    dp[n] = 0
    if check[n - 1] is True:
        dp[n] += dp[n - 1]
    if check[n - 2] is True:
        dp[n] += dp[n - 2]
    dp[n] %= mod

print(dp[N])

Measured memory_bytes: 20456
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int x;
	int y;
} data;

int ev_str(string a)
{
	int len = a.size() / 2;
	if (a.substr(0, len) == a.substr(len, len))
		return a.size();
	else 
		return 0;
}

int  main()
{
	string s;
	cin >> s;
	s.erase(--s.end());
	priority_queue<int> q;
	for (int i = s.size()-1; i >= 0; i--)
	{
		if (i % 2)
		{
			string a = s.substr(0, i+1);
			if (ev_str(a))
			{
				q.push(ev_str(a));
			}
		}
	}
	cout << q.top() << endl;
	return (0);
}


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

using namespace std;

int main(){
    priority_queue<int,vector<int>,greater<int>>pq;
    string s;
    int answer1=0,tempaman;

    cin>>s;
    int countingman[26];
    for(int i=0;i<26;i++)countingman[i]=0;
    for(char i:s)countingman[i-'a']++;
		
    for(int i=0;i<26;i++)if(countingman[i]>0)pq.push(countingman[i]);

    if(pq.size()==1){
        printf("%d\n",pq.top());
        return 0;
    }

    while(pq.size()>1){
        tempaman=pq.top();
        pq.pop();
        answer1+=tempaman+pq.top();
        pq.push(tempaman+pq.top());
        pq.pop();
    }
    printf("%d\n",answer1);
}



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

vector< pair<int, int> > v[100010];
int n, m;
int l[200010];
int r[200010];
int d[200010];
int bio[100010];
int yes[100010];
int dist[100010];
int da = 1;

void dfs(int x) {
	yes[x] = 1;
	for (int i = 0; i < v[x].size(); i ++) {
		
		if (da == 0) {return;}
		
		int sus = v[x][i].first;
		int cost = v[x][i].second;
		if (dist[sus] != -1 && dist[sus] - dist[x] != cost) {
			da = 0;
			return;
		}
		
		if (yes[sus] == 0) {
			dist[sus] = dist[x] + cost;
			if (dist[sus] > 1000000000) {da = 0; return;}
			dfs(sus);
		}
	}
	
}

int main () {

	cin >> n >> m;
	memset(dist, -1, sizeof dist);
	for (int i = 0; i < m; i ++) {
		cin >> l[i] >> r[i] >> d[i];
		v[l[i]].push_back( make_pair(r[i], d[i]) );
		v[r[i]].push_back( make_pair(l[i], -d[i]) );
		bio[ r[i] ] = 1;
	}
	int j = 0;
	for (int i = 1; i <= n; i ++) {
		
		if (v[i].size() > 0 && bio[i] == 0 && yes[i] == 0) {
			dist[i] = 0;
			dfs(i);
			j = 1;
		}
		
	}
	
	/*for (int i = 1; i <= n; i ++) {
		cout << dist[i] << " ";
	}*/
	if (m == 0) {cout << "Yes";}
	else if (j == 0 || da == 0) {cout << "No";}
	else {cout << "Yes";}

	return 0;
}


Measured memory_bytes: 15104
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n;
LL w, v,W,dp[200005];
int main()
{
	cin >> n >> W;
	for (int j = 1; j <= W; j++)
		dp[j] = -mod * mod;
	for (int i = 0; i < n; i++)
	{
		cin >> w >> v;
		for (int j = W; j >= 0; j--)
			dp[j + w] = max(dp[j + w], dp[j] + v);

	}
	for (int i = 1; i <= W; i++)
		dp[i] = max(dp[i-1],dp[i]);
	cout << dp[W] << endl;
	return 0;
}

/*



*/

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

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let s: String = read!();
    let s = s.chars().collect_vec();
    let len = s.len();

    for i in 0..len {
        for j in i..len {
            if &format!("{}{}", &s[..i].iter().collect::<String>(), &s[j..].iter().collect::<String>()) == "keyence" {
                println!("{}", "YES");
                return;
            }
        }
    }

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


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
    
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 7820
#define _GLIBCXX_DEBUG //提出時にはこれは消す
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,n, flag;
  cin >> x >> n;
  int p[n];
  for(int i=0; i<n; i++)
    cin >> p[i];
  sort(p, p+n);
  int ct=0;
  while(1){
    flag = 0;
    for(int i=0; i<n; i++){
      if(x-ct==p[i]){
	flag = 1;
	break;
      }
    }
    if(flag==0){
      cout << x-ct;
      return 0;
    }
    flag = 0;
    for(int i=0; i<n; i++){
      if(x+ct==p[i]){
	flag = 1;
	break;
      }
    }
    if(flag==0){
      cout << x+ct;
      return 0;
    }
    ct++;
  }
  return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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


const ll INF = 2e9;

struct edge{
    ll to; ll cost;
};

int main(){
    int n, m; cin >> n >> m;
    vector<vector<edge> > tree(n);
    vector<ll> dist(n, INF);
    REP(i, 0, m){
        ll l, r, d; cin >> l >> r >> d;
        l--, r--;
        tree[l].pb({r, d});
        tree[r].pb({l, -1*d});
    }
    REP(i, 0, n){
        if(dist[i] != INF){continue;}
        dist[i] = 0;
        stack<ll> s;
        s.push(i);
        while(!s.empty()){
            int now = s.top();
            s.pop();
            REP(l, 0, tree[now].size()){
                edge e = tree[now][l];
                int next = e.to, c = e.cost;
                if(dist[next] == INF){
                    dist[next] = dist[now] + c;
                    s.push(next);
                }else{
                    if(dist[next] == dist[now] + c){
                        continue;
                    }else{
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 13952
import java.io.*;
import java.util.*;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;


class Main {
	public static void main(String[] a) throws IOException {
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
		int hit = 0;
		int blow = 0;
		int[] ans = new int [4];
		int[] guess = new int[4];
		
		for(int i = 0;i<4;i++){
			ans[i] = scan.nextInt();
		}
		for(int i = 0;i<4;i++){
			guess[i] = scan.nextInt();
		}
		for(int i = 0;i < 4;i++){
			if(ans[i] == guess[i]){
				hit = hit + 1;
			}
		}
		for(int i = 0;i < 4;i++){
			for(int k = 0;k < 4;k++){
				if(k != i){
					if(ans[i]==guess[k]){
						blow = blow + 1;
					}
				}
			}
		}
		System.out.println(hit + " "+blow);
		}	
 }
}

Measured memory_bytes: 26436
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int main(){
  FAST_IO
  int N;
  cin >> N;
  if(N == 3 || N == 5 || N == 7) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}



Measured memory_bytes: 3652
N=int(input())
tree=[set() for _ in range(N)]
for i in range(1,N):
    u,v,w=map(int,input().split())
    u=u-1
    v=v-1
    tree[u].add((v,w))
    tree[v].add((u,w))
ans=[-1]*N
q=[(0,0,-1)]
while q:
    now, ndis, priv = q.pop()
    if ndis % 2 == 0:
        ans[now] = 0
    else:
        ans[now] = 1
    for nex, dis in tree[now]:
        if nex == priv:
            continue
        q.append((nex, ndis + dis, now))
for i in ans:
    print(i)

Measured memory_bytes: 50340
n = int(input())
p =  list(map(int, input().split()))

b = sorted(p)
cnt = 0
if p == b:
    print("YES")
else:
    for i in range(n):
        if p[i] != b[i]:
            cnt += 1
            if cnt == 3:
                print("NO")
                break    
    if cnt == 1:
        print("NO")
    if cnt == 2:
        print("YES")

Measured memory_bytes: 3060
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let mut a: Vec<i32> = s.map(|a| a.parse().unwrap()).collect();
	a.sort();
	let mut cum = vec![0; n + 1];
	let mut pnum = vec![0; *a.last().unwrap() as usize * 2 + 1];
	for (i, a) in a.iter().rev().enumerate() {
		cum[i + 1] = cum[i] + *a as i64;
		pnum[*a as usize] += 1;
	}
	for i in (0..pnum.len() - 1).rev() {
		pnum[i] += pnum[i + 1];
	}
	let mut l = 2;
	let mut r = a.last().unwrap() * 2 + 1;
	'a: while r - l > 1 {
		let mid = l + (r - l) / 2;
		let mut cnt = 0;
		for a in a.iter().rev() {
			cnt += pnum[std::cmp::max(0, mid - *a) as usize];
			if cnt >= m {
				l = mid;
				continue 'a;
			}
		}
		r = mid;
	}
	let (lsum, lcnt) = a.iter().fold((0, 0), |r, a|{
		let c = pnum[std::cmp::max(0, l - *a) as usize];
		(r.0 + c as i64 * *a as i64 + cum[c], r.1 + c)
	});
	let ans = lsum - (lcnt - m) as i64 * l as i64;
	println!("{}", ans);
}


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

using namespace std;

template <class T> inline T updmax(T& a, T b) { return a = max(a, b); }
template <class T> inline T updmin(T& a, T b) { return a = min(a, b); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(n, 0), b(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    vector<pair<int, int>> ab(n);
    for (int i = 0; i < n; i++) { ab[i] = make_pair(a[i], -b[i]); }
    sort(ab.begin(), ab.end());
    priority_queue<int> q;
    int idx = 0;
    long long ans = 0;
    for (int i = 1; i <= m; i++) {
        while (idx != n && ab[idx].first <= i) q.push(-ab[idx++].second);
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 2428
n,m = map(int,input().split())
A = {}
for i in range (1,n+1):
    a,b = map(int,input().split())
    A[i] = [a,b]

B = {}
for i in range(1,m+1):
    c,d = map(int,input().split())
    B[i] = [c,d]

for v in A.values():
    t = float('inf')
    ans = 0
    for x,w in B.items():
        if abs(v[0]-w[0])+abs(v[1]-w[1]) < t:
            t = abs(v[0]-w[0])+abs(v[1]-w[1])
            ans = x
    print (ans)


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=10000;
const double INF=1000000000;
const int MAX=100001;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int c[40][40][40][40];
int main(){
    int w,h;
    while(cin>>w>>h,w+h){
        int ans[40][40]={};
        for(int i=0;i<2*h-1;i++){
            if(i%2){
                for(int j=0;j<w;j++){
                    cin>>c[i/2][j][i/2+1][j];
                }
            }else{
                for(int j=0;j<w-1;j++){
                    cin>>c[i/2][j][i/2][j+1];
                }
            }
        }
        queue<P> q;
        q.push(P(0,0));
        ans[0][0]=1;
        while(!q.empty()){
            int x=q.front().first;
            int y=q.front().second;
            q.pop();
            if(x==w-1&&y==h-1)break;
            for(int i=0;i<4;i++){
                int nx=x+dx[i];
                int ny=y+dy[i];
                if(nx<0||nx>=w||ny<0||ny>=h||c[y][x][ny][nx]||c[ny][nx][y][x]||ans[ny][nx]){
                    continue;
                }
                ans[ny][nx]=ans[y][x]+1;
                q.push(P(nx,ny));
            }
        }
        cout<<ans[h-1][w-1]<<endl;
    }
    return 0;
}

                           



Measured memory_bytes: 6768
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    X = II()
    if(X >= 30):
        print("Yes")
    else:
        print("No")
	

if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
using System;
using System.Collections;
using System.Linq;

public class MainApp
{
    static public void Main(string[] args)
    {
        var x = Console.ReadLine().Split(' ');
        int a = int.Parse(x[0]);
        int b = int.Parse(x[1]);
        int c = int.Parse(x[2]);
        int output = a + b + c - Math.Max(a, Math.Max(b, c));
        Console.WriteLine(output);


    }

}

Measured memory_bytes: 11092
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)


main :: IO ()
main = do
    [n,k] <- r'
    let r = if k==1 then 0 else n-k
    print r


Measured memory_bytes: 380
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  string s;cin>>s;
  vector<ll>v(n);
  rep(i,0,n)v[i]=s[i]-'A';
  rep(i,n,2*n+2)v.PB(~(i-n)&1);
  ll num=0;//先頭Bで操作を行う(右から出る)回数
  ll now=0;//操作回数
  bool top=v[0];
  while(now<k&&num<n){
    now++;
    if(top){
      num++;
      top=v[num]^(num&1);
    }
    else{
      top=true;
    }
  }
  if(n&1)top^=(k-now)&1;
  //cout<<now spa top<<endl;
  vector<ll>ret(n);
  rep(i,0,n){
    ret[i]=v[i+num]^(num&1);
  }
  ret[0]=top;
  if(n==1)ret[0]=(k&1)^v[0];
  rep(i,0,n)if(ret[i])cout<<"B";else cout<<"A";
  cout<<endl;
  //debug(ret,n);
  return 0;
}

Measured memory_bytes: 9736
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        if (K % 2 == 0) {
            System.out.println((K / 2) * (K / 2));
        } else {
            System.out.println((K / 2) * (K / 2 + 1));
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    cout << min(n % k, k - (n % k)) << "\n";
    return 0;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

# https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#3-1-mod-p-%E3%81%AE%E4%B8%96%E7%95%8C%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B%E5%89%B2%E3%82%8A%E7%AE%97%E3%81%A8%E3%81%AF


def modinv(a):
  b = MOD
  u = 1
  v = 0
  while b != 0:
    t = a // b
    a -= t * b
    a, b = b, a
    u -= t * v
    u, v = v, u
  u %= MOD
  if u < 0:
    u += MOD
  return u


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

# a = [e for e in a if e != 0]

# if len(a) < k:
#   print(0)
#   exit()

a.sort(key=lambda x: abs(x), reverse=True)

b = a[:k]
c = a[k:]

n = 0
pro_abs_b = 1
for e in b:
  if e < 0:
    n += 1
  pro_abs_b *= abs(e)
  pro_abs_b %= MOD
pro_b = (-1)**n * pro_abs_b % MOD

n_ = 0
pro_abs_ = 1
for e in a[len(a) - k:]:
  if e < 0:
    n_ += 1
  pro_abs_ *= abs(e)
  pro_abs_ %= MOD
pro_ = (-1) ** n_ * pro_abs_ % MOD

if n % 2 == 0:
  print(pro_b)
  exit()

anses = []
last_posinb = None
last_neginb = None
for e in b:
  if e > 0:
    last_posinb = e
  if e < 0:
    last_neginb = e
first_posinc = None
first_neginc = None
for e in reversed(c):
  if e > 0:
    first_posinc = e
  if e < 0:
    first_neginc = e

# print(last_posinb, last_neginb)
# print(first_posinc, first_neginc)
if last_posinb is not None and first_neginc is not None:
  anses.append((-first_neginc / last_posinb, pro_b *
                modinv(last_posinb) * first_neginc % MOD))
if last_neginb is not None and first_posinc is not None:
  anses.append((-first_posinc / last_neginb, pro_b *
                modinv(last_neginb) * first_posinc % MOD))

if len(anses) != 0:
  print(max(anses)[1])
else:
  print(pro_)


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

int main()
{
  //入力
  int k,a,b;
  cin>>k>>a>>b;

  bool flag=false;

  for(int i=a;i<=b;i++)
  {
    if(i % k == 0)
    {
      flag=true;
    }
  }
  
  //出力
  if(flag == true){
    cout<<"OK"<<endl;
  }
  else {
    cout<<"NG"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <cmath>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n;  cin >> n;
    int W;  cin >> W;
    vector<int>w(n);
    vector<ll>v(n);
    rep(i, n)   cin >> w[i] >> v[i];
    //solve
    vector<vector<ll> >dp(1000, vector<ll>(1e5+10));
    rep(i, n){
        for(int j = 0; j <= W; j++){
            if(j+w[i] <= W){
                dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+v[i]);
            }
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[n][W] << endl;
}


Measured memory_bytes: 785152
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 int a;
 string s;
 cin >> a >> s;
 if(a>=3200) cout << s;
 else cout<< "red";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<int> num(26, 0), now(26);
    string s;
    cin >> s;
    repi(i, s){
        ++num[(int)(*i - 'a')];
    }
    rep(i, n -1){
        fill(now.begin(), now.end(), 0);
        cin >> s;
        repi(j, s){
            ++now[(int)(*j - 'a')];
        }
        rep(j, 26){
            num[j] = min(now[j], num[j]);
        }
    }
    rep(i, 26){
        rep(j, num[i]){
            cout << (char)(i + 'a');
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;
typedef long long int ll;
    
int main()
{
    int N;
    vector<int> A;
    cin >> N;
    int tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N - 1; i++) {
        if (A[i] == A[i + 1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <cstdio>
#include <cstring>

int main(){
    int n;
    scanf("%d", &n);
    double x;
    char u[4], j[] = "JPY";
    double sum = 0.0;
    for(int i = 0; i < n; i++){
        scanf("%lf %s", &x, &u);

        if(strcmp(u, j) == 0){
            sum += x;
        }else{
            sum = sum + x * 380000;
        }

    }

    printf("%f\n", sum);

    return 0;
}

Measured memory_bytes: 128