akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>


void allNull(char str[], int n);


int main(void) {
	int N;
	char buff[1000], buff2[1000];
	char answer[1000];
	int i, j, k;
	int a, b, s, up;
	
	scanf("%d", &N);
	while (N--) {
		up = 0;
		allNull(buff, sizeof(buff));
		allNull(buff2, sizeof(buff2));
		allNull(answer, sizeof(answer));
		
		scanf("%s", buff);
		scanf("%s", buff2);
		
		if( (i = strlen(buff)) > 80 || (j = strlen(buff2)) > 80) {
			printf("overflow\n");
			continue;
		}
		
		if( i < j)	k = j;
		else		k = i;
		answer[k + 1] = '\0';
		for(; k >= 0; k--) {
			if( i > 0)
				a = buff[i-- - 1] - '0';
			else
				a = 0;
			if( j > 0)
				b = buff2[j-- -1 ] - '0';
			else
				b = 0;
			s = (a + b + up) % 10;
			answer[k] = s + '0';
			up = (a + b + up) / 10;
		}
		if( answer[0] == '1') {
			if( strlen(answer) > 80) {
				printf("overflow\n");
				continue;
			}
		}
		else {
			for (i = 0; i <= strlen(answer); i++)
				answer[i] = answer[i+1];
			}
			
		printf("%s\n", answer);
	}
	
	return 0;
}


void allNull(char str[], int n) {
	int i;
	for(i = 0; i < n && str[i] != '\0'; n++)
		str[i] = '\0';
}

Measured memory_bytes: 584
n = int(input())
h = list(map(int,input().split()))
ans = 'Yes'
temp = h[0]
for i in range(1,n):
  if h[i]>temp:
    h[i] -= 1
  elif temp>h[i]:
    ans = 'No'
  temp = h[i]
print(ans)

