akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  int N;
  cin >> N;
  FORIN(a, 1, 10) {
    FORIN(b, 1, 10) {
      if (a * b == N) {
        print("Yes");
        return 0;
      }
    }
  }
  print("No");
  return 0;
}

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

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<ll> sumW(n + 1, 0);
    REP(i, n) {
        if (s[i] == 'W') sumW[i + 1] = sumW[i] + 1;
        else sumW[i + 1] = sumW[i];
    }
    // for (auto i : sumW) cout << i << ' ';
    // cout << '\n';

    vector<ll> sumE(n + 1, 0);
    REP(i, n) {
        if (s[i] == 'E') sumE[i + 1] = sumE[i] + 1;
        else sumE[i + 1] = sumE[i];
    }
    // for (auto i : sumE) cout << i << ' ';
    // cout << '\n';

    ll mini = INT_MAX;
    REP(i, n + 1) {
        ll toRight = sumW[i];
        ll toLeft = sumE[n] - sumE[i];
        // cout << toRight << ' ' << toLeft << '\n';
        mini = min(mini, toRight + toLeft);
    }

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


Measured memory_bytes: 5396
n, l = map(int, input().split())
ret = 0
eat = [1e9, 0]
for i in range(1, n+1):
    ret += i
    if abs(i + l - 1) < eat[0]:
        eat = [abs(i + l - 1), i + l - 1]
ret += ((l - 1) * n)
print(ret - eat[1])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int DEBUG = 0;

int n;
vector<vector<int>> d;
vector<vector<bool>> ex;

void bfs(int i, int j) {
    vector<P> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    for (auto p : dir) {
        int ni = i + p.second, nj = j + p.first;
        if (!(0 <= ni && ni < n && 0 <= nj && nj < n) || d[ni][nj] <= d[i][j])
            continue;
        
        if (ex[i][j]) {
            if (d[ni][nj] == d[i][j] + 1)
                continue;
            d[ni][nj] = d[i][j] + 1;
        }
        else
            d[ni][nj] = d[i][j];
        
        bfs(ni, nj);
    }
}

int main() {
    cin >> n;
    vector<int> p(n*n);
    for (int i = 0; i < n * n; i++)
        cin >> p[i];
    
    for (int i = 0; i < n; i++) {
        vector<int> di;
        vector<bool> exi;
        for (int j = 0; j < n; j++) {
            int dij = min(min(i, n-i-1), min(j, n-j-1));
            di.push_back(dij);
            exi.push_back(true);
        }
        d.push_back(di);
        ex.push_back(exi);
    }
    
    if (DEBUG >= 1) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (ex[i][j])
                    cout << " " << d[i][j] << " ";
                else
                    cout << "[" << d[i][j] << "]";
            }
            cout << endl;
        }
        cout << endl;
    }
    
    int ans = 0;
    for (auto pi : p) {
        pi--;
        int i = pi / n, j = pi % n;
        ex[i][j] = false;
        ans += d[i][j];
        bfs(i, j);
        
        if (DEBUG) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (ex[i][j])
                        cout << " " << d[i][j] << " ";
                    else
                        cout << "[" << d[i][j] << "]";
                }
                cout << endl;
            }
            cout << endl;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 50684
#include "bits/stdc++.h"
//#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
  int A[3],b;
  rep(i,3)cin>>A[i];
  sort(A,A+3);
  b=0;
  rep(i,2)b+=A[i+1]-A[i];
  cout<<b<<endl;
}

Measured memory_bytes: 256
S = list(input())
od = ['R', 'U', 'D'] 
ev = ['L', 'U', 'D'] 

ans = 'Yes'
for i,s in enumerate(S):
    if i%2 == 0:
        if s in od:
            pass
        else:
            ans = 'No'
            break
    else:
        if s in ev:
            pass
        else:
            ans = 'No'
            break

print(ans)

Measured memory_bytes: 3060
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <time.h>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9

