akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
vector<int> a[N][N];
int vis[N],u[N],v[N],tot,ne[N*2],fi[N],zz[N*2],flag[N][N],out[N],l,in[N];
int x[N],y[N],cnt[N][N],n,m,ans,fa[N];
void jb(int x,int y){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
	flag[x][y]=1;
}
void dfs(int x,int y){
	fa[x]=y;in[x]=++l;
	for (int i=fi[x];i;i=ne[i])
		if (zz[i]!=y)dfs(zz[i],x);
	out[x]=++l;
}
int pd(int x,int y){
	return in[x]<=in[y]&&out[x]>=out[y];
}
void fg(int x,int y){
	while (!pd(x,y)){
		ans+=flag[x][fa[x]];
		flag[x][fa[x]]=0;
		cnt[x][fa[x]]--;
		cnt[fa[x]][x]--;
		x=fa[x];
	}
	while (x!=y){
		ans+=flag[fa[y]][y];
		flag[fa[y]][y]=0;
		cnt[y][fa[y]]--;
		cnt[fa[y]][y]--;
		y=fa[y];
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<n;i++){
		scanf("%d%d",&x[i],&y[i]);
		jb(x[i],y[i]);jb(y[i],x[i]);
	}
	dfs(1,0);
	for (int i=1;i<=m;i++){
		scanf("%d%d",&u[i],&v[i]);
		int x=u[i],y=v[i];
		while (!pd(x,y)){
			a[x][fa[x]].push_back(i);
			a[fa[x]][x].push_back(-i);
			x=fa[x];
		}
		while (x!=y){
			a[y][fa[y]].push_back(-i);
			a[fa[y]][y].push_back(i);
			y=fa[y];
		}
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)cnt[i][j]=a[i][j].size();
	while (1){
		int p=0;
		for (int i=1;i<n;i++)
			if (cnt[x[i]][y[i]]==1&&flag[x[i]][y[i]]!=flag[y[i]][x[i]]){
				p=i;
				break;
			}
		if (!p){
			for (int i=1;i<n;i++)
				if (cnt[x[i]][y[i]]>=2){
					p=i;
					break;
				}
		}
		if (!p)for (int i=1;i<n;i++)
			if (cnt[x[i]][y[i]]>=1){
				p=i;
				break;
			}
		if (!p)break;
		if (!flag[x[p]][y[p]])swap(x[p],y[p]);
		for (int i=0;i<a[x[p]][y[p]].size();i++)
			if (!vis[abs(a[x[p]][y[p]][i])]){
				vis[abs(a[x[p]][y[p]][i])]=1;
				int now=abs(a[x[p]][y[p]][i]);
				if (a[x[p]][y[p]][i]<0)swap(u[now],v[now]);
				fg(u[now],v[now]);
				break;
			}
	}
	printf("%d\n",ans);
	for (int i=1;i<=m;i++)printf("%d %d\n",u[i],v[i]);
}


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

int main()
{
  int X,Y,ans=0;
  cin >> X >> Y;
  for (int i = 0; i < X+1; i++)
  {
    if (i*2+(X-i)*4==Y)
    {
      ans=1;
    }
    
  }
  if (ans==1)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
  
  
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define v(x) vector<x>
#define pb push_back 
#define mp make_pair
#define maxint 1e18
#define mint -1e18

int main(){
	string s;
	cin>>s;
	ll x = 0,n=s.size();
	for(int i=0;i<n;i++){
		x += (s[i]-'0');
	}
	cout<<(x%9==0 ? "Yes\n":"No\n")<<'\n';

	return 0;
}

Measured memory_bytes: 3728
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const LL INF = 1e9 + 10;

int main(){
	int n, m, k;	scanf("%d%d%d", &n, &m, &k);
	bool f = false;
	for(int i = 0; i <= n; ++i) {
		for(int j = 0; j <= m; ++j) {
			if(i * m + j * n - 2 * i * j == k)	f = true;
		}
	}
	if(f)	puts("Yes");
	else	puts("No");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  string s, t; cin >> s >> t;
  map<char, char> stmap;
  set<char> tset;
  bool is_swap = true;
  REP(i, s.size()) {
    if (stmap.find(s.at(i)) != stmap.end()) {
      if (stmap.find(s.at(i))->second != t.at(i)) {
        is_swap = false; break;
      }
    } else if (tset.find(t.at(i)) != tset.end()) {
      is_swap = false; break;
    } else {
      stmap.insert({s.at(i), t.at(i)});
      tset.insert(t.at(i));
    }
  }
  if (is_swap) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
void output(int n){
	cout<<n<<endl;
	exit(0);
}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	string s;
	cin>>s;
	if(s=="RRR")output(3);
	if(s=="SSS")output(0);
	if(s=="SRR")output(2);
	if(s=="RSR")output(1);
	if(s=="RRS")output(2);
	if(s=="SSR")output(1);
	if(s=="RSS")output(1);
	if(s=="SRS")output(1);
    return 0;
}



Measured memory_bytes: 3612
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int X = sc.nextInt();
        int Y = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int[] p = new int[A];
        int[] q = new int[B];
        int[] r = new int[C];
        for (int i=0; i<A; i++) {
            p[i] = sc.nextInt();
        }
        for (int i=0; i<B; i++) {
            q[i] = sc.nextInt();
        }
        for (int i=0; i<C; i++) {
            r[i] = sc.nextInt();
        }

        System.out.println(solve(X, Y, A, B, C, p, q, r));
    }

    private static long solve(int X, int Y, int A, int B, int C, int[] p, int[] q, int[] r) {
        long count = 0;

        Arrays.sort(p);
        Arrays.sort(q);
        Arrays.sort(r);

        for (int i=0; i<X; i++) {
            count += p[A-i-1];
        }
        for (int i=0; i<Y; i++) {
            count += q[B-i-1];
        }

        int idxP = A-X;
        int idxQ = B-Y;

        for (int i=C-1; i>=0; i--) {
            // System.err.println("i=" + i + ", idxP=" + idxP + ", idxQ=" + idxQ);
            if (idxP == A && idxQ == B) break;
            if (idxP == A) {
                if (q[idxQ] > r[i]) {
                    break;
                }
                // System.err.println("replace q[" + idxQ + "] = "  + q[idxQ] + " with r[" + i + "] = " + r[i]);
                count += r[i] - q[idxQ++];
            } else if (idxQ == B) {
                if (p[idxP] > r[i]) {
                    break;
                }
                // System.err.println("replace p[" + idxP + "] = "  + p[idxP] + " with r[" + i + "] = " + r[i]);
                count += r[i] - p[idxP++];
            } else {
                if (p[idxP] <= q[idxQ] && p[idxP] < r[i]) {
                    // System.err.println("replace p[" + idxP + "] = "  + p[idxP] + " with r[" + i + "] = " + r[i]);
                    count += r[i] - p[idxP++];
                } else if (p[idxP] > q[idxQ] && q[idxQ] < r[i]) {
                    // System.err.println("replace q[" + idxQ + "] = "  + q[idxQ] + " with r[" + i + "] = " + r[i]);
                    count += r[i] - q[idxQ++];
                }
            }
        }

        return count;
    }
}

