akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 2000
int N1,A[MAX];

int Solve(int x,int y){
  int r;
  if(y==0)return 1;
  if(x>=N1)return 0;

  r=Solve(x+1,y)||Solve(x+1,y-A[x]);
  return r;
}

int main (){

  int i,B,N2;

  scanf("%d",&N1);

  for(i=0;i<N1;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&N2);

  for(i=0;i<N2;i++){
    scanf("%d",&B);
    if(Solve(0,B)==1){
      printf("yes\n");
    }
    else printf("no\n");
  }
  
  return 0;
}




Measured memory_bytes: 2052
#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>;

int main() {
  int n, m;
  cin >> n >> m;
  set<int> factor;
  for (int i = 1; i * i <= m; ++i) {
    if (m % i == 0) {
      factor.insert(i);
      factor.insert(m / i);
    }
  }
  int ans = 1;
  for (auto itr = factor.begin(); itr != factor.end(); ++itr) {
    int g = *itr;
    if (m / g >= n) ans = g;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
import fractions

a, b, c, d = map(int, input().split())


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def s(i):
    if a % i == 0:
        t = b // i - a // i + 1
    else:
        t = b // i - a // i
    return t


if __name__ == "__main__":
    n = b - a + 1 - (s(c) + s(d) - s(lcm(c, d)))
    print(n)


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

int main() {
  long long n; cin >> n;
  
  long long times = 0;
  long long ans = 0;
  while(n > 0) {
  	ans += pow(2, times);
    times++;
    n /= 2;
  }
  cout << ans << endl;

  return 0; 
}

Measured memory_bytes: 4032
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

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

    if (s.back() == 's') {
        cout << s << "es" << endl;
    } else {
        cout << s << "s" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
	char s[200001];
	char t[200001];
	int moji = 0, i, ans = 0;
	
	/*
	for(i = 0; i <=200; i++){
		s[i] = '0';
	}
	*/
	
	scanf("%s", s);
	scanf("%s", t);
	
	while(s[moji] != '\0'){
		moji++;
	}
	moji -= 1;
	
	for(i = 0; i <= moji; i++){
		if(s[i] != t[i]){
			ans++;
		}
	}
	
	//printf("%d\n", moji);
	printf("%d", ans);
	
	return 0;
}

Measured memory_bytes: 2092
# -*- coding: utf-8 -*-
import math
import datetime

# 入力
#N = int(input())
#S = str(input())
#H, W = map(int, input().split())
b = str(input())

if b == "A" :
  print ("T")
elif b == "T" :
  print ("A")
elif b == "C" :
  print ("G")
elif b == "G" :
  print ("C")

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

const int MOD = 1e9 + 7;
const int MAXN = 1e5;
int k;
vector<vector<int>> to(MAXN);


ll fac[MAXN], finv[MAXN], inv[MAXN];

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

// 順列組み合わせ計算
ll P(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
}

ll dfs(int v, int parent=-1){
	ll res = 1;
	int childn,childk;
	
	if(parent==-1){
		res = k;
		childn = to[v].size();
		childk = k-1;
	}
	else{
		childn = to[v].size()-1;
		childk = max(k-2,0);
	}
	
	res = (res * P(childk,childn)) % MOD;
	
	for(auto child : to[v]){
		if(child == parent) continue;
		res = (res * dfs(child,v)) % MOD;
	}
	
	return res;
}

int main(){
	
	COMinit();
	int n;
	cin >> n >> k;
	
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	
	cout << dfs(0) << endl;
	return 0;
}


Measured memory_bytes: 12800
/*
  AUTHOR:SOURABH
  CREATED:10:01:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll n,i,j=1;
    cin>>n;
    vll a(n),d(n),c(n);
    fn(i,n)
    {cin>>a[i];c[i]=i+1;}
    fn(i,n)
    cin>>d[i];
    map<vll,ll> b;
    b[c]=j++;
    W(next_permutation(c.begin(),c.end()))
    {
        b[c]=j++;
    }
    cout<<abs(b[d]-b[a]);
    return 0;
}































Measured memory_bytes: 6528
from collections import Counter
n = int(input())
s = []
for i in range(n):
    t = input()
    q = [t[i] for i in range(10)]
    q.sort()
    r = ""
    for i in range(10):
        r += q[i]
    s.append(r)

x = Counter(s).most_common()
ans = 0
for a,b in x:
    ans += b*(b-1)//2

print(ans)

Measured memory_bytes: 77400
//####################################################################
//#####In the Name Of Allah,the Most Gracious,the Most Merciful.######
//####################################################################

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

#define maxn            100010
#define esp             1e-6
#define mod             1000000007
#define ll              long long


ll Q, H, S , D, N;

int main()
{
        cin >> Q >> H >> S >> D >> N;

        ll val1 = min(Q * 8, min(H * 4, min(S * 2, D)));
        ll val2 = min(Q * 4, min(H * 2, S));

        ll ans = 0;

        if(N >= 2){
                ll go = N / 2;
                ans += (go * val1);
                N -= (go * 2);
        }
        if(N == 1) ans += val2;

        cout << ans << endl;

        return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define init()                 \
  ios::sync_with_stdio(false); \
  cin.tie(0)

#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b)
{
  return a == 0 ? b
                : b == 0 ? a
                         : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b)
{
  return a * b / gcd(a, b);
}

template <long long MAX>
class CombinationCalculator
{
  long long mod_;
  long long fac[MAX];
  long long finv[MAX];
  long long inv[MAX];

public:
  CombinationCalculator(long long mi = MOD) : fac(), finv(), inv()
  {
    mod_ = mi;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
      fac[i] = fac[i - 1] * i % mod_;
      inv[i] = mod_ - inv[mod_ % i] * (mod_ / i) % mod_;
      finv[i] = finv[i - 1] * inv[i] % mod_;
    }
  }

  long long c(long long n, long long k) const
  {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod_) % mod_;
  }
};

template <long long MAX = 210000>
using CC = CombinationCalculator<MAX>;

template <typename T>
T modpow(T a, T n, T mod = MOD)
{
  T res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
T modinv(T a, T m = MOD)
{
  T b = m, u = 1, v = 0;
  while (b)
  {
    T t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main()
{
  init();

  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  s[k - 1] = tolower(s[k - 1]);

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin>>N>>M;
    vector<int>vec(N);
    for(int i=0;i<N;i++)cin>>vec[i];
    for(int i=1;i<M+1;i++){
        for(int k=0;k<N-1;k++)if(vec[k]%i>vec[k+1]%i)swap(vec[k],vec[k+1]);
    }
    for(int i=0;i<N;i++)cout<<vec[i]<<endl;
}


Measured memory_bytes: 3112
import sys
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())

a,b,n=reads()
x=min(b-1,n)
print(int((a*x)/b))


Measured memory_bytes: 9492
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int n,k,t,i,res;
  string s;
  cin >> s >> k;
  n=s.size();
  for(i=0;i<n;i++){
    t=(int)('z'-s[i]);
    if(k>t&&t<25){
      s[i]='a';
      k-=t+1;
    }
    if(k==0) break;
  }
  if(k>0){
    t=(int)(s[n-1]-'a')+k;
    t%=26;
    s[n-1]='a'+(char)t;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,ts;
int a[100010];

int main()
{
	a[0]=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
	 cin>>a[i];
	 ts+=abs(a[i]-a[i-1]);
	 }
	 ts+=abs(a[n]);
    for(int i=1;i<=n;i++)
    {int ans=ts;
	 if(i==0) {
	    ans-=abs(a[i])+abs(a[i+1]-a[i])-abs(a[i+1]);
	    cout<<ans<<endl;
	    continue;
		}
	 if(i==n)
	 {
		 ans-=abs(a[n]-a[n-1]);
		 ans+=abs(a[n-1]);
		 ans-=abs(a[n]);
		 cout<<ans<<endl;
		 }	
	 else {
	      ans-=abs(a[i]-a[i-1])+abs(a[i+1]-a[i]);
	      ans+=abs(a[i-1]-a[i+1]);
	       cout<<ans<<endl;
		   }
	 }
 return 0;}

Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int W = cin.nextint;
        int a = cin.nextint;
        int b = cin.nextint;

        if (a < b)
        {
            WriteLine(Math.Max(b - (a + W), 0));
        }
        else
        {
            WriteLine(Math.Max(a - (b + W), 0));
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  long long N, K;
  cin >> N >> K;
  long long cnt = N / K;
  long long ans;
  if (K % 2 == 0) {
    ans = pow(cnt, 3) + pow(N / (K / 2) - cnt, 3);
  } else {
    ans = pow(cnt, 3);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <utility>
#include <string.h>
#include <math.h>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;
const ll INF = 1e9 + 5;

ll ap(ll c)
{
	ll k = 0;
	while (c > 0)
	{
		k = c % 10;
		c /= 10;
	}
	return k;
}
ll jari(ll c)
{
	ll k = 1;
	while (c > 0)
	{
		k *= 10;
		c /= 10;
	}
	return k;
}

char a[500001][15];
void solve()
{
	int k;
	cin >> k;
	memset(a, 0, sizeof(a));
	for (int i = 1; i <= 9; i++)
		a[i][0] = i+'0';

	int pos1 = 10, pos2=1;
	while (pos1 <= k)
	{
		int len = strlen(a[pos2]);
		switch (a[pos2][len - 1])
		{
		case '0':
			for (int i = 0; i < len; i++)
				a[pos1 + 1][i] = a[pos1][i] = a[pos2][i];
			a[pos1][len] = '0';
			a[pos1 + 1][len] = '1';
			pos1 += 2;
			pos2++;
			break;
		case '9':
			for (int i = 0; i < len; i++)
				a[pos1 + 1][i] = a[pos1][i] = a[pos2][i];
			a[pos1][len] = '8';
			a[pos1 + 1][len] = '9';
			pos1 += 2;
			pos2++;
			break;
		default:
			for (int i = 0; i < len; i++)
				a[pos1 + 2][i] = a[pos1 + 1][i] = a[pos1][i] = a[pos2][i];
			a[pos1][len] = a[pos2][len - 1] - 1;
			a[pos1 + 1][len] = a[pos2][len - 1];
			a[pos1 + 2][len] = a[pos2][len - 1] + 1;
			pos1 += 3;
			pos2++;
			break;
		}
	}

	cout << a[k] << endl;
}

int main()
{
//	int t;
//	cin >> t;
//	while(t-->0)
	solve();
}

Measured memory_bytes: 7552
#include <stdio.h>

int main (void)
{
    int n, a, b;

    scanf("%d", &n);

    if (n == 1) {
        puts("Hello World");
    } else {
        scanf("%d", &a);
        scanf("%d", &b);
        printf("%d\n", a + b);
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main{
 public static void main(String args[]){
  Scanner stdIn = new Scanner(System.in);
  int a = stdIn.nextInt();
  int b = stdIn.nextInt();
  
  System.out.print(a*b);
  System.out.print(" ");
  System.out.println(2*(a+b));
 }
}

Measured memory_bytes: 26212
#include<iostream>
#include<vector>
using namespace std;
int w,h;
int cal(vector<vector<int> > v,int x,int y){
	int ans=0;
	vector<vector<int> > dp(h,vector<int>(w,0));
	for(int i=0;i<y;i++){
		for(int j=0;j<x;j++){
			if(v[i][j]==1)
			ans+=v[i][j];
		}
	}
	dp[0][0]=ans;
	for(int i=0;i<=h-y;i++){//y
		if(i!=0){
			dp[i][0]=dp[i-1][0];
			for(int j=0;j<x;j++){//x
				dp[i][0]+=v[i+y-1][j]-v[i-1][j];
			}
			ans=max(dp[i][0],ans);
		}
		for(int j=1;j<=w-x;j++){//x
			dp[i][j]=dp[i][j-1];
			for(int k=i;k<i+y;k++){//y
				dp[i][j]+=v[k][j+x-1]-v[k][j-1];
			}
			ans=max(dp[i][j],ans);
		}
	}
	return ans;
}
int main(){
	int n;
	while(cin>>n,n){
		cin>>w>>h;
		vector<vector<int> > v(h,vector<int>(w,0));
		int x,y;
		for(int i=0;i<n;i++){
			cin>>x>>y;x--;y--;
			v[y][x]=1;
		}
		cin>>x>>y;
		cout<<cal(v,x,y)<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[100007];
int dp[100007];

int cal(int pos)
{
    if(pos==n)return 0;

    if(dp[pos]!=-1)return dp[pos];
    dp[pos]=cal(pos+1)+abs(a[pos]-a[pos+1]);
    for(int i=2;i<=k;i++){
        if(pos+i<=n){
            dp[pos]=min(dp[pos],cal(pos+i)+abs(a[pos]-a[pos+i]));
        }
    }
    return dp[pos];
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin >>n>>k;
    for(int i=1;i<=n;i++)cin >>a[i];
    cout << cal(1)<<endl;
    
}

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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005

int main(){
sp;
int c1=0,c0=0;
string s;
cin>>s;
for(auto &it:s){
    c1+=(it=='1');
    c0+=(it=='0');
}
cout<<min(c1+c1,c0+c0);
return 0;}


Measured memory_bytes: 512
def ans(n):
    tmp=0
    for i in range(N):
        tmp+=abs(a[i]-a[n-1])
    return tmp


N=int(input())
a=list(map(int,input().split()))

a=[a[i]-i-1 for i in range(N)]
a.sort()

print(ans(N//2) if N%2==0 else ans(N//2+1))

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

int main(){

  int n;
  cin >> n;
  string result;
  map<string,int> mp;

  for(int i=0;i<n;i++){
    cin >> result;
    mp[result]++;
  }

  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 3572
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i - 1] > a[i]) {
      ll d = a[i - 1] - a[i];
      ans += d;
      a[i] += d;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4820
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long lint;
typedef long long ll;
int qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e10;
#define F first
#define S second
lint grid[502][502];
int main() {
	
	lint h, w; cin >> h >> w;

	//gridに入力を受け取る
	rep(h) {
		repj(w) {
			cin >> grid[i + 1][j + 1];
		}
	}


	vector<pair<pair<int, int>, pair<int, int>>> ans;
	for (int i = 1; i <= h; i++) {
		if (i % 2 == 1) {
			for (int j = 1; j < w; j++) {
				if (grid[i][j] % 2 == 1) {
					pair<int, int> a1 = mp(i, j);
					pair<int, int> a2 = mp(i, j + 1);
					ans.pb(mp(a1, a2));
					grid[i][j]--;
					grid[i][j + 1]++;
				}
			}
			if (i == h) break;
			if (grid[i][w] % 2 == 1) {
				pair<int, int> a1 = mp(i, w);
				pair<int, int> a2 = mp(i+1, w);
				ans.pb(mp(a1, a2));
				grid[i][w]--;
				grid[i + 1][w]++;
			}
		}
		else {
			for (int j = w; j > 1;j--) {
				if (grid[i][j] % 2 == 1) {
					pair<int, int> a1 = mp(i, j);
					pair<int, int> a2 = mp(i, j-1);
					ans.pb(mp(a1, a2));
					grid[i][j]--;
					grid[i][j-1]++;
				}
			}
			if (i == h) break;
			if (grid[i][1] % 2 == 1) {
				pair<int, int> a1 = mp(i, 1);
				pair<int, int> a2 = mp(i+1, 1);
				ans.pb(mp(a1, a2));
				grid[i][1]--;
				grid[i+1][1]++;
			}
		}
	}
	cout << ans.size() << endl;
	for (auto i : ans) {
		printf("%d %d %d %d\n", i.first.first, i.first.second, i.second.first, i.second.second);
	}
	return 0;

}

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

typedef long long ll;

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

    int N;

    cin >> N;

    vector<int> D(N);

    for(int i = 0; i < N; i++) {
        cin >> D[i];
    }

    vector<int> S = D;

    sort(S.begin(), S.end(), greater<int>());

    for(int i = 0; i < N; i++) {
        if(D[i] == S[0]) {
            cout << S[1] << endl;
        } else {
            cout << S[0] << endl;
        }
    }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	int n;
	cin >> n;
	if(n<105)
	{
		cout<<0<<endl;
		return 0;
	}
	int ans =0; 
	for(int i=105;i<=n;i+=2)
	{
		vector<int> a;
		int I=i;
		for(int j=2;j*j<i;++j)
		{
			int foo=0;
			
			while(I%j==0)
			{
				foo++;
				I/=j;
			}
			if(foo)a.push_back(foo);
		}
		if(I!=1)a.push_back(1);
		int foo=1;
		for(int j=0;j<a.size();j++)
		{
			foo*=(a[j]+1);
		}
		if(foo==8)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long llong;
static const int max_n = 100010;
using namespace std;
// vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
vector<vector<pair<llong, llong>>> adj_list(max_n);
vector<llong> tree_dist(max_n, 0);
llong N;

void dfs(llong u, llong prev, llong d){
    // printf("input %lld\n", u);
    tree_dist[u] = d;
    // if((int)adj_list[u].size()==1){
    //     return;
    // }
    for(int i=0;i<(int)adj_list[u].size();i++){
        auto adj_node = adj_list[u][i];
        // printf("adj node = %lld, dist = %lld", adj_node.first, adj_node.second);
        if(adj_node.first != prev){
            llong dist = adj_node.second + d;
            dfs(adj_node.first, u, dist);
        }
    }
}

int main(){
    llong u, v, w;
    scanf("%lld", &N);
    for(int i=0;i<N-1;i++){
        scanf("%lld %lld %lld", &u, &v, &w);
        adj_list[u-1].push_back(make_pair(v-1, w));
        adj_list[v-1].push_back(make_pair(u-1, w));
    }

    dfs(0, -1, 0);

    for(int i=0;i<N;i++){
        // printf("tree dist i = %lld\n", tree_dist[i]);
        printf("%lld\n", tree_dist[i] % 2);
    }


}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end

int n,dp[19][1<<18]; string s;

int main(){
   cin>>n>>s; int m=1<<n;
   rep(i,0,m)scanf("%d",&dp[0][i]);
   rep(i,0,n){
      int len=1<<i;
      rep(j,0,m){
         int x=dp[i][j],y=dp[i][(j+len)%m];
         if(x>y)swap(x,y);
         if(s[y-x-1]=='0')dp[i+1][j]=x; else dp[i+1][j]=y;
      }
   }
   rep(i,0,m)printf("%d\n",dp[n][i]);
   return 0;
}


Measured memory_bytes: 22924
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct road
{
    double s;
    double t;
    long long x;
};
struct peo
{
    long long d;
    long long vt;
    long long res;
    long long fi;
};
road a[1000000];peo b[1000000];int n,q;

void readdata()
{
    cin>>n>>q;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i].s>>a[i].t>>a[i].x;
        a[i].s-=(0.5+a[i].x);
        a[i].t-=(0.5+a[i].x);
    }
    for (int i=1;i<=q;i++)
    {
        cin>>b[i].d;
        b[i].vt=i;
    }
}

void genner()
{
    for (int i=1;i<=q;i++)
        b[i].res=-1;
}

bool cmp1(road a,road b)
{
    return a.x<b.x;
}

bool cmp2(peo a,peo b)
{
    return a.d<b.d;
}

bool cmp3(peo a,peo b)
{
    return a.vt<b.vt;
}

int find1(int l,int r,double k)
{
    while (l<=r)
    {
        int mid=(l+r)/2;
        if ((b[mid].d>=k)&&(b[mid-1].d<k)) return mid;
        if (b[mid].d<k) l=mid+1;
        else r=mid-1;
    }
    return 0;
}

int find2(int l,int r,double k)
{
    while (l<=r)
    {
        int mid=(l+r)/2;
        if ((b[mid].d<=k)&&(b[mid+1].d>k)) return mid;
        if (b[mid].d>k) r=mid-1;
        else l=mid+1;
    }
    return 0;
}

void solve()
{
    for (int i=1;i<=n;i++)
    {
        int x=find1(1,q,a[i].s);
        int y=find2(1,q,a[i].t);
        if ((x!=0)&&(y!=0))
        {
            while (x<=y)
            {
                if (b[x].res==-1)
                {
                    b[x].res=a[i].x;
                    b[x].fi=y;
                }
                else
                {
                    x=b[x].fi;
                }
                x++;
            }
        }
    }
}

void xuat()
{
    for (int i=1;i<=q;i++)
    {
        cout<<b[i].res<<"\n";
    }
}

int main()
{
  //  freopen("a.inp","r",stdin);
  //  freopen("a.out","w",stdout);
    readdata();
    genner();
    b[0].d=-1e10;
    b[q+1].d=1e10;
    sort(a+1,a+1+n,cmp1);
    sort(b+1,b+1+q,cmp2);
    solve();
    sort(b+1,b+1+q,cmp3);
    xuat();
    return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
using namespace std;
#define int long long

signed main() {
  string s, t;
  cin >> s >> t;
  vector<char> v, w;
  for (int i = 0; i < s.size(); i++) {
    v.push_back(s[i]);
  }
  for (int i = 0; i < t.size(); i++) {
    w.push_back(t[i]);
  }
  sort(v.begin(), v.end());
  sort(w.begin(), w.end(), greater<char>());
  for (int i = 0; i < min(s.size(), t.size()); i++) {
    if (v[i] < w[i]) {
      cout << "Yes" << endl;
      return 0;
    } else if (v[i] > w[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (s.size() < t.size()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#n = int(input())
n,k = map(int,input().split())
#a_L = list(map(int,input().split()))

if abs(n-k) >= n:
    print(n)
    exit()

if n > k:
    tmp = n%k
    print(min(tmp,abs(tmp-k)))
    exit()

if n==k:
    print(0)
    exit()

if n == 0:
    print(0)


print(abs(n-k))


Measured memory_bytes: 3060
import java.util.*

fun lcm(a:Int, b:Int):Int {
    return a * b / gcd(a, b)
}
fun gcd(a:Int, b:Int):Int {
    return when(b){
        0 -> a
        else -> gcd(b, a % b)
    }
}
class Harmony(private val pattern:Int = 0){
    constructor(pattern:String):this(pattern.toInt(16))
    fun merged(other:Harmony):Harmony {
        return Harmony(pattern or other.pattern)
    }
    override fun toString(): String {
        return (pattern / 16).toString(16).capitalize() + (pattern % 16).toString(16).capitalize()
    }
}
class Rythm(private val mHarmonies:Array<Harmony> = Array(1){Harmony()}){
    companion object {
        operator fun invoke(string:String):Rythm{
            val length = string.length / 2
            val array = (0 until string.length step 2).map{string.substring(it, it + 2)}
            val g = array.withIndex().filter{i -> i.value != "00"}.fold(length){l, r -> gcd(l, r.index)}
            return Rythm((0 until length step g).map{Harmony(array[it])}.toTypedArray())
        }
    }
    val length:Int
        get() = mHarmonies.size
    fun mergedSize(rythm: Rythm):Int = lcm(this.length, rythm.length)
    fun merge(rythm: Rythm):Rythm? {
        if (mergedSize(rythm) > 1024) return null
        val res = Array(mergedSize(rythm)){Harmony()}
        val h = res.size / length
        for (i in 0 until length){
            res[i * h] = res[i * h].merged(mHarmonies[i])
        }
        val v = res.size / rythm.length
        for (i in 0 until rythm.length){
            res[i * v] = res[i * v].merged(rythm.mHarmonies[i])
        }
        return Rythm(res)
    }
    override fun toString(): String {
        return mHarmonies.joinToString("") { it.toString()}
    }
}

fun main(args:Array<String>):Unit {
    repeat(readLine()!!.toInt()){
        println(Array(readLine()!!.toInt()){
            readLine()!!.trim()
        }.fold(Rythm() as Rythm?){l, r -> l?.merge(Rythm(r))} ?: "Too complex.")
    }
}


Measured memory_bytes: 72764
#include <stdio.h>

int main(void){
    int n;
    int i;
    int a;
    int b;
    int worst;
    int miniv;
    scanf("%d", &n);
    scanf("%d %d", &worst, &miniv);
    for (i = 0; i < n - 1; i++){
        scanf("%d %d", &a, &b);
        if (a > worst){
            worst = a;
            miniv = b;
        }
    }

    printf("%d\n", worst + miniv);


}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  ll N, A, B; cin >> N >> A >> B;
  vector <ll> H(N);

  ll start = 0, end = 0;
  for (int i = 0; i < N; i++){
    cin >> H[i];
    end += H[i] / B;
    if (H[i] % B != 0) end++;
  }


  vector < pair<ll, bool> > result;
  result.push_back(make_pair(0, false));
  result.push_back(make_pair(end, true));
  
  int C = 0;
  while (C <= 1){
    ll now = start + (end - start) / 2;
    ll cnt = 0;
    for (int i = 0; i < N; i++){
      ll res = H[i] - now * B;
      if (res > 0){
        cnt += res / (A - B);
        if (res % (A - B) != 0) cnt++;
      }
    }

    if (now >= cnt){
      result.push_back(make_pair(now, true));
      end = now;
    }else{
      result.push_back(make_pair(now, false));
      start = now;
    }
    if (end - start == 1) C++;
  }

  sort(result.begin(), result.end());

  for (int i = 0; i < result.size() - 1; i++){
    if (result[i].second == false && result[i + 1].second == true){
      cout << result[i + 1].first << endl;
      break;
    }
    
  }
  
  

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(NULL);
    ios::sync_with_stdio(false);    
    string s,t,m;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    cin>>m;
    if(m==s)cout<<a-1<<" "<<b<<endl;
    else cout<<a<<" "<<b-1<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math

#a,b,c = map(int, input().split())
s = input()
li = [''] * 3
for i in range(3):
    li[i] = s[i]
li.sort()
li2 = ['a', 'b', 'c']
if (li == li2):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

bool isPrime(int x){
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
int main() {
    int s,w; cin >> s >>w;
    if(s <= w){
        cout << "unsafe" <<endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x;
    cin >> x;
    if ( x>=1800 ) cout << 1;
    else if ( x>1599 ) cout << 2;
    else if ( 1399<x ) cout << 3;
    else if ( 1199<x ) cout << 4;
    else if ( 999<x ) cout << 5;
    else if ( 799<x ) cout << 6;
    else if ( 599<x ) cout << 7;
    else cout << 8;
    cout << '\n';
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) 
{ v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i]; }
template<class T, class U> void read_n(vector<pair<T, U>>& v, size_t n)
{ v = vector<pair<T, U>>(n); 
  for (lli i=0; i<n; ++i) cin >> v[i].first >> v[i].second; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli h, w;
vector<string> s;
vector<vector<lli>> v;

pair<lli, lli> dfs(lli i, lli j) {
  lli vi = 1, vj = 0;
  lli c = s[j][i];
  lli tc = c=='#' ? '.' : '#';
  s[j][i] = '*';
  lli bl = (c=='#' ? 1 : 0), wh = (c=='.' ? 1 : 0);
  for (lli d=0; d<4; ++d) {
    lli ti = i+vi, tj = j+vj;
    if (0<=ti && ti<w && 0<=tj && tj<h && s[tj][ti]==tc) {
      auto p = dfs(ti, tj);
      bl += p.first; wh += p.second;
    }
    lli t = vi; vi = -vj; vj = t;
  }
  return make_pair(bl, wh);
}

int main() {
  cin >> h >> w;
  read_n(s, h);
  lli ans = 0;
  for (lli j=0; j<h; ++j) {
    for (lli i=0; i<w; ++i) {
      if (s[j][i] == '#') {
	auto p = dfs(i, j);
	ans += p.first * p.second;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 17920
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n,t,a;
    cin >> n >> t >> a;
    vector<double>h(n);
    vector<double>b(n);
    rep(i,n){
        cin >> h[i];
        b[i] = t-0.006*h[i];
    }
    double hoge = 1<<30;
    int ans = 0;
    rep(i,n){
        if(hoge > abs(b[i]-a)){
            ans = i;
            hoge = abs(b[i]-a);
        }
    }
    cout << ans + 1 << endl;
}

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

int main(){
    int n;
    double t, a;
    cin >> n >> t >> a;

    int ans = -1;
    double dist = DBL_MAX;

    double h;
    for(int i = 1; i <= n; i++){
        cin >> h;
        h = t-h*0.006;
        double tmp = abs(h-a);
        if(tmp < dist){
            dist = tmp;
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<62;
constexpr double eps = (1e-9);

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

  int n, t;
  cin >> n >> t;
  vector<pair<ll, ll>> ab;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ab.push_back({a, b});
  }

  sort(ALL(ab));

  vector<vector<ll>> dp(n, vector<ll>(t + 1, 0));
  for (int j = ab[0].first; j < t; j++) {
    dp[0][j] = ab[0].second;
  }

  for (int i = 1; i < n; i++) {
    ll a = ab[i].first;
    ll b = ab[i].second;
    for (int j = 0; j < t; j++) dp[i][j] = dp[i-1][j];
    for (int j = a; j < t; j++) {
      chmax(dp[i][j], dp[i-1][j-a] + b);
    }
  }

  ll ans = max(dp[n-1][t-1], ab[0].second);

  for (int i = 1; i < n; i++) {
    chmax(ans, dp[i-1][t-1] + ab[i].second);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 73684
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            if (map.containsKey(B)) {
                List<Integer> list = map.get(B);
                list.add(A);
            } else {
                List<Integer> list = new ArrayList<>();
                list.add(A);
                map.put(B, list);
            }
        }
        List<Integer> keySet = new ArrayList<>(map.keySet());
        Collections.sort(keySet);
        long count = 0;
        for (Integer key : keySet) {
            for (Integer task : map.get(key)) {
                count += task;
                if (key < count) {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }    
}


Measured memory_bytes: 92760
m=f=r=0
while True:
    m,f,r=map(int,input().split())
    x=m+f
    if m==f==r==-1:
        break
    elif m==-1 or f==-1 or x<30:
        print('F')
    elif x>=80:
        print('A')
    elif 65<=x<80:
        print('B')
    elif 50<=x<65 or r>=50:
        print('C')
    else:
        print('D')
    

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, A, B; cin >> N >> A >> B;
    ll ulim = B*(N-1)+A, dlim = A*(N-1)+B;
    bool ok = true;
    if(A > B) ok = false;
    if(A < B && N == 1) ok = false;
    if(ok) cout << ulim-dlim+1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int x;
	cin>>x;
	int ans=0;
	ans+=x/500*1000;
	x%=500;
	ans+=x/5*5;
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

#define MAX 35
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

int H,W,T;
vector<piii> vec;

bool check(int s){
  int now = s;

  for(int i = 0 ; i < vec.size() ; i++){
    if(vec[i].second.first == now){
      now = vec[i].second.second;
    }else if(vec[i].second.second == now){
      now = vec[i].second.first;
    }
  }
  return now == T;
}

int main(){
  int S;
  bool G[MAX][MAX][MAX];
  char in;
  
  while(cin >> W,W){
    memset(G,false,sizeof(G));
    vec.clear();
    cin >> S >> T >> H; S--; T--;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W-1 ; j++){
        cin >> in;
        if(in == '1'){
          if(j > 0){
            G[i][j-1][j] = true;
          }
          G[i][j][j+1] = G[i][j+1][j+2] = true;
          vec.push_back(piii(i,pii(j,j+1)));
        }
      }
    }
    sort(vec.begin(),vec.end());
    if(check(S)){
      cout << 0 << endl;
    }else{
      bool found = false;
      for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W-1 ; j++){
          if(G[i][j][j+1]) continue;
          vector<piii> tmp = vec;
          vec.push_back(piii(i,pii(j,j+1)));
          sort(vec.begin(),vec.end());
          if(check(S)){
            cout << i+1 << " " << j+1 << endl;
            found = true;
            goto end;
          }
          vec = tmp;
        }
      }
    end:;
      if(!found){
        cout << 1 << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1252
/**Which of the favors of your Lord will you deny ?**/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second
#define INF INT_MAX

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
                    TIn, null_type, less<TIn>,
                    rb_tree_tag, tree_order_statistics_node_update>;

/*
PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

*/

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

LL ara[nmax];

int main()
{
    optimizeIO();

    int n;
    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>ara[i];

    LL ans = 0;

    for(int i=1;i<n;i++)
    {
        LL nij = ara[i]/2;

        LL baki = ara[i] - nij*2;

        LL por = min(baki,ara[i+1]);

        ara[i+1] -= por;

//        DBG(ara[i]);
//        DBG(nij);
//        DBG(por);

        ans += nij + por;
    }

    ans += ara[n]/2;

    cout<<ans<<endl;

    return 0;
}




Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = (10**9 +7)
for j in range(61):# 2**j 桁に対して1なものの数を求める
    num_one = 0
    for i in range(len(a)):
        if a[i] & 2**j: 
            num_one += 1
    #print(j,num_one)
    ans += (2**j % mod) * (n-num_one)*(num_one) % mod
    #print(ans)
print(ans%mod)

Measured memory_bytes: 122936
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_134
{
    class F
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            long mask = 1000000000 + 7;
            long[,,] dp = new long[n + 5, n + 5, k + 5];
            dp[0, 0, 0] = 1;
            for(int i = 0; i <= n; i++)
            {
                for(int j = 0; j <= n; j++)
                {
                    for(int l = 0; l <= k; l++)
                    {
                        if (l + 2 * j >= k + 5) continue;

                        dp[i + 1, j, l + 2 * j] += dp[i, j, l] * (1 + 2 * j);
                        dp[i + 1, j, l + 2 * j] %= mask;

                        dp[i + 1, j + 1, l + 2 * j] += dp[i, j, l];
                        dp[i + 1, j + 1, l + 2 * j] %= mask;

                        if (j > 0)
                        {
                            dp[i + 1, j - 1, l + 2 * j] += dp[i, j, l] * j * j;
                            dp[i + 1, j - 1, l + 2*j] %= mask;
                        }
                    }
                }
            }

            WriteLine(dp[n, 0, k]);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

const int MAX=2e5+5;
int n,k,a[MAX],tree[MAX];

void update(int idx) {
	while(idx<=n+1) {
		tree[idx]++;
		idx+=idx&-idx;
	}
}

int query(int idx) {
	int rs=0;
	while(idx>0) {
		rs+=tree[idx];
		idx-=idx&-idx;
	}
	return rs;
}

int32_t main() {
	//freopen("input","r",stdin);
	cin>>n>>k;
	vector<int> V;
	map<int,int> M;
	V.push_back(0);
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		a[i]+=a[i-1]-k;
		V.push_back(a[i]);
	}
	sort(V.begin(),V.end());
	V.resize(unique(V.begin(),V.end())-V.begin());
	int cnt=0;
	for(int x:V)
		M[x]=++cnt;
	int rs=0;
	update(M[0]);
	for(int i=1;i<=n;i++) {
		rs+=query(M[a[i]]);
		update(M[a[i]]);
	}
	cout<<rs;
}


Measured memory_bytes: 20476
#include <stdio.h>

int main(){
  int N, i, min, left=0, right=0;
  char S[300000];

  scanf("%d", &N);
  scanf("%s", S);

  for(i=1;i<N;i++){
    if(S[i] == 'E') right++;
  }
  min = right;
  for(i=1;i<N;i++){
    if(S[i] == 'E') right--;
    if(S[i-1] == 'W') left++;
    if(min > left+right) min = left+right;
  }
  printf("%d\n", min);
  return 0;
}

Measured memory_bytes: 512