akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	string S; cin >> S;
	int n = S.length();

	int m = 0;
	for(int i = 0; i < n; i++) {
		int l = 0;
		for(int j = i; j < n; j++) {
			if(S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T') {
				l++;
			} else {
				m = max(m, l);
				break;
			}
			m = max(m, l);
		}
	}
	cout << m << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 4e3+7;
char buff[N];
int freq[3][N];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",buff);
	string str = (string)buff;
	
	for(int i = n-1 ; i >= 0 ; i--)
	{
		if (str[i] == 'R') freq[0][i] = 1;
		else if (str[i] == 'G') freq[1][i] = 1;
		else if (str[i] == 'B') freq[2][i] = 1;
		for(int j = 0 ; j < 3 ; j++) freq[j][i] += freq[j][i+1];
	}
	ll ans = 0;
	for(int i = 0 ; i < n ; i++)
	{
		for(int j = i+1 ; j < n ; j++)
		{
			if (str[i] == str[j]) continue;
			
			if ((str[i] == 'R' && str[j] == 'G') || (str[i] == 'G' && str[j] == 'R'))
			{
				ans += freq[2][j+1];
				if (2*j-i < n && str[j*2-i] == 'B') ans--;
			}
			if ((str[i] == 'B' && str[j] == 'G') || (str[i] == 'G' && str[j] == 'B'))
			{
				ans += freq[0][j+1];
				if (2*j-i < n && str[j*2-i] == 'R') ans--;
			}
			if ((str[i] == 'R' && str[j] == 'B') || (str[i] == 'B' && str[j] == 'R'))
			{
				ans += freq[1][j+1];
				if (2*j-i < n && str[j*2-i] == 'G') ans--;
			}
 		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3840
#include <iostream>
using namespace std;
int main(){
    int N,i,j;
    string s,z="ABC";
    cin>>N>>s;
    j=0;
    for(i=0;i<N-1;i++){
        if(s[i]==z[0]&&s[i+1]==z[1]&&s[i+2]==z[2]){
            j+=1;
        }
    }
    cout<<j;
}

Measured memory_bytes: 256
using System;
public class Hello{

    public static void Main(){

      while(true){

      int sum = 0;
      string line = Console.ReadLine();
      if(line=="0") break;
      for(int i=0; i<line.Length;i++){
        sum += line[i]-'0';
      }
      var x = line[0]-'0';
      Console.WriteLine(sum);
      }
    }
  //#####################
    public static int[] LineToInt(){
      string line = Console.ReadLine();
      string[] arrStr = line.Split(' ');
      int[] arrInt = new int[arrStr.Length];

      for(var i=0; i<arrStr.Length;i++){
        arrInt[i] = int.Parse(arrStr[i]);
      }
      return arrInt;
  }
}



Measured memory_bytes: 17848
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vi h(n+1);
		for(int i=1;i<=n;i++) scanf("%d", &h[i]);

		vector<bool> f(n+1, true);
		for(int i=0;i<m;i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);

			if(h[a]==h[b])
			{
				f[a]=f[b]=false;
			}
			if(h[a]<h[b]) swap(a, b);
			f[b]=false;
		}

		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if(f[i]) ans++;
		}
//		for(int mh:h) printf("%d ", mh); printf("\n");
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 3180
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,m;
	std::cin >> n >> m;
	std::vector<int> pen(n,0);
	std::vector<bool> ac(n,false);
	rep(i,m) {
		int p;
		std::string s;
		std::cin >> p >> s;
		p--;
		if(ac[p]) continue;
		if(s=="WA") pen[p]++;
		else ac[p]=true;
	}
	int accnt = 0;
	int wacnt = 0;
	rep(i,n) {
		if(ac[i]) {
			accnt++;
			wacnt+=pen[i];
		}
	}
	std::cout << accnt << ' ' << wacnt << ENDL;
	return 0;
}


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


