akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

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


int main(){
    LL Q,H,S,D,N;
    cin >> Q >> H >> S >> D >> N;
    LL ans=0;
    LL two_lit=D;
    LL one_lit=S;
    LL five_mililit=H;
    
    two_lit=min(two_lit,S*2);
    two_lit=min(two_lit,H*4);
    two_lit=min(two_lit,Q*8);
    one_lit=min(one_lit,H*2);
    one_lit=min(one_lit,Q*4);
    five_mililit=min(five_mililit,Q*2);
    LL count=0;
    while(count!=N){
        if(N-count>=2){
            count+=2;
            ans+=two_lit;
        }
        else{
            if(N-count>=1){
                count+=1;
                ans+=one_lit;
            }
        }
    }
    cout << ans;
}

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

using namespace std;

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

	if (N[1] == N[2] && (N[0] == N[2] || N[3] == N[2])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int n,b;
  int A = 0;
  int B = 0;
  cin >> n;
  int a[n];
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  sort(a,a + n);
//  for(int i = 0;i < n;i++){
//    cout << a[i];
//  }
  for(int j = n - 1;j >= 0;j--){
    if(j % 2 == 0){
      A += a[j];
    }
    if(j % 2 != 0){
      B += a[j];
    }

  }
  int C;
  C = abs(A - B);
  cout << C <<'\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
#include <list>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

# define ll long long

int main(void) {
	ll n;
	cin >> n;
	ll x = 1;
	int ans = 0;
	int y = 0;
	ll m = n;
	while(m) {
		ans += m % 10;
		m /= 10;
	}
	while(n - x >= 0) {
		ll m = n - x;
		int k = 0;
		int yy = y;
		while(m) {
			if(--yy >= 0) {
				k += 9;
			} else {
				k += m % 10;
			}
			m /= 10;
		}
		ans = max(k, ans);
		x *= 10;
		y++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

while True:
    n, h = map(int, raw_input().split())
    if n == 0:
        break
    m = {}
    for loop in range(h):
        S, p1, p2 = raw_input().split()
        p1 = int(p1)
        p2 = int(p2)
        for i in range(1, n + 1):
            if S == 'xy':
                m[(p1, p2, i)] = 1
            if S == 'xz':
                m[(p1, i, p2)] = 1
            if S == 'yz':
                m[(i, p1, p2)] = 1
    print n ** 3 - len(m)
            


Measured memory_bytes: 13432
#include<bits/stdc++.h>
using namespace std;
int n;
int a[123123];
void pd()
{
	int t=0;
  for(int i=1;i<=n;i++) if(a[i]<a[i-1]) {t=1;break;}
  if(!t) {printf("YES\n");exit(0);}
}

int main()
{int i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&a[i]);
  pd();
  for(i=1;i<=n;i++) 
    for(j=1;j<=n;j++)
      swap(a[i],a[j]),pd(),swap(a[i],a[j]);
printf("NO\n");
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcases int t;cin>>t;while(t--)
#define int ll
#define pb push_back
#define mod 1000000007
#define for0 for(int i=0;i<n;i++)
#define for1 for(int i=1;i<n;i++)
#define inp0(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define inp1(arr) for(int i=1;i<=n;i++)cin>>arr[i];
#define disp0(arr) for(int i=0;i<n;i++)cout<<arr[i]<<" ";
#define disp1(arr) for(int i=1;i<=n;i++)cout<<arr[i]<<" ";
int binaryexp(int a,int b){int ans=1;
    while(b>0){
        int last_bit=(b&1);if(last_bit)ans*=a;a*=a;b=b>>1;}
    return ans;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
void start()
{
	fast
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}
int highestPowerOf2(int n) {return (n & (~(n - 1)));}
int leftMostSetBit(int n) {int k = (int)(log2(n));return k;}
void solve()
{
	int a;
	cin>>a;
	cout<<(a+(a*a)+(a*a*a))<<"\n";
}
signed main()
{
	start();
	int t=1;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    vi even;
    rep(i, 0, n) {
        if (a[i] % 2 == 0)
            even.push_back(a[i]);
    }
    int cnt = 0;
    rep(i, 0, even.size()) {
        if (even[i] % 3 == 0 || even[i] % 5 == 0)
            cnt++;
    }
    if (cnt == even.size())
        cout << "APPROVED";
    else
        cout << "DENIED";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <tuple>
#include <utility>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);(i)++)
#define for2(i,m,n) for (ll (i)=(m);(i)<(n);(i)++)
#define for3(i,m,n,d) for (ll (i)=(m);(i)<(n);(i)+=(d))
#define INF (1LL << 60)

void solve()
{
    ll x;
    cin >> x;
    ll ans = (x / 11) * 2;
    x %= 11;
    if (x == 0) {
        ;
    }
    else if (x <= 6) {
        ans += 1;
    }
    else {
        ans += 2;
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 256
class union_find():
  def __init__(self,n):
    self.n=n
    self.parents=[-1]*n
  def find(self,x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]
  def union(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return 
    if self.parents[x]>self.parents[y]:
      x,y=y,x
    self.parents[x]+=self.parents[y]
    self.parents[y]=x
    
def main():
  N,M=map(int,input().split())
  box=union_find(N)
  for i in range(M):
    x,y,z=map(int,input().split())
    box.union(x-1,y-1)
  box.find(1)
  ans=0
  for i, x in enumerate(box.parents):
    if x<0:
      ans+=1
  print(ans)
main()
    
    

Measured memory_bytes: 5444
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

struct edge{
    llong to;
    llong cost;
};

vecllong dijkstra(llong start, vector<vector<edge>> edges) {
    vecllong minCost(edges.size(), INF);

    priority_queue<
        pair<llong, llong>,  // cost, index
        vector<pair<llong, llong>>,
        greater<pair<llong, llong>>
    > nodeHeap;

    nodeHeap.push(make_pair(0, start));

    while (!nodeHeap.empty()) {
        llong cost = nodeHeap.top().first;
        llong node = nodeHeap.top().second;
        nodeHeap.pop();

        if (minCost[node] <= cost) {
            continue;
        }

        minCost[node] = cost;

        for_each(edges[node].begin(), edges[node].end(), [&](edge e){
            llong nextNode = e.to;
            llong newCost = cost + e.cost;
            nodeHeap.push(make_pair(newCost, nextNode));
        });
    }

    return minCost;
};

vvecllong minDist;
vecllong visit;

llong search(llong now, vector<bool> confilm) {
    confilm[now] = true;
    llong ret = INF;
    FOR(i, confilm.size()) {
        if(!confilm[i]) {
            ret = min(ret, search(i, confilm) + minDist[visit[now]][visit[i]]);
        }
    }
    if(ret == INF) {
        ret = 0;
    }
    return ret;
};

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

    llong N, M, R;
    cin >> N >> M >> R;

    visit.resize(R);
    FOR(i, R) {
        llong r;
        cin >> r;
        r--;
        visit[i] = r;
    }

    vector<vector<edge>> edges(N, vector<edge>(0));
    FOR(i, M) {
        llong from, to, dist;
        cin >> from >> to >> dist;
        from--;
        to--;
        edges[from].push_back({to, dist});
        edges[to].push_back({from, dist});
    }

    minDist.resize(N);
    FOR(i, R) {
        minDist[visit[i]] = dijkstra(visit[i], edges);
    }

    llong ans = INF;
    FOR(i, R) {
        vector<bool> confilm(R, false);
        ans = min(ans, search(i, confilm));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3444
#include<iostream>
using namespace std;
long long n,k,sum=0;
char a;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(a=='I')
		{
			sum++;
		}
        if(a=='D')
        {
        	sum--;
		}
        k=max(k,sum);
    }
    cout<<k<<endl;
    return 0;
}

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

int main(){
	int N, i, j;
	cin >> N;
	for(i = 1; i < 10; i++){
		for(j = 0; j <= i; j++)
		if(i * j == N){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}


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

int main(){
    int s,m,t;
    cin >> s;
    t = s/3600;//1時間は3600秒
    s = s - t*3600;
    m = s/60;//s%3600で3600で割った余り。
    s = s- m*60;
    cout << t << ":" << m << ":" << s << endl;
}


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

int main(){
    int h,w;
    cin >> h >> w;
    char in[h+2][w+2];
    for(int i=0;i<w+2;i++){
        in[0][i] = '#';
        in[h+1][i] = '#';
    }
    for(int i=1;i<h+1;i++){
        in[i][0] ='#';
        for(int j=1;j<w+1;j++){
            cin >> in[i][j];
        }
        in[i][w+1] = '#';
    }

    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            cout << in[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

n,m,k = map(int,input().split())

ab = [[] for j in range(n)]
cd = [[] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
    
for i in range(k):
    c,d = map(int,input().split())
    cd[c-1].append(d-1)
    cd[d-1].append(c-1)
    
check = [-1]*n

def dfs(x,check):
    #if check[x] != -1:
    #    return
    for i in range(len(ab[x])):
        cho = ab[x][i]
        #print(cho,x)
        if check[cho] != -1:
            continue
        check[cho] = num
        dfs(cho,check)
    
    return

num = 0
for i in range(n):
    #print(i,check[i])
    if check[i] != -1:
        continue
    dfs(i,check)
    num += 1
#print(check)
grp_num = max(check)
grp_size = [0]*(grp_num+1)

for i in range(n):
    if check[i] == -1:
        continue
    grp_size[check[i]] += 1

for i in range(n):
    hiku = 0
    for j in range(len(cd[i])):
        #print(cd[i],check[i],cd[i][j],check[cd[i][j]])
        if check[cd[i][j]] == check[i]:
            hiku += 1
            #print(hiku,hiku,hiku,hiku,hiku)
    if check[i] == -1:
        print(0)
    else:
        print(grp_size[check[i]]-len(ab[i])-hiku-1,end=' ')

Measured memory_bytes: 62384
def unbalance? (word)
  word_size = word.length
  (word_size - 1).times do |i|
    return true, "#{i + 1} #{i + 2}" if word[i] == word[i+1]
  end
  (word_size - 2).times do |i|
    return true, "#{i + 1} #{i + 3}" if word[i] == word[i+2]
  end
  return false
end

flg, ans = unbalance? gets.chomp
if flg
  puts ans
else
  puts "-1 -1"
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int a,b,k; cin>>a>>b>>k;
    rep(i,k){
        if(i%2==0){
            if(a%2==1) a--;
            b+=a/2;
            a/=2;
        }else{
            if(b%2==1) b--;
            a+=b/2;
            b/=2;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c)<=d) cout << "Yes" << endl;
    else if(abs(a-b)<=d &&abs(b-c)<=d) cout << "Yes" << endl;
    else cout << "No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());

        boolean flag = false;

        for(int i = 1; i < 10; ++i) {
            if((n % i == 0) && (n/i < 10)) {
                flag = true;
                break;
            }
            else continue;
        }

        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
int a,b; cin>>a>>b;
double ans=(a+b)/(2*D);
cout<<ceil(ans);
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 2e6+5;
const dd eps = 1e-8;
const int mod = 1e9+7;
int n,vis[N],vis2[N];
ll gcd(ll a,ll b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
ll a[N];
int main(){
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  ll now = 0;
  cin>>n;
  bool paok = true;
  bool seok = true;
  bool have1 = false;
  for(int i = 1;i <= n;i++) {cin>>a[i];}
  for(int i = 1;i <= n;i++){
    now = gcd(now,a[i]);
    vis[a[i]]++;
  }
  for(int i = 2;i <= 1e6+100;i++){
    for(int j = i;j <= 1e6+100;j+=i){
      if(vis[j]) vis2[i]+=vis[j];
    }
  }
  for(int i = 2;i <= 1e6+100;i++){
    if(vis2[i] > 1) {paok = false;break;}
  }
  if(have1) paok = false;
  if(now != 1) seok = false;
  if(paok) cout<<"pairwise coprime"<<endl;
  else if(seok or have1) cout<<"setwise coprime"<<endl;
  else cout<<"not coprime"<<endl;
  return 0;
}


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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int h, w;
  cin >> h >> w;

  // 1行目
  for (int i = 0; i < w + 2; ++i) {
    cout << "#";
  }
  cout << endl;

  for (int i = 0; i < h; ++i) {
    string s;
    cin >> s;
    s = "#" + s + "#";
    p(s);
  }

  // 最終行
  for (int i = 0; i < w + 2; ++i) {
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/* greedy */

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int h,w,n,sr,sc; string S,T;
    while (cin >> h >> w >> n >> sr >> sc >> S >> T) {
        S = ' ' + S; T = ' ' + T; n++;
        int L = sc, R = sc, U = sr, D = sr;
        bool ans = true;
        FOR(i,1,n) {
            L -= S[i] == 'L';
            R += S[i] == 'R';
            U -= S[i] == 'U';
            D += S[i] == 'D';
            if (L <= 0 || R > w || U <= 0 || D > h)
                ans = false;
            L += T[i] == 'R'; L = min(w,L);
            R -= T[i] == 'L'; R = max(1,R);
            U += T[i] == 'D'; U = min(h,U);
            D -= T[i] == 'U'; D = max(1,D);
        }
        const string res = ans ? "YES" : "NO";
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 984
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	int res=0,a[100],b[100],n;
	map<pair<int,int>,int > cnt;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i]>>b[i];
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int x=a[i]-a[j];
			int y=b[i]-b[j];
			cnt[{x,y}]++;
			cnt[{-x,-y}]++;
			res=max(max(cnt[{x,y}],cnt[{-x,-y}]),res);
		}
	}
	cout<<n-res;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
void flip(string &s, int i) {
	for (int j = N-1; j <= N+1; j++) {
		if (s[(j + i) % N] == 'x') {
			s[(j + i) % N] = 'o';
		}
		else {
			s[(j + i) % N] = 'x';
		}
	}
}
int main() {
	
	cin >> N;
	string s;
	cin>>s;
	string a;
	string res;
	res = "";
	a = s;
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			res.push_back('S');
		}
		else if(i==1){
			res.push_back('S');
		}
		else {
			if (s[i - 1] == 'x') {
				res.push_back('W');
				flip(s, i);
				
			}
			else {
				res.push_back('S');
			}
		}
		
	}
	if (s[0] == 'o' &&s[N - 1] == 'o') {
		cout << res << endl;
		return 0;
	}
	s = a;
	res.clear();
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			res.push_back('S');
		}
		else if (i == 1) {
			res.push_back('W');
			flip(s, i);
		}
		else {
			if (s[i - 1] == 'x') {
				res.push_back('W');
				flip(s, i);

			}
			else {
				res.push_back('S');
			}
		}

	}
	if (s[0] == 'o' &&s[N - 1] == 'o') {
		cout << res << endl;
		return 0;
	}
	s = a;
	res.clear(); 
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			res.push_back('W');
			flip(s, i);
		}
		else if (i == 1) {
			res.push_back('S');
		}
		else {
			if (s[i - 1] == 'x') {
				res.push_back('W');
				flip(s, i);

			}
			else {
				res.push_back('S');
			}
		}

	}
	if (s[0] == 'o' &&s[N - 1] == 'o') {
		cout << res << endl;
		return 0;
	}
	s = a;
	res.clear(); 
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			res.push_back('W');
			flip(s, i);
		}
		else if (i == 1) {
			res.push_back('W');
			flip(s, i);
		}
		else {
			if (s[i - 1] == 'x') {
				res.push_back('W');
				flip(s, i);

			}
			else {
				res.push_back('S');
			}
		}

	}
	if (s[0] == 'o' &&s[N - 1] == 'o') {
		cout << res << endl;
		return 0;
	}

	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
 
int main(void) {
  int K, A, B;
  int mod_A, mod_B;
  
  cin >> K;
  cin >> A >> B;
  
  mod_A = A % K;
  mod_B = B % K;
 
  if (B - A < K) {
    if ((mod_A == 0) || (mod_B == 0)) {
      cout << "OK";
    }
    else if (mod_A > mod_B) {
      cout << "OK";
    }
    else {
      cout << "NG";
    }
  }
  else {
    cout << "OK";
  }
} 

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main() {
    cin.tie(0);
    // ios::sync_with_stdio(false);
    int n; scanf("%d",&n);
    map<string, int> mp;
    while(n--){
        string s; cin >> s;
        mp[s]++;
    }  
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", mp["AC"], mp["WA"], mp["TLE"], mp["RE"]);
    return 0;
}

Measured memory_bytes: 3756
import numpy as np

n,m=map(int,input().split())

hoge=[]
huga=[]
hago=[]
h=0
w=0
for i in range(n):
  hoge.append(list(input()))

for i in range(n):
  if(hoge[i].count("#")!=0):
    h+=1
    huga.append(hoge[i])
    
hoge=np.array(huga).T.tolist()

for i in range(m):
  if(hoge[i].count("#")!=0):
    w+=1
    hago.append(hoge[i])
    
hago=np.array(hago).T.tolist()
    
for i in range(h):
  for j in range(w):
    print(hago[i][j],end="")
  print("")

Measured memory_bytes: 14028
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

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

    ll ans = 0;
    for(int i=N-1; i>=0; i--){
        if(K > 0) K--;
        else ans += H[i];
    }
    cout << ans << endl;
}

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

int n, m, d;
string s, t;

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

int main() {
    ios::sync_with_stdio(0);

    cin >> n >> m;
    cin >> s >> t;

    d = gcd(n, m);
    int k1 = n / d;
    int k2 = m / d;

    for (int i = 0; i < d; ++i) {
        if (s[i * k1] != t[i * k2]) {
            cout << "-1\n";
            return 0;
        }
    }

    cout << 1LL * k1 * k2 * d << "\n";

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    //"010101..."からのずれの数をa, "101010..."からのずれの数をbとする
    int a = 0, b = 0;
    for (int i=0; i<s.size(); i++) {
        if (i%2 == 0) {
            if (s[i] == '1') {
                a++;
            } else {
                b++;
            }
        } else {
            if (s[i] == '0') {
                a++;
            } else {
                b++;
            }
        }
    }
    cout << min(a,b) << endl;
}

Measured memory_bytes: 3728
local n,m = io.read("*n", "*n")
local xsum,ysum,mod=0,0,1000000007
for i=0,n-1 do
  local x=io.read("*n")
  xsum = xsum + x*(i-(n-1-i))
  xsum=xsum%mod
end
for i=0,m-1 do
  local y=io.read("*n")
  ysum = ysum + y*(i-(m-1-i))
  ysum=ysum%mod
end
print(xsum*ysum%mod)

Measured memory_bytes: 760
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(ll i=0;i< (n);i++)
#define rep1(i,n) for(ll i=1;i<= (n);i++)
using namespace std;
typedef long long ll;
const static ll MOD = (1e+9)+7;

ll modcross(ll a,ll k){
    if(k == 0)return 0;
    if(k % 2 == 1)return (a + modcross(a,k-1)) % MOD;
    ll t = modcross(a,k/2) % MOD;
    return (t * 2) % MOD; 
}

int main(){
    ll n,k;cin>>n>>k;
    vector<ll> A(n,0);rep(i,n)cin>>A[i];
    ll ans = 0;
    for(ll i = 0;i<n-1;i++){
        for(ll j = i+1;j<n;j++){
            if(A[i]>A[j])ans += (k*(k+1))/2 % MOD ;
            if(A[i]<A[j])ans += (k*(k-1))/2 % MOD;
            ans %= MOD;
        }
    }
    cout<<ans%MOD<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	string s;
	cin>>s;
	int sum=0;
	for(char c:s){
		sum+=(c-'0');
		sum%=9;
	}
	if(sum)cout<<"No";
	else cout<<"Yes";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3768
#include<stdio.h>
int main()
{
    int x,y,i,j;
    while(1)
    {
        scanf("%d%d",&x,&y);
        if(x==0&&y==0)
        {
            break;
        }
        for(i=0;i<x;i++)
    {
        for(j=0;j<y;j++)
        {
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
    }

    return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N; cin >> N;
  vector<PLL> xs(N);
  REP(i,N){
	cin >> xs[i].FF;
	xs[i].SS = i;
  }

  set<int> s, s_;
  s.insert(-1);
  s.insert(N);
  s_.insert(-1);
  s_.insert(N);
  SORT(xs);
  LL ans = 0;
  REP(i,N){
	int ix = xs[i].SS;
	s.insert(ix);
	s_.insert(N-1-ix);
	LL r = *s.upper_bound(ix);
	LL l = N-1 - *s_.upper_bound(N-1-ix);
	ans += xs[i].FF * (ix-l) * (r-ix);
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 22144
s=input()
#print(s)

if s=="RRR":
    ans=3
if s=="RRS":
    ans=2
if s=="RSR":
    ans=1
if s=="RSS":
    ans=1
if s=="SRR":
    ans=2
if s=="SRS":
    ans=1
if s=="SSR":
    ans=1
if s=="SSS":
    ans=0
print(ans)

Measured memory_bytes: 61772
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int a,b,k;cin>>a>>b>>k;
    int c=0;
    for(int i=a;;i--){
        if(a%i==0 && b%i == 0){
            c++;
        }
        if(c==k){
            cout<<i<<endl;
            return;
        }
    }
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

#define ll long long

#define MOD 1000000007

int main()
{
    ll n,m;
    vector<ll> a;
    cin >> n >> m;
    ll temp;
    if(m != 0){
        for (int i = 0; i < m; i++)
        {
            cin >> temp;
            a.push_back(temp);
        }
    }
    

    ll* dp;
    dp = new ll[n+1];
    ll k = 0;
    for (int i = 0; i < n+1; i++)
    {
        if(m!=0)
        {
            if(i == a[k])
            {
                dp[i] = 0;
                k++;
            }else if (i>1)
            {
                dp[i] = dp[i-1]+dp[i-2];
            }else{
                dp[i] = 1;
            }
        }else{
            if (i>1)
            {
                dp[i] = dp[i-1]+dp[i-2];
            }else{
                dp[i] = 1;
            }
        }
        
        dp[i] = dp[i]%MOD;
    }
    cout << dp[n]%MOD << endl;
    
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int n, k;
  cin >> n >> k;
  (k - n % k >= n % k) ? cout << n % k << "\n" : cout << (k - n % k) << "\n";
return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  int a[5];
  while(~scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4])) {
    bool s = true;
    sort(a, a+5);
    FOR(i, 1, 5) {
      //cout << a[i-1] << " " << a[i] << endl;
      if(a[i] != a[i-1] + 1) s = false;
    }
    if(a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13)
      s = true;

    int cnt[14] = {0};
    REP(i, 5) cnt[a[i]]++;
    int four = 0, three = 0, pair = 0;
    FOR(i, 1, 14) {
      if(cnt[i] == 4) four = 1;
      else if(cnt[i] == 3) three = 1;
      else if(cnt[i] == 2) pair++;
    }
    if(four) {
      cout << "four card" << endl;
    } else if(three && pair) {
      cout << "full house" << endl;
    } else if(s) {
      cout << "straight" << endl;
    } else if(three) {
      cout << "three card" << endl;
    } else if(pair == 2) {
      cout << "two pair" << endl;
    } else if(pair == 1) {
      cout << "one pair" << endl;
    } else {
      cout << "null" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string S;
    cin >> S;
    string res = "";
    rep(i, S.size()) res += "x";
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h> 
int main() 
{   
	int h,w,i,j;       
	while(1)
	{     
		scanf("%d %d",&h,&w);     
		if (h==0 && w ==0)       
		break;     
		else
		{       
			for(i=0;i<=h-1;i++)
			{     
				for (j=0;j<=w-1;j++)
				{       
					if ((i+j)%2==0)
					{       
						printf("#");       
					}       
					if((i+j)%2==1)
					{        
						printf(".");       
					}         
				}     
				printf("\n");       
			}       
			printf("\n");     
		}   
	}   
	return 0; 
}

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

int main()
{
    int M, D;
    cin >> M >> D;
    int count = 0;
    for(int m = 1; m <= M; m++) {
        for(int d = 1; d <= D; d++) {
            int d1 = d % 10;
            int d10 = d / 10;
            if(d1 >= 2 && d10 >= 2 && d1*d10 == m) {
                count += 1;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
a = [0] * n
b = [0] * n

temp = 10 ** 10
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] > b[i]:
        temp = min(temp, b[i])

if temp == 10 ** 10:
    print(0)
else:
    print(sum(a) - temp)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;


void solve(long long A, long long B, long long T){
    cout << T / A * B << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long T;
    scanf("%lld",&T);
    solve(A, B, T);
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i= 0; i<n;i++) {
            sum += sc.nextInt();
        }
        if (sum >= h) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 50540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int N; cin >> N;
  string S;
  for (int i = 0; i < 32; ++i) {
    S = to_string(N - (ll)ceil((double)N / (-2)) * (-2)) + S;
    N = (ll)ceil((double)N / (-2));
    if (N == 0) break;
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int n,y,b[50],r[50],t[50],i,a,mx,m,j;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		scanf("%d",&y);
		for(i=1;i<=n;i++){
			scanf("%d %d %d",&b[i],&r[i],&t[i]);
		}
		mx=0;
		m=0;
		for(i=1;i<=n;i++){
			if(t[i]==1){
				a=10000+100*y*r[i];
			}
			if(t[i]==2){
				a=10000;
				for(j=0;j<y;j++){
					a+=a*r[i]/100;
				}
			}
			// printf("i=%d a=%d t=%d\n",i,a,t[i]);
			if(mx<a){
				mx=a;
				m=b[i];
			}
		}
		printf("%d\n",m);
	}
	return 0;
}


Measured memory_bytes: 2620
#include<iostream>
#include<algorithm>
#include<climits>
#include<utility>
#include<vector>
#include<deque>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int NMAX=1<<17;
int k;
vector<pi> edge[100010];
int d[100010];
int o1_bfs(){
  rep(i,k){
    d[i]=INT_MAX;
  }
  deque<int> deq;
  deq.push_back(1);
  d[1]=1;
  while(deq.size()){
    int a=deq.front();deq.pop_front();
    if(a==0) break;
    rep(i,edge[a].size()){
      int pf=edge[a][i].first,ps=edge[a][i].second;
      if(ps+d[a]<d[pf]){
	if(ps==0){
	  deq.push_front(pf);
	  d[pf]=d[a];
	}
	else{
	  deq.push_back(pf);
	  d[pf]=d[a]+1;
	}
      }
    }
  }
  return d[0];
}
  
int main(){
  scan(k);
  rep(i,k){
    edge[i].push_back(pi((i*10)%k,0));
  }
  rep(i,k-1){
    edge[i].push_back(pi(i+1,1));
  }
  edge[k-1].push_back(pi(0,1));
  prin(o1_bfs());
  //  rep(i,k)prin(d[i]);
  
  
  return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <random>
#include <chrono>
#include <bitset>
#include <fstream>
#include <sstream>

using namespace std;

typedef long long ll;
typedef long double ld;

ll big = 1000000007ll;
ll n,m,k;

char M[10][10];

int main()
{

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll a,b,c,d,e;
    ll c1,c2,c3,c4;

   cin >> n >> m;
   bool pos = 1;
   for(c1 = 0; c1 < n; c1++){
        for(c2 = 0; c2 < m; c2++){
            char ch;
            cin >> ch;
            M[c1][c2] = ch;
        }
   }

   for(c3 = 0; c3 < n+m-1; c3++){
    
    ll coun = 0;
    for(c1 = 0; c1 < n; c1++){
        for(c2 = 0; c2 < m; c2++){
            if(c1+c2 == c3){
                if(M[c1][c2] == '#')coun++;
            }
        }
    }
    if(coun != 1)pos = 0;
    
   }

    if(pos){
        cout << "Possible\n";
    }
    else{
        cout << "Impossible\n";
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		s = sc.next();
		if (s.length() == 2)
			System.out.println(s);

		else {
			for (int i = s.length() - 1; i >= 0; --i) {
				System.out.print(s.charAt(i));
			}
		}
		sc.close();
	}

}


Measured memory_bytes: 22740
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>
#include <complex>
#include <vector>
#include <functional>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define INF 100000000
typedef pair<int,int> P;
int main()
{
	string s;
	while(getline(cin,s)){
		int JOI=0,IOI=0;
		if(s[0]==EOF)break;
		for(int i=0;i<(int)s.size()-2;i++){
			if(s[i+1]=='O'&&s[i+2]=='I'){
				if(s[i]=='J')JOI++;
				else if(s[i]=='I')IOI++;
			}
		}
		printf("%d\n%d\n",JOI,IOI);
	}
    return 0;
}

Measured memory_bytes: 1200
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static final char a = 'A';
	public static final char c = 'C';
	public static final char g = 'G';
	public static final char t = 'T';
	public static void main(String [] args) {
		Scanner scanner = new Scanner(System.in);
		char b = scanner.next().charAt(0);
		Map<Character,Character> map = new TreeMap<Character,Character>();
		map.put(a, t);
		map.put(t, a);
		map.put(g, c);
		map.put(c, g);
		System.out.print(map.get(b));
		scanner.close();
	}
}

Measured memory_bytes: 21844
/*Points to be noted :
1)Don't be afraid to fail.
2)Never give up easily,keep trying.
3)Don't care about other ppl's progress.
4)Spend much time on each problem & keep trying. I WILL DO IT!💯*/

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//


#include<bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define int long long int
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define r0 return 0;
#define tc int t;cin>>t;while(t--)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define md 998244353
#define inf 1000000000000000 //1e15
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd(a,b)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}
int factorial(int n)
{
    int fact=1;
    for(int i=2;i<=n;i++)
    fact=fact*i;
    
    return fact;
}
int ncr(int n,int r)
{
    return factorial(n)/(factorial(r)*factorial(n-r));
}
void c_p_c()
{
    crap;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
signed main()
{
    c_p_c();
    char ch;
    cin>>ch;
    if(ch>='a' && ch<='z')
    cout<<'a'<<endl;
    else if(ch>='A' && ch<='Z')
    cout<<'A'<<endl;
    

}

Measured memory_bytes: 3636
import math
import itertools

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

li = list(itertools.permutations(P,N))
li.sort()

a = 0
b = 0

for i in range(math.factorial(N)):
    if li[i] == P:
        a = i
    else:
        a = a

for i in range(math.factorial(N)):
    if li[i] == Q:
        b = i
    else:
        b = b
        
print(abs(a-b))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 666666
map<int,int> vis;
int arr[N];
signed  main(){
 	int n;
 	cin>>n;
 	for(int i=1;i<=n;i++){
 		scanf("%lld",&arr[i]);
 		vis[arr[i]]++;
	} 
	int sum=0;
 	for(int i=1;i<=200000;i++){
 		if(vis[i]>1){
 			int t=vis[i];
 			sum+=(t*(t-1))/2;
		 }	
	}
	//cout<<sum<<'\n';
	for(int i=1;i<=n;i++){
		int t1=vis[arr[i]]-1;
		int t2=sum-(vis[arr[i]]*(vis[arr[i]]-1)/2);
		cout<<t2+max((t1*(t1-1)/2),0ll)<<'\n';
	}
    return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int n, q; cin >> n >> q;
    queue<pair<string, int>> que;
    REP(i, n) {
        string s;
        int t;
        cin >> s >> t;
        que.push(make_pair(s, t));
    }
    int t = 0;
    while(!que.empty()) {
        pair<string, int> p = que.front(); que.pop();
        if(p.second <= q) {
            t += p.second;
            cout << p.first << " " << t << endl;
        } else {
            t += q;
            p.second -= q;
            que.push(p);
        }
    }

    return 0;
}


Measured memory_bytes: 6368