akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

def main():
    x,y,z,k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    #a.sort()
    #a.reverse()
    #b.sort()
    #b.reverse()
    #c.sort()
    #c.reverse()
    ans = []
    for i in a:
        for j in b:
            ans.append(i+j)
    ans.sort()
    ans.reverse()
    ans = ans[:k]
    res = []
    for i in c:
        for j in ans:
            res.append(i+j)
    res.sort()
    res.reverse()
    res = res[:k]
    print(*res, sep="\n")
    
if __name__=="__main__":
    main()

Measured memory_bytes: 217680
use std::io;

macro_rules! get {
    ($t: ty) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.parse::<$t>().unwrap()
        }
    };
    ($($t: ty), *) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            let mut inter = x.split_whitespace();
            (
                $(inter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

macro_rules! insert_vec {
    ($t: ty) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.split_whitespace().map(|x| x.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

macro_rules! word_chars_vec {
    () => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.chars().collect::<Vec<_>>()
        }        
    };
}


fn gcd (i: i64, j: i64) -> i64 {
    if i == 0 {
        j 
    }
    else {
        gcd(j % i, i)
    }
}

fn lcm (i: i64, j: i64) -> i64 {
    i / gcd(i, j) * j
}


fn main() {
    let (a, b, c, d) = get!(i64, i64, i64, i64);
    let b_c_count = b / c;
    let b_d_count = b / d;
    let b_dup_count = b / lcm(c, d);
    let b_count = b_c_count + b_d_count - b_dup_count;

    let a_c_count = (a - 1) / c;
    let a_d_count = (a - 1) / d;
    let a_dup_count = (a - 1) / lcm(c, d);
    let a_count = a_c_count + a_d_count - a_dup_count;

    println!("{}", b - a - (b_count - a_count) + 1);

}


Measured memory_bytes: 4352
#include<stdio.h>
#define M 500000

int a[M],b[M],count=0;

main()
{
  int i, n;

  scanf("%d", &n);
  for(i=0; i<n; i++)
    scanf("%d", &a[i]);
  ms(a, 0, n-1);
  for(i=0; i<n-1; i++){
 printf("%d ", a[i]); 
  }

  printf("%d\n%d\n", a[n-1], count);
  return 0;
} 


void ms(int *a,int l,int r)
{
  int i,j,k,m;
  if(r>l){
    m=(r+l)/2;
    ms(a, l, m);
    ms(a, m+1, r);

    for(i=m+1; i>l; i--){
      b[i-1]=a[i-1];
	}
 
    for(j=m; j<r; j++){
      b[r+m-j]=a[j+1];
	}

    for(k=l; k<=r; k++){
      a[k]=(b[i]<b[j])?b[i++]:b[j--];
      count++;
    }
  }
}
 

Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> S >> T;
    REP(i, S.size()) {
        if (S[i] != T[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3868
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::{min, max};

fn main() {
    input! {
    a: usize,
    b: usize,
    q: usize,
    s:[i64; a],
    t:[i64; b],
    x:[i64; q]
    }
    let mut l: Vec<(i64, char)> = vec![];
    for i in 0..a {
        l.push((s[i], 's'));
    }
    for i in 0..b {
        l.push((t[i], 't'));
    }
    l.sort();
    for i in 0..q {
        let k = l.lower_bound(&(x[i], 'x'));
        let li = if k > 0 { k - 1 } else { 0 };
        let ri = if k < l.len() {k} else {k - 1};
        let ans = min((l[li].0 - x[i]).abs() + check(l[li], &s, &t),
                      (l[ri].0 - x[i]).abs() + check(l[ri], &s, &t));
        println!("{}", ans);
    }
}

fn check(v: (i64, char), s: &Vec<i64>, t: &Vec<i64>) -> i64{
    let res = if v.1 == 's' {
        let k = t.lower_bound(&v.0);
        min((t[if k > 0 {k - 1} else {0}] - v.0).abs(),
            (t[if k < t.len() {k} else {k - 1}] - v.0).abs())
    } else {
        let k = s.lower_bound(&v.0);
        min((s[if k > 0 {k - 1} else {0}] - v.0).abs(),
            (s[if k < s.len() {k} else {k - 1}] - v.0).abs())
    };
    res
}

use std::cmp::Ordering;

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (high + low) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}




Measured memory_bytes: 12436
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define X real()
#define Y imag()


template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

typedef complex<double> P;
int n, m;

main(){
	scanf("%d%d", &n, &m);
	vector<P> p(n);
	REP(i, n) scanf("%lf%lf", &p[i].X, &p[i].Y);
	vector<pair<double, pii> > e;
	REP(i, m){
		int u, v;
		scanf("%d%d", &u, &v);u--;v--;
		e.push_back(pair<double, pii>(abs(p[u]-p[v]), pii(u, v)));
	}
	sort(RALL(e));
	UnionFind uf(n);
	double ans = 0;
	FOR(it, e)
		if(!uf.unionSet(it->second.first, it->second.second)) ans += it->first;
	printf("%.9f\n", ans);
	return 0;
}

Measured memory_bytes: 1864
n,m=map(int,input().split())
acount=0
wcount=0
a=[False]*n
w=[0]*n
for i in range(m):
  p,m=input().split()
  p=int(p)
  if m=="AC":
    if a[p-1]==False:
      acount+=1
      a[p-1]=True
  else:
    if a[p-1]==False:
      w[p-1]+=1
      
for i in range(n):
  if a[i-1]==1:
    wcount+=w[i-1]
    
print(acount,wcount)

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

using namespace std;

int main(){
  int n; cin >> n;
  int k,p;
  for(int i=0;i<n;++i) {
    cin >> k >> p;
    cout << (k-1)%p+1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3108
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> t = new ArrayList<>();
        List<Integer> x = new ArrayList<>();
        List<Integer> y = new ArrayList<>();
        t.add(0);
        x.add(0);
        y.add(0);
        for(int i = 0;i < n;i++){
            t.add(sc.nextInt());
            x.add(sc.nextInt());
            y.add(sc.nextInt());
        }
        boolean can = true;
        for(int i = 1;i <= n;i++){
            int dt = t.get(i) - t.get(i-1);
            int dist = Math.abs(x.get(i)-x.get(i-1)) + Math.abs(y.get(i)-y.get(i-1));
            if(!(dist <= dt && ((dist % 2) == (dt % 2)))){
                can = false;
            }
        }
        if(can){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


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

using namespace std;

typedef long long ll;

int main() {
    ll n;   cin >> n;
    ll mod = 1e9+7;
    ll ans = 1;
    for (int i = 0; i < n; i++)
        ans = (ans * 10) % mod;
    
    ll tmp = 1, cnt = 1;
    for (int i = 0; i < n; i++) {
        tmp = (tmp * 9) % mod;
        cnt = (cnt * 8) % mod;
    }
    
    ans = (ans - tmp - tmp + cnt + 3*mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,MOD=1e9+7,a,b,ans,bik[200001],h,w,c,d,A,B,C,D,L;
ll f(ll x,ll y){
    if(y==0)return 1;
    if(y%2==0)return f(x,y/2)*f(x,y/2)%MOD;
    return x*f(x,y-1)%MOD;
}
ll comb(ll x, ll y){
    return bik[x]*f(bik[x-y],MOD-2)%MOD*f(bik[y],MOD-2)%MOD;
}
int main(void){
    bik[0]=1;
    for(ll i=1;i<=200000;i++){
        bik[i]=bik[i-1]*i;
        bik[i]%=MOD;
    }
    cin>>h>>w>>a>>b;
    A=h-a,B=w-b,C=b+1,D=a+1;
    L=min(A,B);
    A--,B--,C--,D--;
    //cout<<A<<B<<C<<D<<endl;
    for(int i=0;i<L;i++){
        ans+=(comb(A+C,A)*comb(B+D,B))%MOD;
        ans%=MOD;
        A--,B--,C++,D++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
import heapq
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
heapq.heapify(l)
a=[]
heapq.heapify(a)
fd=heapq.heappop(l)
heapq.heappush(a,-fd[1])
ans=0
for day in range(fd[0],m+1):
    while l:
        temp=heapq.heappop(l)
        if temp[0]>day:
            heapq.heappush(l,temp)
            break
        else:
            heapq.heappush(a,-temp[1])
    if a:
        ans+=heapq.heappop(a)
print(-ans)

Measured memory_bytes: 27880
#include<bits/stdc++.h>
using namespace std;
int h[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>h[i];
	int max=h[1];
	for(int i=2;i<=n;i++)
	{
		if(h[i-1]-h[i]>1||max-h[i]>1)
		{
			cout<<"No";
			return 0;
		}
		if(h[i]>max) max=h[i];
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int n;
vector<vector<int>> bridge;
vector<int> dist[2];
int score[2] = {0};

void dfs(int idx, int v, int d) {
    if (dist[idx][v] != INT_MAX) {
        return;
    }
    
    dist[idx][v] = d;
    
    rep(i, sz(bridge[v])) {
        dfs(idx, bridge[v][i], d + 1);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    bridge.resize(n);
    rep(i, 2) dist[i].resize(n, INT_MAX);
    
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        
        bridge[a].push_back(b);
        bridge[b].push_back(a);
    }
    
    rep(i, 2) {
        dfs(i, i * (n - 1), 0);
    }
    
    rep(i, n) {
        if (dist[0][i] <= dist[1][i]) {
            score[0]++;
        }
        else {
            score[1]++;
        }
    }
    
    cout << ((score[0] > score[1]) ? "Fennec" : "Snuke") << endl;
    return 0;
}

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

int main()
{
  	std::string A, B, C;
  	std::cin >> A >> B >> C;
  	if(A.back() == B.front() && B.back() == C.front()){
      	std::cout << "YES";
    }else{
      	std::cout << "NO";
    }
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string,string> p;

int main(){
  int N,i,j,bi;
  cin>>N;
  map<p,ll> cnt;
  string s;
  cin>>s;
  ll ans=0;
  for(bi=0;bi<(1<<N);bi++){
	string a="", b="";
	for(i=0;i<N;i++){
		if((bi>>i)&1) a+=s[i];
		else b+=s[i];
	}
	cnt[p(a,b)]++;
  }
  for(bi=0;bi<(1<<N);bi++){
	string a="", b="";
	for(i=0;i<N;i++){
		if((bi>>i)&1) a+=s[i+N];
		else b+=s[i+N];
	}
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	ans+=cnt[p(a,b)];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 87040
//Hmy
#include<iostream>
using namespace std;

int main()
{
	int n, x, cnt=0;
	while(1){
		cnt = 0;
	cin >> n >> x;
	if(n == 0 && x ==0)
	break;
	for(int i = 1; i <= n-2; i++)
		for(int j = i+1; j <= n-1; j++)
			for(int l = j+1; l <= n; l++)
				if(i+j+l == x)
					cnt++;
	cout << cnt << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
#define I INT32_MAX
#define IM INT_MIN
#define MOD 1000000007
#define ll long long
#define lli long long int
#define rep(i,n) for (int i = 0; i < n; i++)
#define repk(i,k,n) for (int i = k; i <= n; i++)
#define repr(i,k,n) for (int i = k; i >= n; i--)
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef set<int> si;


void solve() {
	ll m, n;
	cin >> m >> n;
	char arr[m][n];
	rep(i, m) {
		rep(j, n) {
			cin >> arr[i][j];
		}
	}
	ll dp[m + 1][n + 1];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for (ll i = 0; i < m; i++) {
		for (ll j = 0; j < n; j++) {
			if (arr[i][j] == '#') {
				continue;
			}
			if (j == 0 and i == 0) {
				continue;
			}
			if (i == 0) {
				dp[i][j] = dp[i][j - 1];
			}
			else if (j == 0) {
				dp[i][j] = dp[i - 1][j];
			}
			else {
				dp[i][j] = (dp[i][j] % MOD + dp[i - 1][j] % MOD + dp[i][j - 1] % MOD) % MOD;
			}
		}
	}
	cout << dp[m - 1][n - 1] << endl;
}

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

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

}






Measured memory_bytes: 12392
#include <stdio.h>
#include <inttypes.h>

uint64_t soinsu[32];
int soinsuNum[32];
int soinsuCount = 0;

int search(int idx, uint64_t A, uint64_t B) {
	if (idx >= soinsuCount) {
		int Acnt = 0, Bcnt = 0;
		while (A > 0) Acnt++, A /= 10;
		while (B > 0) Bcnt++, B /= 10;
		return Acnt >= Bcnt ? Acnt : Bcnt;
	} else {
		int i;
		int result = 9999;
		for (i = 0; i <= soinsuNum[idx]; i++) {
			uint64_t newA = A, newB = B;
			int j;
			int candidate;
			for (j = 0; j < soinsuNum[idx]; j++) {
				if (j < i) newA *= soinsu[idx]; else newB *= soinsu[idx];
			}
			candidate = search(idx + 1, newA, newB);
			if (candidate < result) result = candidate;
		}
		return result;
	}
}

int main(void) {
	uint64_t N;
	uint64_t d;
	if (scanf("%" SCNu64, &N) != 1) return 1;
	for (d = 2; d * d <= N; d++) {
		if (N % d == 0) {
			soinsu[soinsuCount] = d;
			soinsuNum[soinsuCount] = 0;
			while (N % d == 0) {
				N /= d;
				soinsuNum[soinsuCount]++;
			}
			soinsuCount++;
		}
	}
	if (N > UINT64_C(1)) {
		soinsu[soinsuCount] = N;
		soinsuNum[soinsuCount] = 1;
		soinsuCount++;
	}
	printf("%d\n", search(0, 1, 1));
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

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

		String str[] = br.readLine().split(" ");

		int r = Integer.parseInt(str[0]);
		int d = Integer.parseInt(str[1]);
		int x = Integer.parseInt(str[2]);

		for (int i = 0; i < 10; i++) {
			x = r * x - d;
			System.out.println(x);
		}
	}
}


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

using namespace std;

template <class T> T abs(T x) { return x < 0 ? -x : x; }

int main() {
  int n;
  scanf("%d", &n);
  int st = 0, sx = 0, sy = 0;
  for (int i = 0; i < n; ++i) {
    int t, x, y;
    scanf("%d %d %d", &t, &x, &y);
    int nt = st + abs(x - sx) + abs(y - sy);
    if (nt > t || (t - nt) % 2 == 1) {
      puts("No");
      return 0;
    }
    st = t;
    sx = x;
    sy = y;
  }
  puts("Yes");
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>

int main() {
  intmax_t dp[110] = {};
  int l, k;
  scanf("%d %d", &l, &k);

  dp[1] = 1;
  dp[k] = 1;
  for (int i=1; i+2<=l; ++i) {
    dp[i+1+1] += dp[i];
    if (i+1+k <= l)
      dp[i+1+k] += dp[i];
  }
  intmax_t res = 0;
  for (int i=0; i<=l; ++i) res += dp[i];
  printf("%jd\n", res);
}



Measured memory_bytes: 2712
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i=1;i<=s.size();i++){
        if (s[i]==s[i-1]){
            ans += 1;
            if (s[i-1]=='0') s[i]= '1'; 
            else s[i]= '0';
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 512
S=input()
flag=0
if S[0]=="A":
    pass
else:
    flag=1
#print(S)
S=S[1:]
#print(S)
if S[1:-1].count("C")==1:
    pass
else:
    flag=1
#print(S[1:-1])
#print(A)
list1=[]
for i in range(len(S)):
    if S[i]=="C":
        pass
    else:
        list1.append(S[i])
if len(S)==len(list1)+1:
    if "".join(list1).islower()==True:
        pass
    else:
        flag=1
else:
    flag=1
    
if flag==0:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   ll N;
   ll a[5];
   cin >> N;
   for (int i = 0; i < 5; i++) cin >> a[i];
   ll ans = 0;
   if (N % a[0] == 0) ans = N / a[0];
   else ans = N / a[0] + 1;

   for (int i = 1; i < 5; i++) {
      if (a[i - 1] < a[i]) ans += 1;
      else {
         if (N % a[i] == 0) ans = max(ans + 1, i + N / a[i]);
         else ans = max(ans + 1, i + N / a[i] + 1);
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    map<pii, int> mp; // 先頭, 末尾
    rep3(i, 1, n + 1) {
        ++mp[{to_string(i)[0] - '0', i % 10}];
    }
    
    ll ans = 0;
    rep3(i, 1, 10) rep3(j, 1, 10) {
        ans += mp[{i, j}] * 1LL * mp[{j, i}];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
const ll MOD = 1e9+7;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

int main(){
    int N,M; cin>>N>>M;
    vvi graph(M,vi(2));
    rep(i,M){
        rep(j,2){
            cin>>graph[i][j];
        }
    }
    
    vi vec(N);
    rep(i,N){
        vec[i]=i+1;
    }

    int ans =0;
    do{
        int ok =0;
        rep(i,N-1){
            rep(j,M){
                if((vec[i]==graph[j][0] && vec[i+1]==graph[j][1])|| (vec[i]==graph[j][1] && vec[i+1]==graph[j][0])) ok++;
            }
        }
        if(ok==N-1) ans++;

    } while(next_permutation(vec.begin() +1, vec.end()));

    cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m = map(int, input().split())

hito = []
chk =[]
hito = [[int(i) for i in input().split()] for _ in range(n)]
chk = [[int(i) for i in input().split()] for _ in range(m)]
#print ('hito',hito)
#print ('chk',chk) 

for i in range(n):
  a = hito[i][0]
  b = hito[i][1]
  min = 9999999999
  min_j = 0
  for j in range(m):
    c = chk[j][0]
    d = chk[j][1]
    ans =  abs(a - c) + abs(b - d)
    if min > ans:
      min = ans
      min_j = j
  print(min_j + 1)


Measured memory_bytes: 3064
// 
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif





int n;
cin>>n;

string s;
cin>>s;

if(n==s.length() or n>s.length()){
	cout<<s<<endl;
}
else{
	//int x=0;
	for (int i = 0; i <n; ++i)
	{
		/* code */
		cout<<s[i];
		//x=i;
	}

	cout<<"..."<<endl;
}

return 0;
}












Measured memory_bytes: 3592
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

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

func main() {
	s := readString()
	for i := len(s) - 1; i >= 0; i-- {
		if i%2 == 0 && (s[:i/2]+s[:i/2] == s[:i]) {
			fmt.Println(i)
			os.Exit(0)
		}
	}
}


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

int main(){
  int n,m;
  int i,j,k;
  ll x[100006];
  ll y[100006];
  ll a,b;
  ll ans = 0;

  scanf("%d %d", &n, &m);

  for(i = 1;i <= n;i++) scanf("%lld", &x[i]);
  for(i = 1;i <= m;i++) scanf("%lld", &y[i]);

  a = 0; b = 0;
  for(k = 1;k <= n;k++){
    a = (a + ((2*k - n - 1)*x[k]) % MODSIZE) % MODSIZE;
  }

  for(k = 1;k <= m;k++){
    b = (b + ((2*k - m - 1)*y[k]) % MODSIZE) % MODSIZE;
  }

  printf("%lld\n", a*b % MODSIZE);



  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cctype>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i = 0 ; i < (int)(n) ; i++)
#define f first
#define s second
#define mp make_pair
typedef pair<int, string>P;

//top, front, right, left, back, bottom;
string table[24] = {"012345","024135","043215","031426",
		    "103254","135024","152304","120534",
		    "201453","215043","254103","240513",
		    "304152","345012","351402","310542",
		    "402351","425031","453201","430521",
		    "513240","534120","542310","521430"};

P selectDice[8];
string face[8];
bool ok;
bool used[8];

bool check(int d1, int s1, int d2, int idx, int s2){
   char c1 = face[selectDice[d1].f][((int)selectDice[d1].s[s1]-'0')];
   char c2 = face[d2][((int)table[idx][s2]-'0')];
   if((isupper(c1) && isupper(c2)) || (islower(c1) && islower(c2)))return false;
   return (c1 - 32 == c2) || (c1 == c2 - 32);
} 

void dfs(int index){
   if(ok)return;
   
   if(index==8) ok = true;
   
   else{
      for(int i = 0 ; i < 8 ; i++){
	 if(used[i])continue;
	 used[i] = true;
	 for(int j = 0 ; j < 24 ; j++){
	    if(index==1 && !check(0, 2, i, j, 3))continue;
	    if(index==2 && !check(0, 1, i, j, 4))continue;
	    if(index==3 && (!check(1, 1, i, j, 4) || !check(2, 2, i, j, 3)))continue;
	    if(index==4 && !check(0, 5, i, j, 0))continue;
	    if(index==5 && (!check(1, 5, i, j, 0) || !check(4, 2, i, j, 3)))continue;
	    if(index==6 && (!check(2, 5, i, j, 0) || !check(4, 1, i, j, 4)))continue;
	    if(index==7 && (!check(3, 5, i, j, 0) || !check(5, 1, i, j, 4) || !check(6, 2, i, j, 3)))continue;
	    
	    selectDice[index] = mp(i, table[j]);
	    dfs(index+1);
	 }
	 used[i] = false;
      } 
   }
}

string solve(){
   ok = false;
   memset(used,false,sizeof(used));
   dfs(0);
   return ok ? "YES" : "NO";
}

int main(){
   while(cin >> face[0]){
      if(face[0]=="0")break;
      
      for(int i = 1 ; i < 8 ; i++) cin >> face[i];
	
      cout << solve() << endl;
   }
   return 0;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  REP(i, N){
    cin >> x[i];
  }
  int ans = INF;
  REP(i, N-K+1){
    int time;
    if(x[i] >= 0 || x[i+K-1] <= 0){
      time = max(abs(x[i]), abs(x[i+K-1]));
    }
    else{
      time = min(abs(x[i]), abs(x[i+K-1]))*2 + max(abs(x[i]), abs(x[i+K-1]));
    }
    ans = min(ans, time);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
 using namespace std ;
 int main()
{
short int c=0;
char s[3];

cin>>s;

if(((s[0]=='a')&&(s[1]=='b')&&(s[2])=='c')||
  ((s[0]=='a')&&(s[1]=='c')&&(s[2])=='b')||
  
((s[0]=='b')&&(s[1]=='a')&&(s[2])=='c')||
((s[0]=='b')&&(s[1]=='c')&&(s[2])=='a')||

((s[0]=='c')&&(s[1]=='b')&&(s[2])=='a')||
((s[0]=='c')&&(s[1]=='a')&&(s[2])=='b'))

 cout<<"Yes";
else
cout<<"No";

}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main()
{
    	string s;
    	cin >> s;
    	int n = s.length();
    	
		bool isPal = true;
		
		for(int i = 0;i < n;i++) {
			if(s[i] != s[n-1-i]) {
				isPal = false;
			}
		}
		
		for(int i=0;i < (n-1)/2;i++) {
			if(s[i] != s[(n-1)/2-1-i]) {
				isPal = false;
			}
		}
		
		(isPal)? cout << "Yes" : cout << "No";
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 90000000000000000;
int PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

ll z = 0;

int main(){
  string S,T;cin >> S >> T;
  int s = S.size(),t = T.size();
  bool frag = false;
  if(t > s){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i = s-1;i >= t - 1;i--){
    bool F = 1;
    for(int j = 0;j < t;j++){
      if(S[i-t+j+1] != T[j]){
        if(S[i-t+j+1] != '?'){
          F = 0;
        }
      }
      //cout << S[i-t+j+1];
    }
    //cout << endl;
    if(F){
      for(int j = 0;j < t;j++){
        S[i-t+j+1] = T[j];
      }
      frag = 1;
      break;
    }
  }
  for(int i = 0;i < s;i++){
    if(S[i] == '?'){
      S[i] = 'a';
    }
  }
  if(frag){
    cout << S << endl;
  }else{
    cout << "UNRESTORABLE" << endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
int main() {
	int x, y,i;
	vector<int> s;
	s.resize(12);
	s[0] = 0;
	s[1] = 31;
	s[2] = 29;
	s[3] = 31;
	s[4] = 30;
	s[5] = 31;
	s[6] = 30;
	s[7] = 31;
	s[8] = 31;
	s[9] = 30;
	s[10] = 31;
	s[11] = 30;
	while (cin >> x >> y) {
		if (x == 0)break;
		for (i = 0; i < x; i++) {
			y += s[i];
		}
	    if (y % 7 == 1) {
			cout << "Thursday" << endl;
		}
		else if (y % 7 == 2) {
			cout << "Friday" << endl;
		}
		else if (y % 7 == 3) {
			cout << "Saturday" << endl;
		}
		else if (y % 7 == 4) {
			cout << "Sunday" << endl;
		}
		else if (y % 7 == 5) {
			cout << "Monday" << endl;
		}
		else if (y % 7 == 6) {
			cout << "Tuesday" << endl;
		}
		else if (y % 7 == 0) {
			cout << "Wednesday" << endl;
		}
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n - 1);
  for (int& a : A)
    cin >> a;
  vector<int> num(n, 0);
  for (int a : A)
    ++num[a - 1];
  for (int m : num)
    cout << m << "\n";

  return 0;
}


Measured memory_bytes: 4468
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			for(int i=n-1;i>=2;i--){
				boolean flag=true;
				for(int j=2;j<Math.sqrt(i)+1;j++){
					if(i%j==0){
						flag=false;
						break;
					}
				}
				if(flag||i==2){
					System.out.print(i+" ");
					break;
				}
			}
			for(int i=n+1;;i++){
				boolean flag=true;
				for(int j=2;j<Math.sqrt(i)+1;j++){
					if(i%j==0){
						flag=false;
						break;
					}
				}
				if(flag){
					System.out.println(i);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 17172
import math

def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)


K = int(input())

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += gcd(i, j, k)
print(ans)


Measured memory_bytes: 68148
target = input()
rev = target[::-1]
n = 0
prev = n
result = "YES"
while(n<len(rev)):
    for i in ["maerd", "esare", "resare", "remaerd"]:
        if rev[n:n+len(i)] == i:
            n += len(i)
    if prev == n:
        result = "NO"
        break
    prev = n
print(result)

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

using namespace std;

const int maxn=1e5+500;
long long a[maxn];

int main()
{
	long long n,x;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	long long cnt=0;
	for(int i=0;i<n;i++){
		x-=a[i];
		if(x<0){
			cnt++;
		
		}
	}
	if(cnt>0)
	cout<<n-cnt;
	else if(x>0)
	cout<<n-1;
	else
	cout<<n;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    string s=in<string>();
    vector<int> str;
    REP(i,N){
        str.pb(s[i]-'a');
    }
    int cnt_1;cnt_1=0;
    ll k;k=1;
    REP(i,26){
        if(count(all(str),i)==1){
            cnt_1++;
        }else if(count(all(str),i)>1){
            k=k*(count(all(str),i)+1);
            k%=MOD;
        }
    }
    ll ans;ans=1;
    REP(i,cnt_1){
        ans*=2;
        ans%=MOD;
    }
    ans*=k;
    ans%=MOD;
    if(ans>1){
        ans--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 972
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N;i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define INF 1 << 28

inline void chmax(int &a,int b) {
  a = max(a,b);
}

inline void chmin(int &a,int b) {
  a = min(a,b);
}

int main()
{
  int W, H, N, cnt = 0;
  int A, B;
  int x, y;
  cin >> W >> H >> N;--N;
  cin >> x >> y;
  while(N--) {
    cin >> A >> B;
    while(x < A && y < B) {
      cnt++,x++,y++;
    }
    while(x > A && y > B) {
      cnt++,x--,y--;
    }
    while(x < A) {
      cnt++,x++;
    }
    while(x > A) {
      cnt++,x--;
    }
    while(y < B) {
      cnt++,y++;
    }
    while(y > B) {
      cnt++,y--;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3068
Module Module081A

    Sub Main(ByVal args() As String)
        Dim result As Integer
        Dim Input As String
        Dim i As Integer
        Input = Console.ReadLine()

        For i = 1 To 3
            If Input(i - 1) = "1" Then
                result = result + 1
            End If
        Next

        Console.Write(result)
    End Sub
End Module


Measured memory_bytes: 19792
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int M;
bool used[114514];
bool x[114514];
bool s[114514];
int depth[114514];
vector<int> es[114514];
vector<pii> check, ans;

bool Dfs(int v, int p) {
  depth[v] = depth[p]+1;
  used[v] = true;
  bool ret = 0;
  //cout << "v-" << v << endl;
  for (int u : es[v]) {
    if (used[u]) {
      if (p == u) continue;
      if (depth[u] > depth[v]) continue;
      //cout << u<< ",,,"<<v<< endl ;
      check.eb(pii(v, u));
      continue;
    }

    ret ^= 1^Dfs(u, v);
  }
  x[v] = ret;
  return ret;
}

void Dfs2(int v, int p) {
  used[v] = true;
  for (int u : es[v]) {
    if (used[u]) continue;

    Dfs2(u, v);
    s[v] ^= s[u];
  }
  x[v] ^= s[v];
  if (v != p) {
    if (x[v]) ans.eb(pii(v, p));
    else ans.eb(pii(p, v));
  }
}


signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    es[a].eb(b);//insert(b);
    es[b].eb(a);//insert(a);
  }

  if (M%2) {
    puts("-1");
    return 0;
  }

  Dfs(0, 0);
  for (auto &p : check) {
    s[p.X] ^= 1;
    //cout << p.X << " ;" << p.Y << endl;
    ans.eb(p);
  }
  fill(used, used+N, false);
  Dfs2(0, 0);
  if (x[0]) {
    puts("-1");
    return 0;
  }

  //cout << ans.size() << endl;
  assert(ans.size() == M);
  rep(i, M) {
    cout << ans[i].X+1 << " " << ans[i].Y+1 << endl;
  }
}


Measured memory_bytes: 16628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = sc.nextInt();
		int W = sc.nextInt();

		int ans = 0;

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

			int A = sc.nextInt();
			int B = sc.nextInt();

			if(H <= A && W <= B) {
				ans++;
			}

		}


		System.out.println(ans);

	}

}

Measured memory_bytes: 26708
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string l;
const int maxn=1e5+5;
ll dp[maxn];
const int mod=1e9+7;
int main()
{
    ll s=1;
    cin>>l;
    dp[0]=1;
    int len=l.size();
    for(int i=1;i<len;i++)
    {
        dp[i]=dp[i-1]*3%mod;
    }
    ll ans=0;
    for(int i=0;i<len;i++)
    {
        if(l[i]=='1')
        {
            ans=(ans+dp[len-i-1]*s)%mod;
            s=2*s%mod;
        }
    }
    ans=(ans+s)%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
	int main(){
		int a,b,p,m;
		scanf("%d %d",&a,&b);
		m=a*b;
		p=(a+b)*2;
		if(1<=a,b<=100){
		printf("%d %d\n",m,p);
		}
		return 0;
	}



Measured memory_bytes: 2624
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 #define PI 3.141592653
using namespace std;

vector<int> adj[200001];
bool vis[200001];
ll inc[200001];

void dfs(int s){
	for(auto x: adj[s]){
		if(vis[x] == 0){
			inc[x] += inc[s];
			vis[x] = 1;
			dfs(x);
		}
	}
}


void solve(){
	int n; cin>>n;
	int q; cin>>q;
	for(int i=0; i<n-1; i++){
		int x,y; cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	for(int i=0; i<q; i++){
		ll p, x;
		cin>>p>>x;
		inc[p] += x;
	}
	vis[1] = 1;
	dfs(1);
	for(int i=1; i<=n; i++) cout<<inc[i]<<" ";



}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}


Measured memory_bytes: 21376
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll H,W,N,c=0;
  cin>>H>>W>>N;
  ll a[N];
  ll ans[H][W];
  for(ll i=0;i<N;i++) cin>>a[i];

  for(ll i=0;i<H;i++){
    for(ll j=0;j<W;j++){
      if(a[c]==0) c++;
      if(i%2==0) ans[i][j]=c+1;
      else ans[i][W-j-1]=c+1;
      a[c]--;
    }
  }
  for(ll i=0;i<H;i++){
    for(ll j=0;j<W;j++){
      cout<<ans[i][j];
      if(j!=W-1) cout<<" ";
    }
    cout<<endl;
  }
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{  
            int a,b,c,d,k;

            while(~scanf("%d",&k))
            {   d=k%10;
                c=(k/10)%10;
                b=(k/100)%10;
                a=(k/1000)%10;
                if(a+b+c+d==7) {printf("%d+%d+%d+%d=7\n",a,b,c,d);return 0;}
                if(a+b-c+d==7) {printf("%d+%d-%d+%d=7\n",a,b,c,d);return 0;}
                if(a+b-c-d==7) {printf("%d+%d-%d-%d=7\n",a,b,c,d);return 0;}
                if(a+b+c-d==7) {printf("%d+%d+%d-%d=7\n",a,b,c,d);return 0;}
                if(a-b+c+d==7) {printf("%d-%d+%d+%d=7\n",a,b,c,d);return 0;}
                if(a-b-c+d==7) {printf("%d-%d-%d+%d=7\n",a,b,c,d);return 0;}
                if(a-b+c-d==7) {printf("%d-%d+%d-%d=7\n",a,b,c,d);return 0;}
                if(a-b-c-d==7) {printf("%d=%d-%d-%d=7\n",a,b,c,d);return 0;}



            }



}

Measured memory_bytes: 128
import sys
import math
import collections
import bisect
import itertools
import decimal

# import numpy as np

# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===


class UnionFind():
    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 size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n = ni()
    a = na()

    tmp = len(a)

    # 素数列挙
    def Eratosthenes(n):  # N以下のすべての値に対して素数を返す
        a = [[] for _ in range(n + 1)]
        if n >= 2:
            for i in range(2, n + 1):
                if len(a[i]) == 0:
                    for j in range(i, n + 1, i):
                        a[j].append(i)
        return a

    l = max(a)
    p = Eratosthenes(l)
    cnt = [0 for _ in range(l + 1)]

    pc = True
    tc = True

    for ai in a:
        for pi in p[ai]:
            cnt[pi] += 1
            if cnt[pi] >1:
                pc = False
            if cnt[pi] == n:
                tc = False
                break


    if pc:
        print("pairwise coprime")
    elif tc:
        print("setwise coprime")
    else:
        print("not coprime")

if __name__ == '__main__':
    main()


Measured memory_bytes: 303840
#include <iostream>
#include <math.h>

int main(void) {
	long int in;
	long int i = 2;
	std::cin >> in;
	std::cout << in << ":";
	while (in != 1) {
		if (i > sqrt(in)) {
			std::cout << " " << in;
			break;
		} else if (in % i != 0) {
			i += 1;
		} else {
			in = in / i;
			std::cout << " " << i; 
			i = 2;
		}
	}
	std::cout << std::endl;
}

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

Measured memory_bytes: 580
# include <string.h>
# include <iostream>
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
	float N = 0;

	float Ans = 0.00000000;
	
	cin >> N;
	int test = N;
	
	if ( N == 1 ) {
		Ans = 1.0;
	} // 
	
	else if ( test % 2 == 0 ) {
		Ans = 0.5;
	} // else if
	
	else {
		Ans = ( ( N / 2 ) + 0.5 ) / N;
	} // else
	
	cout << Ans; 
  
} // main()

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> t(n);
    REP(i,n) cin >> t[i];
    int m;cin>>m;
    int p,x;
    REP(i,m){
        cin >> p >> x;
        --p;
        int sum = 0;
        REP(j,n){
            if(j==p){
                sum+=x;
            } else {
                sum+=t[j];
            }
        }
        cout << sum << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m = map(int, input().split())
ab = []
for _ in range(m):
    a,b = map(int, input().split())
    if a==1:
        ab.append(b)
    elif b==n:
        ab.append(a)
print('POSSIBLE' if len(ab)-len(set(ab)) != 0 else 'IMPOSSIBLE')

Measured memory_bytes: 23288