akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
ps = [int(p)-1 for p in input().split()]
xys = [tuple(int(x)-1 for x in input().split()) for _ in range(m)]

nodes = range(n)
union = {node:node for node in nodes}

def root(node):
    if union[node] == node:
        return node
    union[node] = root(union[node])
    return union[node]

for x, y in xys:
    rx = root(x)
    ry = root(y)
    union[rx] = ry

groups = {node:{node} for node, rootn in union.items() if node==rootn} 
for node in nodes:
    if node in groups:
        continue
    group = groups[root(node)]
    group.add(node)
    groups[node] = group

print(sum(p in groups[i] for i, p in enumerate(ps)))

Measured memory_bytes: 61360
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;
int n,m,top,nn,cnt,IN[4000005];
ll a[100005],s[100005],ans[100005];
map<ll,ll> mp;
map<ll,int> id;
void init(ll x){
	if(x<=n) return;
	if(id.find(x)!=id.end()) return;
	id[x]=++cnt;
	int l=1,r=top,mid,pos;
	while(l<=r){
		mid=l+r>>1;
		if(s[mid]<x) pos=mid,l=mid+1;
		else r=mid-1;
	}
	mp[s[pos]]=0;
	ll rst=x%s[pos];
	mp[rst]=0;
	init(s[pos]);
	init(rst);
	IN[id[s[pos]]]++;
	IN[id[rst]]++;
}
void dfs(ll x){
	if(x<=n) return;
	ll w=mp[x];int l=1,r=top,mid,pos;
	while(l<=r){
		mid=l+r>>1;
		if(s[mid]<x) pos=mid,l=mid+1;
		else r=mid-1;
	}
	if(mp.find(s[pos])==mp.end()) mp[s[pos]]=0;
	ll rst=x%s[pos];
	if(mp.find(rst)==mp.end()) mp[rst]=0;
	mp[s[pos]]+=x/s[pos]*w;
	mp[rst]+=w;
	IN[id[s[pos]]]--;
	IN[id[rst]]--;
	int X=IN[id[s[pos]]],Y=IN[id[rst]];
	if(!X) dfs(s[pos]);
	if(!Y) dfs(rst);
}
int main(){
	scanf("%d%d",&n,&m);
	a[1]=n;
	for(int i=1;i<=m;i++) scanf("%lld",&a[i+1]);
	m++;
	for(int i=1;i<=m;i++){
		while(top&&a[i]<=s[top]) top--;
		s[++top]=a[i];
	}
	nn=n;
	if(s[1]<n) n=s[1];
	mp[s[top]]=1;
	init(s[top]);
	dfs(s[top]);
	ll sum=0;
	for(int i=n;i;i--){
		if(mp.find(i)!=mp.end()) sum+=mp[i];
		ans[i]=sum;
	}
	for(int i=1;i<=nn;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 60160
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long

int main(){
  int x=0;
  int max=0;
  int n;
  string s;
  
  cin>>n;
  cin>>s;

  for(int i=0;i<n;i++){
    if(s.at(i)=='I'){
      x++;
    }else if(s.at(i)=='D'){
      x--;
    }
    
    if(x>max){
      max=x;
    }
  }

  cout<<max;

  

  return 0;
}


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

long long n;
int ans = INT_MAX;
int lg10(long long x) {
	int ret = 0;
	while(x) ret++, x /= 10;
	return ret;
}
int main() {
	cin >> n;
	for(int i = 1; i <= sqrt(n); i++) if(n%i == 0) ans = min(max(lg10(i), lg10(n/i)), ans);
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	int len;
	ll cnt = 0, ans = 0;

	cin >> S;
	len = S.length();

	rep(i, len) {
		if (S[i] == 'B') cnt++;
		else ans += cnt;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  ll a = 0;
  while(a < N){
    a += 1000;
  }
  cout << a - N << endl;

}


Measured memory_bytes: 3632
inputs = list(map(int, input().split()))
N = inputs[0]
M = inputs[1]
X = inputs[2]
Y = inputs[3]

Xposi = list(map(int, input().split()))
Yposi = list(map(int, input().split()))

Xposi.sort()
Yposi.sort()

if X<Y and  Xposi[-1] < Y and X < Yposi[0]  and Xposi[-1] < Yposi[0]:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double[] a = new double[N];
		for(int i = 0; i < N; i++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			int b = sc.nextInt();
			int p = sc.nextInt();
			if(b >= 5 && p >= 2)
				a[i] = (x*b + y*p)*0.8;
			else if(!(b >= 5) && p >= 2 && (x*5 + y*p)*0.8 <= x*b + y*p)
				a[i] = (x*5 + y*p)*0.8;
			else if(b >= 5 && !(p >= 2) && (x*b + y*2)*0.8 <= x*b + y*p)
				a[i] = (x*b + y*2)*0.8;
			else
				a[i] = x*b + y*p;
		}
		for(int i = 0; i < N; i++)
			System.out.println((int)a[i]);
		}
	}

Measured memory_bytes: 23296
N = int(input())
p = list(map(int, input().split()))
tmp = [i + 1 for i in range(N)]
ans = 'NO'
if p == tmp:
    ans = 'YES'
else:
    cnt = 0
    for i in range(N):
        if p[i] != tmp[i]:
            cnt += 1
    if cnt == 2:
        ans = 'YES'
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(){
	long long int n ;
	cin >> n ; 
	long long int  ans1 = 1;
	long long int ans  = 1;
	for(long long int i = 1;i<=n;i++){
		ans = (ans*10)%mod;
	}
	for(long long int i = 1 ; i<=n;i++){
		ans1 = (ans1*8)%mod;
	}
	long long int ans3 = 1 ;
	for(long long int  i = 1 ; i<=n;i++){
		ans3 = (ans3*9)%mod;
	}
	ans3 = (2*ans3)%mod;
	
	ans = (((ans+ans1)%mod-ans3)%mod + mod)%mod;
 cout << ans;
}


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

class Node
{
public:
    Node(int key)
    {
        m_key = key;
    }

    int get_key()
    {
        return m_key;
    }
private:
    int m_key;
};

int main() {
    int H;
    std::cin >> H;
    std::vector<Node*> tree;
    for (int i = 1; i <= H; i++)
    {
        int key;
        std::cin >> key;
        Node* new_node = new Node(key);
        tree.push_back(new_node);
    }
    for (int i = 1; i <= H; i++) {
        std::cout << "node " << i << ": key = " << tree[i-1]->get_key() << ", ";
        if (i != 1) {
            int parent_num = i / 2;
            std::cout << "parent key = " << tree[parent_num - 1]->get_key() << ", ";
        }
        if (i * 2 <= H) {
            std::cout << "left key = " << tree[2 * i - 1]->get_key() << ", ";
        }
        if (i * 2 + 1 <= H) {
            std::cout << "right key = " << tree[2 * i]->get_key() << ", ";
        }
        std::cout << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3160
var n, i, tmp: longint;
    a, b: array[1..100000] of longint;

begin
    read(n);
    for i := 1 to n do read(a[i]);
    i := n - 1;
    while i > 0 do
    begin
        tmp := tmp + a[i] - a[i - 1];
        i := i - 2;
    end;
    b[n] := tmp + a[n];
    for i := (n - 1) downto 1 do b[i] := a[i] * 2 - b[i + 1];
    for i := 1 to n do write(b[i], ' ');
end.
{
b[2] - b[1] = (a[3] / 2 + a[2] / 2) - (a[2] / 2 + a[1] / 2);
            = (a[3] - a[1]) / 2;
b[4] - b[3] = (a[5] - a[3]) / 2;
}

Measured memory_bytes: 1920
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Beginner091
{
    public class ABC091B
    {
        public static void Main(string[] args)
        {
            Dictionary<String, int> dic = new Dictionary<string, int>();
            int N = int.Parse(Console.ReadLine());

            for(int i=0; i<N; i++)
            {
                string S = Console.ReadLine();

                if(dic.ContainsKey(S))
                {
                    dic[S] = dic[S] + 1;
                }
                else
                {
                    dic.Add(S, 1);
                }
            }

            int M = int.Parse(Console.ReadLine());
            for(int i = 0; i < M; i++)
            {
                string T = Console.ReadLine();

                if(dic.ContainsKey(T))
                {
                    dic[T] = dic[T] - 1;
                }
                else
                {
                    dic.Add(T, -1);
                }
            }

            int max = 0;
            foreach(KeyValuePair<string, int> kv in dic)
            {
                max = Math.Max(max, kv.Value);
            }
            
            Console.WriteLine(max);
        }
    }
}

Measured memory_bytes: 13152
n=int(input())
job=[]
for _ in range(n):
  job.append(list(map(int, input().split())))

job.sort(key=lambda x: x[1])
time=0
for j in job:
  time+=j[0]
  if time>j[1]:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 54888
#include <bits/stdc++.h>
#define MAX (ll)(2e2 + 7)
#define INF (ll)(5e5 + 7)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;

int main () {
	ll x, d, k;
	cin >> x >> k >> d;
	x = abs (x);
	ll y = x / d;
	if (y >= k) {
		cout << (x - min (k, y) * d) << "\n";
	}
	else {
		ll le = (k - y) & 1;
		ll p = x - y * d;
		if (le) {
			p -= d;
		}
		cout << abs (p) << '\n';
	}
}
			
		


Measured memory_bytes: 3632
num_array = [int(s) for s in input().split(" ")]

can_calc_nums = list(filter(lambda x: 1 <= x and x <= 9, num_array))
answer = -1
if len(can_calc_nums) == 2:
	answer = can_calc_nums[0] * can_calc_nums[1]

  
print(answer)
  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  int l = 0, r = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] < x)
      l++;
    else
      r++;
  }
  cout << min(l, r) << endl;
  return 0;
}