const double eps = 1e-10;
ll a[55];
const ll maxn = 1e16 +1000;
int main()
{
    long long  k;
    cin >> k;
    ll t = k / 50;
    k %= 50;
    for(int i = 0 ; i < 50 ; i ++) {
        a[i] = i + t;
    }
    for(int i = 0 ; i < k ; i ++) {
        a[49-i] ++;
    }

    cout << 50<<endl;
    for(int i = 0 ; i < 50 ; i ++) {
        if(i) cout <<" ";
        cout <<a[i];
    }
    cout <<endl;

    return 0;
}



Measured memory_bytes: 256
// ABC072B - OddString

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

int main() {
	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i++) {
		if (i % 2 == 0) {
			cout << S[i];
		}
	}
	cout << endl;

	return 0;
}


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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define bitcount(n) __builtin_popcount(n)

int main(){
    int N;
    cin >> N;
    cout << N * 800 - N / 15 * 200 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int read()
{int x=0,f=0;
char c=getchar();
while (c<'0'||c>'9') 
{if (c=='-') f=1;
c=getchar();
}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
if (f) x=-x;
return x;
}
char s[200005],o[200005];
int cnt[27],n;
vector <int> vec[27];
int t[200005],p[200005];
inline int ask(int p)
{int s=0;
while (p)
{s+=t[p];p-=(p&(-p));}
return s;
}
inline void add(int p)
{while (p<=n)
{t[p]++;p+=(p&(-p));}
}
pair<int,int> u[100005];
int cont=0;
int main (){
	scanf ("%s",s+1);
	n=strlen(s+1);int i,num=0;
	for (i=1;i<=n;i++)
	{cnt[s[i]-'a']++;
	vec[s[i]-'a'].push_back(i);
	}
	for (i=0;i<26;i++)
	{if (cnt[i]%2==1) {num++;}
	}
	if (num>=2) {puts("-1");return 0;}
	for (i=0;i<26;i++)
	{int p1=0,p2=cnt[i]-1;
	while (p1<p2)
	{u[++cont].first=vec[i][p1];
	u[cont].second=vec[i][p2];
	p1++;p2--;
	}
	if (cnt[i]&1) {p[(n+1)/2]=vec[i][p1];}
	}
	sort(u+1,u+cont+1);
	for (i=1;i<=cont;i++)
	{p[i]=u[i].first;
	p[n+1-i]=u[i].second;
	}
	ll ans=0;
	for (i=1;i<=n;i++)
	{ans+=ask(n)-ask(p[i]);
	add(p[i]);
	}
	printf ("%lld",ans);
	return 0;
}
	
	

Measured memory_bytes: 3832
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

class SplitStream {
	typedef basic_ostream<char, char_traits<char> > BaseOst;
	std::ostream& ost_m;
	bool line_is_empty_m;
public:
	SplitStream(std::ostream& ost);
	template <typename T>
	SplitStream& operator<<(T right);
	SplitStream& operator<<(BaseOst& (*right)(BaseOst&));
};
SplitStream::SplitStream(std::ostream& ost) : ost_m(ost), line_is_empty_m(true) {}
template <typename T>
SplitStream& SplitStream::operator<<(T right) {
	if (!line_is_empty_m) ost_m << ' ';
	line_is_empty_m = false;
	ost_m << right;
	return *this;
}
/* std::endl のみ */
SplitStream& SplitStream::operator<<(BaseOst& (*right)(BaseOst&)) {
	ost_m << '\n';
	ost_m.flush();
	line_is_empty_m = true;
	return *this;
}
SplitStream Scout(cout);

int N, K, A, B;

int main() {
	cin >> N >> K >> A >> B;
	cout << (N > K ? A * K + B * (N - K) : A * N) << endl;;
	return 0;
}

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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = a / 100;
            int c = a % 100;
            if(c > 5 * b)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1);
            }
        }
    }
}


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

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; }

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    int N;
    cin>>N;
    vector<int> C(N),S(N),F(N);
    rep(i,N-1) cin>>C[i]>>S[i]>>F[i];
    rep(i,N){
        int ans = 0;
        int p = i;
        while(p<N-1){
            if(ans<=S[p]){
                ans = S[p]+C[p];
                p++;
                continue;
            }
            else{
                ans = ((ans-1)/F[p])*F[p]+F[p]+C[p];
                p++;
                continue;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
    int A, P;
    cin >> A >> P;
    cout << (3 * A + P) / 2 << endl;
}


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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  
  bool ans = true;
  for(int i = 0; i < a + b + 1; i++){
    if(i != a && s.at(i) == '-' || i == a && s.at(i) != '-') ans = false;
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		Otoshidama solver = new Otoshidama();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}


	static class Otoshidama {

		private int y;
		private int n;

		private Scanner scanner;
		private String output;

		public Otoshidama() {
			scanner = new Scanner(System.in);
		}

		public void readInput() {
			n = Integer.parseInt(scanner.next());
			y = Integer.parseInt(scanner.next());
			return ;
		}

		public void solve() {
			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) {
						output = String.format("%d %d %d", i,j,(n-i-j));
						return;
					}
				}
			}
			output = "-1 -1 -1";
			return ;
		}

		public void writeOutput() {
			System.out.println(output);
		}

	}

}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<vector<int> > hxy(N, vector<int>(3,0));
    for(int i=0; i<N; i++){
        cin >> hxy[i][1] >> hxy[i][2] >> hxy[i][0];
    }
    sort(hxy.rbegin(), hxy.rend());

    bool flag=true;
    for(int cx=0; cx<=100; cx++){
        for(int cy=0; cy<=100; cy++){
            long long H;
            if(hxy[0][0]>0){
                H=hxy[0][0]+abs(hxy[0][1]-cx)+abs(hxy[0][2]-cy);
            }else{
                H=1;
            }

            flag=true;
            for(int i=0; i<N; i++){
                long long h=hxy[i][0]+abs(hxy[i][1]-cx)+abs(hxy[i][2]-cy);
                if(hxy[i][0]==0 && H<=h)continue;
                if(H!=h){
                    flag=false;
                    break;
                }
            }
            if(flag==true){
                cout << cx << ' ' << cy << ' ' << H << endl;
                return 0;
            }
        }
    }
}

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