Measured memory_bytes: 20660
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int K, S;
  int ans = 0;
  cin >> K >> S;
  for(int X=0; X<=K; ++X)
  {
    for(int Y=0; Y<=(S-X) && Y<=K; ++Y)
    {
      if(S-(X+Y) <= K)
        ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input());
ans = 0;
all9 = 1;
while n//10 > 0 :
    ans += 9;
    if all9 == 1 and (n - n//10*10) < 9 :
        all9 = 0;
    n = n//10;

if all9 == 1 :
    ans = ans + n;
else :
    ans = ans + n - 1;

print(ans);


Measured memory_bytes: 9076
#include <iostream>
#include <array>
#include <algorithm>

int main() {
  unsigned int a1, a2, a3, b1, b2, b3;
  std::cin >> a1 >> b1;
  std::cin >> a2 >> b2;
  std::cin >> a3 >> b3;

  const std::array<unsigned int, 3 * 2> town_array = {a1, a2, a3, b1, b2, b3};
  const size_t num_1 = std::count(town_array.begin(), town_array.end(), 1);
  const size_t num_2 = std::count(town_array.begin(), town_array.end(), 2);
  const size_t num_3 = std::count(town_array.begin(), town_array.end(), 3);
  const size_t num_4 = std::count(town_array.begin(), town_array.end(), 4);

  if (num_1 < 3 && num_2 < 3 && num_3 < 3 && num_4 < 3) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
a.sort(key=lambda x:-x[1])
ans = 0
s = set()
q = []
for i in range(k):
    ans += a[i][1]
    if a[i][0] in s:
        q.append(a[i][1])
    s.add(a[i][0])
ans += len(s)**2
ans1 = ans
k1 = k
while k1 < n and q:
    if not a[k1][0] in s:
        ans1 += a[k1][1] - q.pop() + 2*len(s) + 1
        ans = max(ans,ans1)
        s.add(a[k1][0])
    k1 +=  1
print(ans)

Measured memory_bytes: 32256
int N[]={ 6,10,18,14,  2,13,22,11,  3, 5,21,19,  1,17,23, 7,  0, 9,20,15,  4,12,16, 8};
int E[]={15, 7,11,19,  8, 3,14,23, 16, 0, 6,22,  4, 2,18,20, 12, 1,10,21,  9, 5,13,17};
int W[]={ 9,17,13, 5, 12,21,10, 1,  4,20,18, 2, 16,22, 6, 0,  8,23,14, 3, 15,19,11, 7};
int S[]={16,12, 4, 8, 20, 9, 0,15, 23,17, 1, 7, 21, 5, 3,19, 22,13, 2,11, 18,10, 6,14};
n,d,a;
char s[9];
main(c)
{
for(;c-48&&scanf("%s",s);)
c=*s,
c<60&&a?printf("%d\n",a),a=d=0:0,
d=
(c-78?0:N[d])+
(c-69?0:E[d])+
(c-87?0:W[d])+
(c-83?0:S[d])+
(c-82?0:d&28|d%4+1&3)+
(c-76?0:d&28|d%4+3&3),
a+=d/4+1,d%=24;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;
map<ll, int>M;
ll n, m, ans;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n>>m;
    ll pref=0;
    M[0]=1;
    for(int i=1; i<=n; i++)
    {
        ll a;
        cin>>a;
        pref+=a;
        ans+=M[pref%m];
        M[pref%m]++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 4224
n,q = list(map(int,input().split()))
s = input()
lll = [0 for _ in range(n)]
for i in range(n-1):
  if s[i] == "A" and s[i+1] == "C":
    lll[i+1] = lll[i] + 1
  else:
    lll[i+1] = lll[i]
for i in range(q):
  l,r = list(map(int,input().split()))
  print(lll[r-1] - lll[l-1])

Measured memory_bytes: 6196
$%=<>;@_=<>;$_=pop@_;map{push@{$`+~-$_*$%},$'+$_%3*$%for/ /..3}@_;/ /;@d[@q=$`]=3;map$d[$_]//=((push@q,$_),$d[$q]+1),@{$q=$_}for@q;print$d[$']/3-1

Measured memory_bytes: 198784
#include <bits/stdc++.h>
#define ll long long int
#define v vector<ll>
#define vv vector<v>
using namespace std;
ll MOD=1e9+7;
int LIM=1e5+10;
vv adj(LIM);
vv dp(LIM,v(2,1));
void dfs(int n,int p)
{
    for (int i=0; i<adj[n].size(); i++)
    {
        if (adj[n][i]!=p)
        {
            dfs(adj[n][i],n);
            dp[n][0]=dp[n][0]*(dp[adj[n][i]][0]+dp[adj[n][i]][1])%MOD;
            dp[n][1]=(dp[n][1]*dp[adj[n][i]][0])%MOD;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for (int i=1; i<n; i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1,1);
    cout<<(dp[1][0]+dp[1][1])%MOD;
	return 0;
}

Measured memory_bytes: 15360
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int t[505][505], c[505][505];

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    rep(i,m) {
        int l, r;
        cin >> l >> r;
        t[l][r]++;
    }
    rep(i,n)rep(j,n) {
        c[i+1][j+1] = c[i+1][j] + t[i+1][j+1];
    }
    rep(i,q) {
        int p, q;
        cin >> p >> q;
        int ans = 0;
        for (int j = p; j <= q; j++) {
            ans += c[j][q];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5540
#include <bits/stdc++.h>
#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(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if(S == U) {
    A--;
  } else {
    B--;
  }
  cout << A << " " << B << endl;
}


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

int kaijo(int N){
  int ans=1;
  for(int i=1;i<=N;i++){
    ans*=i;
  }
  return ans;
}

int main() {
  long N,M,R;
  cin>>N>>M>>R;
  vector<vector<long>> d(N,vector<long>(N));
  vector<long> r(R);
  for(int i=0;i<R;i++) cin>>r[i],r[i]--;
  for(int i=0;i<N;i++)for(int j=0;j<N;j++) if(i!=j) d[i][j]=1e18;
  for(int i=0;i<M;i++){
    long a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    d[a][b]=c,d[b][a]=c;
  }

  for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++){
    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  }


  long ans=1e18;
  for(int i=0;i<kaijo(R+1);i++){
    long c=0;

    for(int j=0;j<R-1;j++){
      c+=d[r[j+1]][r[j]];
    }

    ans=min(ans,c);
    next_permutation(r.begin(),r.end());
  }
cout<<ans<<endl;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int i=0,j,c=0,saidai=0,m,n,a[100000];
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(i=0;i<n;i++)
    {
        while(a[i]%2==0)
        {
            c++;
            a[i]=a[i]/2;
        }
    }
    cout << c << endl;

    return 0;

}


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

#ifdef LOCAL
  #include <contest/local.hpp>
#else
  #define LOG(...) do {} while (false)
#endif

#define REP(i,n) for (decltype (n) i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) (x).begin (), (x).end ()

using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);
  cout << fixed << boolalpha;
  cerr << fixed << boolalpha;

  int n;
  cin >> n;
  vector <int> v;

  REP (i, n)
  {
    int d;
    cin >> d;
    v.emplace_back (d);
  }

  sort (ALL (v));

  auto low = v [n / 2 - 1];
  auto high = v [n / 2];

  LOG (low);
  LOG (high);
  LOG (v);
  auto ans = high - low;
  cout << ans << endl;
}



Measured memory_bytes: 892
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory>
#include <deque>

using namespace std;
#define pf push_front
#define pb push_back
typedef long long LL;
const int maxn = 1005;

deque<int> s,t;LL N;int mx;

int main()
{
	#ifdef Amberframe
		freopen("agc012c.in","r",stdin);
		freopen("agc012c.out","w",stdout);
	#endif
	scanf("%lld",&N);N++;
	for (int i=0;i<50;i++)
		if (N>>i&1) mx=i;
	for (int i=mx-1,o=0;i>=0;i--)
	{
		++o;s.pb(o);t.pb(o);
		if (N>>i&1) ++o,s.pf(o),t.pb(o);
	}
	printf("%d\n",(int)(s.size()+t.size()));
	for (unsigned i=0;i<s.size();i++)
		printf("%d ",s[i]);
	for (unsigned i=0;i<t.size();i++)
		printf("%d ",t[i]);
	return 0;
}

Measured memory_bytes: 256
#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;
using ll = long long;

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; }
const ll LINF = 1e18;

int main()
{
  int N; cin >> N;
  int ans = 0;
  for (int i = 3; i <= N; i+=2) {
    int cnt = 0;
    for (int j = 1; j <= N; j++) {
      if (i%j==0) cnt++;
    }
    if (cnt == 8) {
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
  public static void main(String[] args) throws IOException {
    // TODO 自動生成されたメソッド・スタブ
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
 
    String strText = input.readLine();
    StringBuffer sb = new StringBuffer();
 
    for (int index = 0; index < strText.length(); index++) {
      // 小文字の場合
      if(Character.isLowerCase(strText.charAt(index))) {
        sb.append(Character.toUpperCase(strText.charAt(index)));
      // 大文字の場合
      } else if (Character.isUpperCase(strText.charAt(index))) {
        sb.append(Character.toLowerCase(strText.charAt(index)));
      } else {
        sb.append(strText.charAt(index));
      }
    }
    System.out.println(sb.toString());
  }
 
}


Measured memory_bytes: 24376
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<string> s(n);
	for (int a = 0; a < n; a++) {
		string b;
		cin >> b;
		s[a] = b;
	}
	for (int a = 0, c = 0; a < n; a++) {
		for (int b = 0; b < n; b++) {
			if (s[a] == s[b])c++;
		}
		if (c != 1) { cout << "No" << endl; return 0; }
		c = 0;
	}
	for (int a = 0; a < n-1; a++) {
		if (s[a].back() == s[a + 1].front())continue;
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

}

Measured memory_bytes: 256
#![allow(dead_code)]

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(&src);

    let s = sc.chars();
    let ans = match s[0] {
        'S' => "Cloudy",
        'C' => "Rainy",
        _   => "Sunny"
    };
    format!("{}", ans)
}

#[test]
fn test() {
    assert_eq!(solve(r"Sunny"),r"Cloudy");
    assert_eq!(solve(r"Rainy"),r"Sunny");
}

fn main() {
    let mut input = String::new();
    use std:: io::Read;
    std::io::stdin().read_to_string(&mut input).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&input).as_bytes());
}

struct Scanner<I> {
    src: I
}

impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner { src: src.split_whitespace() }
    }
}

impl<'a, I> Scanner<I> where I: std::iter::Iterator<Item=&'a str> {
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

Measured memory_bytes: 4352
def main():
    N, M = map(int, input().split())
    ac = [False] * N
    penalties = [0] * N
    for _ in range(M):
        p, S = input().split()
        num = int(p) - 1
        if ac[num]:
            continue
        if S == "AC":
            ac[num] = True
        else:
            penalties[num] += 1
    ans = 0
    penalty = 0
    for i in range(N):
        if ac[i]:
            ans += 1
            penalty += penalties[i]
    print(ans, penalty)


if __name__ == "__main__":
    main()


Measured memory_bytes: 47856
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

int n,ma,mb;
vector<int> A,B,C;
v2<vector<int>> dp;

const int INF = 1e9;

int f(int index, int a, int b){
    if(a<0 || b<0) return INF;
    if(index==-1){
        if(a==0 && b==0) return 0;
        else return INF;
    }
    if(dp[index][a][b] != -1) return dp[index][a][b];

    dp[index][a][b] = min(f(index-1, a, b), C[index]+f(index-1, a-A[index], b-B[index]));
    if(dp[index][a][b] > INF) dp[index][a][b] = INF;
    return dp[index][a][b];
}

void solve(){
    cin>>n>>ma>>mb;
    A = vector<int>(n), B = vector<int>(n), C = vector<int>(n);
    for(int i = 0; i < n; ++i) cin >> A[i] >> B[i] >> C[i];
    
    dp = fill(n, 10*n+1, vector<int>(10*n+1, -1));

    int ans = INF;
    for(int i = 1; ma*i<=10*n && mb*i<=10*n; ++i){
        ans = min(ans, f(n-1, ma*i, mb*i));
    }

    if(ans==INF) cout << "-1\n";
    else cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 29556
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

int n, t;
vector<int> G[101];
int d[101];

void bfs(int v) {
	d[v] = 0;
	queue<int> q;
	q.push(v);
	while (!q.empty()) {
		int e = q.front(); q.pop();
		for (int i = 0; i < G[e].size(); ++i) {
			int ne = G[e][i];
			if (d[ne] != -1) continue;
			d[ne] = d[e] + 1;
			q.push(ne);
		}
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int u, k; cin >> u >> k;
		while (k--) {
			int v; cin >> v;
			G[u].push_back(v);
		}
	}

	memset(d, -1, sizeof(d));
	bfs(1);

	for (int i = 1; i <= n; ++i)
		cout << i << " " << d[i] << endl;

	return 0;
}


Measured memory_bytes: 3152
class UnionFind(val size: Int) {
    private val vec = IntArray(size){-1}
    fun root(a: Int): Int {
        return if (vec[a] < 0) {
            a
        }else {
            val root = root(vec[a])
            vec[a] = root
            root
        }
    }
    fun sizeOf(a: Int): Int {
        return -vec[root(a)]
    }
    fun unite(a: Int, b: Int) {
        val ar = root(a)
        val br = root(b)
        if (ar == br) return
        if (vec[ar] < vec[br]) {
            vec[ar] += vec[br]
            vec[br] = ar
        }else {
            vec[br] += vec[ar]
            vec[ar] = br
        }
    }
}
fun main() {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val uft = UnionFind(n)
    repeat(m) {
        val (a, b) = readLine()!!.trim().split(' ').map(String::toInt)
        uft.unite(a - 1, b - 1)
    }
    println((0 until n).map{uft.sizeOf(it)}.max()!!)
}

Measured memory_bytes: 62068
#include<stdio.h>
int main(void){
  int a ,b ,count = 0 , i;
  scanf("%d %d",&a ,&b);

  for(i = 1; i <= 12 ; i++){
    if(a > i){
      count ++;
    }else if(a == i && b >= i){
      count ++;
      break;
    }else{
      break;
    }
  }
  printf("%d\n",count);
  return 0;
}


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

int main(int argc, char const *argv[])
{
	long long s;
	cin>>s;
	long long ans=10000LL;
	while (s>=100LL)
	{
		ans=min(ans,abs(s%1000LL-753LL));
		s/=10LL;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main()
{
  int n;
  cin>>n;
  using T = pair<int,int>;
  vector<T> vp;
  for(int i:boost::irange(0, n)) {
    int p;
    cin>>p;
    vp.emplace_back(p, i);
  }
  boost::sort(vp, greater<T>());
  multiset<int> s;
  s.insert(-1);
  s.insert(-1);
  s.insert(n);
  s.insert(n);
  ll sum = 0;
  for (auto&& p : vp) {
    int pi, i;
    tie(pi, i) = p;
    auto itr = s.lower_bound(i);
    ll r1 = *itr;
    ll r2 = *next(itr);
    ll l1 = *prev(itr);
    ll l2 = *prev(prev(itr));
    sum += pi * ((l1-l2)*(r1-i)+(i-l1)*(r2-r1));
    s.insert(i);
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 5748
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <algorithm>

using namespace std;

struct Dijkstra{
  int INF=1000000000, MAX_V=1000001, st = -1;
  struct edge{int to, cost;};
  typedef pair<int, int> p;
  vector<vector<edge>> G;
  vector<int> d;
  priority_queue<p, vector<p>, greater<p> > que; //class, inner, compair
  Dijkstra(int s){
    G.resize(s+2);
    d.resize(s+2, INF);
  }
  inline void insert(int a, int b, int c){
    G[a].push_back(edge{b, c});
  }
  void init(){
    for(int i=0;i<d.size();i++) d[i] = INF;
  }
  void dijkstra(int start){
    init();
    st = start;
    d[start]=0;
    que.push(p(0, start));
    while(!que.empty()){
      p p_now=que.top(); que.pop();
      int v = p_now.second;
      if(d[v]<p_now.first) continue;
      for(int i=0;i<G[v].size();i++){
        edge e = G[v][i];
        if(d[e.to]>d[v]+e.cost){
          d[e.to]=d[v]+e.cost;
          que.push(p(d[e.to], e.to));
        }
      }
    }
  }
};
int main(){
  int h, w;std::cin >> h >> w;
  array<int, 2> s, e;
  std::cin >> s[0] >> s[1];
  std::cin >> e[0] >> e[1];
  s[0]--, s[1]--, e[0]--, e[1]--;

  vector<string> S(h);
  string t(1000, '.');
  //for(int i=0;i<h;i++) S[i] = t;
  for(int i=0;i<h;i++) std::cin >> S[i];

  Dijkstra di(h*w);
  for(int x=0;x<h;x++){
    for(int y=0;y<w;y++){
      if(S[x][y]=='#') continue;
      for(int i=-2;i<=2;i++){
        for(int j=-2;j<=2;j++){
          int X = x + i, Y = y + j;
          if(X<0||X>=h||Y<0||Y>=w||S[X][Y]=='#') continue;
          int D = abs(i) + abs(j);
          if(D==0) continue;
          if(D==1) di.insert(x*w + y, X*w + Y, 0);
          else di.insert(x*w + y, X*w + Y, 1);
        }
      }
    }
  }

  di.dijkstra(s[0]*w + s[1]);
  int ans = di.d[e[0] * w + e[1]];
  if(ans == 1000000000) std::cout << -1 << '\n';
  else std::cout << ans << '\n';
}


Measured memory_bytes: 102540
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
    
#########################################################

n = int(input())
a = list(map(int,input().split()))
m = 10**9+7

#r[i]:1/kのiまでの累積和
r = [0]
w = 0
for i in range(1,n+1):
    w = (w + mod_inv(i,m))%m
    r.append(w)

#fact = n!
fact = 1
for i in range(1,n+1):
    fact = fact*i%m

res = 0
for j in range(1,n+1):
    #p(i,j)の和
    sum_p = (r[j]+r[n-j+1]-1) % m
    
    res = (res + a[j-1]*sum_p*fact) % m

print(res % m)

Measured memory_bytes: 14252
import sys
sys.setrecursionlimit(100000000)

N = int(input())

v_to = [[] for i in range(N + 1)]
v_color = [-1 for i in range(N + 1)]

for i in range(1, N):
  u, v, w = map(int, input().split())
  v_to[u].append((v, w))
  v_to[v].append((u, w))

def unko(i, par):
  for to, w in v_to[i]:
    if to == par:
      continue
    if w % 2 == 1:
      v_color[to] = 1 - v_color[i]
    else:
      v_color[to] = v_color[i]
    unko(to, i)


v_color[1] = 0
unko(1, 1)

for i in range(1, N + 1):
  print(v_color[i])

Measured memory_bytes: 79408
import sys

n, *a = map(int, sys.stdin.read().split())
a = [None] + a

def main():
    res = [0] * (n + 1)
    chosen = []
    for i in range(n, 0, -1):
        tmp = sum(res[i*2:n+1:i]) & 1
        if tmp ^ a[i]:
            res[i] = 1
            chosen.append(i)

    if chosen:
        m = len(chosen)
        return [m], chosen[::-1]
    else:
        return [[0]]

if __name__ == '__main__':
    ans = main()
    for a in ans:
        print(*a, sep=' ')

Measured memory_bytes: 13220
def main():
    import heapq
    
    def dijkstra(graph,s,cd,c):
        dist = [[float("inf")]*2505 for _ in range(n)]
        q = []
        dist[s][c] = 0
        heapq.heappush(q, (0,s,c))
        
        while q:
            d, p,c = heapq.heappop(q)
            
            if dist[p][c] < d:
                continue
            if c+cd[p][0] < 2500:
                if dist[p][c+cd[p][0]] >  d+cd[p][1]:
                    dist[p][c+cd[p][0]] = d+cd[p][1]
                    heapq.heappush(q, (d+cd[p][1],p,c+cd[p][0]))
            else:
                if dist[p][2500] >  d+cd[p][1]:
                    dist[p][2500] = d+cd[p][1]
                    heapq.heappush(q, (d+cd[p][1],p,2500))
            for nn,nc,nt  in graph[p]:
                if c >= nc and dist[nn][c-nc] >   d+nt:
                    dist[nn][c-nc] =    d+nt
                    heapq.heappush(q,(d+nt,nn,c-nc))
            
                    
        for i in dist[1:]:
            print(min(i))
    n,m,s = map(int,input().split())
    E = [[] for i in range(n)]
    la = []
    for i in range(m):
        u,v,a,b = map(int,input().split())
        u -= 1
        v-= 1
        la.append(a)
        E[u].append((v,a,b))
        E[v].append((u,a,b))

    cd = [list(map(int,input().split())) for i in range(n)]

    dijkstra(E,0,cd,min(s,2500))
if __name__ == "__main__":
    main()

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	int times_change=0;
	FOR(i, 1, n - 1) {
		if (s[i] != s[i - 1])times_change++;
	}
	times_change = max(0, times_change - 2 * k);
	int res = n - times_change - 1;
	pv(res)
	return(0);
}

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

int a[20], b[20] ;
int dp[ (1<<18) ][ 50 ] ;
int n ;
const int inf = 1e8 ;

int go ( int mask, int mx ) {
    if ( __builtin_popcount(mask) == n ) return 0 ;
    auto &rf = dp[mask][mx] ;
    if ( rf!=-1 ) return rf ;
    int cur = 0, v = __builtin_popcount(mask) ;
    rf = inf ;
    for ( int i = 0 ; i < n ; ++i ) {
        if ( mask&(1<<i) ) {
            --v ;
            continue ;
        }
        if ( (cur+v) % 2 && b[i] >= mx ) rf = min(rf, go ( mask|(1<<i), b[i] ) + cur) ;
        if ( (cur+v) % 2 == 0 && a[i] >= mx ) rf = min ( rf, go(mask|(1<<i), a[i])+cur ) ;
        ++cur;
    }
    return rf ;
}

int main() {
  //  freopen("input.txt", "r", stdin ) ;
    memset ( dp, -1, sizeof dp ) ;
    cin >> n ;
    for ( int i = 0 ; i < n ; ++i )
        cin >> a[i] ;
    for ( int i = 0 ; i < n ; ++i )
        cin >> b[i] ;
    if ( go(0,0) >= inf ) cout << "-1\n" ;
    else cout << go(0,0) << '\n' ;
}


Measured memory_bytes: 51456
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
using namespace std;
const int INF = 1e9;
int t;
string s;
int main(){
  string c="AKIHABARA";
  cin>>s;
  for(int i=0;i<s.size();i++){
    
    if(s[i]==c[t]){
      t++;
    }else{
      if(s[i]==c[t+1] && c[t]=='A'){
	t+=2;
      }else {cout<<"NO"<<endl;return 0;}
    }
  }
  if(t>=8)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}



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

signed main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int &i:a)
    cin>>i;
  int ans=0;
  
  for(int i=0;i<n-1;i++){
    if(a[i]<=a[i+1])
      continue;
    else{
      ans+=a[i]-a[i+1];
      a[i+1]=a[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4836
line_num = int(raw_input())
for n in range(line_num):
	a,b,c = map(int, raw_input().split(" "))
	if a>b:
		if a>c:
			if a*a == b*b + c*c:
				print "YES"
				continue
		else:
			if c*c == a*a + b*b:
				print "YES"
				continue
	else:
		if b>c:
			if b*b == a*a + c*c:
				print "YES"
				continue
		else:
			if c*c == a*a + b*b:
				print "YES"
				continue
	print "NO"

Measured memory_bytes: 38000
# include <iostream>
using namespace std; 
int main(){
  int n,a,b,c,d; 
  cin>>n; 
  a=b=c=d=0;
  string str; 
  while(n--){
    cin>>str; 
    if(str=="AC"){
      a++;
    }
    else
    if(str=="WA"){
      b++;
    }
    else
    if(str=="TLE"){
      c++;
    }
    else{
      d++;
    }
  }
  cout<<"AC x "<<a<<endl; 
  cout<<"WA x "<<b<<endl; 
  cout<<"TLE x "<<c<<endl; 
  cout<<"RE x "<<d; 
  return 0;
}

Measured memory_bytes: 3584
// **** WHEN THE GOING GETS TOUGH, THE TOUGH GETS GOING. ****

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
typedef vector<ii> vii;
typedef vector<lii> lvii;

#define min_prq(t) priority_queue<t,vector<t>,greater<t>>
#define max_prq(t) priority_queue<t>
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll ans=0;
lvi dp;
vector<bool> visited;
lvvi adj;
ll dfs(ll x)
{
	if(visited[x]) return dp[x];
	visited[x]=true;
	dp[x]=0;
	for(auto next:adj[x])
	{
		dp[x]=max(dp[x],1+dfs(next));
	}
	ans=max(ans,dp[x]);
	return dp[x];
}

signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n,m;
	cin>>n>>m;
	adj.resize(n+2);
	dp.resize(n+2);
	visited.resize(n+2);
	for (int i = 0; i < m; ++i)
	{
		ll x,y;
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(int i=1;i<=n;i++)
	{
		if(!visited[i])
		{
			dfs(i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
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;
}

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int ans = 0;
    int a[2];
    cin >> a[0] >> a[1];
    REP(k,2){
        if (a[k] == 1) ans += 300000;
        if (a[k] == 2) ans += 200000;
        if (a[k] == 3) ans += 100000;
    }

    if ((a[0] == 1) and (a[1] == 1)) ans += 400000;
    cout << ans << endl;
}

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

using namespace std;

int main(){
  int i,j,k,n,m;
  string s;
  cin >> n >> k;
  long long int r[n+1];
  for(i=1;i<=n;i++){
    r[i]=i%k;
  }
  if(k%2==0){
    long long int ch1=0,ch0=0;
    for(i=1;i<=n;i++){
      if(r[i]==k/2)ch1++;
      if(r[i]==0)ch0++;
    }
    long long int ans=0;
    //if(ch1==1)ans++;
    ans+= ch1*ch1*ch1;
    //if(ch0==1)ans++;
    ans+= ch0*ch0*ch0;
    cout << ans << endl;
  }else{
    long long int ch0=0;
    for(i=1;i<=n;i++){
      if(r[i]==0)ch0++;
    }
    long long int ans=0;
    //if(ch0==1)ans++;
    ans+= ch0*ch0*ch0;
    cout << ans << endl;
  }
  return 0;
}


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

use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn runlength(s: &String) -> Vec<(char, usize)> {
    let mut res = Vec::new();
    let mut cur: char = '$';
    let mut cnt = 0;
    for x in s.chars() {
        if x != cur {
            if cnt > 0 {
                res.push((cur, cnt));
            }
            cur = x;
            cnt = 1;
        } else {
            cnt += 1;
        }
    }
    if cnt > 0 {
        res.push((cur, cnt));
    }
    res
}

fn main() {
    loop {
        from_line!(n:usize, m:usize, p:u32);
        if n == 0 { break; }
        let mut s = 0;
        let mut g: u32 = 1;
        for i in 1..n+1 {
            from_line!(v:u32);
            s += v;
            if i == m { g = v; }
        }
        println!("{}", if g == 0 { 0 } else { s * (100 - p) / g });
    }
}



Measured memory_bytes: 5040
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <cstdio>
#include <deque>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <stdlib.h>
#include <stack>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	string s; cin >> s;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] > s[0]) {
			s[0] = s[0] + 1;
			for (int j = 0; j < s.size(); j++) {
				cout << s[0];
			}
			return 0;
		}
	}
	for (int j = 0; j < s.size(); j++) {
		cout << s[0];
	}
	




}




Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
    int ac=0, wa=0, tle=0, re=0;
    int n;
    char s[10];
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        scanf("%s", &s);
        if(strcmp(s, "AC") == 0) ac++;
        if(strcmp(s, "WA") == 0) wa++;
        if(strcmp(s, "TLE") == 0) tle++;
        if(strcmp(s, "RE") == 0) re++;
    }

    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);

    return 0;
}

Measured memory_bytes: 1724
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		ArrayList<Integer> result = new ArrayList<Integer>();
		Scanner insert = new Scanner(System.in);
		int n = -1;
		int m = -1;
		int a = -1;
		while(true) {
			String line = insert.nextLine();
			String array[] = line.split(" ");
			n = Integer.parseInt(array[0]);
			m = Integer.parseInt(array[1]);
			a = Integer.parseInt(array[2]);
			if((n==0) && (m == 0) && (a == 0)) {
				break;
			}
			int max = 0;
			HashMap<String,Integer> mapper = new HashMap<String,Integer>();
			for(int i =0; i < m; i++) {
				line = insert.nextLine();
				String array2[] = line.split(" ");
				if(Integer.parseInt(array2[0]) > max) {
					max = Integer.parseInt(array2[0]);
				}
				mapper.put(array2[0] + "," + array2[1], Integer.parseInt(array2[2]));
				mapper.put(array2[0] + "," + array2[2], Integer.parseInt(array2[1]));
			}
			for(int i = max; i > 0; i --) {
				if(mapper.containsKey(Integer.toString(i) + "," + Integer.toString(a))) {
					a = mapper.get(Integer.toString(i) + "," + Integer.toString(a));
				}
			}
			result.add(a);

		}
		for(int i = 0;i < (result.size());i++) {
			System.out.println(result.get(i));
		}
	}
}






Measured memory_bytes: 99108
#include<stdio.h>
#define MAXN 200000

int main(){
    int k, n, distance, mindis;
    int a[MAXN];

    scanf("%d %d", &k, &n);
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);

    for(int i=0; i<n; i++){
        if( i )
            distance = k-a[i]+a[i-1];
        else
            distance = a[n-1]-a[i];
        if( !i||distance<mindis )
            mindis = distance;
    }
    printf("%d", mindis);

    return 0;
}


Measured memory_bytes: 896
N = int(input())
H = list(map(int, input().split()))

M = 0
i = 0
while i<N-1:
    tmp = 0
    while i<N-1 and H[i]>=H[i+1]:
        tmp+=1
        i+=1
    M = max(M, tmp)
    i+=1

print(M)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i+=2){
        int sum=0;
        REP(j,i+1){
            if(i%(j+1)==0)sum++;      
        }
    if(sum==8) ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define TC ll t; cin >> t; while(t--)
typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll s,w;
    cin >> s >> w;
    cout << (s>w?"safe":"unsafe") << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
    int a,b,c,i,x;
    scanf("%d",&x);
    for(i=0;i<x;i++){
        scanf("%d%d%d",&a,&b,&c);
    if(a==b || a==c || b==c){
        printf("NO\n");
    }
    else if(a*a==b*b+c*c){
        printf("YES\n");
    }
    else if(b*b==a*a+c*c){
        printf("YES\n");
    }
    else if(c*c==a*a+b*b){
        printf("YES\n");
    }
    else
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();

		if(S.equals("abc")|S.equals("acb")|S.equals("bac")|
				S.equals("bca")|S.equals("cab")|S.equals("cba")) {
		System.out.println("Yes");
		}else {
			System.out.println("No");

		}




	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef complex<int> ci;
typedef complex<double> cd;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define ft front()
#define bk back()
#define ins insert
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define FORI(a, b) for (auto(a) = (b).begin(); (a) != (b).end(); ++(a))
#define ROFI(a, b) for (auto(a) = (b).rbegin(); (a) != (b).rend(); ++(a))
#define CEIL(a, b) ((a) + (b)-1) / (b)
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <typename t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}

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

    int X;
    cin >> X;
    cout << X / 500 * 1000 + X % 500 / 5 * 5 << endl;

    return 0;
}