vector<ll> dist;
void bfs(vector<vector<pair<int,ll>>> g,int r)
{
	queue<int> que;
	que.push(r);
	dist[r]=0;
	while(!que.empty())
	{
		int p=que.front();
		que.pop();
		for(pair<int,ll> v : g[p])
		{
			if(dist[v.first]!=-1) continue;
			dist[v.first]=dist[p]+v.second;	
			que.push(v.first);
		}
	}
}
int main()
{
	int N;
	cin>>N;
	dist.resize(N,-1);
	vector<vector<pair<int,ll>>> g(N,vector<pair<int,ll>>());
	rep(i,N-1)
	{
		int a,b,c;
		cin>>a>>b>>c;
		a--;
		b--;
		g[a].push_back(make_pair(b,c));
		g[b].push_back(make_pair(a,c));
	}
	int Q,K;
	cin>>Q>>K;
	K--;
	bfs(g,K);
	rep(i,Q)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		cout<<dist[x]+dist[y]<<endl;
	}
	return 0;
}


Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Y "YES\n"
#define N "NO\n"
#define pi acos(-1.0)
#define pb push_back
#define lcm (a*b)/__gcd(a,b)
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
	    int cnt=0;
	    string a,b;
	    cin>>a>>b;
	    for(int i=0;i<a.size();i++)
        {
            if(a[i]!=b[i])cnt++;
        }
        cout<<cnt;
	    //cout<<Y;
	    //cout<<N;
	}
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; 

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     db(i)               cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int a,b,c,d,x,y; cin>>a>>b>>c>>d;
    x = a/d + (a%d!=0);
    y = c/b + (c%b!=0);
    if(x>=y) cout<<"Yes\n";
    else cout<<"No\n";
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>