#define REP(id, num) for (auto id = 0; id < num; id++) 

#define MAX_NUM (int)1e5 + 10
#define INF (int)1e9

using namespace std;

int dp[MAX_NUM];
int h[MAX_NUM];

void chmin(int &a, int b);

int main()
{
  REP(id, MAX_NUM)
    dp[id] = INF;

  int N;
  cin >> N;

  REP(id, N)
    cin >> h[id];

  //cin >> h[0];
  dp[0] = 0;

  // 配るDP
  REP(id, N)
  {
    chmin(dp[id + 1], dp[id] + abs(h[id + 1] - h[id]));
    chmin(dp[id + 2], dp[id] + abs(h[id + 2] - h[id]));
  }

  cout << dp[N - 1] << endl;
}

void chmin(int &a, int b)
{
  if (a > b)
    a = b;
}


Measured memory_bytes: 1024
n = int(input())
f = []
for i in range(n):
    f1 = list(map(int,input().split()))
    f.append(f1)
p = []
for i in range(n):
    p1 = list(map(int,input().split()))
    p.append(p1)
dayl = [0,1,2,3,4,5,6,7,8,9]
ans = []
for i in range(1,2**10):
    day = []
    for j in range(10):
        if ((i >> j) & 1):
            day.append(dayl[j])
    ans1 = 0
    for x in range(n):
        count = 0
        for j in day:
            count += f[x][j]
        ans1 += p[x][count]
    ans.append(ans1)