Measured memory_bytes: 3540
#include <iostream>

using namespace std;

int main()
{
	int a, b, x;
	
	cin >> a >> b >> x;
	
	
	if (a > x) {
		cout << "NO" << endl;
	}
	else if (a + b >= x) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;

fn main() {
   input! {
      dn: usize,
      c: [i64; 26],
      s: [[i64;26]; dn],
      t: [Usize1; dn],
   }

   let mut score = 0;
   let mut last = vec![0; 26];
   for (i, &t) in t.iter().enumerate() {
      score += s[i][t];
      last[t] = i + 1;
      for j in 0..26 {
         score -= c[j] * (i + 1 - last[j]) as i64;
      }
      println!("{}", score);
   }
}


Measured memory_bytes: 2304
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
const int Maxn = 1e5 + 5;
LL n, b[Maxn], a[Maxn];
 
int main(){
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + 1 + n);
    int cnt = 0;
    for (int i = n; i > 1; i--) {
        if (a[i] == a[i-1]){
            b[++cnt] = a[i];
            i--;
            if(cnt == 2){
                cout << b[1]*b[2] << endl;
                return 0;
            }
        }
    }
    cout << "0" << endl;
    return 0;
}

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

void solve()
{
    long long n;
    cin>>n;
    long long  sum = 0;
    for(long long i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0)continue;
        else
        sum +=i;
    }
    cout<<sum<<endl;
}