/*動的計画法で解く*/
int main(){
	//並んでいる数字の個数を表す整数Nを入力
	int n;
	std::cin >> n;
	//二次元のベクタ用意 dp[i][j]はi - 1 項まで計算した結果がjである数
	std::vector<std::vector<long long int> > dp(n, std::vector<long long int>(21, 0));
	//入力数値保存用
	std::vector<int> num(n, 0);
	//数値入力
	for(int i = 0; i < n; ++i){
		int x;
		std::cin >> x;
		num[i] = x;
	}
	//初期値（一番左の数）
	dp[0][num[0]] = 1;
	//処理
	for(int i = 1; i < n - 1; ++i){ //2項からN - 1項までの計算
		for(int j = 0; j < 21; ++j){
			//もし1つ前の計算結果がjの場合の数があればその加減を求める
			if(dp[i - 1][j] > 0){
				//それがもし0以上20以下なら
				if((j + num[i]) >= 0 && (j + num[i]) <= 20){
					//和
					dp[i][j + num[i]] += dp[i - 1][j];
				}
				if((j - num[i]) >= 0 && (j - num[i]) <= 20){
					//差
					dp[i][j - num[i]] += dp[i - 1][j];
				}
			}
		}
	}
	//必要な結果はn - 1項まで計算した結果がnum[n-1]である数　つまりdp[n-2][num[n-1]]
	std::cout << dp[n - 2][num[n - 1]] << std::endl;
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	ll n;
	cin>>n;
	ll a[100];
	ll d=1;
	int i=0;
	while(d<=n){
        a[i]= (n%(d*10)-n%(d))/d;
        i++;
        d*=10;
	}
	int k=i;
	int s;
	bool x=1;
	for(i =1;i<k;i++){
        if(a[k-i-1]!=9){
            x=0;
        }
	}
	if(x==1){
        cout<<9*(k-1)+a[k-1];
	}
	else{
        cout<<9*(k-1)+a[k-1]-1;
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, h, m float64
	fmt.Scan(&a, &b, &h, &m)

	if h >= 12 {
		h -= 12
	}

	l := 360 * (float64(m) / 60)
	s := 30*float64(h) + 30*(float64(m)/60)
	var ang float64
	if l > s {
		ang = l - s
	} else {
		ang = s - l
	}
	if ang >= 180 {
		ang = 360 - ang
	}
	fmt.Println(math.Sqrt(a*a + b*b - 2*a*b*math.Cos(math.Pi*ang/180)))
}


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
double min(double a,double b){
  if(a<b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int translate(char c){
  if(c == '1') return 1;
  if(c == '2') return 2;
  if(c == '3') return 3;
  if(c == '4') return 4;
  if(c == '5') return 5;
  if(c == '6') return 6;
  if(c == '7') return 7;
  if(c == '8') return 8;
  if(c == '9') return 9;
  
}
void Yes(){
  cout << "Yes" << endl;
}
void YES(){
  cout << "YES" << endl;
}
void No(){
  cout << "No" << endl;
}
void NO(){
  cout << "NO" << endl;
}
int main(){
  int N,T; cin >> N >> T;
  
  int localmin = 1001;
  for(int i = 0; i < N; i++){
  	int c,t; cin >> c >> t;
    if( t <= T ){
      localmin = min(c,localmin);
    }
  }
  if(localmin == 1001) cout << "TLE" << endl;
  else cout << localmin << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    if (500 * k >= x) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Map<Integer, Integer> hpf = new TreeMap<>();
        Map<Integer, Integer> hid = new TreeMap<>();
        Map<Integer, Integer> hyy = new TreeMap<>();
        for (int i = 0; i < m; i++) {
            int Pref = Integer.parseInt(sc.next());
            int Year = Integer.parseInt(sc.next());
            hyy.put(Year, Pref);
            hid.put(Year, i);
            hpf.put(Pref, 0);
        }
        sc.close();
        String ans[] = new String[m];
        for (int key : hyy.keySet()) {
            hpf.put(hyy.get(key), hpf.get(hyy.get(key)) + 1);
            ans[hid.get(key)] = String.format("%06d", hyy.get(key)) + String.format("%06d", hpf.get(hyy.get(key)));
        }
        PrintWriter pw = new PrintWriter(System.out);
        for (int i = 0; i < m; i++) {
            pw.println(ans[i]);
        }
        pw.flush();
    }
}

Measured memory_bytes: 149912
#include <iostream>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int t = M*1900+(N-M)*100;
    int Xms = t;
    for(int i = 1; i <= M; i++){
        Xms *= 2;
    }
    cout << Xms << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int N;
    cin >> N;

    if (N%1000 == 0) ans = 0;
    else ans = 1000-(N%1000);
    cout << ans << endl;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/practice/abc173/abc173_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/practice/abc173/abc173_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/practice/abc173/abc173_a && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3528
N = int(input())
p = [int(input()) for _ in range(N)]

sorted_p = sorted(p)
half_price = int(sorted_p[-1] / 2 )
total_price = 0

for i in range(N-1):
    total_price += sorted_p[i]
total_price += half_price

print(total_price)


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

int main(){
    string N;
    cin>>N;
    vector<int> vec(4);
    vector<char>z(3);

    for(int i=0;i<4;i++){
        vec.at(i)=(int)(N.at(i)-'0');
    }

    for(int tmp=0;tmp<(1<<4);tmp++){
        int sum=vec.at(0);
        bitset<4> n(tmp);
        for(int i=1;i<4;i++){
            if(n.test(i)){
                sum+=vec.at(i);
                z.at(i-1)='+';
            }else{
                sum-=vec.at(i);
                z.at(i-1)='-';
            }
        }
        if(sum==7){
            cout<<vec.at(0)<<z.at(0)<<vec.at(1)<<z.at(1)<<vec.at(2)<<z.at(2)<<vec.at(3)<<"=7"<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>

using namespace std;

// #define LOG(...) printf(__VA_ARGS__)
#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define INF 1e9

struct P
{
	int stage, cost, state;

	bool operator >(const P& p) const{
		return cost > p.cost;
	}
};

int main() {
	int n;
	while(cin >> n, n){
		vvi stage_times(n, vi(n + 1));
		REP(i, n){
			REP(j, n + 1){
				cin >> stage_times[i][j];
			}
		}

		vi dp(1 << n, INF);
		dp[0] = 0;
		REP(l, n){
			vi dp_stk(1 << n, INF);

			LOG("--------------------------\n");

			REP(i, dp.size()){//横
				if(dp[i] == INF) continue;
				REP(j, n){//行く先の街
					LOG("is need to go %d from %d, %d\n",j, i, i &(1 << j));
					if((i &(1 << j)) == 0){//次の街に行ってないかどうか
						int nxt = i|(1<<j);
						REP(k, n){//装備
							if(i & (1 << k)){
								if (dp_stk[nxt] > dp[i] + stage_times[j][k + 1]){
									dp_stk[nxt] = dp[i] + stage_times[j][k + 1];
									LOG("now %d to %d using %d\n",i, nxt, k);
								}
							}
						}
						//装備なし
						LOG("%d %d\n",dp_stk[nxt], dp[i] + stage_times[j][0]);
						if (dp_stk[nxt] > dp[i] + stage_times[j][0]){
							dp_stk[nxt] = dp[i] + stage_times[j][0];
							LOG("now %d to %d noitem\n",i, nxt);
						}
					}
				}
			}

			dp = dp_stk;
		}

		cout << dp[(1 << n) - 1] << endl;
	}
}

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

int main() {
	int n,k,ans=0;
	cin>>n>>k;
	int dp[n+1];
	for(int i=1;i<=n;i++)
		dp[i]=0;
	while(k--){
		int d;
		cin>>d;
		for(int i=0,x;i<d;i++){
			cin>>x;
			dp[x]++;
		}
	}
	for(int i=1;i<=n;i++)
		if(!dp[i])
			ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;

int main(){
    int N;

    cin >> N;
    
    vector<int> p(N),q(N);

    rep(i,0,N){
        cin >> p[i];
        q = p;
        sort(q.begin(),q.end());
    }
    int cnt=0;

    rep(i,0,N){
        if(p[i] != q[i]){
            cnt++;
        }
        
    }
    if(cnt <=2){
        cout << "YES" <<endl;
    }else{
        cout << "NO" <<endl;
    }



    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int area = x * y;
		int Circum = x * 2 + y * 2; 
		System.out.println(area + " " + Circum);
		
	}
}

Measured memory_bytes: 26012
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        if(r == 1 || c == 1) {
            System.out.println("1");
        }
        else {
           if(r % 2 == 0) {
                System.out.println((r/2)*(long)c);
            }
            else if(r % 2 != 0) {
                long ans = 0;
                int temp = (r/2)+1;
                for(int i = 1; i <= c; i++) {
                    if(i % 2 != 0) {
                        ans += temp;    
                    }
                    else {
                        ans += temp-1;
                    }
                }
                System.out.println(ans);   
            } 
        }
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, wsum, bsum;
string s;
ll ans;
//ll a[200005];

//ll const BAD = 1e9+7;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	cin >> s;
	for (ll i = 0; i < n; i++){
		//if (s[i] == '.' && s[i+1] == '#' && s[i+2] == '.'){ans += 1}
		if (s[i] == '.'){wsum +=1;}
		}
		ans = bsum+wsum;
		for (ll i = 0; i < n; i++){
			if (s[i] == '.'){
				wsum -= 1;
				}else if (s[i] == '#') {
					bsum += 1;
					}
			ans= min(ans, bsum+wsum);	
				}
		cout << ans;
}

Measured memory_bytes: 1228
import java.util.*;

class Main{

    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();

	int Y = sc.nextInt();

	int a = -1;

	int b = -1;

	int c = -1;

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

	for(int j=0; j<=N-i; j++){

	if((10000*i+5000*j+1000*(N-i-j))==Y){

	a = i;

	b = j;

	c = N-i-j;	

   }			

  }

  }

	System.out.println(a+" "+b+" "+c);	

 }
}

Measured memory_bytes: 23252
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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


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

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int nissu = sc.nextInt();
        
        for(int a=0; a<nissu; a++){
            int Nkin = sc.nextInt();
            int Pkin = sc.nextInt();
            int Nmai = sc.nextInt();
            int Pmai = sc.nextInt();
            int gokei=(Nkin*Nmai)+(Pkin*Pmai);
            
            if(Nmai>=5&&Pmai>=2){
                gokei = (Nkin*Nmai+Pkin*Pmai)*4/5;
            }else{
                if(Nmai<5){
                    Nmai = 5;
                }
                if(Pmai<2){
                    Pmai = 2;
                }
                int hiki = (Nkin*Nmai+Pkin*Pmai)*4/5;
                
                if(gokei>hiki){
                    gokei = hiki;
                }
            }
                System.out.println(gokei);
        }
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}
                
                
            

Measured memory_bytes: 23276
# -*- coding: utf-8 -*-

mat1 = {}
mat2 = {}

n, m, l = map(int, raw_input().split())
for i in range(1, n+1):
    list = map(int, raw_input().split())
    for j in range(1, m+1):
        mat1[(i, j)] = list[j-1]

for j in range(1, m+1):
    list = map(int, raw_input().split())
    for k in range(1, l+1):
        mat2[(j, k)] = list[k-1]

for i in range(1, n+1):
    buf = ""
    for k in range(1, l+1):
        res = 0
        for j in range(1, m+1):
            res += mat1[(i, j)]*mat2[(j, k)]
        buf += str(res) +" "
    buf = buf.rstrip()
    print buf

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	int N, M; cin >> N >> M;
	vector<int> a(M), b(M);
	rep(i, M) scanf("%d%d", &a[i], &b[i]), a[i]--, b[i]--;
	union_find uf(N * 2);
	rep(i, M) uf.unite(a[i], N + b[i]), uf.unite(N + a[i], b[i]);
	bool bipartite = true;
	rep(u, N) if (uf.same(u, N + u)) bipartite = false;
	if (bipartite) {
		int x = 0, y = 0;
		rep(u, N) if (uf.same(0, u)) x++; else y++;
		cout << (ll)x * y - M << endl;
	}
	else cout << (ll)N * (N - 1) / 2 - M << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int a[100][1000],n,cnt[100],u,sum,chain;string S,T;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>S;u=0;sum=0;
		for(int i=0;i<10;i++){cnt[i]=0;}
		for(int i=0;i<S.size();i++){
			if(S[i]=='['){
				u++;T="";chain=0;
			}
			else if(S[i]==']'){
				if(T!=""){
					cnt[u]=0;
					u--;
					a[u][cnt[u]]=stoi(T);
					cnt[u]++;
					T="";
				}
				else{
					chain++;
					sum=0;
					sort(a[u],a[u]+cnt[u]);
					if(chain==1){
						for(int i=0;i<cnt[u]/2+1;i++){
							sum+=a[u][i]/2+1;
						}
						cnt[u]=0;
						u--;
						a[u][cnt[u]]=sum;
					}
					else{
						sum=0;
						for(int i=0;i<cnt[u]/2+1;i++){
							sum+=a[u][i];
						}
						cnt[u]=0;
						u--;
						a[u][cnt[u]]=sum;
					}
					cnt[u]++;
				}
			}
			else{
				T+=S[i];chain=0;
			}
		}
		u=0;
		cout<<sum<<endl;
	}
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int h, w, i, j;
	cin >> h >> w;
	vs c(h);
	for (i = 0; i < h; i++) {
		cin >> c[i];
		cout << c[i] << endl << c[i] << endl;
	}

}