print(max(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define inf 1001001001
using namespace std;
typedef long long ll;
int main(void) {
    int n, t; cin >> n >> t;
    int mi = inf;
    rep(i, n) {
        int a, b; cin >> a >> b;
        if(b<=t) mi = min(mi, a);
    }
    if(mi == inf) cout <<"TLE";
    else cout << mi;
}



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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const llint INF = 1e9;
const llint llINF = 1e18;

int main () {
    int n; cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    int next = 1, ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == next) {
            next++;
        } else {
            ans++;
        }
    }
    if (ans == n) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()

	dna := []string{"A", "C", "G", "T"}
	dict := map[string]bool{}
	for _, v1 := range dna {
		for _, v2 := range dna {
			for _, v3 := range dna {
				key := v1 + v2 + v3
				dict[key] = false
			}
		}
	}

	for sc.Scan() {
		inputs := strings.Split(sc.Text(), " ")

		switch inputs[0] {
		case "insert":
			dict[inputs[1]] = true
		case "find":
			if dict[inputs[1]] {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		}
	}
}



Measured memory_bytes: 38272
# -*- coding: utf-8 -*-
N,K=map(int, raw_input().split())
A=map(int, raw_input().split())

#10**12は2進数で40桁あるので、余裕を見て50桁分用意しておく
keta=50
L=[[N,0]]
#a1~anの同じ桁を見て、0の出現個数、1の出現個数を数える
for i in range(keta-1,-1,-1): #i 何桁目を見ているかを表す
    count=[ 0 for _ in range(2) ]
    for a in A:
        key=a>>i&1  #key aを2進数で表現した時、i桁目が0か1かをkeyに代入
        count[key]+=1
    L.append(count)

T=[ float("-inf") for _ in range(keta+1) ]
F=[ float("-inf")  for _ in range(keta+1) ]
F[0]=0

for i in range(1,keta+1):
    bit=K>>(keta-i)&1
    if bit==1:
        F[i]=F[i-1]+2**(keta-i)*L[i][0] #未満:Falseのdp表の横向き（→）の遷移
        #max( 未満:False→未満：Trueへのdp表の斜めの遷移, 未満:Falseのdp表の横向き（→）の遷移 bitが1、未満:Falseのdp表の横向き（→）の遷移 bitが0 )
        T[i]=max( F[i-1]+2**(keta-i)*L[i][1],T[i-1]+2**(keta-i)*L[i][0],T[i-1]+2**(keta-i)*L[i][1] )
    else:
        F[i]=F[i-1]+2**(keta-i)*L[i][1] #未満:Falseのdp表の横向き（→）の遷移
        T[i]=max( T[i-1]+2**(keta-i)*L[i][0],T[i-1]+2**(keta-i)*L[i][1] )   #未満:Trueのdp表の横向き（→）の遷移


print max(T[-1],F[-1])


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

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

int main() {
    string s;
    cin >> s;
    if(s[s.size() - 1] == 's') {
        cout << s + "es" << endl;
    } else {
        cout << s + 's' << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> V(K);
    REP(i, K) V[i] = 0;
    REP(i, N) V[i%K]++;
    cout << V[0]-V[V.size()-1] << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(x,b) (0<=(x)&&(x)<(b))
using namespace std;
int box[5][5][5];
int M[2][27];

int judge(int z, int y, int x){
  int a = 0;
  for(int i = -1; i <= 1; ++i)
    for(int j = -1; j <= 1; ++j)
      for(int k = -1; k <= 1; ++k)
	if(BW(z+i,5) && BW(y+j,5) && BW(x+k,5))
	  a += box[z+i][y+j][x+k];
	
  a -= box[z][y][x];
  if(M[box[z][y][x]][a]) return 1;
  return 0;
}

int main(){
  int N, cnt = 1, a, b;
  char in[8];
  while(scanf("%d", &N) && N){
    rep(i, 5) rep(j, 5){
      scanf("%s", in);
      rep(k, 5) box[i][j][k] = in[k]-'0';
    }
    rep(i, 2){
      rep(j, 27) M[i][j] = 0;
      scanf("%d", &a);
      while(a--){
	scanf("%d", &b);
	M[i][b] = 1;
      }
    }
    rep(j, 27) M[1][j] ^= 1;

    rep(h, N){
      queue<int>zq,xq,yq;
      rep(i, 5) rep(j,5) rep(k, 5){
	if(judge(i, j, k)){
	  zq.push(i); yq.push(j); xq.push(k);
	}
      }

      while(!zq.empty()){
	int z, x, y;
	z = zq.front(); zq.pop();
	y = yq.front(); yq.pop();
	x = xq.front(); xq.pop();
	box[z][y][x] ^= 1;
      }
    }
    if(cnt>1) puts("");
    printf("Case %d:\n", cnt);
    rep(i, 5){
      rep(j, 5){
	rep(k, 5) printf("%d", box[i][j][k]);
	puts("");
      }
      if(i != 4) puts("");
    }
    cnt++;
  }
  return 0;
}

Measured memory_bytes: 1200
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
         
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
        const int N=300006;
        int unread[N],d[N];
        signed main()
        {
        	double n;
        	cin>>n;
        	
        	double l=n/3;
        	double b=(n-n/3)/2;
        	double h=n-(l+b);
        	cout<<fixed<<setprecision(6)<<l*b*h;
		}

Measured memory_bytes: 256
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var d = new int[int.Parse(Console.ReadLine())].Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).OrderBy(x => -x.Sum()).ToArray();
		Console.WriteLine(d.Where((x, i) => i % 2 == 0).Sum(x => x[0]) - d.Where((x, i) => i % 2 == 1).Sum(x => x[1]));
	}
}