Measured memory_bytes: 256
n,m = map(int, raw_input().split(" "))
if n==1==m:
    print 1
elif n == 1:
    print m - 2
elif m == 1:
    print n - 2
elif n == 2 or m == 2:
    print 0
else:
    print (n-2)*(m-2)

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

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

int main() {
    int n; cin >> n;
    vector<int> P(n), Q(n);
    rep(i,n) cin >> P[i];
    rep(i,n) cin >> Q[i];

    vector<int> O(n);
    rep(i,n) O[i] = i + 1;
    int p = 0, q = 0;
    int cnt = 0;
    do {
        int a = 0, b = 0;
        rep(i,n){
            if(P[i] == O[i]) a++;
            if(Q[i] == O[i]) b++;
        }
        if(a == n) p = cnt;
        if(b == n) q = cnt;
        cnt++;
    } while (next_permutation(O.begin(),O.end()));
    
    cout << abs(p - q) << endl;

}

Measured memory_bytes: 256
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  double a, b, x, th;
  scanf("%lf %lf %lf", &a, &b, &x);
  if(a * a * b <= 2 * x) th=atan(2 * b / a - 2 * x / a / a / a) / M_PI * 180;
  else th=atan(a * b * b / 2 / x) / M_PI * 180;
  printf("%lf", th);
  return 0;
}

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<string> s(m);
  for (int i = 0; i < m; i++) cin >> p[i] >> s[i];
  vector<bool> a(n, false);  // n問の問題
  vector<int> k(n, 0);
  int ac = 0;
  int wa = 0;
  for (int i = 0; i < m; i++) {
    if (a[p[i] - 1] == false) {
      if (s[i] == "WA") k[p[i] - 1]++;
      if (s[i] == "AC") {
        a[p[i] - 1] = true;
        ac++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == true) {
      wa += k[i];
    }
  }
  cout << ac << " " << wa << endl;
}