Measured memory_bytes: 256
package main

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

func main() {
	x, a, b := nextInt(), nextInt(), nextInt()
	if math.Abs(float64(x-a)) < math.Abs(float64(x-b)) {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
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;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
void debug(vector<vector<ll>>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;}};
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->second++;

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n),b(n+1),c(n+1);
  for(i=0;i<n;i++){
    cin>>a[i];
    b[i+1]=max(b[i],a[i]);
  }
  for(i=n-1;i>=0;i--){
    c[i]=max(c[i+1],a[i]);
  }
  for(i=0;i<n;i++){
    cout<<max(b[i],c[i+1])<<endl;
  }


  return 0;
}

Measured memory_bytes: 7808
h,w,n=map(int,input().split())
sy,sx=map(int,input().split())
s=input()
t=input()
for i in range(n):
  tmp1=s[i]
  tmp2=t[i]
flag=True
for i in range(4):
  if i==0 or i==1:
    pos=sx
  elif i==2 or i==3:
    pos=sy
  for j in range(1,n+1):
    tmp1=s[j-1]
    tmp2=t[j-1]
    if i==0:
      if tmp1=='L':
        pos-=1
        if pos==0:
          flag=False
      if tmp2=='R':
        pos+=1
        if pos>w:
          pos=w
    elif i==1:
      if tmp1=='R':
        pos+=1
        if pos>w:
          flag=False
      if tmp2=='L':
        pos-=1
        if pos==0:
          pos=1
    elif i==2:
      if tmp1=='U':
        pos-=1
        if pos==0:
          flag=False
      if tmp2=='D':
        pos+=1
        if pos>h:
          pos=h
    elif i==3:
      if tmp1=='D':
        pos+=1
        if pos>h:
          flag=False
      if tmp2=='U':
        pos-=1
        if pos==0:
          pos=1