Measured memory_bytes: 30512
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
/*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());*/
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}
void solve(){
    string s;
    cin >> s;
    int n = (int)s.size();
    ll ans = 0;
    for(int i = 0; i < (1 << (n - 1)); ++i){
        vector<int> pos = {-1};
        for(int j = 0; j < n - 1; ++j){
            if(i & (1 << j)){
                pos.push_back(j);
            }
        }
        pos.push_back(n - 1);
        for(int j = 0; j < (int)pos.size() - 1; ++j){
            ll cur = 0;
            ll t = 1;
            for(int k = pos[j + 1]; k > pos[j]; --k){
                cur += t * (s[k] - '0');
                t *= 1LL * 10;
            }
            ans += cur;
        }
    }
    cout << ans << endl;

}

int main(){
    /*ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);*/

    int t;
    t = 1;
    int test = 0;
    while(t--){
        /*cout << "Case " << ++test << ": ";*/
        solve();
    }

}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long

using namespace std;

inline ll read()
{
    ll ret=0,flag=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
    while(c>='0'&&c<='9')ret=ret*10+(c^'0'),c=getchar();
    return flag*ret;
}

const ll N=2e5+5;
ll n;
ll s[N];
ll sum[N],_xor[N];
ll ans;

int main()
{
    n=read();
    for(ll i=1;i<=n;i++)s[i]=read();
    for(ll i=1;i<=n;i++)sum[i]=s[i]+sum[i-1],_xor[i]=s[i]^_xor[i-1];
    for(ll l=1,r=1;l<=n;)
    {
        while(r<n&&sum[r+1]-sum[l-1]==(_xor[r+1]^_xor[l-1]))
            r++;
        ans+=r-l+1;
        l++;
        if(r<l)r=l;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>S;
    cout<<(S[0] == S[2] ? "Yes" : "No")<<endl;
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  lint w, h, x, y;
  cin >> w >> h >> x >> y;

  double ans1 = w * h;
  printf("%.6f ", (double)(w * h) / 2);
  if (w % 2 == 0 && h % 2 == 0) {
    if (x == w / 2 && y == h / 2) {
      printf("1\n");
    } else {
      printf("0\n");
    }
  } else {
    printf("0\n");
  }

  return 0;
}

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

double dist(int *a, int *b, int N) {
  int sum = 0;
  for(int i = 0; i < N; i++)
    sum += (a[i] - b[i]) * (a[i] - b[i]);
  return sqrt(sum);
}

int main()
{
  int N, D;
  cin >> N >> D;
  int **a = new int*[N];
  for(int i = 0; i < N; i++)
    a[i] = new int[D];
  for(int i = 0; i < N; i++)
    for(int j = 0; j < D; j++)
      cin >> a[i][j];
  int count = 0;
  for(int i = 0; i < N - 1; i++) {
  	for(int j = i + 1; j < N; j++) {
      double tmp = dist(a[i], a[j], D);
      if((tmp - (int)tmp) == 0.0)
        count++;
    }
  }
  cout << count << endl;
  for(int i = 0; i < N; i++)
    delete[] a[i];
  delete[] a;
  return 0;
}

Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()
    a = na()

    dp = [INF for _ in range(n)]
    dp[0] = 0

    for i in range(n):
        nxt1 = min(i + 1, n - 1)
        cost = abs(a[i] - a[nxt1])
        dp[nxt1] = min(dp[nxt1], dp[i] + cost)

        nxt2 = min(i + 2, n - 1)
        cost = abs(a[i] - a[nxt2])
        dp[nxt2] = min(dp[nxt2], dp[i] + cost)

    print(dp[n - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 21896
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 1100000000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;

vector<ll> X,Y;

int main(){
    ll x[100],y[100],ans=7000000000000000000;
    int N,K,count=0;
    cin>>N>>K;

    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i];
        X.push_back(x[i]);
        Y.push_back(y[i]);
    }

    sort(X.begin(),X.end());sort(Y.begin(),Y.end());
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            for(int k=0;k<N-1;k++){
                for(int l=k+1;l<N;l++,count=0){
                    for(int n=0;n<N;n++){
                        if(x[n]>=X[i] && x[n]<=X[j] && y[n]>=Y[k] && y[n]<=Y[l]) count++;
                    }
                    //cout<<count<<endl;
                    if(count>=K) ans=min(ans,(X[j]-X[i])*(Y[l]-Y[k]));
                }
            }
        }
    }
    cout<<ans<<endl;


}


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

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7;