Measured memory_bytes: 93476
#! /usr/bin/python3

while True:
    n, r = list(map(int, input().split()))
    if n == 0 and r == 0 : break
    
    deck = list(range(n, 0, -1))
    for i in range(r):
        p, c = list(map(int, input().split()))
        p -= 1
        p_cards = deck[:p]
        c_cards = deck[p:p+c]
        remain = deck[p+c:]
        deck = c_cards + p_cards + remain
    print(deck[0])

Measured memory_bytes: 6720
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(n)]
CD=[list(map(int,input().split())) for i in range(m)]
ans=[]
for i in range(n):
  dis = 10**9
  plc = -1
  for j in range(m):
    if dis > abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1]):
      plc = j+1
      dis = abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
  ans.append(plc)
for i in range(n):
  print(ans[i])

Measured memory_bytes: 69748
gets
A,D=gets.split.map(&:to_i)
h=Hash.new{|h,k|h[k]=(A-D)+D*k}
gets.to_i.times{
x,y,z=gets.split.map(&:to_i)
h[y],h[z]=h[z],h[y] if x==0
h[y]=h[z] if x==1
}
p h[gets.to_i]

Measured memory_bytes: 8704
#include<bits/stdc++.h>
#define ll  long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
void solve()
{
    ll n,m,k,x,y=0,res=0,l,cnt=0,sum=0,z,sum1=0,cnt1=0,h,res1;
    cin>>n;
    rep(i,0,n)
    {
        cin>>x;
        if(x>=res)
            cnt++;
        res=max(res,x);
    }
    cout<<cnt;



}
int main()
{   speed_up
    ll t;
   // cin>>t;
    t=1;
    while(t--)
        solve();
}


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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		int w,h;
		cin>>w>>h;
		bool a[105][105]={};
		int x,y;
		for (int i = 0; i < n; ++i) cin>>x>>y,--x,--y,a[x][y]=1;
		int s,t;
		cin>>s>>t;
		int ans=0;
		for (int i = 0; i <= w-s; ++i)
		{
			for (int j = 0; j <= h-t; ++j)
			{
				int m=0;
				for (int k = 0; k < s; ++k)
				{
					for (int l = 0; l < t; ++l)
					{
						if(a[i+k][j+l]) ++m;
					}
				}
				ans=max(ans,m);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3000
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        sc.close();

        String ans ;

        if ( a.equals( b ) ) {
            System.out.println( "H" );
        } else {
            System.out.println( "D" );
        }
    }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 1;
  for (int i = 1; i * i <= m; ++i) {
    if (m % i == 0) {
      if (m / i >= n) {
        ans = max(ans, i);
      }
      if (i >= n) {
        ans = max(ans, m / i);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3544
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

bool cmp(pair<int, int[3]> p, pair<int, int[3]> q)
{
    return (p.second[1] > q.second[1]) || (p.second[1] == q.second[1] && p.second[2] < q.second[2])
        || (p.second[1] == q.second[1] && p.second[2] == q.second[2] && p.first < q.first);
}

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;

        pair<int, int[3]> team[300];
        int select[1000] = {0};

        for (int i = 0; i < n; i++) {
            cin >> team[i].first >> team[i].second[0] 
                >> team[i].second[1] >> team[i].second[2];
        }
        sort(team, team + n, cmp);
        
        int sl = 0;  // Number of the selected team.
        for (int i = 0; i < n; i++) {
            if ((sl < 10 && select[team[i].second[0] - 1] < 3) ||
                (sl < 20 && select[team[i].second[0] - 1] < 2) ||
                (sl < 26 && select[team[i].second[0] - 1] == 0)) {
                    sl++;
                select[team[i].second[0] - 1]++;
                cout << team[i].first << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
using namespace std;
int main() {

	int s;
	int m;
	int h;

	cin >> s;

	h = s / 3600;
	s = s - h * 3600;

	m = s / 60;
	s = s - m * 60;
	
	cout << h << ":" << m << ":" << s << endl;

	return 0;
}


Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();

		switch (str) {
		case "SUN":
			System.out.println(7);
			break;
		case "MON":
			System.out.println(6);
			break;
		case "TUE":
			System.out.println(5);
			break;
		case "WED":
			System.out.println(4);
			break;
		case "THU":
			System.out.println(3);
			break;
		case "FRI":
			System.out.println(2);
			break;
		case "SAT":
			System.out.println(1);
			break;
		}
	}
}


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

int main(){
	string s,t;
	cin>> s >> t;
	bool ok = true;
	rep(i,s.size()){
		if(s[i] != t[i]) ok = false;
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;


int main(){
	string tmp;
	while(getline(cin,tmp,'\n')){
		for(string::iterator it = tmp.begin(); it != tmp.end(); it++){
			if(*it >= 'a' && *it <= 'z'){
				*it -= 32;
			}
		}

		cout << tmp << endl;
	}

	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vs vector<string>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define mc map<char,ll>
#define itr ::iterator
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define fn(i,a,b) for(ll i=a;i>b;i--)
#define fne(i,a,b) for(ll i=a;i>=b;i--)
#define fm(it,m) for(it = m.begin();it != m.end();++it)
#define all(v) v.begin(),v.end()
#define M 1000000007
#define pi 3.14159265358979323846


int main()
{  
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

   int n=0,x=0,t=0;
   cin>>n>>x>>t;

   int k  =  ceil(double(n)/x);
   cout<<k*t;


   return 0;
}


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

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int answer = 1;
  int odd_pattern = 1;
  rep(i, N) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      odd_pattern *= 2;
    } else {
      odd_pattern *= 1;
    }
    answer *= 3;
  }
  answer -= odd_pattern;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int n,A[50];

int solve(int i, int m){
  if(m == 0)return 1;
  if(i >= n)return 0;
  int res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

int main(){
  int i,q,M;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
  scanf("%d",&A[i]);
}
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M)==1)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



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

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

  ll n, k;
  cin >> n >> k;
  vector<int> dp = {};
  dp.resize(n, 0);

  // 累積和
  for (auto i = 0; i < n + 1; i++)
  {
    if (i != 0)
    {
      dp[i] = (dp[i - 1] + i) % MOD;
    }
  }

  ll total = 0;
  for (ll i = k; i < n + 1; i++)
  {
    ll max = dp[n] - dp[n - i];
    ll min = dp[i - 1];
    ll val = max - min + 1;

    total += val;
    total %= MOD;
  }

  if (total < 0)
    total += MOD;

  total += 1;
  total %= MOD;
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h> 
 
#define ll long long
using namespace std; 
 
int main() 
{ 
   ll n,i;
   cin>>n;
   ll a[n];
   ll sum=0;
   vector< ll >v;
   for(i=0;i<n;i++){
       cin>>a[i];
       sum+=a[i];
   }
   ll q;
   cin>>q;
   ll b , c;
   unordered_map< ll, ll > hm;
   for(ll j=0;j<n;j++){
               hm[a[j]]++;
           }
              
   for(i=0;i<q;i++){
            cin>>b>>c;
            sum=sum+hm[b]*(c-b);
            hm[c]+=hm[b];
            hm[b]=0;
            cout<<sum<<"\n";
   }
   return 0;
}
 
 
 

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

void Add(int &a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
  while (a < 0) a += MOD;
}
 
void Mul(int &a, int b) {
  a = 1LL * a * b % MOD;
}
 
int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}
 
namespace Math {
  const int NMAX = (int)1e7;
  int pow2[1 + NMAX];
  int fact[1 + NMAX], tcaf[1 + NMAX];
  void Precalc() {
    fact[0] = pow2[0] = 1;
    for (int i = 1; i <= NMAX; ++i) {
      pow2[i] = pow2[i - 1];
      Add(pow2[i], pow2[i]);
 
      fact[i] = fact[i - 1];
      Mul(fact[i], i);
    }
    tcaf[NMAX] = Pow(fact[NMAX], -1);
    for (int i = NMAX - 1; i >= 0; --i) {
      tcaf[i] = tcaf[i + 1];
      Mul(tcaf[i], i + 1);
      assert(1LL * fact[i] * tcaf[i] % MOD == 1);
    }
  }
  int Choose(int n, int k) {
    if (k > n || n < 0) return 0;
    return 1LL * fact[n] * tcaf[n - k] % MOD * tcaf[k] % MOD;
  }
};

int main() {
  Math::Precalc();
    ll n,k;
    cin >> n >> k;
    if (k==1) {cout << 0 << endl;return 0;}
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    ll mi=0,ma=0;
    rep(i,n){
      (mi+=(a[i]+MOD)%MOD*Math::Choose(n-i-1,k-1)%MOD)%=MOD;
    }
    reverse(all(a));
    rep(i,n){
      (ma+=(a[i]+MOD)%MOD*Math::Choose(n-i-1,k-1)%MOD)%=MOD;
    }
    cout << (MOD+ma-mi)%MOD << endl;
}


Measured memory_bytes: 118272
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

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

		// 入力
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}

		// 計算
		long result = 0;
		long cnt = 0;
		long cnt2 = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < n; i++){
		    for(int j : list){
		        if(j > a[i]){
		            cnt++;
		        }else if(j < a[i]){
		            cnt2++;
		        }
		    }
		    list.add(a[i]);
		}
		
        BigInteger b_k = new BigInteger(String.valueOf(k));
        BigInteger b_k_1 = new BigInteger(String.valueOf(k-1));
        
        BigInteger b = b_k.multiply(b_k_1).multiply(BigInteger.valueOf(cnt + cnt2)).divide(BigInteger.valueOf(2)).add(BigInteger.valueOf(cnt).multiply(BigInteger.valueOf(k)));
        BigInteger res = b.mod(BigInteger.valueOf(1000000007));
		//System.out.println(b.toString());
		//System.out.println(res.toString());
		
        result = cnt*k + (cnt + cnt2)*((k*(k-1))/2);
        
        long k_ = k%1000000007;
        long k_1 = (k - 1);
        long c_ = (cnt + cnt2)%1000000007;
        long t = (c_*k_)%1000000007;
        long result2 = (cnt*k_)%1000000007 + (t*k_1/2)%1000000007;

		// 出力
		//System.out.println(cnt);
		//System.out.println(cnt2);
		//System.out.println(result);
	    //System.out.println(result%1000000007);
	    //System.out.println(floorMod(result, 1000000007L));
		//System.out.println(result2);
	    //System.out.println(result2%1000000007);
		//System.out.println(k_1);
		//System.out.println(t);
		System.out.println(res);
	}

}