if flag==True:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3896
#nに行くまでの道で正の閉路があればいくらでも大きくすることができる
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
  a,b,c=map(int,input().split())
  es.append([a-1,b-1,c])

def BellmanFord(n,s,es):
  d=[-float("INF")]*n
  d[s]=0
  cnt=0
  while(1):
    update=False
    for p,q,r in es:
      if d[p]!=-float("INF") and d[q]<d[p]+r:
        d[q]=d[p]+r
        update=True
    cnt+=1
    if not update:
      break
    if cnt==n:
      #負の経路がある場合
      #さらにこっからn回繰り返してd[n-1]が更新されるかみる
      negative=[False]*n
      for i in range(n):
        for p,q,r in es:
          if d[q]<d[p]+r:
            negative[q]=True
            d[q]=d[p]+r
      if negative[n-1]==True:
        print("inf")
        exit()
      else:
        print(d[n-1])
        exit()
        
  print(d[n-1])
  
  
  
BellmanFord(n,0,es)

Measured memory_bytes: 74676
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		for (auto i : boost::irange(0, 63))
		{
			if (p & (1ULL << i))
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
	template<std::uint64_t Mod>class modnum :
		private boost::addable<modnum<Mod>>,
		private boost::subtractable<modnum<Mod>>,
		private boost::multipliable<modnum<Mod>>,
		private boost::dividable<modnum<Mod>>
	{
		std::uint64_t val;
		void clamp()
		{
			val %= Mod;
		}
	public:
		modnum() = default;
		modnum(std::int64_t v) :val()
		{
			if (v < 0)
			{
				v += (std::abs(v) / Mod + 1) * Mod;
			}
			val = v;
			clamp();
		}
		modnum(std::uint64_t v) :val(v)
		{
			clamp();
		}
		modnum(std::int32_t v) :modnum(static_cast<std::int64_t>(v))
		{

		}
		modnum(std::uint32_t v) :modnum(static_cast<std::uint64_t>(v))
		{

		}
		friend std::ostream& operator<<(std::ostream& os, modnum const& num)
		{
			return os << num.val;
		}
		auto& operator+=(modnum const& rhs)
		{
			val += rhs.val;
			clamp();
			return *this;
		}
		auto& operator-=(modnum const& rhs)
		{
			val += Mod - rhs.val;
			clamp();
			return *this;
		}
		auto& operator*=(modnum const& rhs)
		{
			val *= rhs.val;
			clamp();
			return *this;
		}
		auto& operator/=(modnum const& rhs)
		{
			val *= pow(rhs, Mod - 2).val;
			clamp();
			return *this;
		}
		auto const& operator*()const
		{
			return val;
		}
	};
}
using mod_t = lib::modnum<998244353>;