/////////////////////////////////////////////////////////////////////

const int N = 3e3 + 20;

int a[N], dp[N][N][2];

int32_t main(){

    sync;

    int n; cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int l = n - 1; l >= 0; l--) for(int r = l; r < n; r++) {
    	if (a[l] + dp[l + 1][r][1] < a[r] + dp[l][r - 1][1]) dp[l][r][0] = a[r] + dp[l][r - 1][1], dp[l][r][1] = dp[l][r - 1][0];
    	else dp[l][r][0] = a[l] + dp[l + 1][r][1], dp[l][r][1] = dp[l + 1][r][0];
    }
    cout << dp[0][n - 1][0] - dp[0][n - 1][1] << endl;

    return 0;
}

Measured memory_bytes: 141568
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;


static const int MMAX = 20;
static const int NMAX = 50000;
static const int INFTY = (1 << 29);



int main(){


  int n, m; //金額，　種類

  cin >> n >> m;

  int C[MMAX + 1];//コインの種類
  int T[NMAX + 1];//コインの枚数のメモリDPテーブル

  for(int i = 1; i <= m; ++i) cin >> C[i];

  REP(i, NMAX) T[i] = INFTY;  //十分大きな値を入れて初期化

  T[0] = 0;

  for(int i = 1; i <= m; ++i){
    for(int j = 0; j + C[i]<= n; ++j){
      T[j + C[i]] = min(T[j + C[i]], T[j] + 1);
    }
  }

  cout << T[n] << endl;

  return 0;


}


Measured memory_bytes: 3280
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int n = reader.nextInt();
		solver(n);
	}
	
	public static void solver(int N) {
		// write logic
		int ans = 0;
		for(int i=1; i<=N; i+=2) {
			int tmp = 0;
			for (int j=1; j<=i; j++) {
				if (i%j==0) tmp++;
			}
			if (tmp == 8) ans++;
		}
		System.out.println(ans);
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}



Measured memory_bytes: 32388
import Data.Char