Measured memory_bytes: 28336
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete
 
f m n = g m n 0 0 "" []
  where
    g m n x y s l
      | x==m && y==n = s : l
      | (x<=4 && y<=4) || (x==4 && y==5) || (x==5 && y==4) = let t = g m n (x+1) y (s++"A") l in g m n x (y+1) (s++"B") t
      | otherwise = l
 
main = getInts >>= mapM_ putStrLn . reverse . apply2 f


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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    
    int x = 0, max = 0;
    
    for(int i = 0; i < n; i++){
        if(s.at(i) == 'I'){
            x++;
        }else{
            x--;
        }                    //i文字目をみたあとのx
//        cout << x << " ";
        
        if(max < x){
            max = x;
        }
    }
    
    cout << max << endl;
        
}




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

typedef long long LL;
string s,t;

vector<int> idx[30];

int cari(int now, int cur){
  if(idx[now].back() < cur) return s.size();
  if(idx[now][0] >= cur) return idx[now][0];
  int l=0;
  int r=idx[now].size()-1;
  int ans = r;
  while(l<=r){
    int mid = (l+r)/2;
    if(idx[now][mid] >= cur){
      ans = mid;
      r = mid-1;
    } else {
      l = mid+1;
    }
  }
  return idx[now][ans];
}