void Main()
{
	int N;
	std::cin >> N;
	int f;
	std::cin >> f;
	std::vector<int> count(N);
	++count[f];
	for (auto i : boost::irange(1, N))
	{
		int v;
		std::cin >> v;
		++count[v];
	}
	if (f != 0 || count[0] != 1)
	{
		std::cout << 0 << std::endl;
		return;
	}
	mod_t result = 1, prev = 1;
	for (auto i : boost::irange(1, N))
	{
		result *= lib::pow(prev, count[i]);
		prev = count[i];
	}
	std::cout << result << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl '\n'
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL);
#define pb push_back
#define pii pair<int,int>
#define ll long long int 
#define pll pair<ll,ll> 
#define mp make_pair
#define f first
#define s second
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}



//~ _________________________________________________________________________________


using namespace std;

ll sum(int l,int r,vector<ll> v)	
{		
	ll x=0;
	for(int i=l;i<=r;++i)
			x+=v[i];
	
	return x;
}

int main()
{
	fio
	int n;
	cin>>n;
	
	vector<ll> v(n);
	
	for(int i=0;i<n;++i)
	{
		cin>>v[i];
	}
	ll dp[n][n];
	memset(dp,0,sizeof(dp));
	
	//dp[l][r] = min cost to merge l->r slimes to 1;
	

	for(int l=n-1;l>=0;--l)
	{
		for(int r=l;r<n;++r)
		{
			if(l==r)
				dp[l][r]=0;
			else
			{
			ll t=sum(l,r,v);
			
			dp[l][r]=1e15L;
		// i is the splitter index
				for(int i=l;i<r;++i)
				{
					dp[l][r]=min(dp[l][r],dp[l][i] + dp[i+1][r]+t);
				}
			}
		}
	}
	
	
	cout<<dp[0][n-1]<<endl;
	return 0;


}
	
	





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

using namespace std;

const int mod = 1000000007;