main = do
  s <- getLine
  let x = read s
      y = f s 0
  if mod x y == 0
    then putStrLn "Yes"
    else putStrLn "No"

f :: String -> Int -> Int
f [] n = n
f (x:xs) n = f xs $ n + (ord x) - (ord '0')

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

using namespace std;


#define MAXN 501
int main() {
  int a, b;
  string ans[100];
  cin >> a >> b;
  for (int i = 0; i < 100; ++i) {
    if (i<50) {
      string s(100, '.');
      ans[i] = s;
    } else {
      string s(100, '#');
      ans[i] = s;
    }
  }
  for (int i = 0; i < b-1; ++i) {
    int r = i/50;
    int s = i%50;
    ans[r*2+1][s*2] = '#';
  }
  for (int i = 0; i < a-1; ++i) {
    int r = i/50;
    int s = i%50;
    ans[r*2+51][s*2] = '.';
  }
  cout << 100 <<  " " << 100 << endl;
  for (int i = 0; i < 100; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] array = new int[n];
		for(int i=0;i<k;i++) {
			int d = sc.nextInt();
			for(int j=0;j<d;j++) {
				array[sc.nextInt()-1]=1;
			}
		}
		int count=0;
		for(int i=0;i<n;i++) {
			if(array[i]==0) count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 46172
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  stack<int> S1;
  stack<pair<int, int> > S2;
  char ch;
  int sum = 0;
  for (int i = 0; cin >> ch; i++){
    if(ch == '\\') S1.push(i);
    else if (ch == '/' && S1.size() > 0){
      int j = S1.top(); S1.pop();
      sum += i-j;
      int a = i - j;
      while(S2.size()>0 && S2.top().first >j){
        a += S2.top().second; S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  while(S2.size() > 0){ans.push_back(S2.top().second); S2.pop();}
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++){
    cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1284
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
scs = sorted([tuple(map(int, input().split())) for _ in range(M)])
ans = ['0'] * N

if M == 0:
    if N != 1:
        ans[0] = '1'
    print(''.join(ans))
    sys.exit()

if scs[0][0] != 1:
    if N != 1:
        ans[0] = '1'

for s, c in scs:
    if ans[s-1] != '0' and ans[s-1] != str(c):
        print(-1)
        sys.exit()
    else:
        ans[s-1] = str(c)

if ans[0] == '0' and N != 1:
    print(-1)
else:
    print(''.join(ans))

Measured memory_bytes: 61812
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

int edge[26][26],nasi[26][26];
int visi[26];

void dfs(int node){
	rep(i,26)if( nasi[node][i]>0 && !visi[i] ){
		visi[i] = 1;
		dfs(i);
	}
}

int main(){
	int n;
	string in;
	
	while(scanf("%d",&n),n){
		rep(i,26)rep(j,26)edge[i][j]=nasi[i][j]=0;
		memset(visi,0,sizeof(visi));

		set<int> st;
		rep(i,n){
			cin>>in;
			char a = in[0];
			char b = in[in.size()-1];
			edge[a-'a'][b-'a']++;
			nasi[a-'a'][b-'a'] = nasi[b-'a'][a-'a'] = 1;
			st.insert(a-'a');
			st.insert(b-'a');
		}

#if DEB
		rep(i,26){
			rep(j,26){
				printf("%d ",edge[i][j]);
			}
			puts("");
		}
#endif

		visi[*(st.begin())] = 1;
		dfs(*(st.begin()));
		set<int>::iterator it;
		bool f = true;
		for(it=st.begin(); it!=st.end(); it++){
			if( !visi[*it] ){
				f = false; break;
			}
		}
		if( !f ){
			puts("NG"); continue;
		}
		
		f = true;
		rep(i,26){
			int sum = 0;
			rep(j,26)sum += (edge[i][j]-edge[j][i]);
			if( sum!=0 ){
				f = false;
				break;
			}
		}
		puts(f?"OK":"NG");
	}
	
	return 0;
}

Measured memory_bytes: 936
#include<bits/stdc++.h>
using namespace std;
int n,tw,fo,sing;
 int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i) 
	{
		int x;
		scanf("%d",&x);
		if (x%4==0) fo++;
		else if (x%2==0) tw++;
		else sing++;
	}
	if (tw>0) sing++;
	sing--;
	if (fo-sing<0) puts("No");
	else puts("Yes");
 } 

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdlib>
#include <typeinfo>

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

using namespace std;

template<class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template<class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void trace(int A[], int N) {
  for (int i = 0; i < N; ++i) {
    if (i > 0) cout << " ";
    cout << A[i];
  }
  cout << endl;
}

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

string str_tolower(string s) {
  transform(s.begin(), s.end(), s.begin(),
            [](unsigned char c) { return tolower(c); });
  return s;
}

////////////////////////////////////////////////////////////

string str;
int q;
string command;
int a;
int b;
string p;

int main() {
  cin >> str;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> command;
    if (command == "replace") {
      cin >> a >> b >> p;
      str.replace(a, b - a + 1, p);
    } else if (command == "reverse") {
      cin >> a >> b;
      p = str.substr(a, b - a + 1);
      reverse(p.begin(), p.end());
      str = str.replace(a, b - a + 1, p);
    } else if (command == "print") {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
}



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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

class Packet {
public:
	int t, s, d;
	bool operator<(Packet p) {
		return t < p.t;
	}
};

signed main() {
	for (int N, M; cin >> N >> M&&N;) {
		vector<char> f(N, false);
		f[0] = true;
		vector<Packet> P(M);
		rep(i, 0, M) {
			cin >> P[i].t >> P[i].s >> P[i].d;
			P[i].s--, P[i].d--;
		}
		sort(P.begin(), P.end());
		rep(i, 0, M) {
			if (f[P[i].s])f[P[i].d] = true;
		}
		int ans = 0;
		rep(i, 0, N) {
			if (f[i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3268
var
  i,a,b:longint;
  s:string;
begin
  read(a,b);
  if a>b then
    begin
      i:=a;a:=b;b:=i;
    end;

  for i:=a to b do
    if (a*b*i) mod 2=1 then
      begin
        write('Yes');
        exit;
      end;
  write('No');
end.

Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as BC
import Data.Maybe

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

comb :: Int -> [a] -> [[a]]
comb 0 xs = [[]]
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs

main :: IO ()
main = do
  getLine
  ds <- readIntsLine
  let mul [x, y] = x * y
  print . sum . map mul $ comb 2 ds

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main() {
  int N,W;
  cin>>N>>W;
  vector<int> wi(N),v(N);
  for(int i(0);i<N;i++){
    cin>>wi[i]>>v[i];
  }
  ll dp[101][100001] = {0};
  for(int i(1);i<=N;i++){
    for(int w(0);w<=W;w++){
      if(w >= wi[i-1]){
        dp[i][w] = max(dp[i-1][w],dp[i-1][w-wi[i-1]] + v[i-1]);
      }else{
        dp[i][w] = dp[i-1][w];
      }
    }
  }
  ll ans(0);
  for(int i(0);i<=W;i++){
    ans = max(ans,dp[N][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int main()
{long long int x,y,z,a,b,c;
 cin>>a>>b>>c;
 x=a;
 y=b;
 z=c;
 long long int temp1;
 temp1=x;
 x=y;
 y=temp1;
 long long int temp2;
 temp2=x;
 x=z;
 z=temp2;
 cout<<x<<" "<<y<<" "<<z;
}
 
 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
char a[300010];
int w[300010],e[300010];
int ans=0x7fffffff;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<=n;i++)
	{
		scanf("%c",&a[i]);
		if(a[i]=='W') w[i]=w[i-1]+1,e[i]=e[i-1];
		else e[i]=e[i-1]+1,w[i]=w[i-1];
	}
	for(int i=1;i<=n;i++)
		ans=min(ans,w[i-1]+e[n]-e[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2944