akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

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

void solve(){
    int n;
    cin >> n;
    if(n < 1000){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
}

int main(){
    solve();
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll H,N; cin >> H >> N;
    ll sum = 0;
    for (int i = 0;i < N;i++){
        ll t; cin >> t;
        sum += t;
    }

    cout << (sum >= H ? "Yes":"No") << endl;

    return 0;

}

Measured memory_bytes: 256
N, K = map(int, input().split())
p = 10**9+7
S = 0
memo = []
for i in reversed(range(1, K+1)):
  rep = K//i
  num = pow(rep, N, p)
  sub = 0
  if rep > 1:
    for j in range(rep - 1):
      sub += memo[- i - j * i][1]
  num -= sub
  S += i * num
  S = S%p
  memo += [(i, num)]
print(S)

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100010
#define MAX_V 		102
#define MAX_E 		1005

const ll LINF = (ll)1e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	int N,K;cin >> N>>K;
	Vint A(N);
	REP(i,N)cin>>A[i];

	int ans = 0;
	REP(i,N){
		if(A[i] >= K)ans ++;
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	char hand[200200];
	for(int i = 0; i < 200200; i++) hand[i] = 'y';
	ll n,k; cin>>n>>k;
	ll r,s,p; cin>>r>>s>>p;
	string  t; cin>>t;
	char prev = 'y'; ll ans = 0;
	for(int i = 0; i < n; i++){
		if(t[i] == 'r') {
			if(i-k >= 0){
				if(hand[i-k] != 'p') { hand[i] = 'p'; ans += p;}
			}
			else { hand[i] = 'p'; ans += p;}
		}
		else if(t[i] == 'p') {
			if(i-k >= 0){
				if(hand[i-k] != 's') { hand[i] = 's'; ans += s;}
			}
			else { hand[i] = 's'; ans += s;}
		}
		else if(t[i] == 's') {
			if(i-k >= 0){
				if(hand[i-k] != 'r') { hand[i] = 'r'; ans += r;}
			}
			else { hand[i] = 'r'; ans += r;}
		}
		else {}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  ll tmp1 = 0, tmp2 = 0;
  REP(i, N-1) {
    tmp1 += i+1;
  }
  REP(i, M-1) {
    tmp2 += i+1;
  }
  cout << tmp1 + tmp2 << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func scanText() string {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	return sc.Text()
}

func reverse(s string) (result string) {
	for _, v := range s {
		result = string(v) + result
	}
	return
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	N := 2019
	s := reverse(scanText())
	m := make([]int, N)
	total := 0
	d := 1
	m[0] = 1
	for _, c := range s {
		n, _ := strconv.Atoi(string(c))
		total += n * d
		total %= 2019
		d = (d * 10) % N
		m[total]++
	}
	sum := 0
	for _, v := range m {
		sum += v * (v - 1) / 2
	}
	fmt.Println(sum)
}


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

int cnt = 0;
void InsertionSort(int A[], int n, int g)
{
    for (int i = g; i < n; i++)
    {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v)
        {
            A[j+g] = A[j];
            j = j-g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void ShellSort(int A[], int n)
{
    int m, l=1, G[100];
    while (l <= n)
    {
        G[m] = l;
        l = 3*l+1;
        m++;
    }
    for (int i = 0; i < m/2; i++) swap(G[i], G[m-(i+1)]);
    for (int i = 0; i < m; i++) InsertionSort(A, n, G[i]);
    printf("%d\n", m);
    for (int i = 0; i < m; i++) printf("%d ", G[i]);
    printf("\n%d\n", cnt);
}

int main() 
{
    int n;
    int A[1000000];
    cin >> n;
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    ShellSort(A, n);
    for (int i = 0; i < n; i++) printf("%d\n", A[i]);
}


Measured memory_bytes: 7096
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int a[22][22],h,w,mi;
using namespace std;
void dfs(int y,int x,int depth){
	if(depth>=mi)return;
	r(i,4){
		int y1=y,x1=x,c=0,cc=1;
		while(1){
			if(i>1){
				if(y1<0||y1>=h){c++;goto P;}
				if(cc&&i==2&&a[y1+1][x1]==1){c++;goto P;}
				if(cc&&i==3&&a[y1-1][x1]==1){c++;goto P;}
				if(y1+1<h&&i==2&&a[y1+1][x1])goto P;
				if(y1-1>=0&&i==3&&a[y1-1][x1])goto P;
			}
			else{
				if(x1<0||x1>=w){c++;goto P;}
				if(cc&&i==0&&a[y1][x1+1]==1){c++;goto P;}
				if(cc&&i==1&&a[y1][x1-1]==1){c++;goto P;}
				if(x1+1<w&&i==0&&a[y1][x1+1])goto P;
				if(x1-1>=0&&i==1&&a[y1][x1-1])goto P;
			}y1+=dy[i];x1+=dx[i];cc=0;
		}
		P:;int y2=y1+dy[i],x2=x1+dx[i];
		if(!c){if(a[y2][x2]==3||mi<depth+1){mi=depth+1;return;}
		else{
			a[y2][x2]=0;
			dfs(y1,x1,depth+1);
			a[y2][x2]=1;
		}}
	}
}
int main(){
	int hh,ww;
	while(cin>>w>>h,w){
		r(i,h)r(j,w){
			cin>>a[i][j];
			if(a[i][j]==2){
				a[i][j]=0;
				hh=i;mi=11;
				ww=j;
			}
		}
		dfs(hh,ww,0);
		if(mi==11)cout<<-1<<endl;
		else cout<<mi<<endl;
	}
}

Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int [] iList= new int[n];
		int right = 0;
		for (int i=0;i<n;i++) {
			iList[i] = sc.nextInt();
			right += iList[i];
		}
		int left = 0;
		List<Integer> dis = new ArrayList<>();

		for (int i=0;i<n-1;i++) {
			left += iList[i];
			right -= iList[i];
			dis.add(Math.abs(left-right));
		}



		System.out.println(Collections.min(dis));
	}

}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int mod = 998244353;

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,s;
cin>>n>>s;
vector<int>a(n);
rep(i,n)cin>>a[i];
vector<mint> dp(s+1,0);
dp[0]=1;
rep(i,n){
    vector<mint> p(s+1,0);
    swap(dp,p);
    rep(j,s+1){
        dp[j]+=p[j]*2;
        if(j+a[i]<=s){
            dp[j+a[i]]+=p[j];
        }
    }
}
cout<<dp[s]<<endl;
return 0;
}

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

int main() {
  int r,D,x;
  int ans = 0;

  cin >> r >> D >> x;

  for (int i = 0; i < 10; i++) {
	ans = r * x - D;
    cout << ans << endl;
    x = ans;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<string, int > P;
bool cmp( pair< P, int > a, pair< P, int > b )
{
    if( a.first.first == b.first.first ) return a.first.second > b.first.second;
    return a.first.first < b.first.first;
}
main()
{
    int n;
    cin >> n;
    vector< pair<P, int> > p(n), q(n);
    for( int i=0; i < n; i++ )
    {
        cin >> p[i].first.first >> p[i].first.second;
        p[i].second = i + 1;
    }
    q = p;
    sort( begin(p), end(p), cmp );
    for( int i = 0; i < n; i++ )
    {
        printf( "%d\n", p[i].second); 
    }
    return 0;
}

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

//vector <long long> v;

//long long int  x[1000000], y[1000000], pot[30], czy=0, w, n, m;
char s;

int main()
{
    long long int a, b, c, d, k, i, j, q, t, p;

//    q=1;
//    scanf("%lld", &q);
//    for(t=0; t<q; t++)
    {
        scanf("%c", &s);

        if(s>='a' && s<='z')printf("a\n");
        else printf("A\n");
    }

    return(0);
}


Measured memory_bytes: 3760
N = int(input())
R = [int(input()) for i in list(range(N))]
maxv = -1000000000
minr = R[0]

for i in list(range(1, N)):
    maxv = max(maxv, R[i] - minr)
    minr = min(minr, R[i])

print(maxv)

Measured memory_bytes: 23576
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){


  while(1){
    int n;
    cin >> n;
    if(n==0)break;
    string s;
    int r=0,l=0,sum=0,ans=0;
    rep(i,n){
      cin >> s;
      
      if(s[0] == 'l'){
	if(l) l=0;
	else l=1;
      }
      if(s[0] == 'r'){
	if(r) r=0;
	else r=1;
      }
      if(sum == 0 && r+l == 2){
	sum = 2;
	ans++;
      }
      else if(sum == 2 && r+l==0){
	sum = 0;
	ans++;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  ll n;
  
  cin >> n;
  
  vector<string> w(n);  rep(i, 0, n) cin >> w[i];
  
  bool ans = true;
  rep(i, 1, n) {
    if(w[i][0] != w[i-1][w[i-1].size()-1]) ans = false;
  }
  
  rep(i, 0, n) {
    rep(j, i+1, n) {
      if(w[i] == w[j]) ans = false;
    }
  }
  
  cout << ( ans ?"Yes" :"No") << "\n";

}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, m; std::cin >> n >> m;
  vi cnt(n);
  rep(i, m) {
    int l, r; std::cin >> l >> r;
    --l, --r;
    cnt[l]++;
    if (r+1 < n) cnt[r+1]--;
  }
  srep(i, 1, n) cnt[i] += cnt[i-1];
  int ans = 0;
  rep(i, n) if (cnt[i] == m) ans++;
  std::cout << ans << "\n";
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long int dp[101][100001];

main(){
long long int n,k;
cin>>n>>k;
long long int ar[n];
for(int i=0;i<n;i++)cin>>ar[i];
//memset(dp,1,sizeof(dp));

for(int i=0;i<n;i++)dp[i][0]=1;


for(int i=0;i<n;i++)for(int j=1;j<=k;j++)
{
if(i==0){if(j<=ar[i])dp[i][j]=1;
	else{  dp[i][j]=0;} }
	
else{
dp[i][j]=(dp[i-1][j]+dp[i][j-1]);


	if(ar[i]<j){dp[i][j]-=dp[i-1][j-1-ar[i]];}
}
//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;

dp[i][j]=(1000000007+dp[i][j])%1000000007;

}
cout<<dp[n-1][k];



}


Measured memory_bytes: 81648
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define endl '\n'

int mod = 1e9 + 7;

int pw(int a, int k) {
    if (k == 0) return 1;
    if (k % 2) return ((long long) pw(a, k - 1) * a) % mod;
    int t = pw(a, k / 2);
    return ((long long) t * t) % mod;
}

int rv(int a) {
    return pw(a, mod - 2);
}

int ml(int a, int b) {
    return ((long long)a * b) % mod;
}

int ml(int a, int b, int c) {
    return ml(ml(a, b), c);
}

int dv(int a, int b) {
    return ml(a, rv(b));
}

int sm(int a, int b) {
    return (a + b) % mod;
}

int df(int a, int b) {
    return ((long long)a + mod - b) % mod;
}

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

string yy = "YES\n";
string nn = "NO\n";
string imp = "IMPOSSIBLE\n";



int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1; // cin >> t;
    while (t--) {
        string s; cin >> s;
        if (s.back() == 's') {
            cout << s << "es";
        }
        else cout << s << "s";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3680
n = int(input())
h = [0 for _ in range(n)]

th = 100
for x in range(1,th+1):
  for y in range(1,th+1):
    for z in range(1,th+1):
      val = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if val <= n:
        h[val-1] += 1

for i in range(n):
  print(h[i])

Measured memory_bytes: 9148
#include<bits/stdc++.h>
using namespace std;
int main()
{
int X,Y;
cin>>X>>Y;
int s[102]={0};
for(int i=0;i<Y;i++){
int a;
cin>>a;
s[a]=1;
}
if(Y==0){
cout<<X<<endl;
return 0;
}
int diff=INT_MAX;
int res,res1;
for(int i=0;i<=101;i++)
{
 if(s[i]==0)
 {
     res=abs(X-i);
     if(res<diff){
     diff=res;
     res1=i;
     }
 }
}
cout<<res1<<endl;
return 0;
}

Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#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

using namespace std;
int main()
{
	int Alength;
	cin >> Alength;
	vector<int> B(Alength - 1),A(Alength);
		for (int i = 0; i < Alength-1; i++)
		{
			cin >> B.at(i);
		}
		A.at(0) = B.at(0);
		for (size_t i = 1; i < Alength-1; i++)
		{
			A.at(i) = min(B.at(i), B.at(i - 1));
		}
		A.at(Alength - 1) = B.at(Alength - 2);
		int Answer;
		for (size_t i = 0; i < Alength; i++)
		{
			Answer += A.at(i);
		}
		cout << Answer << endl;
}


Measured memory_bytes: 256
from heapq import heapify, heappop, heappush

def main():

    # Aをpriority qにつっこむ
    # 大きい順にM回discountする
    # 最後に総計を計算する

    N, M = map(int,input().split())
    A = list(map(int,input().split()))
    A = [-a for a in A]
    heapify(A)

    while M > 0:
        a = -heappop(A)
        a //= 2
        heappush(A, -a)
        M -= 1
    
    ans = 0
    for a in A:
        ans -= a

    print(ans)

if __name__ == "__main__":
    main()


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

#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N, x;
    cin >> N >> x;
    int l[N];
    rep(i, N){
        cin >> l[i];
    }
    int ans = 0;
    int s = 0;
    rep(i, N){
    if(s <= x){
        ans++;
        s += l[i];
    }else{
        break;
    }
    }
    if(s <= x){
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 1005, M = 36;

ii P[MX];

main() {
	if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
	ios_base::sync_with_stdio(0), cin.tie(0);

	int N; cin >> N;
	for (int i = 0; i < N; ++i) cin >> P[i].f >> P[i].s;

	bool b = (P[0].f+P[0].s)&1;
	for (int i = 1; i < N; ++i) if ((P[i].f+P[i].s)&1^b) {
		cout << -1;
		return 0;
	}

	if (!b) {
		for (int i = 0; i < N; ++i) --P[i].f;
		cout << M+1 << '\n' << 1 << ' ';
	}
	else cout << M << '\n';
	for (int i = M-1; i >= 0; --i) cout << (1ll<<i) << ' ';
	cout << '\n';

	for (int j = 0; j < N; ++j) {
		if (!b) cout << 'R';

		int X = P[j].f, Y = P[j].s;

		for (int i = M-1; i >= 0; --i) {
			if (X > 0 && abs(Y) <= X) {
				cout << 'R';
				X -= (1ll<<i);
			}
			else if (X < 0 && abs(Y) <= -X) {
				cout << 'L';
				X += (1ll<<i);
			}
			else if (Y > 0 && abs(X) <= Y) {
				cout << 'U';
				Y -= (1ll<<i);
			}
			else {
				cout << 'D';
				Y += (1ll<<i);
			}
			//cout << X << ' ' << Y << '\n';
		}
		cout << '\n';
		//cout << X << ' ' << Y << '\n';
	}
}


Measured memory_bytes: 3600
//
// Created by Hideaki Imamura on 2020-03-12.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll H;

ll rec(ll x) {
    if (x == 1) return 1;
    return 1 + rec(x / 2) * 2;
}

int main() {
    cin >> H;
    cout << rec(H) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
	int Q; 
	cin >> Q;
	for(int q = 0; q < Q; q++){
		long long int A, B; 
		cin >> A >> B; 
		long long int Q = pow(A * B, 0.5); 
		if(A == Q && B == Q){cout << 2 * Q - 2 << endl;}
        else if(A * B == Q * Q){cout << 2 * Q - 3 << endl;}
        else if((A * B - 1) / Q == Q){cout << 2 * Q - 2 << endl;}
		else{cout << 2 * Q - 1 << endl;}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x,y,r,tmp;

  scanf("%d%d",&x,&y);

  if(x < y){
    tmp = x;
    x = y;
    y = tmp;
  }

  r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }

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



Measured memory_bytes: 2144
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	vector<int> A(N);
	for (int i = 1; i < N; ++i) {
		A[i] = A[i - 1] + (S[i] == 'C' && S[i - 1] == 'A');
	}
	for (int i = 0; i < Q; ++i) {
		int L, R;
		cin >> L >> R; --L;
		cout << A[R - 1] - A[L] << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
import itertools

N, M = map(int,input().split())
k = []
for i in range(M):
    k.append(list(map(int,input().split())))
p = list(map(int,input().split()))
ks = [i[0] for i in k]
ss = [i[1:] for i in k]

prods = list(itertools.product([0, 1], repeat=N))
count = 0
for prod in prods:
  check = 0
  for i in range(M):
    s = ss[i]
    # sごとに
    n = sum([prod[j-1] for j in s])
    if n % 2 == p[i]:
      check += 1
  if check == M:
    count += 1
print(count)

Measured memory_bytes: 3188
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	h := getNextInt(scanner)
	w := getNextInt(scanner)
	a := getNextInt(scanner)
	b := getNextInt(scanner)

	for i := 0; i < h; i++ {
		for ii := 0; ii < w; ii++ {
			if i < b {
				if ii < a {
					fmt.Fprint(writer, 0)
					continue
				}
				fmt.Fprint(writer, 1)
				continue
			}
			if ii < a {
				fmt.Fprint(writer, 1)
				continue
			}
			fmt.Fprint(writer, 0)
		}
		fmt.Fprintln(writer, "")
	}

	writer.Flush()
}


Measured memory_bytes: 6528
#include <cstdio>
using namespace std;
const int mod=998244353;
int dp[200005];
int sum[13];
int l[13],r[13];
int n,k;
int m;
void check(int ki,int x){
	if(x-l[ki]>0)sum[ki]=(sum[ki]+dp[x-l[ki]])%mod;
	if(x-r[ki]-1>0)sum[ki]=(sum[ki]-dp[x-r[ki]-1])%mod;
	if(sum[ki]<0)sum[ki]+=mod;
}
int main(){
	dp[1]=1;
	scanf("%d%d",&n,&k);
	for(int i=0;i<k;++i){
		scanf("%d%d",l+i,r+i);
	}
	for(int i=2;i<=n;++i){
		for(int j=0;j<k;++j){
			check(j,i);
			dp[i]=(dp[i]+sum[j])%mod; 
		} 
	}
	printf("%d\n",dp[n]);
	return 0;
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define V vector
signed main(){
  ll N,i,ans;cin>>N>>ans;
  REP(i,N-1){
    ll A;cin>>A;ans=__gcd(A,ans);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long ans = n/(a+b)*a;
        ans += Math.min(a,n%(a+b));
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
using namespace std;
	
int n,a,b;
int main(){
	scanf("%d%d%d",&n,&a,&b);
	if(n*a<b){ 
		printf("%d",(n*a)); 
	}else{
		printf("%d",b); 
	}
	return 0;
} 

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

ll N,A,B,C,D;


int solve(){
	for(ll i=0;i<N;i++){
		ll a = A + C*i - D*(N-1-i);
		ll b = A + D*i - C*(N-1-i);
		if(a <= B && B <= b){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

int main(){
	cin >> N >> A >> B >> C >> D;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
string s;
int main(){
	cin >> s;
	if(s.size()<26){
		for(char c='a';c<='z';c++)
			if(s.find(c)==string::npos){
				cout << s << c;
				return 0;
			}
	}
	for(int i=s.size()-2;i>=0;i--){
		if(s[i]<s[i+1]){
			char t=s[i+1];
				for(int j=i+1;j<s.size();j++)
					if(s[j]>s[i])t=min(t,s[j]);
			s[i]=t;
			s=s.substr(0,i+1);
			cout << s;
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define loop(vals,times) for(vals=0;vals<times;vals++)
#define reg(time) for(int val=0;val<time;val++)
using namespace std;

int main()
{
    int q,qweri,p;
    vector<int> A(0);
    cin>>q;
    reg(q){
    cin>>qweri;
    if(qweri==0){
     cin>>p;
     A.push_back(p);
    }
    if(qweri==1){
        cin>>p;
        cout<<A.at(p)<<endl;
        if(A.size()==0)break;
    }
    if(qweri==2){
        A.pop_back();
    }
    }
}



Measured memory_bytes: 3804
List= [int(input()) for i in range(5)]
amari =9
time = 0
flag = False;
for i in List:
    if(i%10 != 0):
        time += 10 - i%10
        amari = min(amari,i%10)
        flag = True
output = sum(List) + time
if(flag):
    output -= 10 - amari
print(output)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int         long long int
#define vi           vector<int>
#define pii          pair<int,int>
#define vpp          vector<pii>
#define mii          map<int,int>
#define pb           push_back
#define endl        '\n'
#define rep(i,a,bb)  for(int i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         int T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzint(x)
//const int inf = 5 * (1e+18);
const int mod = 1e+18;


vector<vector<int>> v;
int n, m, x;
vector<int> o;
int ans  = mod;
void solve(vector<int> a, int i, int price)
{

  int count = 0;
  for (int j = 0; j < m; j++)
  {
    if (a[j] >= x) count++;
  }
  if (count == m) {ans = min(ans, price); return ;}


  if (i == n) return ;

  solve(a, i + 1, price);
  vi b(m, 0);
  for (int j = 0; j < m; j++)
  {
    b[j] = a[j] + v[i][j + 1];
  }
  solve(b, i + 1, price + v[i][0]);
}

int32_t main()
{
  fast;

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif



  cin >> n >> m >> x;
  vi a;

  for (int i = 0; i < n; i++)
  {
    a.clear();
    for (int j = 0; j <= m; j++)
    {
      int t;
      cin >> t;
      a.pb(t);
    }
    v.pb(a);
  }

  for (int i = 0; i < m; i++)
    o.pb(0);
  solve(o, 0, 0);
  if (ans == mod) cout << -1;
  else
    cout << ans;







}




Measured memory_bytes: 3664
import java.util.*;

public class Main{
	public static void main(String[] artgs){
		int res = 0;
		String s = new Scanner(System.in).nextLine();
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '+') res++;
			else res--;
		}

		System.out.println(res);
	}
}


Measured memory_bytes: 21716
#include<stdio.h>
#include<vector>
#include<queue>
#include<functional>
#define INF 1000000000
using namespace std;
typedef pair<int, int>P;

vector<P> G[100];
int n;
int solve(int s, int g){
	long long d[100];
	priority_queue < P, vector<P>, greater<P>>pque;
	fill(d, d + n, INF);
	d[s] = 0;
	pque.push(P(0, s));
	while (!pque.empty()){
		P p = pque.top(); pque.pop();
		int x = p.second;
		if (d[x] < p.first)continue;
		for (int i = 0; i < G[x].size(); i++){
			P e = G[x][i];
			if (d[e.first] > d[x] + e.second){
				d[e.first] = d[x] + e.second;
				pque.push(P(d[e.first], e.first));
			}
		}
	}
	return d[g] == INF ? -1 : d[g];
}
int main() {
	int k, q, a, b, c;
	scanf("%d%d", &n, &k);
	if (!(n | k))return 0;
	for (int i = 0; i < n; i++)
		G[i].clear();
	for (int i = 0; i < k; i++){
		scanf("%d", &q);
		if (q){
			scanf("%d%d%d", &a, &b, &c);
			a--; b--;
			G[a].push_back(P(b, c));
			G[b].push_back(P(a, c));
		}
		else{
			scanf("%d%d", &a, &b);
			a--;b--;
			printf("%d\n", solve(a, b));
		}
	}
	main();
}

Measured memory_bytes: 2736
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<math.h>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vtype(type) vector<type>
#define vvtype(type) vector<vector<type>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

struct edge
{
	long long to; ll name;
	bool operator<(const edge& rhs) const {
		return name > rhs.name;
	}
};

ll const MAX = 1e5 + 5;

vvll G(MAX);
vll dp(MAX);
vll visited(MAX);


void dfs(ll cur) {
	visited[cur] = 1;
	ll non_antena = 0;
	ll cnt = 0;
	for (auto next : G[cur]) {
		if (visited[next] == 1) {
			continue;
		}
		dfs(next);
		cnt += dp[next];
		if (dp[next] == 0) {
			non_antena++;
		}
	}
	if (non_antena > 1) {
		cnt += non_antena - 1;
	}
	dp[cur] = cnt;
	//cout << cur << " " << cnt << endl;
}

int main() {
	ll n;
	cin >> n;
	REP(i, 1, n - 1) {
		ll a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll start = -1;
	REP(i, 0, n - 1) {
		if (SIZE(G[i]) >= 3) {
			start = i;
		}
	}	
	if (start == -1) {
		cout << 1 << endl;
		return 0;
	}

	dfs(start);
	if (dp[start] == 0) {
		cout << 1 << endl;
	}
	else {
		cout << dp[start] << endl;
	}
}

Measured memory_bytes: 11008
#include <stdio.h>

int memo[100][4][4];
int rireki[102];
int calc(int yotei[100],int day,int max);

int main(int argc,char* argv[]) {
	int N,K;
	int yotei[100]={0};
	int rireki[200];
	int i,j;
	int oneyotei,onepasta;
	scanf("%d %d",&N,&K);
	for(i=0;i<K;i++) {
		scanf("%d %d",&oneyotei,&onepasta);
		yotei[oneyotei-1]=onepasta;
	}
	for(i=0;i<100;i++) {
		for(j=0;j<4;j++) {
			memo[i][j][0]=-1;
			memo[i][j][1]=-1;
			memo[i][j][2]=-1;
			memo[i][j][3]=-1;
		}
	}
	rireki[0]=0;
	rireki[1]=0;
	printf("%d\n",calc(yotei,0,N));
	return 0;
}

int calc(int yotei[100],int day,int max) {
	int mode;
	int result=0;
	if(rireki[day]==rireki[day+1])mode=rireki[day];
	else mode=0;
	if(day>=max)return 1;
	if(memo[day][rireki[day]][rireki[day+1]]>=0)
		return memo[day][rireki[day]][rireki[day+1]];
	if(yotei[day]!=0) {
		if(mode!=yotei[day]) {
			rireki[day+2]=yotei[day];
			result+=calc(yotei,day+1,max);
		}
	} else {
		if(mode!=1) {
			rireki[day+2]=1;
			result+=calc(yotei,day+1,max);
		}
		if(mode!=2) {
			rireki[day+2]=2;
			result+=calc(yotei,day+1,max);
		}
		if(mode!=3) {
			rireki[day+2]=3;
			result+=calc(yotei,day+1,max);
		}
	}
	result%=10000;
	memo[day][rireki[day]][rireki[day+1]]=result;
	return result;
}

Measured memory_bytes: 0
n, m = map(int, input().split())
p = list(map(int, input().split()))
xys = [list(map(int, input().split())) for _ in range(m)]
mapp = [[] for _ in range(n + 1)]
for xy in xys:
    mapp[xy[0]].append(xy[1])
    mapp[xy[1]].append(xy[0])

bfs = [0] * (n + 1)
count = 0
for i in range(1, n + 1):
    nexts = mapp[i]
    if not(bfs[i]):
        bfs[i] = i
    for j in nexts:
        if bfs[j]:
            continue
        bfs[j] = i
        nexts += mapp[j]
    if bfs[i] == bfs[p[i - 1]]:
        count += 1
print(count)

Measured memory_bytes: 46752
n,y =map(int,input().split())

ans=[]
for i in range(n+1):
    for j in range(n-i+1):
        if i*1000 + j*5000 + (n-i-j)*10000 == y:
            ans.append( str(n-i-j)+" "+str(j)+" "+str(i) )
            
if len(ans)==0:
    print(-1," ",-1," ",-1)
else:
    print(ans[0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,l,r,a,b,ans=0,p,q;
priority_queue<int> L;
priority_queue<int,vector<int>,greater<int>> R;
void pushL(int x){L.push(x-a);}
void pushR(int x){R.push(x-b);}
int topL(){return p=L.top()+a;}
int topR(){return q=R.top()+b;}
signed main()
{
	scanf("%lld",&n);
	while(n--)
	{
		scanf("%lld%lld",&l,&r);
		int len=r-l;
		b+=len;
		pushL(r);pushR(r);
		while(topL()>topR())
		{
			ans+=p-q;
			L.pop();R.pop();
			pushL(q);pushR(p);
		}
		a-=len;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 2036
def main():
    N = int(input())
    S = input()
    R, G, B = [0] * (N + 1), [0] * (N + 1), [0] * (N + 1)
    for i in range(N - 1, -1, -1):
        R[i], G[i], B[i] = R[i + 1], G[i + 1], B[i + 1]
        if S[i] == 'R':
            R[i] += 1
        elif S[i] == 'G':
            G[i] += 1
        else:
            B[i] += 1
    ans = 0
    for i in range(N):
        for j in range(i + 1, N - 1):
            if S[i] == S[j]:
                continue
            if j + (j - i) + 1 < N + 1:
                if S[i] + S[j] == 'RG':
                    ans += B[j + 1]
                    if B[j + (j - i) + 1] != B[j + (j - i)]:
                        ans -= 1
                elif S[i] + S[j] == 'GR':
                    ans += B[j + 1]
                    if B[j + (j - i) + 1] != B[j + (j - i)]:
                        ans -= 1
                elif S[i] + S[j] == 'RB':
                    ans += G[j + 1]
                    if G[j + (j - i) + 1] != G[j + (j - i)]:
                        ans -= 1
                elif S[i] + S[j] == 'BR':
                    ans += G[j + 1]
                    if G[j + (j - i) + 1] != G[j + (j - i)]:
                        ans -= 1
                elif S[i] + S[j] == 'GB':
                    ans += R[j + 1]
                    if R[j + (j - i) + 1] != R[j + (j - i)]:
                        ans -= 1
                elif S[i] + S[j] == 'BG':
                    ans += R[j + 1]
                    if R[j + (j - i) + 1] != R[j + (j - i)]:
                        ans -= 1
            else:
                if S[i] + S[j] == 'RG':
                    ans += B[j + 1]
                elif S[i] + S[j] == 'GR':
                    ans += B[j + 1]
                elif S[i] + S[j] == 'RB':
                    ans += G[j + 1]
                elif S[i] + S[j] == 'BR':
                    ans += G[j + 1]
                elif S[i] + S[j] == 'GB':
                    ans += R[j + 1]
                elif S[i] + S[j] == 'BG':
                    ans += R[j + 1]
    print(ans)


if __name__ == '__main__':
    main()


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

enum
{
    MAX_V = 300 + 10, MAX_Z = 2000 + 50
};

const long long INF = 1000000000000;
long long dp[MAX_Z][MAX_V];
long long SG[MAX_V][MAX_V], LG[MAX_V][MAX_V];
int rt[MAX_Z], rtl;
int n, m;

void floyd()
{
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                SG[i][j] = min(SG[i][j], SG[i][k] + SG[k][j]);
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                LG[i][j] = min(LG[i][j], LG[i][k] + LG[k][j]);
    for(int i = 1; i <= n; i++)
        LG[i][i] = SG[i][i] = 0;
}

int main()
{
    while(~scanf("%d%d", &n, &m), n+m)
    {
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                SG[i][j] = LG[i][j] = INF;
        for(int i = 0; i < m; i++)
        {
            int x, y;
            long long cs;
            char tp;
            scanf("%d %d %lld %c", &x, &y, &cs, &tp);
            if(tp == 'S')
            {
                SG[x][y] = min(SG[x][y], cs);
                SG[y][x] = min(SG[y][x], cs);
            }
            else
            {
                LG[x][y] = min(LG[x][y], cs);
                LG[y][x] = min(LG[y][x], cs);
            }
        }
        scanf("%d", &rtl);
        for(int i = 1; i <= rtl; i++)
            scanf("%d", &rt[i]);

        floyd();
        for(int i = 1; i <= rtl; i++)
            for(int j = 1; j <= n; j++)
                dp[i][j] = INF;

        dp[1][rt[1]] = 0;
        for(int i = 2; i <= rtl; i++)
            for(int j = 1; j <= n; j++)
                for(int k = 1; k <= n; k++)
                {
                    if(j != k)
                        dp[i][j] = min(dp[i][j], dp[i - 1][k] + LG[k][rt[i - 1]] + SG[k][j] + LG[j][rt[i]]);
                    else
                        dp[i][j] = min(dp[i][j], dp[i - 1][k] + LG[rt[i-1]][rt[i]]);
                }

        long long ans = *min_element(dp[rtl] + 1, dp[rtl] + n + 1);
        if(ans == INF);
        else printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
 
int main(){
  int n,slen;
  string s,d[38]={
    "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t",
    "u","v","w","x","y","z","ld","mb","mp","nc","nd","ng","nt","nw","ps","qu","cw","ts"
  };
  map<P,int> m;
  vector<int> v;
  cin>>n;
  for(int i=0;i<38;i++)
    for(int j=0;j<38;j++)
      m.insert(make_pair(P(i,j),0));
  while(cin>>s){
    slen=s.size();
    s+="#####";    
    for(int i=0;i<slen;i++){
      string subs=s.substr(i,2);
      int f=0,ind;
      for(int j=0;j<38;j++){
    if(j<26&&s[i]==d[j][0])ind=j;
    if(subs==d[j]){
      f=1;
      i++;
      v.push_back(j);
    }
      }
      if(!f)v.push_back(ind);
    }
    for(int i=0;i<v.size()-1;i++)
      m[P(v[i],v[i+1])]++;
    v.clear();
  }
  map<P,int>::iterator ite;
  int ans1=0,ans2=0,ansmax=m[P(0,0)];
  for(ite=m.begin();ite!=m.end();ite++){
    if(ans1!=(*ite).first.first){
      cout<<d[ans1]<<' '<<d[ans2]<<' '<<ansmax<<endl;
      ans1++;
      if(ansmax<(*ite).second){
    ans2=(*ite).first.second;
    ansmax=(*ite).second;
      }
      ans2=0,ansmax=m[P(ans1,0)];
    }else{
      if(ansmax<(*ite).second){
    ans2=(*ite).first.second;
    ansmax=(*ite).second;
      }
    }
  }
  cout<<d[ans1]<<' '<<d[ans2]<<' '<<ansmax<<endl;
  
  m.clear();
  return 0;
}

Measured memory_bytes: 1336
{-# OPTIONS_GHC -O #-}

import Data.List
import Control.Monad

main=do
    [n,x]<-map read.words<$>getLine::IO[Int]
    ms<-replicateM n readLn :: IO[Int]

    print $ n + ((x - (sum ms)) `div` (minimum ms)) 

Measured memory_bytes: 1020
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
  int s[50][2],c[50][2];
  int m,n,i,j,d,p,t;
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)scanf("%d%d",&s[i][0],&s[i][1]);
  for(i=0;i<m;i++)scanf("%d%d",&c[i][0],&c[i][1]);
  for(i=0;i<n;i++){
    d=abs(s[i][0]-c[m-1][0])+abs(s[i][1]-c[m-1][1]);p=m-1;
    for(j=m-1;j>-1;j--){
      t=abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]);
      if(d>=t){d=t;p=j+1;}
    }
    printf("%d\n",p);
  }
}


Measured memory_bytes: 128
x,k,d = gets.strip.split.map(&:to_i)
x = -x if x<0
if x / d >= k
  p x - d * k
else
  k0 = x / d
  k0 -= 1 if (k-k0) % 2 != 0
  if k0 + 2 > k
    p x - d * k0
  else
    p [x - d * k0, d * (k0 + 2) - x].min
  end
end


Measured memory_bytes: 14396
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const long long mod = 1e9+7;
int n,m;
int d;
string s;
long long f[2][10005][105];
bool c[2][10005][105];


void inp()
{
    cin >> s;
    n = s.size();
    cin >> d;
}


long long tryyy(int t, int p, int m)
{
    if (p == n)
    {
        if (m == 0) return 1;
        else return 0;
    }
    if (c[t][p][m]) return f[t][p][m];
    long long tmp = 0;
    if (t == 1)
    {
        int x = s[p] - '0';
        tmp = tryyy(1,p+1,(m+x)%d);
        for (int i = 0; i < x; i++)
        tmp = (tmp + tryyy(0, p + 1, (m+i)%d))%mod;
    }
    else
    {
        for (int i = 0; i <= 9; i++)
        tmp = (tmp + tryyy(0,p+1,(m+i)%d))%mod;
    }
    c[t][p][m] = true;
    f[t][p][m] = tmp;
    return tmp;
}


void proc()
{
    long long ans = tryyy(1,0,0);
    if (ans == 0)
    {
        ans = mod-1;
    }
    else ans--;
    cout << ans;
}



int main()
{
    inp();
    proc();
    return 0;
}


Measured memory_bytes: 19456
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n, a, b;
	cin >> n >> a >> b;
	int cnt[3] = {};
	for(int i = 0; i < n; ++i){
		int p;
		cin >> p;
		int k;
		if(p <= a){ k = 0; }
		else if(p <= b){ k = 1; }
		else{ k = 2; }
		++cnt[k];
	}
	cout << *min_element(ALL(cnt)) << '\n';
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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




int main() {

	ll N;
	cin >> N;

	ll A[MAX];

	repn(i, N) cin >> A[i];

	
	ll sum = 0;
	repn(i, N) sum += A[i];

	ll ans = sum;

	repn(i,N){
		sum -= 2 * A[i];
		ans = min(ans, abs(sum));
	}

	cout << ans;

	
	system("PAUSE");
}


Measured memory_bytes: 3960
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
// int n, heights[100] = {10, 30, 40, 20};
long int n, heights[100000];
std::vector<long int> v(100000,-1);

int min_cost(long int ind)
{
	// cout<<"ind is:"<<ind<<endl;
	if(v.at(ind) != -1)
		return v.at(ind);
	if(ind >= n)
		return INT_MAX;
	if(ind == n-1)
		return 0;

	long int left = INT_MAX;
	if(ind+1<n)
		left = abs(heights[ind] - heights[ind+1]) + min_cost(ind+1);
	
	// cout<<"Left:"<<left<<"\n";
	long int right = INT_MAX;
	if(ind+2<n)
		right = abs(heights[ind] - heights[ind+2]) + min_cost(ind+2);
	// cout<<"Right:"<<right<<"\n";

	// cout<<"min is:"<<min(left, right)<<endl;
	v.at(ind) = min(left, right);
	return min(left, right);
}

int main()
{
	// cout<<"Enter number of stones:";
	cin>>n;
	// n = 4;
	// cout<<"\nEnter heights:";
	for(long int i=0; i<n; i++)
		cin>>heights[i];

	// cout<<"\nElements of vector:";
	// for(int i:v)
		// cout<<i<<"\t";
	// heights[4] = {10, 30, 40, 20};
	// cout<<"Minimum cost is:";
	cout<<min_cost(0);
}

Measured memory_bytes: 7896
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int answer = a*b/2;
        
        System.out.println(answer);
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int r;
  	cin>>r;
  	if (r<1200) cout<<"ABC";
  	else if (r<2800) cout<<"ARC";
    else cout<<"AGC";
  	cout<<endl;
}


Measured memory_bytes: 256