int main()
{
    int n, m, i;
    scanf("%d%d", &n, &m);

    if(abs(n - m) >= 2)
    {
        puts("0");
        return 0;
    }

    int r = 1;
    for(i = 1; i <= n; i++)
        r = 1LL * r * i % mod;
    for(i = 1; i <= m; i++)
        r = 1LL * r * i % mod;

    if(n == m)
        r = 1LL * r * 2 % mod;

    printf("%d\n", r);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ULL ull
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int, pii >
#define pll pair <ll,ll>
#define pb push_back
#define big 20160116
#define INF 2147483647
#define pq priority_queue
using namespace std;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
namespace Mymath{
	LL qp(LL x,LL p,LL mod){
		LL ans=1;
		while (p){
			if (p&1) ans=ans*x%mod;
			x=x*x%mod;
			p>>=1;
		}
		return ans;
	}
	LL inv(LL x,LL mod){
		return qp(x,mod-2,mod);
	}
	LL C(LL N,LL K,LL fact[],LL mod){
		return fact[N]*inv(fact[K],mod)%mod*inv(fact[N-K],mod)%mod;
	}
	template <typename Tp> Tp gcd(Tp A,Tp B){
		if (B==0) return A;
		return gcd(B,A%B);
	}
	template <typename Tp> Tp lcm(Tp A,Tp B){
		return A*B/gcd(A,B);
	}
};
namespace fwt{
	using namespace Mymath;
	void FWT(int a[],int n,LL mod)
	{
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=(x+y)%mod,a[i+j+d]=(x-y+mod)%mod;
	                //xor:a[i+j]=x+y,a[i+j+d]=x-y;
	                //and:a[i+j]=x+y;
	                //or:a[i+j+d]=x+y;
	            }
	}

	void UFWT(int a[],int n,LL mod)
	{
		LL rev=inv(2,mod);
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=1LL*(x+y)*rev%mod,a[i+j+d]=(1LL*(x-y)*rev%mod+mod)%mod;
	                //xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2;
	                //and:a[i+j]=x-y;
	                //or:a[i+j+d]=y-x;
	            }
	}
	void solve(int a[],int b[],int n,LL mod)
	{
	    FWT(a,n,mod);
	    FWT(b,n,mod);
	    for(int i=0;i<n;i++) a[i]=1LL*a[i]*b[i]%mod;
	    UFWT(a,n,mod);
	}
};
const int Maxn=100005;
int a[Maxn],n,k;
int main(){
	scanf("%d %d",&n,&k);
	k--;
	int pos;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i]==1) pos=i;
	}
	int ans=1e9;
	for (int i=0;i<=k;i++){
		int lf=i,rg=k-i;
		lf=max(0,pos-1-lf);
		rg=max(0,(n-pos)-rg);
		int cur=(lf+k-1)/k+(rg+k-1)/k;
		ans=min(ans,cur);
	}
	cout<<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;

int N, M, cnt = 0;
char s[MAX_N];
int g[MAX_N];
vector<int> ans;

int main() {
    scanf("%d %d", &N, &M);
    scanf("%s", s);
    for (int i = 0; i <= N; i++) {
        if (s[i] == '0') {
            g[cnt++] = i;
        }
    }
    int cur = N;
    while (cur != 0) {
        int i = lower_bound(g, g+cnt, cur-M) - g;
        if (g[i] == cur) {
            printf("-1\n");
            return 0;
        }
        ans.push_back(cur-g[i]);
        cur = g[i];
    }
    for (int i = ans.size()-1; i >= 1; i--) {
        printf("%d ", ans[i]);
    }
    printf("%d\n", ans[0]);
    return 0;
}


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