int main()
{
    int t;
    t=1;
    while(t--)
        solve();
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,n,j) for(ll i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010

int main()
{
    int N;
    cin >> N;
    vector<ll> f(N+1);
    rep(i,N+1)f[i]=1;
    ll j=1;
    FOR(i,N/2+1,2){
        j=1;
        while(i*j<=N){
            f[i*j]++;
            ++j;
        }
    }
    FOR(i,N+1,N/2+1){
        f[i]++;
    }
    ll ans=0;
    
    FOR(k,N+1,1){
        ans+=k*f[k];
    }
    if(N==1){
        ans=1;
    }
    //cout << f[40];
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<tuple<string,int,int>> v(n);

  for(int i=0; i<n; i++){
    cin >> get<0>(v.at(i)) >> get<1>(v.at(i));
    get<1>(v.at(i)) = -get<1>(v.at(i));
    get<2>(v.at(i)) = i+1;
  }

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

  for(int i=0; i<n; i++){
    cout << get<2>(v.at(i)) << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int m,n;
ll pre[200000],ex,ans;
map <ll,ll> md;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        ll a; cin>>a;
        pre[i]=pre[i-1]+a;
        md [pre[i] % m] ++;
    }
    ex = 0;
    for(int i=1;i<=n;i++){
        ans += md[ex];
        md[pre[i]%m]--;
        ex = pre[i] % m;
    }
    cout<<ans<<newl;
}


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

double pi=3.141592653589793238;

int main()
{
	int a,b,h,m;
	scanf("%d%d%d%d",&a,&b,&h,&m);
	double dig=abs(h*30.0+0.5*m-6.0*m-360.0);
	printf("%.12lf",sqrt(1.0*a*a+1.0*b*b-2.0*a*b*cos(dig/360*2*pi)));
}

Measured memory_bytes: 4248
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const int N = 2e5 + 10, MOD =  998244353;

void solve() {
  int a, b;
  cin >> a >> b;
  cout << a*b;
}

int main()  {
  ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                  

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

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

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

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    string S;
    cin >> S;
    int ret = 0;
    for(int i = 0;i < S.size();i++) {
        ret += S.at(i) - '0';
        ret %= 9;
    }
    if(ret == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3748
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    string s;
    int c = 0,maxc = 0;
    bool flag;
    char target[] = {'A','T','G','C'};
    cin >> s;

    rep(i, s.size()){
        flag = false;
        rep(j, 4){
            if(s.at(i) == target[j]){
                flag = true;
            }
        }

        if(flag){
            c++;
        }else{
            c = 0;
        }

        maxc = max(c,maxc);
    }

    cout << maxc << endl;
}



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

const int N = 2e3 + 10, mod = 1e9 + 7;

vector<int> adj[N];
int dis[N][N];

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        int n, u, v; scanf("%d%d%d", &n, &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
        for(int i = 1; i <= n - 1; i++) {
            adj[i].push_back(i + 1);
            adj[i + 1].push_back(i);
        }
        vector<int> res(n + 1, 0);
        for(int u = 1; u <= n; u++) {
            queue<pair<int, int>> q;
            q.push({u, 0});
            for(int v = 1; v <= n; v++) dis[u][v] = 1e9;
            while(!q.empty()) {
                int uu = q.front().first, w = q.front().second;
                q.pop();
                if(w > dis[u][uu]) continue;
                dis[u][uu] = w;
                for(int v : adj[uu]) {
                    if(w + 1 < dis[u][v]) q.push({v, w + 1});
                }
            }
            for(int v = u + 1; v <= n; v++) {
                res[dis[u][v]]++;
            }
        }
        for(int i = 1; i < n; i++) printf("%d\n", res[i]);
    }    
    return 0;
}

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


int main(int argc,char** argv)
{

	int d, n;
	cin >> d >> n;
	if(d == 0){
		if(n==100) cout << n+1 <<endl;
		else cout << n <<endl;
	}
	else if(d == 1){
		if(n==100) cout << n*101 <<endl;
		else cout << n*100 <<endl;
	}
	else{
		if(n==100) cout << n*10100 <<endl;
		else cout << n*10000 <<endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		while (true) {
        // 入力されるH,Wを定義

        int H = scanner.nextInt();
        int W = scanner.nextInt();

        // H,Wともに0の時終了
        if (H == 0 && W == 0) {
        	break;
        }

        for (int i = 0; i < H; i++) {
        	for (int j = 0; j < W; j++) {
        		if (i % 2 == 1 && j % 2 == 1) {
        		System.out.print("#");
        		} else if (i % 2 == 0 && j % 2 == 0){
        			System.out.print("#");
        		} else if (i % 2 == 1 && j % 2 == 0) {
        			System.out.print(".");
        		} else if (i % 2 == 0 && j % 2 == 1) {
        			System.out.print(".");
	        	}
	        }
	        System.out.println("");
			}
        System.out.println("");
		}
	}
}



Measured memory_bytes: 33388
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> g(h);
  rep(i,h) cin >> g[i];

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(g[i][j] == '#') continue;
      int cnt = 0;
      for(int k = -1; k < 2; k++){
        for(int l = -1; l < 2; l++){
          if(k == 0 && l == 0) continue;
          if(i+k < 0 || i+k > h-1 || j+l<0 || j+l>w-1) continue;
          if(g[i+k][j+l] == '#') cnt++;
        }
      }
      g[i][j] = cnt + '0';
    }
  }

  rep(i,h) cout << g[i] << endl;

}