int main(){
  cin >> s;
  cin >> t;
  for(int i=0;i<s.size();i++){
	idx[s[i]-'a'].push_back(i);
  }
  int put = 0;
  int cur = 0;
  for(int i=0;i<t.size();i++){
    int now = t[i]-'a';
    if(idx[now].size() == 0){
      cout << "-1\n";
      return 0;
    }
    cur = cari(now,cur);
    if(cur == s.size()){
      put++;
      cur = idx[now][0];
    }
    cur++;
    if(cur == s.size()){
      put++;
      cur = 0;
    }
  }
  LL ans = (LL)s.size() * (LL)(put) + (LL)(cur);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1216
package main

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

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func main() {
	X, A := getIn()
	out := calc(X, A)
	fmt.Println(out)
}

func calc(X, A int) (out int) {
	if X < A {
		out = 0
	} else {
		out = 10
	}
	return
}

func getIn() (int, int) {
	return getInt(), getInt()
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.io.*;

public class Main{
	public static int[] increase(int[] x){
		for(int i = 0; i < x.length; i++){
			int min = i;
			for(int j = i; j < x.length; j++){
				if( x[j] < x[min] ){
					min = j;
				}
			}
			int temp = x[i];
			x[i] = x[min];
			x[min] = temp;
		}
		return x;
	}
	
	public static int[] rule(int[] dataA, int[] dataB){
		int[] result = new int[2];
		int turn = 0;
		int countA = 0;
		int countB = 0;
		while( countA != dataA.length && countB != dataB.length ){
			int x = 0;
			for(int i = 0; i < dataA.length; i++){
				if( turn == 0 ){
					if( dataA[i] < x ){
						if( i == dataA.length-1 ){
							turn = 1;
							break;
						} else {
							continue;
						}
					} else {
						turn = 1;
						x = dataA[i];
						dataA[i] = -1;
						countA++;
						i = 0;
						if( countA == dataA.length ){
							break;
						}
					}
				}
				if( turn == 1 ){
					if( dataB[i] < x ){
						if( i == dataB.length-1 ){
							turn = 0;
							break;
						} else {
							continue;
						}
					} else {
						turn = 0;
						x = dataB[i];
						dataB[i] = -1;
						countB++;
						i = 0;
						if( countB == dataB.length ){
							break;
						}						
					}
				}
			}
		}
		
		if( countA == dataA.length ){
			result[0] = dataB.length-countB;
			result[1] = 0;
		} else {
			result[0] = 0;
			result[1] = dataA.length-countA;
		}
		return result;
	}
	
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		int[][] result = new int[100][2];
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			int index = 0;
			
			while( stdIn.hasNext() ){
				int n = -1;
				if( stdIn.hasNextInt() ){
					n = stdIn.nextInt();
				} else {
					stdIn.next();
				}
				if( n == 0 ){
					break;
				}
				int[] dataA = new int[n];
				int[] dataB = new int[n];
				int[] check = new int[2*n];
				for(int i = 0; i < n; i++){
					dataA[i]= stdIn.nextInt();
					check[dataA[i]-1] = 1;
				}
				int j = 0;
				for(int i = 0; i < n; i++){
					for(; j < 2*n; j++){
						if( check[j] == 0 ){
							dataB[i] = j+1;
							j++;
							break;
						}
					}
				}
				dataA = increase(dataA);
		/*		for(int i = 0; i < dataA.length; i++){
					System.out.println(dataA[i]);
				}
				for(int i = 0; i < dataB.length; i++){
					System.out.println(dataB[i]);
				}*/
				result[index] = rule(dataA, dataB);
				index++;
			}
			
			for(int i = 0; i < index; i++){
				System.out.println(result[i][0]);
				System.out.println(result[i][1]);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[26];
ll b[26];
int main() {
	string s;
	cin>>s;
	for(ll i=0;i<s.size();i++){
		ll now=s[i]-'a';
		a[now]=1;
	}
	for(ll i=0;i<26;i++){
		if(a[i]==0){
			cout << s+char(i+'a');
			return 0;
		}
	}
	for(ll i=s.size()-2;i>=0;i--){
		if(s[i]<s[i+1]){
			for(ll j=0;j<=i;j++){
				if(j==i){
					for(ll k=0;k<=j;k++){
						ll now=s[k]-'a';
						b[now]=1;
					}
					ll now=s[j]-'a';
					for(ll k=now;k<26;k++){
						if(b[k]==1){
							continue;
						}
						cout << char(k+'a');
						return 0;
					}
				}				cout << s[j];
			}
		}
	}
	cout << -1;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import copy

N, L = map(int, input().split())

taste = []
for i in range(1, N+1):
    taste.append(L+i-1)

#print(taste)

plan = sum(taste)

diff = []
ans = []

for i in range(0, N):
    apples = copy.deepcopy(taste)
    apples.pop(i)
    diff.append(abs(plan - sum(apples)))
    ans.append(sum(apples))
    
#print(diff)
#print(ans)

#print(min(diff))
print(ans[diff.index(min(diff))])


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
int main(){
  int N, P;
  std::string S;
  std::cin >> N;
  std::cin >> P;
  std::cin >> S;
  if(P == 2){
    unsigned long count = 0;
    for(int i = 0; i < N; ++i){
      int digit = S[i] - '0';
      if(digit%2 == 0){
        count += i+1;
      }
    }
    std::cout << count << std::endl;
    return 0;
  }
  else if(P == 5){
    unsigned long count = 0;
    for(int i = 0; i < N; ++i){
      int digit = S[i] - '0';
      if(digit%5 == 0){
        count += i+1;
      }
    }
    std::cout << count << std::endl;
    return 0;
  }
  std::vector<unsigned long> countmod(P,0);
  int tmpmod10 = 1;
  int tmpmodb = 0;
  for(int i = 0; i < N; ++i){
    int mod = ((S[N-1-i] - '0') * tmpmod10 + tmpmodb)%P;
    ++countmod[mod];
    tmpmodb = mod;
    tmpmod10 = (tmpmod10*10)%P;
  }

  unsigned long count = 0;
  for(int i = 0; i < P; ++i){
    count += countmod[i] * (countmod[i] - 1) / 2;
  }
  std::cout << count + countmod[0] << std::endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private long solve() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char [][] grid = new char[H+1][W+1];
		sc.nextLine();
		for(int i=1;i<=H;i++){
			String line = sc.nextLine();
			int j=1;
			for(char c: line.toCharArray()){
				grid[i][j++] = c;
			}
		}
 		
 		long dp[][] = new long[H+1][W+1];

 		dp[H][W] =1;
 		
 	 	long MOD = (long) 1e9+7;

 		for(int i=H;i>=1;i--){
 			for(int j=W;j>=1;j--) {

 				if (i==H && j==W) continue;

 				if(grid[i][j]=='#') continue;
 				else dp[i][j] = (((i==H) ? 0 : dp[i+1][j]) + ((j==W) ? 0 : dp[i][j+1]))%MOD;
 			}
 		}

		return dp[1][1];

	}
}

Measured memory_bytes: 62012
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	string s;
	cin>>s;
	vector<int> a;
	rep(i,s.length()){
		if(s.at(i)=='B'){
			if(a.empty()){
				continue;
			}else{
				a.pop_back();
			}
		}else{
			a.push_back(s.at(i)-'0');
		}
	}
	for_each(all(a),[](int x){
		cout<<x;
	});
	cout<<endl;
}


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

namespace ProgramingContest
{
    class Program
    {
        static void Main()
        {

            var bCount = int.Parse(ReadLine());
            var bList = new List<string>();

            for (int i = 0; i < bCount; i++)
            {
                bList.Add(ReadLine());
            }

            var rCount = int.Parse(ReadLine());
            var rList = new List<string>();

            for (int i = 0; i< rCount; i++)
            {
                rList.Add(ReadLine());
            }


            var max = 0;

            foreach (var s in bList){
                var plus = bList.Count(x => x.Equals(s));
                var minus = rList.Count(x => x.Equals(s));
                var r = plus - minus;
                if (max <= r)
                {
                    max = r;
                }
            }

            WriteLine(max);

            }
    }
}


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

int main() {
int A; int B;
  cin>>A>>B;
  if(A!=1&&B!=1){
    if(A>B)
      cout<<"Alice"<<endl;
    else if(A<B)
      cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
  }
  else if (A==1||B==1){
    if(A==1&&B!=1)
      cout<<"Alice"<<endl;
    else if(A!=1&&B==1)
      cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
  }
  
}
    

Measured memory_bytes: 256
module ABC142

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_A

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_A (num)

    ! arguments for this <subroutine>
    integer(INT32), intent(in) :: num

    ! variables for this <subroutine>
    integer(INT32)   :: itr
    integer(INT32)   :: sum
    real   (REAL128) :: possibility

    ! STEP.01
    ! calculate the answer of this task
    if (mod(num, 2_INT32) .eq. 0_INT32) then
      possibility = 5.0e-01_REAL128
    else

      sum = 0_INT32

      do itr = 1_INT32, num, 1_INT32
        if (mod(itr, 2_INT32) .ne. 0_INT32) sum = sum + 1_INT32
      end do

      possibility = sum
      possibility = possibility / num

    end if

    ! STEP.02
    ! output the answer of this task
    print *, possibility

    ! STEP.END
    return

  end subroutine task_A

end module ABC142


program main

  ! <module>s to import
  use, non_intrinsic :: ABC142

  ! require all variables to be explicitly declared
  implicit none

  ! variables for this <program>
  integer(INT32) :: N

  ! STEP.01
  ! read out the given data
  read(unit=INPUT_UNIT, fmt=*) N

  ! STEP.02
  ! calculate & output the answer of this task
  call task_A (N)

end program main

Measured memory_bytes: 640
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}


signed main()
{
    //cin.tie(nullptr); ios::sync_with_stdio(false);

    string s;
    char buf[5];
    while(cin >> s, s != "0000") {
        int ans = 0;

        if (s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) {
            cout << "NA" << endl;
            continue;
        }

        while(s != "6174") {
            string L = s;
            string S = s;
            sort(ALL(L), greater<>());
            sort(ALL(S));
            sprintf(buf, "%04d", stoi(L) - stoi(S));
            s = buf;
            ++ans;
        }

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



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

int main(){

    int a,b;
	char op;
	
	while(1){
		cin >> a >> op >> b;
	if(op == '?')break;
		else if(op=='+'){
			cout << a+b << endl;
		}
		else if(op=='-'){
			cout << a-b << endl;
		}
		else if(op=='*'){
			cout << a*b << endl;
		}
		else if(op=='/'){
			cout << a/b << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
#define double long double
const int INF = 1e18, MOD = 1e9 + 7;

int modpow(int x, int n) {
    int ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

signed main() {
    int n, a;
    cin>>n;
    int cnt[66] = {};
    for (int i = 0; i < n; i++) {
        cin>>a;
        for (int j = 0; j < 60; j++) {
            if ((a >> j) & 1) {
                cnt[j]++;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 60; i++) {
        ans += cnt[i] * (n - cnt[i]) % MOD * modpow(2, i);
        ans %= MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
a_b=[]
a=[]
b=[]
judge=[]
judge_count=0
yes_no_count=0
for i in range(3):
    a_blank,b_blank=map(int,input().split())
    a.append(a_blank)
    b.append(b_blank)

a_b.extend(a)
a_b.extend(b)
for i in range(1,4+1):
    for j in a_b:
        if i==j:
            judge_count+=1
    judge.append(judge_count)
    judge_count=0

for i in judge:
    yes_no_count+=1
    if i==0 or i>=3:
        print("NO")
        break
    elif len(judge)==yes_no_count:
        print("YES")

#print(yes_no_count)

Measured memory_bytes: 3064
from sys import setrecursionlimit
setrecursionlimit(2 * (10 ** 5))

n = int(input())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]

e = [[] for _ in range(n)]

for a, b in ab:
    e[a].append(b)
    e[b].append(a)

MOD = 10 ** 9 + 7

d = []

def modinv(x):
    a = x
    b = MOD
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= MOD
    if u < 0:
        u += MOD
    return u

def dfs(x, p):
    if len(e[x]) == 1:
        if e[x][0] == p:
            d.append(1)
            return 1
    ret = 1
    for z in e[x]:
        if z == p:
            continue
        ret += dfs(z, x)
    if x != 0:
        #print(x, d)
        d.append(ret)
    return ret

dfs(0,-1)

f = []
w = 1
for i in range(n + 1):
    f.append(w)
    w = (w * 2) % MOD

#print(d)

ans = 0
for x in d:
    ans += ((f[x] - 1) * (f[n-x] - 1)) % MOD
    ans %= MOD

#print(ans)

ans = (ans - f[n-1] * n + f[n] - 1 + MOD) % MOD

#print(ans)

ans = (ans * modinv(f[n])) % MOD

print(ans)


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

using namespace std;

typedef vector<bool> vb;
typedef vector<int> vi;

int main()
{
	int n, k;
  	cin >> n >> k;
    
    vi a(n);
    for (int &x : a) cin >> x;

    vi dp(n, 0);
    for (int i = 1; i < n; ++i)
    {
        dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
        for (int j = 2; j <= k; ++j)
            if (i - j >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
    }

    cout << dp[n - 1];
}

Measured memory_bytes: 1024
#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;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  
  ll s = 0;
  rep(i, n-1) {
    if (a[i+1] < a[i]) {
      s += a[i] - a[i+1];
      a[i+1] = a[i];
    }
  }
  cout << s << endl;
  return 0;
} 

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

int main(){
    int a,b; char c;
    cin>>a>>c>>b;
    while(c!='?'){
        if(c=='+')cout<<a+b<<endl;
        else if(c=='-')cout<<a-b<<endl;
        else if(c=='*')cout<<a*b<<endl;
        else cout<<a/b<<endl;
        cin>>a>>c>>b;
    }
    return 0;
}


Measured memory_bytes: 3088
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for(int i = n;i <= 999;++i){
		if(i == 111 || i == 222 || i == 333 || i == 444 || i == 555 || i == 666 || i == 777 || i == 888 || i == 999){
			cout << i << '\n';
			return 0;
		}
	}
	return 0;	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef	    long long       ll;
typedef	    vector<ll>      vll;
#define     pb              push_back
#define	    PB              pop_back
#define	    nn              "\n"
#define	    all(p)          p.begin(),p.end()
#define	    zz(v)           (ll)v.size()
#define	    mms(ar,a)       memset(ar,a,sizeof(ar))
#define	    ss              ' '
#define     S(a)            scanf("%lld",&a)
#define     SS(a,b)         scanf("%lld %lld",&a,&b)
#define     SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define     P(a)            printf("%lld\n",a)
#define     PP(a,b)         printf("%lld %lld\n",a,b)
#define	    gcd(a,b)        __gcd(a,b)
#define	    lcm(a,b)        (a*b)/gcd(a,b)
#define	    pi              acos(-1.0)
#define	    OO              1000000007

int main(){
//    freopen("input.txt","r",stdin);
    ll a,b,c=0,i,j,t,k,lie,m,n,o,x,y,z;
    S(n);
    SS(a,b);
    x=(a+(n-1)/n)*n;
    y=(b/n)*n;
    if(x>=a&&x<=b || y>=a&&y<=b) printf("OK\n");
    else printf("NG\n");

    return 0;
}


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

signed main () {
	int n;
    cin >> n;
    vector < int > p(n + 1, 0);
    for (int i = 1; i <= n; ++i)
        cin >> p[i];
    vector < int > len (n + 1, -1000000);
    int k = 0;
    for (int i = 1; i <= n; ++i) {
        len[p[i]] = 1;
        len[p[i]] = max(len[p[i]], len[p[i] - 1] + 1);
        k = max(len[p[i]], k);
    }
    cout << n - k << '\n';
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 1001001001
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;


int main(){
    string s; cin >> s;
    sort(s.begin(), s.end());
    
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]){
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n;
        cin>>n;
        double p[n];
        rep(i,0,n) cin>>p[i];
        double dp[n+1][n+1];
        rep(i,0,n+1){
            rep(j,0,n+1) dp[i][j] = 0;
        }
        dp[1][1] = p[0];
        dp[1][0] = 1-p[0];
        rep(i,2,n+1){
            dp[i][0] = dp[i-1][0]*(1-p[i-1]);
        }
        rep(i,2,n+1){
            rep(j,1,i+1){
                dp[i][j] = dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
            }
        }
        double ans=0;
        rep(i,n/2+1,n+1) ans+=dp[n][i];
        cout<<fixed<<setprecision(10)<<ans;
    }   
}     

Measured memory_bytes: 70656
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

int q;
int p[3];

int main() {
    std::cin >> q;

    while(q--) {
        std::cin >> p[0] >> p[1] >> p[2];

        int sum = std::min(p[2], std::min(p[0], p[1])); //t3
        
        p[0] -= sum;
        p[1] -= sum;
        p[2] -= sum;
        
        int t2 = std::min(p[0] / 2, p[1]);

        sum += t2;

        p[0] -= t2 * 2;
        p[1] -= t2;

        sum += p[0] / 3;

        std::cout << sum << std::endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int money;
  cin >> money;
  cout << (money / 500) * 1000 + ((money % 500) / 5) * 5 << '\n';
  return 0;
}


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

using namespace std;

int main() {
    int N;
    int a,b;
    int sum=0;
    int max=0;;
    cin >> N;
    vector<int> vect(100003,0);
    for(int i=0; i<N ; i++){
        cin >> a >> b;
        vect[a-1]++;
        vect[b]--;
    }
    for(int i=1; i<100003; i++){
        sum += vect[i];
        if(sum > max && sum >= i) max=i;
    }
    cout << max << endl;
    return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
using namespace std;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;


int main(){
	string S;
	cin>>S;
	char Left = 'R';
	int Sint[S.length()];
	int plase = 0;
	int cnt1,cnt2;
	cnt1 = cnt2 = 0;
	int i;
	for(i = 0; i < S.length(); i++){
		Sint[i] = 0;
		if(Left == 'R'){
			if(Left == S[i]){
				if(cnt2 != 0){
					int a = cnt1 / 2 + cnt1%2;
					int b = cnt2 / 2 + cnt2%2;
					Sint[plase - 1] = cnt2 - b + a;
					Sint[plase] = cnt1 - a + b;
					cnt1 = cnt2 = 0;
					i--;
					plase=0;
				}else{
				cnt1++;//R
				}
			}
			else{
				if(plase==0)plase = i;
				cnt2++;
			}
		
		}
	}
	
	
	int a = cnt1 / 2 + cnt1%2;
					int b = cnt2 / 2 + cnt2%2;
					Sint[plase - 1] = cnt2 - b + a;
					Sint[plase] = cnt1 - a + b;
		for(int i = 0; i < S.length(); i++){
			cout<<Sint[i]<<" ";
		}
		cout<<endl;
}

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if(s[0] != s[2]) cout << "Yes";
	else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, M; cin >> N >> M;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    sort(a.begin(), a.end());

    ll bsum = 0;
    vector<pair<int, int>> cb(M);
    for(int i=0; i<M; i++){
        int b, c; cin >> b >> c;
        cb[i] = {c, b};
        bsum += b;
    }

    int id = 0;
    sort(cb.begin(), cb.end(), greater<pair<int, int>>());
    for(int i=0; i<cb.size(); i++){
        int b = cb[i].second;
        int c = cb[i].first;

        while(a[id]<c && b>0){
            a[id] = c; id++;
            b--;
        }

        if(a[id] >= c) break;
    }

    ll ans = 0;
    for(int i=0; i<N; i++) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define mod 1000000007
using namespace std;
typedef long long int LL;

int main() {
    int N;
    cin >> N;

    int m = 0, a = 0, r = 0, c = 0, h = 0;
    rep(i, N) {
        string str;
        cin >> str;

        if (str[0] == 'M') {
            m++;
        } else if (str[0] == 'A') {
            a++;
        } else if (str[0] == 'R') {
            r++;
        } else if (str[0] == 'C') {
            c++;
        } else if (str[0] == 'H') {
            h++;
        }
    }

    if (m + a + r + c + h < 3) {
        cout << 0 << endl;
        return 0;
    }
    LL ret = 0;
    LL arr[5] = { m, a, r, c, h };
    for (int i = 0; i < 5; i++)
    {
        for (int j = i + 1; j < 5; j++)
        {
            for (int k = j + 1; k < 5; k++)
            {
                ret += arr[i] * arr[j] * arr[k];
            }
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct memo{int sy,sx,gy,gx;};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	vector<vector<int>>a(h,vector<int>(w));
	for(auto&&i:a){
		for(auto&&j:i){
			cin>>j;
		}
	}
	vector<memo>ans;
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			if(a.at(i).at(j)%2==0)continue;
			if(j+1<w){
				++a.at(i).at(j+1);
				ans.push_back({i+1,j+1,i+1,j+2});
			}
			else if(i+1<h){
				++a.at(i+1).at(j);
				ans.push_back({i+1,j+1,i+2,j+1});
			}
		}
	}
	cout<<ans.size()<<"\n"s;
	for(auto&&i:ans)cout<<i.sy<<" "s<<i.sx<<" "s<<i.gy<<" "s<<i.gx<<"\n"s;
}


Measured memory_bytes: 6324