int main(){
    vector<int> vec;
    int s, e;
    cin >> s;
    vec.push_back(s);
    bool flag = true;
    while(flag){
        if(s % 2 == 0) e = s / 2;
        else e = 3 * s + 1;
        vec.push_back(e);
        for(int i = 0; i < vec.size() - 1; i++){
            if(vec[i] == e) flag = false;
        }
        s = e;
    }
    cout << vec.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int A[100],i,j,min,N,flag=1,count=0;

  scanf("%d",&N);
  if(N>=1 && N<=100){
    for(i=0;i<N;i++){
      scanf("%d",&A[i]);
    }
    while(flag){
      flag=0;
      for(j=N-1;j>=1;j--){
	if(A[j]<A[j-1]){
	  min=A[j];
	  A[j]=A[j-1];
	  A[j-1]=min;
	  flag=1;
	  count++;
	}}}
    for(i=0;i<N;i++){
      if(i>0) printf(" ");
      printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 604
#include <stdio.h>

int main(){
	int i;
	int cnt[4]={0};
	for(i = 0;i<3;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		cnt[a-1]++;
		cnt[b-1]++;
	}
	int cnt1 = 0;
	int cnt2 = 0;
	for(i = 0;i<=3;i++){
		if(cnt[i] == 1)cnt1++;
		if(cnt[i] == 2)cnt2++;
	}
	if(cnt1==2&&cnt2==2){
		printf("YES\n");
	}else
		printf("NO\n");
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/
vec<vll> dp;


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n, weight; cin >> n >> weight;
    vi w(n), v(n); rep(i,n) cin >> w[i] >> v[i];

    dp.resize(n+1, vll(112345,infll));  // 価値の総和の最大値は Vmax * Nmax
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 112345; ++j) {
            if(j - v[i] >= 0) chmin(dp[i+1][j], dp[i][j - v[i]] + w[i]);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }

    int ans = -1;
    //  重さが"weight"を越えない中で、価値(二つ目の添え字)が最大のものを探すので
    for(int i = 112344; i >= 0; --i) {
        if(dp[n][i] > weight) continue;
        ans = i;
        break;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 89984
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
w = s.count('W')

pos = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'W':
        ans += i - pos
        pos += 1
print(ans)

Measured memory_bytes: 10140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main() {
  int a ,b;
  scanf("%d %d\n",&a, &b);
  printf("%d\n",a+b/2);
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, m;
  cin>>n>>m;
  cout<<(n==m ? "Yes" : "No")<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
     
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
     
using namespace std;
 
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

ll A = 11;

string f(ll x)
{
    string res;
    while (x)
    {
        res += (char)('0' + x % 10);
        x /= 10;
    }
    reverse(res.begin(), res.end());
    return res;
}

bool ask(ll n)
{
    cout << "? " << n << endl;
    char c;
    cin >> c;
    return (c == 'Y');
    //return (n <= A && f(n) <= f(A)) || (n > A && f(n) > f(A));
}

void ans(ll n)
{
    cout << "! " << n << endl;
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    vector<ll> a = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
    bool ok = true;
    int len = 0;
    rep(i, 1, 10)
    {
        bool res = ask(a[i]);
        if (!res)
        {
            ok = false;
            len = i;
            break;
        }
    }
    if (ok)
    {
        repb(i, 9, 0)
            if (!ask(a[i] - 1))
            {
                ans(a[i]);
                return 0;
            }
        ans(a[0]);
        return 0;
    }
    ll curr = 0;
    rep(p, 0, len - 1)
    {
        ll l = 0, r = 10, mid;
        while (r - l > 1)
        {
            mid = (l + r) / 2;
            if (ask(curr * 10 + mid))
                l = mid;
            else
                r = mid;
        }
        curr = curr * 10 + l;
    }
    ll l = -1, r = 9, mid;
    while (r - l > 1)
    {
        mid = (l + r) / 2;
        if (ask((curr * 10 + mid) * 10))
            r = mid;
        else
            l = mid;
    }
    curr = curr * 10 + r;
    ans(curr);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>


using namespace std;


int main()
{
	int n;
	int* a = new int[n];

	cin >> n;

	for (int i = 0 ; i < n ; i++)	cin >> a[i];

	int count =0;

	for (int i = 0 ; i < n ; i++){
		while (a[i]%2 == 0){
		count++;
		a[i] /= 2;
		}
	}

	cout << count << "\n";
}


Measured memory_bytes: 256
xa,ya,xb,yb=gets.chomp.split(" ").map { |e| e.to_i }


a = xb - xa
b = yb - ya

 x= -b
 y = a

 if b >= 0
   printf("%d %d %d %d",xb+x,yb+y,xa+x,ya+y)
 elsif b < 0
   printf("%d %d %d %d",xb+x,yb+y,xa+x,ya+y)
 end


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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}

const int NBITS = 60;

ll basis[NBITS][2]; 

ll sz[2]={0}; 

void insertVector(ll mask, int no)
{
	for (ll i = 0; i < NBITS; i++)
	{
		if ((mask & 1LL << i) == 0) continue; 
		if (!basis[i][no]) 
		{ 
			basis[i][no] = mask;
			++sz[no];
			return;
		}

		mask ^= basis[i][no];
	}
}

ll checkBasis(ll mask, int no)
{
	for (ll i = 0; i < NBITS; i++)
	{
		if ((mask & 1LL << i) == 0) continue; 
		if (!basis[i][no]) 
		{ 
			// basis[i][no] = mask;
			// ++sz[no];
			return 1;
		}

		mask ^= basis[i][no];
	}
	return 0;
}

int main()
{
	fastio;
	ll t;
	cin>>t;
	while(t--)
	{
		
		ll n,a[1000],i,j,k;
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			// insertVector(a[i]);
		}
		string str;
		cin>>str;	
		ll ans=0;
		// for(j=n-1;j>=0;j--)
		// {
		// 	ll fl=0;
		// 	insertVector(a[j],str[j]-'0');
		// 	if(str[j]=='1')
		// 		fl=checkBasis(a[j], 0);
		// 	if(fl)
		// 	{
		// 		ans=1;
		// 		break;
		// 	}
		// }
		// ll ans=0;
		for(i=0;i<n;i++)
		{
			if(str[i]=='1')
			{
				memset(basis,0,sizeof(basis));
				memset(sz,0,sizeof(sz));
				for(j=i+1;j<n;j++)
				{
					if(str[j]=='0')
						insertVector(a[j],0);
				}
				ans += checkBasis(a[i], 0);
			}
		}
		// for(ll j=0;j<2;j++)
		// {
		// 	for(i=0;i<5;i++)
		// 		cout<<basis[i][j]<<" ";
		// 	cout<<endl;
		// }
		ans = (ans>0);
		cout<<ans<<endl;
	}
    return 0;
}





Measured memory_bytes: 3660