Measured memory_bytes: 3636
from collections import defaultdict
from itertools import combinations
def main():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        s = input()
        d[s[0]] += 1
    ans = 0
    for i, j, k in combinations('MARCH', 3):
        ans += d[i] * d[j] * d[k]
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9472
#include <stdio.h>

int N;
int game[128][6];

int search(int isSente, int left, int right, int ste, int gte) {
	int kateru = 0;
	int daseta = 0;
	if (isSente) {
		if (gte == 0) return 0;
		if ((ste >> (left - 1)) & 1) {
			kateru = kateru || !search(0, left - 1, right, ste & ~(1 << (left - 1)), gte);
			daseta = 1;
		}
		if ((ste >> (right + 1)) & 1) {
			kateru = kateru || !search(0, left, right + 1, ste & ~(1 << (right + 1)), gte);
			daseta = 1;
		}
	} else {
		if (ste == 0) return 0;
		if ((gte >> (left - 1)) & 1) {
			kateru = kateru || !search(1, left - 1, right, ste, gte & ~(1 << (left - 1)));
			daseta = 1;
		}
		if ((gte >> (right + 1)) & 1) {
			kateru = kateru || !search(1, left, right + 1, ste, gte & ~(1 << (right + 1)));
			daseta = 1;
		}
	}
	if (!daseta) {
		kateru = !search(!isSente, left, right, ste, gte);
	}
	return kateru;
}

int main(void) {
	int i, j;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		for (j = 0; j < 6; j++) {
			if (scanf("%d", &game[i][j]) != 1) return 1;
		}
	}
	for (i = 0; i < N; i++) {
		int ste = 0;
		for (j = 0; j < 6; j++) {
			ste |= 1 << game[i][j];
		}
		puts(search(1, 7, 7, ste, 0x3F7E & ~ste) ? "yes" : "no");
	}
	return 0;
}

/*

1111
32109876543210
11111101111110
 3   F   7   E
*/



Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int H,W;
int t[30][30],u[30][30];
ll dfs(int y,int x){
  if(x==W)return dfs(y+1,0);
  if(y==H)return 1;
  if(t[y][x]==1)return dfs(y,x+1);
  ll res=0;
  if(x+1<W&&t[y][x]==0&&t[y][x+1]==0){
    if(u[y][x]<2&&u[y+1][x]<2&&u[y][x+2]<2&&u[y+1][x+2]<2){
      u[y][x]++;u[y+1][x]++;u[y][x+2]++;u[y+1][x+2]++;
      t[y][x]=t[y][x+1]=1;
      res+=dfs(y,x+1);
      t[y][x]=t[y][x+1]=0;
      u[y][x]--;u[y+1][x]--;u[y][x+2]--;u[y+1][x+2]--;
    }
  }
  if(y+1<H&&t[y][x]==0&&t[y+1][x]==0){
    if(u[y][x]<2&&u[y+2][x]<2&&u[y][x+1]<2&&u[y+2][x+1]<2){
      u[y][x]++;u[y+2][x]++;u[y][x+1]++;u[y+2][x+1]++;
      t[y][x]=t[y+1][x]=1;
      res+=dfs(y,x+1);
      t[y][x]=t[y+1][x]=0;
      u[y][x]--;u[y+2][x]--;u[y][x+1]--;u[y+2][x+1]--;
    }
  }
  return res;
}