Measured memory_bytes: 6528
n = input()
print(n + ":", end="")
n = int(n)
while n % 2 == 0:
    print(" 2", end="")
    n //= 2
if n<2:
    print()
    exit()
st = 3
while 1:
    for d in range(st, int(n ** 0.5) + 2, 2):
        if n % d == 0:
            print(" " + str(d), end="")
            st = d
            n //= d
            break
    else:
        print(" " + str(n))
        break



Measured memory_bytes: 5648
#include <iostream>
#include <string>

int main(){
	std::string str;
	int num;
	int start = 0;

	std::cin >> num;

	getline(std::cin, str); // skip "\n"

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

		std::getline(std::cin, str);

		while(start != -1){

			if(start == 0){ // for first loop
				start = (int)str.find("Hoshino", start);
			}else{
				start = (int)str.find("Hoshino", start+7);
			}

			if(start != -1){ // for first loop
				str.replace(start, 7, "Hoshina");
			}

		}

		std::cout << str << std::endl;

		start = 0;
	}

}

Measured memory_bytes: 1208
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
const int maxn=1005;
int n,ans,l[maxn];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		char a='-',b='1';
		putchar(a);
		putchar(b);
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}

int main()
{
	n=read();
	for(int i=1;i<=n;++i)
		l[i]=read(),l[n+i]=read();
	sort(l+1,l+2*n+1);
	for(int i=1;i<=2*n;i+=2)
		ans+=l[i];
	write(ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        string s;string t;
        cin>>s;
        cin>>t;
        lli n=sz(s);
        lli ans=0;
        flli(i,0,n-1)
        {
        	if(s[i]!=t[i])ans++;
        }
        cout<<ans;
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }

Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        char[][] a = new char[n][n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.next().toCharArray();
        }
        char[][] b = new char[m][m];
        for (int i = 0; i < m; i++) {
            b[i] = sc.next().toCharArray();
        }
        
        for (int i = 0; i < n - m + 1; i++) {
            for (int j = 0; j < n - m + 1; j++) {
                if (compare(a, b, i, j, m)) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }

    static boolean compare(char[][] a, char[][] b, int i, int j, int m) {
        for (int k = 0; k < m; k++) {
            for (int l = 0; l < m; l++) {
                if (a[i + k][j + l] != b[k][l]) {
                    return false;
                }
            }
        }
        return true;
    }
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;

	vector<ll> a;
	for(int i=0; i<n; i++){
		ll t;
		cin >> t;
		a.pb(t);
	}
	sort(a.begin(), a.end());

	vector<ll> sum;
	sum.pb(a[0]);
	for(int i=1; i<n; i++){
		sum.pb(sum[i-1] + a[i]);
	}

	int ans = 1;
	for(int i=n-2; i>=0; i--){
		if(a[i+1] <= sum[i]*2){
			ans++;
		}else{
			break;
		}
	}

	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2548