int main(){
  while(1){
    cin>>H>>W;
    if(H==0&&W==0)break;
    cout<<dfs(0,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (500)
#define MAX_M (200000)
#define MAX_Q (100000)

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, Q, ls[MAX_M], rs[MAX_M], ps[MAX_Q], qs[MAX_Q];
  scanf("%d %d %d", &N, &M, &Q);
  for (int i = 0; i < M; i++) {
    scanf("%d %d", &ls[i], &rs[i]);
    ls[i]--;  // NOTE : modified input
    rs[i]--;  // NOTE : modified input
  }
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &ps[i], &qs[i]);
    ps[i]--;  // NOTE : modified input
    qs[i]--;  // NOTE : modified input
  }

  // solve
  int xs[MAX_N][MAX_N] = {};  // xs[l][r] : number running range [l, r]
  int ys[MAX_N][MAX_N];  // ys[l][r] : number running range covered by [l, r]
  for (int i = 0; i < M; i++) {
    xs[ls[i]][rs[i]]++;
  }
  for (int w = 0; w < N; w++) {
    for (int l = 0; l + w < N; l++) {
      const int r = l + w;
      int ys_l_r = w == 0 ? 0 : ys[l + 1][r];
      for (int rd = l; rd <= r; rd++) {
        ys_l_r += xs[l][rd];
      }
      ys[l][r] = ys_l_r;
    }
  }

  for (int i = 0; i < Q; i++) {
    printf("%d\n", ys[ps[i]][qs[i]]);
  }

  return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
 
using namespace std;
 
int main()
{
	int n;
	cin>>n;
	
	vector<int> a(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	int mn = a[0], mx = a[0];
	for(int i = 1; i < n; i++)
    {
		if(mn > a[i])
			mn = a[i];
		if(mx < a[i])
			mx = a[i];
	}
	cout << mx - mn<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
using namespace std;


vector<pair<int,int> > edge[101];

int d[101];
int dijkstra(int s,int g){
	deque<int> q;
	for(int i=0;i<=g;i++)d[i]=1<<30;
	q.push_front(s);
	d[s]=0;
	while(!q.empty()){
		int u=q.front();
		if(u==g)return d[g];
		q.pop_front();
		for(int i=0;i<edge[u].size();i++){
			pair<int,int> p=edge[u][i];
			if(d[u]+p.second<d[p.first]){
				d[p.first]=d[u]+p.second;
				if(p.second==0)q.push_front(p.first);
				else q.push_back(p.first);
			}
		}
	}
	return -1;
}

int main(){
	int n;
	cin>>n;
	map<string,vector<int> > from;
	map<string,int> id;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="goto"){
			cin>>s;
			s[s.size()-1]=':';
			if(id.find(s)!=id.end()){
				edge[i].push_back(make_pair(id[s],0));
			}else{
				from[s].push_back(i);
			}
			edge[i].push_back(make_pair(i+1,1));
		}else{
			if(from.find(s)!=from.end()){
				vector<int> &v=from[s];
				for(int j=0;j<v.size();j++)
					edge[v[j]].push_back(make_pair(i,0));
				v.clear();
			}
			id[s]=i;
			edge[i].push_back(make_pair(i+1,0));
		}
	}
	cout<<dijkstra(0,n)<<endl;
	return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include<vector>
#include<cmath>

using namespace std;

int main()
{
    int H, W, K;
    vector<vector<char>> map;
    cin >> H >> W >> K;
    map.resize(H, vector<char>(W));
    for (int i = 0; i < H; i++){
        string str;
        cin >> str;
        for (int j = 0; j < W; j++){
            char c = str[j];
            map[i][j] = c;
        }
    }
    int count = 0;

    for (int h = 0; h < pow(2, H); h++){
        for (int w = 0; w < pow(2, W); w++){
            int n = 0;
            for (int i = 0; i < H; i++){
                for (int j = 0; j < W; j++){
                    if((h & (int)(pow(2, i))) != 0){
                        continue;
                    }
                    if ((w & (int)(pow(2, j))) != 0)
                    {
                        continue;
                    }
                    if(map[i][j] == '#'){
                        n++;
                    }
                }
            }
            if(n == K){
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 4060
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line;
        int[][] map = new int[10][10];
        while(true) {
            try {
                line = sc.nextLine();
            }catch(Exception e) {
                break;
            }
            String[] A = line.split(",");
            int x = Integer.parseInt(A[0]);
            int y = Integer.parseInt(A[1]);
            int s = Integer.parseInt(A[2]);
            //小
            if(s == 1) {
                if(y-1 >= 0) {
                    map[y-1][x]++;
                }
                for(int i = x-1; i <= x+1; i++) {
                    if(i < 0) {
                        continue;
                    }
                    if(i > 9) {
                        break;
                    }
                    map[y][i]++;
                }
                if(y+1 <= 9) {
                    map[y+1][x]++;
                }
            }
            //中
            if(s == 2) {
                for(int j = y-1; j <= y+1; j++) {
                    if(j < 0) {
                        continue;
                    }
                    if(j > 9) {
                        break;
                    }
                    for(int i = x-1; i <= x+1; i++) {
                        if(i < 0) {
                            continue;
                        }
                        if(i > 9) {
                            break;
                        }
                        map[j][i]++;
                    }
                }
            }
            
            if(s == 3) {
                if(y-2 >= 0) {
                    map[y-2][x]++;
                }
                if(y+2 <= 9) {
                    map[y+2][x]++;
                }
                if(x-2 >= 0) {
                    map[y][x-2]++;
                }
                if(x+2 <= 9) {
                    map[y][x+2]++;
                }
                for(int j = y-1; j <= y+1; j++) {
                    if(j < 0) {
                        continue;
                    }
                    if(j > 9) {
                        break;
                    }
                    for(int i = x-1; i <= x+1; i++) {
                        if(i < 0) {
                            continue;
                        }
                        if(i > 9) {
                            break;
                        }
                        map[j][i]++;
                        
                    }
                }
            }
        }
        int max = 0;
        int count = 0;
        for(int i = 0; i <= 9; i++) {
            for(int j = 0; j <= 9; j++) {
                if(map[i][j] == 0) {
                    count++;
                }
                if(max < map[i][j]) {
                    max = map[i][j];
                }
            }   
        }
        System.out.println(count);
        System.out.println(max);
    }
}


Measured memory_bytes: 26192
N = int(input())
A = [[int(i) for i in input().split()] for _ in range(N)]

dp = [[0]*3 for _ in range(N)]
dp[0] = A[0]

for i in range(1,N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][k] = max(dp[i][k], dp[i-1][j]+A[i][k])

print(max(dp[-1]))


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strs =  br.readLine().split(" ");
    int N = Integer.parseInt(strs[0]);
    int K = Integer.parseInt(strs[1]) - 1;
    String s = br.readLine();
    String[] tmp = new String[N];
    for (int i = 0; i < N; i++) {
      tmp[i] = String.valueOf(s.charAt(i));
    }
    tmp[K] = tmp[K].toLowerCase();
    System.out.println(String.join("", tmp));
  }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int fir[200010],dis[400010],nxt[400010],id;
void link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
int dfn[200010],end[200010],max[200010],fa[200010];
void dfs(int x){
	dfn[x]=++dfn[0];
	for(int i=fir[x];i;i=nxt[i]){
		if(fa[x]==dis[i])continue;
		fa[dis[i]]=x;
		max[dis[i]]=std::max(max[x],dis[i]);
		dfs(dis[i]);
	}
	end[x]=dfn[0];
}
std::unordered_map<ll,int>M;
int Q(int x,int y){
	if(y<=1)return 0;
	ll w=(1ll*x<<20)|y;
	if(M.count(w))return M[w];
	int ret=0;
	for(int i=fir[x];i;i=nxt[i])
		if(dis[i]!=fa[x]&&dis[i]<y)
			ret+=Q(dis[i],y)+1;
	return M[w]=ret;
}
int ans[200010],c[200010];
void DFS(int x){
	for(int i=fir[x];i;i=nxt[i]){
		if(fa[x]==dis[i])continue;
		c[dis[i]]+=c[x];
		DFS(dis[i]);
	}
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),a,b;
	for(int i=1;i<n;++i)a=gi(),b=gi(),link(a,b),link(b,a);
	max[1]=1,dfs(1);
	for(int i=2;i<=n;++i)
		if(i>max[fa[fa[i]]])c[i]=Q(i,max[fa[i]])+1;
		else c[i]=Q(i,max[fa[i]])-Q(i,max[fa[fa[i]]]);
	DFS(1);for(int i=2;i<=n;++i)printf("%d ",c[i]);
	return 0;
}


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

ll xor_sum(ll x){
    ll ret = 0;
    for(ll i = x/4 * 4; i <= x; i++) ret ^= i;
    return ret;
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = xor_sum(b) ^ xor_sum(a-1);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define rep(i,m,n) for(int i=m;i<n;i++)

long gcd(long a,long b){

 while(a%b){
  long r=a%b;
   a=b;
   b=r;
 }
    
  return b;

}

int main(){
 long n;
  cin >> n;
 
 vector<long> a(n);
  rep(i,0,n) cin >> a[i];
  
  long res=a[0];
  rep(i,1,n) res=gcd(res,a[i]);
  
  cout << res << endl;
}

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1,i,j;
   // cin>>t;
    while(t--)
    {
        int n,m,count=0,sum=1,maxi=0,mini=1e18,flag=0;
        cin>>n;
        
        int a[n];
        int prev=1;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            
        }
        for(i=0;i<n;i++)
        {
            if(a[i]==0)
            {
                cout<<0;
                return 0;
            }
        }
        for(i=0;i<n;i++)
        {
            if((sum*a[i])>1000000000000000000 || (sum*a[i])<sum)
            {
                cout<<"-1";
                return 0;
            }
            sum=sum*a[i];
            
        }
        cout<<sum;
    }
}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const ll INF = 1LL<<60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll h, w;
    cin >> h >> w;
    ll ans = INF;
    rep(_, 2) {
        rep(i, h/2) {
            ll a = w * (i+1);
            ll b, c;
            if (((h-i-1)&1) && (w&1)) {
                if (h-i-1 > w) {
                    b = (h-i-1) / 2 * w;
                    c = (h-i) / 2 * w;
                } else {
                    b = w/2 * (h-i-1);
                    c = (w+1)/2 * (h-i-1);
                }
            } else {
                b = (h-i-1) * w / 2;
                c = b;
            }
            chmin(ans, max({a, b, c}) - min({a, b, c}));
        }
        swap(h, w);
    }
    cout << ans << endl;
}

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


def solve(n, a, b, c, d):

    return memo[0]


t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    memo = {}

    def dfs(m, cost):
        if m not in memo or memo[m] > cost:
            memo[m] = cost

            if m > 0:
                dfs(m // 2, cost + (m % 2) * d + a)
                dfs(m // 3, cost + (m % 3) * d + b)
                dfs(m // 5, cost + (m % 5) * d + c)

                dfs((m + (2 - m % 2)) // 2, cost + (2 - m % 2) * d + a)
                dfs((m + (3 - m % 3)) // 3, cost + (3 - m % 3) * d + b)
                dfs((m + (5 - m % 5)) // 5, cost + (5 - m % 5) * d + c)

                dfs(0, cost + m * d)

    dfs(n, 0)
    print(memo[0])


Measured memory_bytes: 122124
//おまじない
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
//#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 200000;

int n;
bool a[maxn+1];
bool ans[maxn+1];
int c = 0;

int main(){
    
    cin >> n;
    rep(i,n)cin >> a[i+1];  //1-indexed
    
    for(int i=n;i>=1;i--){
        int cnt = 0;
        for(int j=i;j<=n;j+=i){
            if(ans[j])cnt++;
        }
        if((cnt%2==0&&a[i]==1)||(cnt%2==1&&a[i]==0)){
            ans[i]=1;
            c++;
        }
    }
    
    cout << c<<endl;
    rep(i,n){
        if(ans[i+1]==1)cout << i+1<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  inputInt3(P,Q,R);
  
  //main
  
  // output
  int M = max({P,Q,R});
  
  cout << P+Q+R-M << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;

const int mx = 100000 + 5;
int n, m, b[2] = {0};
char mark[mx];
// struct edge{
//     int l, r;
//     bool operator<(edge e){
//         if(l != e.l){
//             return l < e.l;
//         }
//         else{
//             return r < e.r;
//         }
//     }
// }ed[mx];

vector<int>pt[mx];

bool judgeBipartite(int now, char c){
    if(mark[now] < 0){
        mark[now] = c;
        ++b[c];
        bool ans = true;
        for(int i = 0; i < pt[now].size() && ans; ++i){
            ans = ans && judgeBipartite(pt[now][i], !c);
        }
        return ans;
    }
    else if(mark[now] == c){
        return true;
    }
    return false;
}
// bool judgeBipartite(point * pt, int start){
//     queue<int>qpt;
//     qpt.push(start);
//     while(!qpt.empty()){
//         int now = qpt.front();
//         qpt.pop();
//         for(int i = 0; i < pt[now].next.size(); ++i){
//             char & l = mark[pt[now].next[i]];
//             if(l < 0){
//                 l = 1 ^ mark[now];
//                 ++b[l];
//                 qpt.push(pt[now].next[i]);
//             }
//             else if(!(l ^ mark[now])){
//                 return false;
//             }
//         }
//     }
//     return true;
// }

int main(){
    memset(mark, -1, sizeof(mark));
    scanf("%d%d", &n, &m);
    for(int i = 0, x, y; i < m; ++i){
        scanf("%d%d", &x, &y);
        pt[x].push_back(y);
        pt[y].push_back(x);
    }
    bool judge = true;
    for(int i = 1; i <= n && judge; ++i){
        if(mark[i] < 0){
            judge = judge && judgeBipartite(i, 0);
        }
    }
    // for(int i = 0, x, y; i < m; ++i){
    //     scanf("%d%d", &x, &y);
    //     ed[i].l = min(x, y);
    //     ed[i].r = max(x, y);
    // }
    // sort(ed, ed + m);
    // mark[1] = 0;
    // int b[2] = {1};
    // for(int i = 0; i < m; ++i){
    //     char & l = mark[ed[i].l], &r = mark[ed[i].r];
    //     // cout<<ed[i].l<<(int)l<<' '<<' '<<ed[i].r<<' '<<(int)r<<endl;
    //     if(l < 0 || r < 0){
    //         if(l < 0){
    //             l = 1 ^ r;
    //             ++b[l];
    //         }
    //         else{
    //             r = 1 ^ l;
    //             ++b[r];
    //         }
    //     }
    //     else if(!(l ^ r)){
    //         judge = false;
    //         break;
    //     }
    // }
    // for(int i = 0; i < n; ++i){
    //     cout<<i<<' '<<(int)mark[i]<<endl;
    // }
    if(judge){
        // cout << b[0] << " " << b[1] << endl;
        printf("%lld\n", (long long)b[0] * b[1] - m);
    }
    else{
        // cout << n <<' '<<m<<endl;
        printf("%lld\n", (long long)n * (n - 1) / 2 - m);
    }
    return 0;
}



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

int main()
{
  int A, B, C, r;

  cin >> A >> B >> C;
  r = A % B;
  for (int i = 0; i < B; i++)
  {
    if ((r * i) % B == C)
    {
      r = -1;
      break;
    }
  }
  if (r == -1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in).useDelimiter("[,\n]");
        int w = sc.nextInt();
        int n = sc.nextInt();
        int num[] = new int[w];
        for(int i=0;i<w;i++){
            num[i]=i+1;
        }
        for(int i=0;i<n;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = 0;
            c=num[a-1];
            num[a-1]=num[b-1];
            num[b-1]=c;
        }
        for(int i=0;i<w;i++){
            System.out.println(num[i]);
        }
        sc.close();
    }
}


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

using namespace std;

typedef long long ll;

int main()
{
    int A,B,C;
    while(cin>>A>>B>>C)
    {
        int k;
        k=A-B;
        if(k<C)
            cout<<C-k<<endl;
        else
             cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
x, op, y = input().split()
x = int(x)
y = int(y)
while op != "?" :
 if op == "+" :
  print(x + y)
 elif op == "-":
  print(x - y)
 elif op == "*":
  print(x * y)
 elif op == "/":
  print(x // y)
 x, op, y = input().split()
 x = int(x)
 y = int(y)

Measured memory_bytes: 7696
#include<iostream>
using namespace std;
const int N=2e5+10;
int main()
{
	string s;
	int k;
	cin>>k;cin>>s;
	int len=s.length();
	if(len>k)
	{
		for(int i=0;i<k;i++)
			cout<<s[i];
		cout<<"...\n";
	}
	else
		cout<<s<<'\n';
	return 0;
}

Measured memory_bytes: 3628
def is_palindromic(n):
    s = str(n)
    for i in range(len(s)//2 + 1):
        if s[i] != s[-i-1]:
            return False
    return True

A, B = list(map(int, input().split()))
ans = 0
for n in range(A, B + 1):
    if is_palindromic(n):
        ans += 1
print(ans)

Measured memory_bytes: 9128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    N, M = map(int,input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    vote = sum(A)

    for i in range(M):
        if A[i] < (vote/(4*M)):
            print('No')
            exit()

    print('Yes')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main() {
  int a;
  int b;
  int c;
  scanf("%d %d %d",&a,&b,&c);
  if (b/a >= c) {
    printf("%d\n",c);
  } else {
    printf("%d\n",b/a);
  }
  return 0;
}

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

int main() {
  long int N, a, b, c, sum=0;
  cin >> N >> a >> b;
  c = N/(a+b);
  sum += c*a; 
  if(N%(a+b) <= a) {
    sum += N%(a+b); 
  } else {
    sum += a;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n;
    cin>>n;
    unordered_set<int>  s;
    vector<int> v;
    int i=1;
    v.push_back(n);
    s.insert(n);
    while (1)
    {
        if (v[i-1]%2==0)
        {
            n=v[i-1]/2;
            v.push_back(n);
            if (s.find(n)!=s.end())
            {
                break;
            }
            s.insert(n);
        }
        else
        {
            n=3*v[i-1]+1;
            v.push_back(n);
            if (s.find(n)!=s.end())
            {
                break;
            }
            s.insert(n);
        }
        i++;
    }

    cout<<i+1;
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s1,s2;
	cin>>s1>>s2;
	s1+=s1;
	if(s1.find(s2,0)!=s1.npos)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
} 


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

ll solve() {
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> w[i] >> v[i];
    }
    ll V = 1e5;
    const ll INF = 1LL<<60;
    vector<ll> dp(V+1, INF);
    dp[0] = 0;
    for ( int i = 0; i < N; i++ ) {
        for ( int k = V; k >= 0; k-- ) {
            ll j = k - v[i];
            if ( j >= 0 ) {
                dp[k] = min(dp[k], dp[j] + w[i]);
            }
            if ( k < V ) {
                dp[k] = min(dp[k], dp[k+1]);
            }
        }
    }
    ll ans = 0;
    for ( int j = V; j >= 0; j-- ) {
        if ( dp[j] <= W ) {
            ans = j;
            break;
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a+b >= c) cout << b + c << endl;
    else cout << 2*b + a + 1 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s,t;
    cin>>s>>t;
    int f=0;
    for(char i='a';i<='z';i++)
    {
        if(t==(string)(s+i))
        {
            cout<<"Yes"<<endl;
            f=1;
            break;
        }
    }
    if(f==0)
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3640