akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
	int W,H,N;
  	cin>>W>>H>>N;
  
  	int x1=0;int x2=W; int y1=0; int y2=H;
  
  	for (int i=0;i<N;i++){
    	int a,b,c;
      	cin>>a>>b>>c;
      	if(c==1 && x1<a){
        	x1=a;
        }
      	if(c==2 && x2>a){
        	x2=a;
        }
      	if(c==3 && y1<b){
        	y1=b;
        }
      	if(c==4 && y2>b){
        	y2=b;
        }
      
      }
    if(x2<x1 || y2<y1){
      	cout<<0<<endl;
      }else{
      	cout<<(x2-x1)*(y2-y1)<<endl;
    }
}    

Measured memory_bytes: 256
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    
    for h in range(H) :
        for w in range(W) :
            if (h + w) % 2 == 0 :
                print("#", end="")
            else :
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7008
n = gets.to_i
a = gets.chomp.split
n.times do |i|
  a[i] = a[i].to_i
end

result = true
n.times do |i|
  if a[i].even? && (a[i] % 3 != 0 && a[i] % 5 != 0)
    result = false
    break
  end
end

if result
  puts "APPROVED"
else
  puts "DENIED"
end

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

char s[210];
char t[110];
int main(){
	scanf("%s%s",s,t);
	ll n=strlen(s);
	rep(i,0,n){
		if(!strcmp(s+i,t)){
			puts("Yes");
			return 0;
		}
		s[n+i]=s[i];
	}
	puts("No");
}

Measured memory_bytes: 128
import numpy as np


K, T = map(int, input().split())
A = list(map(int, input().split()))
A = [(a, i) for i, a in enumerate(A)]

def main():
    if len(A) < 2:
        return K - 1
    s = -1
    answer = 0
    for k in range(K):
        A.sort(reverse=True)
        a, i = A[0]
        b, j = A[1]

        if i != s:
            A[0] = (a - 1, i)
            s = i
            continue

        if b == 0:
            A[0] = (a - 1, i)
            s = i
            answer += 1
            continue

        A[1] = (b - 1, j)
        s = j
    return answer

print(main())


Measured memory_bytes: 21268
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
ll M=1e9+7;
ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll findGCD(ll arr[], ll n) 
{ 
    ll result = arr[0]; 
    for (ll i = 1; i < n; i++)
        result = gcd(arr[i], result); 
  
    return result; 
} 
ll powmp(ll x, ll y, ll p) 
{ 
    ll res = 1;     x = x % p;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 
bool OK(ll key, ll k, ll a[], ll f[], ll n)
{
    ll k1=k;
    f(i,0,n)
    {
        ll t=a[i]*f[i];
        if(t>key) k1 = k1 - (t-key+f[i]-1)/f[i];
    }
    return k1>=0;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,k; cin>>n>>k;
    ll a[n],f[n];
    f(i,0,n) cin>>a[i];
    f(i,0,n) cin>>f[i];
    sort(a,a+n);
    sort(f,f+n,greater<int>());
    ll maxx=0;
    f(i,0,n) maxx=max(maxx,a[i]*f[i]);
    ll left=-1,right=maxx;
    while(right-left>1)
    {
        ll mid = (left+right)/2;
        if(OK(mid,k,a,f,n)) right=mid;
        else left=mid;
    }

    cout<<right<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int hour;
    cin >> hour;
    cout << 24 + (24 - hour) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define PMAX 1000000000
int wmax=0;
int n,k,w[100000];
  
int check(int P){
    int i;
    int count=1,now=P;
    if(P<wmax) return 0;
    for(i=0;i<n;i++){
        if(now>=w[i]){
           now-=w[i];
        }else{
            count++;
            now=P-w[i];
        }
    }
    if(count>k) return 0;
    else return 1;
}
  
int main(void){
    int i;
    int left,right,mid;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
        if(w[i]>wmax) wmax=w[i];
    }
  
    left=0,right=PMAX;
    while(right-left>1){
        mid=(left+right)/2;
        if( check(mid) ) right=mid;
        else left=mid;
    }
    printf("%d\n",right);
    return 0;
}
  

Measured memory_bytes: 984
s = input()
t = input()

a = list(s)
b = list(t)

answer = False

for i in range(len(a)):
    if a == b:
        answer = True
        break
    else:
        c = []
        p = a[len(a)-1]
        c.append(p)
        for j in range(len(a)-1):
            c.append(a[j])
        for h in range(len(a)):
            a[h] = c[h]

if answer:
    print('Yes')
else:
    print('No')

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

void solve(long long a, long long b){
	string str(to_string(a) + to_string(b));
	unsigned long long num = strtoull(str.c_str(), NULL, 0);

	long long val = sqrt(num);
	string out = (val * val) ==  num ? "Yes" : "No";

	cout << out << endl;
}

int main(){	
	long long a;
	long long b;
	scanf("%lld",&a);
	scanf("%lld",&b);
	solve(a, b);
	return 0;
}



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

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

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

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

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

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

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    char S[11];
    FOR(i,0,10)
        cin >> S[i];
    cout << "2018" << "/" << S[5] << S[6] << "/" << S[8] << S[9] << endl;
}


Measured memory_bytes: 256
s = input()

odd = s[::2]
even = s[1::2]

for i in odd:
    if i != "R" and i != "U" and i != "D":
        print("No")
        exit()
for i in even:
    if i != "L" and i != "U" and i != "D":
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 2940
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n;
	string s1, s2;
	cin >> n;
	cin >> s1 >> s2;
	ll ans = 1;
	int i ,prev;
	if (s1[0] == s2[0]) { i = 1; ans *= 3; prev = 1; }
	else { i = 2; ans *= 6; prev = 2; }

	for (; i < n;) {
		if (s1[i] == s2[i]) 
		{
			if (prev == 1) { ans *= 2; i += 1; if (ans >= 1000000007) ans -= 1000000007; }
			else { i += 1; prev = 1; if (ans >= 1000000007) ans -= 1000000007;
			}
		}
		else {
			if (prev == 1) { ans *= 2; i += 2; prev = 2; if (ans >= 1000000007) ans -= 1000000007;
			}
			else { i += 2; ans *= 3; if (ans >= 1000000007) ans -= 1000000007;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 2010
#define int long long
#define fir first
#define sec second
using namespace std;
typedef pair<int,int> pa;
int n, k, q, a[MAXN], b[MAXN], ans = INT_MAX;
inline int read(void) {
	int x=0,f=1;
	char c=cin.get();
	while(!isdigit(c)) {
		f=c=='-'?-1:1;
		c=cin.get();
	}
	while(isdigit(c)) {
		x=(x<<3)+(x<<1)+c-'0';
		c=cin.get();
	}
	return x * f;
}
vector<pa> V;
inline int calc(int l, int r, int MM) {
	int len = r - l + 1,mc = len - k + 1,ret = 0;
	for(int i = l; i <= r; i++) ret += (a[i] <= MM);
	return max(0LL,min(ret, mc));
}
inline bool judge(int min, int max) {
	int L = -1, R = -1;
	V.clear();
	for(int i = 1; i <= n; i++) {
		if(a[i] < min) {
			if(~L)V.push_back({L, R});
			L = -1;
			R = -1;
		} else {
			if(!~L)L = i;
			R = i;
		}
	}
	if(~L)V.push_back({L, R});
	int ret = 0;
	for(auto x : V) {
		ret += calc(x.fir, x.sec, max);
	}
	return ret >= q;
}

signed main(signed argc, char *argv[]) {
	n=read(),k=read(),q=read();
	for(int i = 1; i <= n; i++)a[i]=read();
	memcpy(b, a, sizeof(a));
	sort(b + 1, b + n + 1);
	for(int i = 1; i <= n; i++) {
		if(i + q  > n + 1)break;
		int l = i + q - 1, r = n, tmp = INT_MAX;
		while(l <= r) {
			int mid = (l + r) >> 1;
			if(judge(b[i], b[mid])) {
				tmp = b[mid] - b[i];
				r = mid-1;
			} else l=mid+1;
		}
		ans = min(ans, tmp);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTrainingCamp solver = new BTrainingCamp();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTrainingCamp {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long power = 1;
            for (int i = 1; i <= n; i++) {
                power = power * i;
                power = power % 1000000007;
            }

            out.println(power);
        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        private byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            byte b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct Bar{
	int llen,rlen,lbar,rbar,lwei,rwei;
	Bar():lwei(0),rwei(0){}
	Bar(int ll,int rl,int lb,int rb,int lw=0,int rw=0):llen(ll),rlen(rl),lbar(lb),rbar(rb),lwei(lw),rwei(rw){}
};

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

void mul(vector<Bar>& bars,int root,int n)
{
	if(root==-1) return;
	bars[root].lwei*=n;
	bars[root].rwei*=n;
	mul(bars,bars[root].lbar,n);
	mul(bars,bars[root].rbar,n);
}

int getweight(vector<Bar>& bars,int root)
{
	Bar& bar=bars[root];
	if(bar.lwei>0 && bar.rwei>0)
		return bar.lwei+bar.rwei;
	
	int lwei=bar.lbar==-1?1:getweight(bars,bar.lbar);
	int rwei=bar.rbar==-1?1:getweight(bars,bar.rbar);
	
	int x=lcm(bar.llen*lwei,bar.rlen*rwei);
	bar.lwei=x/bar.llen;
	bar.rwei=x/bar.rlen;
	
	if(bar.lwei!=lwei)
		mul(bars,bar.lbar,bar.lwei/lwei);
	if(bar.rwei!=rwei)
		mul(bars,bar.rbar,bar.rwei/rwei);
	
	return bar.lwei+bar.rwei;
}

int main()
{
	for(int n;cin>>n,n;){
		vector<Bar> bars(n);
		for(int i=0;i<n;i++){
			cin>>bars[i].llen>>bars[i].rlen>>bars[i].lbar>>bars[i].rbar;
			bars[i].lbar--; bars[i].rbar--;
		}
		
		int root=-1;
		{
			vector<int> ischild(n);
			for(int i=0;i<n;i++){
				if(bars[i].lbar!=-1)
					ischild[bars[i].lbar]=1;
				if(bars[i].rbar!=-1)
					ischild[bars[i].rbar]=1;
			}
			root=find(ischild.begin(),ischild.end(),0)-ischild.begin();
		}
		cout<<getweight(bars,root)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, K = il()
    ret = []
    for n in range(1, 101):
        if A % n == 0 and B % n == 0:
            ret.append(n)
    print(sorted(ret, reverse=True)[K - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 10220
import java.util.Scanner;

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

        Boolean flag = false;
        for (int i = -118; i < 120; i++) {
            for (int j = -119; j < 119; j++) {
                if (Math.pow(i, 5) - Math.pow(j, 5) == X) {
                    System.out.println(i + " " + j);
                    flag = true;
                    break;
                }
            }
            if (flag) {
                break;
            }
        }
    }
}

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

int main() {
  int n,k;
  int fn;
  fn = 1;
  cin >> n >> k;
  
  for (int i = 0; i<n;i++) { 
  if (k>=fn) {
    fn *=2;
  }
  else {
    fn += k;
  }
  }
  cout << fn << endl;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
lst = [[int(i) for i in input().split()] for i in range(n)]
nlst = sorted(lst,key= lambda x:x[0])
cnt = 0
 
for i in range(n):
    cnt += nlst[i][1]
    if cnt >= k:
        ans = nlst[i][0]
        break
    
print(ans)

Measured memory_bytes: 23640
#include<stdio.h>

int main(void){
  int i,j,k,l;
  int n1,n2;
  char data1[1000][20],data2[1000][20];
  int id1[1000],id2[1000],day1[1000],day2[1000];
  int tmp;
  int use[2][32],name[10000];

  n1 = 0;
  while(1){
    fgets(data1[n1],20,stdin);
    if(data1[n1][0] == '\n')break;
    n1++;
  }

  n2 = 0;
  while(fgets(data2[n2],20,stdin)!=NULL)n2++;

  for(i=0;i<n1;i++)id1[i] = 0;
  for(i=0;i<n2;i++)id2[i] = 0;
  for(i=0;i<n1;i++)day1[i] = 0;
  for(i=0;i<n2;i++)day2[i] = 0;

  for(i=0;i<n1;i++){
    j = 0;
    while(data1[i][j] != ',')j++;
    tmp = 1;
    for(k=0;k<j;k++){
      id1[i] += (data1[i][j-1-k] - '0') * tmp;
      tmp*=10;
    }
    j++;
    l = 0;
    while(data1[i][j+l] != '\n')l++;
    tmp = 1;
    for(k=0;k<l;k++){
      day1[i] += (data1[i][l-1-k+j] - '0') * tmp;
      tmp*=10;
    }
  }

  for(i=0;i<n2;i++){
    j = 0;
    while(data2[i][j] != ',')j++;
    tmp = 1;
    for(k=0;k<j;k++){
      id2[i] += (data2[i][j-1-k] - '0') * tmp;
      tmp*=10;
    }
    j++;
    l = 0;
    while(data2[i][j+l] != '\n')l++;
    tmp = 1;
    for(k=0;k<l;k++){
      day2[i] += (data2[i][l-1-k+j] - '0') * tmp;
      tmp*=10;
    }
  }

  for(i=0;i<n1-1;i++){
    for(j=i+1;j<n1;j++){
      if(id1[i] > id1[j]){
	tmp = id1[i];
	id1[i] = id1[j];
	id1[j] = tmp;
	tmp = day1[i];
	day1[i] = day1[j];
	day1[j] = tmp;
      }
    }
  }

  for(i=0;i<n2-1;i++){
    for(j=i+1;j<n2;j++){
      if(id2[i] > id2[j]){
	tmp = id2[i];
	id2[i] = id2[j];
	id2[j] = tmp;
	tmp = day2[i];
	day2[i] = day2[j];
	day2[j] = tmp;
      }
    }
  }
  
  for(i=0;i<10000;i++)name[i] = 0;

  for(i=0;i<n1;i++){
    for(j=0;j<n2;j++){
      if(id1[i] == id2[j]){
	if(!name[id1[i]]){
	  tmp = 0;
	  for(k=0;k<32;k++)use[0][k] = 0;
	  for(k=0;k<32;k++)use[1][k] = 0;

	  for(k=0;k<n1;k++){
	    if(id1[k] == id1[i]){
	      if(!use[0][day1[k]]){
		tmp++;
		use[0][day1[k]] = 1;
	      }
	    }
	  }
	  for(k=0;k<n2;k++){
	    if(id2[k] == id1[i]){
	      if(!use[1][day2[k]]){
		tmp++;
		use[1][day2[k]] = 1;
	      }
	    }
	  }
	  printf("%d %d\n",id1[i],tmp);
	  name[id1[i]] = 1;
	}
	j = n2;
      }
    }
  }
  

  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

typedef long long ll;

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

    ll ans = 0;
    for (ll i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            ll tmp = 0;
            while (N % i == 0) {
                N /= i;
                tmp++;
            }

            ll k ;
            for (k = 1; (k+2)*(k+1)/2 <= tmp; k++) ;

            ans += k;
        }
    }

    if (N > 1)
        ans++;

    cout << ans << endl;

    return 0;
}

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

int main(){
  long long n;
  cin >> n;
  if(n == 2){
    cout << 2 << endl;
    return 0;
  }

  while(true){
    for(int i = 2; i < n; i++){
      if(i == n-1){
        if(n % i != 0){
          cout << n << endl;
          return 0;
        } 
      }
      else{
        if(n % i == 0) break;
      }
    }
    n++;
  }

  
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
 const ll mod = 1000000007;

 int main() {
	ll N;
	cin >> N;
	vector<int> A;

	ll s = 0;
	for(int i = 0; i < N; i++){
		ll a;
		cin >> a;
		s += a;
		A.push_back(2 * a);
	}
	/* 
	for(int i = 0; i < N; i++){
		ll noti = 0;
		for (int j = i + 1; j < N + i - 1; j += 2){
			noti += A[j % N];
		}
		cout << s - noti << " ";
	}
	*/

	ll X[N];

	ll even = 0;
	// i = 0
	for (int j = 0+ 1; j < N - 1; j += 2){
			even += A[j % N];
	}
	X[0] = s - even;

	for(int i = 2; i < N; i+=2){
		even = even - A[i-1] + A[i-2];
		X[i] = s - even;
	}

	ll odd = 0;
	// i = 0
	for (int j = 1+ 1; j < N; j += 2){
		odd += A[j % N];
	}
	X[1] = s - odd;
	
	for (int i = 3; i < N; i += 2)
	{
		odd = odd - A[i - 1] + A[i - 2];
		X[i] = s - odd;
	}

	for(int i = 0; i < N; i++){
		cout << X[i] << " ";
	}


	cout << endl;

	return 0;
 }



Measured memory_bytes: 2552
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<bool> vb;
 
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()
 

bool f(vpll &z, ll n, ll s){
  ll l=1,r=n;
  reverse(all(z));
  
  for(pll p:z){
   ll w=p.first;
    if(p.second){
      if(w==-1) r=min(r+1ll,n);
      else l=max(1ll,l-1ll);
    }else{
      if(w==-1) l++;
      else r--;
    }
    if(l>r) return false;
  }
  return (l<=s&&s<=r);
}
void solve(){
  ll H,W,N,sr,sc;
  vs s(2);
  cin >> H >> W >> N >> sr >> sc >> s[0] >> s[1];
  vpll x,y;
  rep(j,0,N){
   rep(i,0,2){
     if(s[i][j]=='L') y.emplace_back(pll(-1,i));
     else if(s[i][j]=='R') y.emplace_back(pll(1,i));
     else if(s[i][j]=='U') x.emplace_back(pll(-1,i));
     else x.emplace_back(pll(1,i));
   }
  }
     
 if(f(x,H,sr)&&f(y,W,sc)) cout << "YES" << endl;
 else cout << "NO" << endl;
  
}

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

Measured memory_bytes: 10976
#include<iostream>
using namespace std;
#define MAX 100000

struct Node{
    int parent,left,right;
};

Node T[MAX];
int D[MAX],s;

int get_depth(int u, int p){
    D[u]=p;
    if(T[u].right != -1){
        get_depth(T[u].right,p);
    }
    if(T[u].left != -1){
        get_depth(T[u].left,p+1);
    }
}

void array_init(Node A[],int n){
    for(int i=0;i<n;++i){
        A[i].parent = A[i].left = A[i].right = -1;
    }
}

void print(int u){
    cout<<"node "<<u<<": parent = "<<T[u].parent<<", depth = "<<D[u]<<", ";
    if(T[u].parent == -1) cout<<"root, ";
    else if(T[u].left==-1) cout<<"leaf, ";
    else cout<<"internal node, ";
    cout<<"[";
    for(int i=0,c=T[u].left;c!=-1;i++,c=T[c].right){
        if(i) cout<<", ";
        cout<<c;
    }
    cout<<"]"<<endl;
}

int main(){
    int num,deg,left,root,child;
    cin >> s;
    array_init(T,s);
    for(int i=0;i<s;i++){
        cin >> num >> deg;
        for(int j=0;j<deg;j++){
            cin >> child;
            if(j==0){
                T[num].left=child;
            }
            else{
                T[left].right=child;
            }
            left=child;
            T[child].parent=num;
        }
    }
    for(int i=0;i<s;i++){
        if(T[i].parent==-1) root=i;
    }
    get_depth(root,0);
    for(int i=0;i<s;i++){
        print(i);
    }
    return 0;
}

Measured memory_bytes: 5840
n = int(input())
pp = list(map(int, input().split()))

# flag = True # p(i) が p(i-1) より大きいか小さいかのフラグ
count = 0
for i in range(1, n - 1):
    partial = sorted(pp[i - 1:i + 2])
    if partial[1] == pp[i]:
        count += 1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n,m;
  cin >> n >> m;
  vector<int> v[n];
  vector<vector<int>> dist(n, vector<int>(n,inf));

  rep(i,m){
    int x,y; cin >> x >> y; x--; y--;
    v[x].emplace_back(y);
  }

  rep(i,n){
    dist[i][i]=0;
    queue<int> q;
    q.push(i);
    while(!q.empty()){
      auto p = q.front(); q.pop();
      for(auto to:v[p]){
        if(dist[i][to]>dist[i][p]+1){
          dist[i][to] = dist[i][p]+1;
          q.push(to);
        }
      }
    }
  }

  int st=-1, gl=-1, c=inf;
  rep(i,n)rep(j,i){
    if(dist[i][j]+dist[j][i]<c && dist[j][i]==1){
      st = i;
      gl = j;
      c = dist[i][j]+dist[j][i];
    }
  }
  if(c==inf){cout << -1 << ln; return 0;}
  int pos = st;
  vector<int> a;
  a.emplace_back(pos);
  while(pos!=gl){
    for(auto to:v[pos]){
      if(dist[pos][gl]-1==dist[to][gl] && dist[st][pos]+1==dist[st][to]){
        pos = to;
        a.emplace_back(pos);
        break;
      }
    }
  }

  cout << a.size() << ln;
  for(auto ans:a){
    cout << ans+1 << ln;
  }
  return 0;
}

Measured memory_bytes: 4224
#include <iostream>

int main() {
  int N;  std::cin>>N;
  int ans = 0;
  for (int x = 1; x <= N; x += 2) {
    int cnt = 0;
    for (int i = 1; i <= x; ++i)
      if (x % i == 0)
        cnt++;
    if (cnt == 8)
      ans++;
  }
  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int i;
	ll y[4],n,t[4],ans=0ll;
	for(i=0; i<4; ++i){
		cin >> y[i];
	}
	for(i=1; i<4; ++i){
		y[i] = min(y[i],2*y[i-1]);
	}
	cin >> n;
	n *= 4;
	for(i=0; i<3; ++i){
		t[i] = n%2;
		n /= 2;
	}
	t[3] = n;
	for(i=0; i<4; ++i){
		ans += y[i] * t[i];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		char[][] map = new char[100][100];
		
		for(int i = 0;i < 100;i++){
			for(int j = 0;j < 100;j++){
				if(j < 50){
					map[i][j] = '#';
				}else{
					map[i][j] = '.';
				}
			}
		}
//		for(int i = 0;i < 100;i++){
//				System.out.println(map[i]);
//		}
		
		int white = 1;
		int t = 0;
		int y = 0;
		while(true){
			if(white == a){
				break;
			}
			
			if(y >= 50){
				y = 0;
				t += 2;
			}
			
			map[t][y] = '.';
			white++;
			y += 2;
		}
		
		int black = 1;
		t = 0;
		y = 51;
		while(true){
			if(black == b){
				break;
			}
			
			if(y >= 100){
				y = 51;
				t += 2;
			}
			
			map[t][y] = '#';
			black++;
			y += 2;
		}
		System.out.println(100 + " "+100);
		for(int i = 0;i < 100;i++){
			System.out.println(map[i]);
	}
		
		
		

	}



}

class UnionFind{
	int[] parent;
	public UnionFind(int N){
		this.parent = new int[N];
		for(int i = 0; i < N;i++){
			parent[i] = i;
		}
	}
	public int root(int x){			//根要素を取得
		if(parent[x] == x){			//初期状態
			return x;
		}else{
			return parent[x] = root(parent[x]);    	//再帰によって根を取得
		}
	}
	public void unite(int x,int y){ 	//統合メソッド
		if(same(x,y)){					//同じ根なら終了
			return;
		}
		int xroot = root(x);
		int yroot = root(y);
		parent[xroot] = yroot;			//統合
		return;

	}

	public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
		return(root(x) == root(y));
	}
}



class Pair implements Comparable{
	long from;		//p
	long end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return num - otherpair.num;
	}
}



Measured memory_bytes: 23764
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	if n == 1
		then putStrLn "Hello World"
		else do
			[ a, b ] <- replicateM 2 readInt
			print $ a + b

Measured memory_bytes: 508
#include <bits/stdc++.h> 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const LL MOD=1e9+7;


int main(){
    int N,A,B;
    cin>>N>>A>>B;
    cout<<min(N*A,B)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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 gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

struct Card { char suit, value; };

void trace(struct Card a[], int N){
  int i;
  FOR(i,0,N-1){
    if(i>0) cout << " ";
    cout << a[i].suit << a[i].value;
  }
  cout << endl;
}

int bubblesort(struct Card a[],int n){
  bool flag = true;
  while(flag){
    flag = false;
    FORD(i,n-1,1){
      if(a[i].value<a[i-1].value){
        swap(a[i],a[i-1]);
        flag = true;
      }
    }
  }
}

int selectionSort(struct Card a[], int n){
  FOR(i,0,n-1){
    int minj = i;
    FOR(j,i,n-1){
      if(a[j].value<a[minj].value) minj = j;
    }
    swap(a[i],a[minj]);
  }
}

int main(){
  Card c1[100], c2[100];
  int n; cin >> n;
  char c;

  FOR(i,0,n-1){
    cin >> c1[i].suit >> c1[i].value;
    c2[i] = c1[i];
  }

  bubblesort(c1,n);
  selectionSort(c2,n);

  trace(c1,n);
  cout << "Stable" << endl;
  bool flag = true;
  trace(c2,n);
  FOR(i,0,n-1){
    if(c1[i].suit!=c2[i].suit) flag = false;
  }
  if(flag) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

}


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

int main(){
    int N;
    cin >> N;
    long* a = new long[N];
    for(int i = 0; i < N ;i ++){
        cin >> a[i];
    }
    int result = 0;

    for(int i = 0; i < N; i ++){
        while(a[i] % 2 == 0){
            a[i] /= 2;
            result ++;
        }
    }
    
    cout << result << endl;  
    
    return 0;
}

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

int main(){
    int N, M, counta = 0, countw = 0;
    cin >> N >> M;
    int WA[100050];
    bool AC[100050];
    for(int i = 0; i <= N; i++){
       WA[i] = 0;
       AC[i] = false;
    }

    while(M--){
        int p;
        string S;
        cin >> p >> S;

        if(AC[p]) continue;
        if(S == "AC"){
            AC[p] = true;
            countw += WA[p];
            counta++;
        }else if(S == "WA"){
            WA[p]++;
        }
    }

    cout << counta << " " << countw << endl;
    
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const long mod = 1e9+7;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  long N, K; cin >> N >> K;
  long long ans = 0;
  vector<int> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = 0; i < N; i++) {
    long long cnt = 0, t = 0;
    for(int j = 0; j < N; j++)if(A[j] > A[i])cnt++,t+=j<i;
    ans += K*(K-1)/2%mod*cnt%mod+t*K%mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
A,B,H,M = map(int,input().split())
import math

jisin = H*30+M*(1/2)
hunsin = M*6
kakudo = max(jisin - hunsin,hunsin-jisin)
if kakudo >= 180:
    kakudo = 360-kakudo
    

c_nijo = A**2+B**2-2*A*B*(math.cos(math.radians(kakudo)))
c = math.sqrt(c_nijo)
print(c)

Measured memory_bytes: 62516
n, q = map(int, input().split())
 
children_map = [None] * n
vals = [0] * n
 
for i in range(1, n):
    a, b = map(int, input().split())
    children_map[b - 1] = a - 1
 
for j in range(q):
    p, x = map(int, input().split())
    vals[p - 1] += x
 
res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))
 
print(" ".join(res))

Measured memory_bytes: 89936
#include <bits/stdc++.h>
using namespace std;
  
int main() {
int a,b,c;cin>>a>>b>>c;
if(b<c)swap(b,c);
if(a<b)swap(a,b);
if(b<c)swap(b,c);
cout<<c<<" "<<b<<" "<<a<<endl;
}


Measured memory_bytes: 3108
use proconio::*;

fn lower_bound<F>(l: usize, r: usize, criteria: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut l = l;
    let mut r = r;
    while r - l > 1 {
        let mid = l + (r - l) / 2;
        if criteria(mid) {
            r = mid;
        } 
        else {
            l = mid;
        }
    }
    return l;
}

fn main() {
    input! {
        n: usize,
        m: usize,
        k: u64,
        a: [u64; n],
        b: [u64; m]
    }
    
    let mut sum_a = vec![0; n + 1];
    let mut sum_b = vec![0; m + 1];

    for i in 0 .. n {
        sum_a[i + 1] = sum_a[i] + a[i];
    }

    for i in 0 .. m {
        sum_b[i + 1] = sum_b[i] + b[i];
    }

    let mut ans = 0;
    
    for i in 0..=n {
        if sum_a[i] > k { break; }

        let criteria = |j: usize| -> bool {
            sum_a[i] + sum_b[j] > k
        };
        let j = lower_bound(0, m + 1, criteria);

        ans = std::cmp::max(ans, i + j);
    }

    println!("{}", ans);
}


Measured memory_bytes: 12472
#include <iostream>
#include <vector>
#include <algorithm> 
using namespace std;
 
vector<vector<int>> v(2, vector<int> (100));
 
int sum(int i, int j, int n) {
	int sum = 0;
	for (int a = 0; a <= i; ++a) {
		sum += v[0][a];
	}
 
	for (int b = i; b < n; ++b) {
		sum += v[1][b];
	}
 
	return sum;
}	
 
int main() {
	int n, res = 0;
	cin >> n;
 
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> v[i][j];
		}
	}
 
	if (n == 1) {
		res = v[0][0] + v[1][0];
	} else {
		for (int i = 0; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				res = max(res, sum(i, j, n));
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;
import java.io.*;

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in1 = br.readLine().split(" ");
    int H = Integer.parseInt(in1[0]);
    int W = Integer.parseInt(in1[1]);
    int D = Integer.parseInt(in1[2]);

    int[][] A = new int[H][W];
    int[] x = new int[H*W];
    int[] y = new int[H*W];
    
    for(int i = 0; i < H; i++){
      in1 = br.readLine().split(" ");
      A[i] = Stream.of(in1).mapToInt(Integer::parseInt).toArray();
    }

    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        --A[i][j];
        x[A[i][j]] = i;
        y[A[i][j]] = j;
      }
    }

    in1 = br.readLine().split(" ");
    int Q = Integer.parseInt(in1[0]);

    int[] L = new int[Q];
    int[] R = new int[Q];

    for(int i = 0; i < Q; i++){
      in1 = br.readLine().split(" ");
      L[i] = Integer.parseInt(in1[0]) - 1;
      R[i] = Integer.parseInt(in1[1]) - 1;
    }

    br.close();

    int[] sum = new int[H*W];

    Arrays.fill(sum, 0);

    for(int i = 0; i < D; i++){
      for(int j = i + D; j < H * W; j += D){
        sum[j] = sum[j - D] + Math.abs(x[j] - x[j - D]) + Math.abs(y[j] - y[j - D]);
      }
    }

    for(int i = 0; i < Q; i++){
      System.out.println(sum[R[i]] - sum[L[i]]);
    }
  }
}

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

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define maxn 500000
char a[maxn],b[maxn];
int s=1;
int main(){
    while(cin>>a[s]){
        s++;
    }
    for(int i=1;i<=s-1;i++){
        b[i]=a[i];
    }
    for(int i=1;i<=s/2;i++){
        swap(a[i],a[s-i]);
    }

    for(int i=1;i<=s-1;i++){
        if(a[i]=='b'){a[i]='d';continue;
        }
         if(a[i]=='d'){a[i]='b';continue;
         }
        if(a[i]=='p'){a[i]='q';continue;
        }
        if(a[i]=='q'){a[i]='p';continue;
        }
    }
    
    for(int i=1;i<=s-1;i++){
        if(a[i]!=b[i]){
            cout<<"No"<<endl;return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
"""
import sys
from collections import OrderedDict


def solve(data):
    # ?£???????1,000,000??\????????????ID?????????
    # ??????????????????????????°????????´??????????????????ID?????\??????????????????????????????????????????
    sums = OrderedDict()
    for id, p, q in data:
        if id in sums:
            sums[id] += p * q
        else:
            sums[id] = p * q
    result = [key for key, value in sums.items() if value >= 1000000]
    return result



def main(args):
    #data = []
    #data.append([1001, 2000, 520])
    #data.append([1002, 1800, 450])
    #data.append([1003, 1600, 625])
    #data.append([1001, 200, 1220])
    while True:
        num = int(input())
        if num == 0:
            break
        data = []
        for _ in range(num):
            data.append([int(x) for x in input().split(' ')])
        result = solve(data)
        if result:
            for ele in result:
                print(ele)
        else:
            print('NA')


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8420
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
s = ans = 0
MOD = 10**9+7
for b, c in zip(a, a[1:]):
    s = (s + (b % MOD)) % MOD
    ans = (ans + s * (c % MOD) % MOD) % MOD
print(ans)

Measured memory_bytes: 95596
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# A * B < N となる A, B を数える

N = int(read())
A = np.arange(1, N + 1)
B = (N - 1) // A
print(B.sum())

Measured memory_bytes: 42356
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
double find_angle(int x, int y, int z)
{


    int volume = x * x * y;

    double ans = 0;

    if (z < volume / 2) {

        double d = (x * y * y) / (2.0 * z);


        ans = atan(d);
    }
    else {

        z = volume - z;
        double d = (2 * z) / (double)(x * x * x);


        ans = atan(d);
    }

    ans = (ans * 180) / 3.14159265;

    return ans;
}

int main()
{

  ios::sync_with_stdio(0);
  cin.tie(0);
  int a,b,x;
  cin>>a>>b>>x;
  cout<<fixed<<setprecision(6)<<find_angle(a,b,x);

  return 0;
}

Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(), v.end());
  int ans = 0;
  rep(i,k) ans += v[i];
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

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


int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    bool flag = true;
    for(int i = n-2;i>=1;i -= 2){
        s.pop_back();s.pop_back();
        if(s.substr(0,i/2) == s.substr(i/2,i/2)) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        cout<<c<<'\n';
    }else if(a==c){
        cout<<b<<'\n';
    }else if(b==c){
        cout<<a<<'\n';
    }
    return(0);
}

Measured memory_bytes: 256
using System;

namespace ITP1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] card = new int[4, 14];
            int rank;
            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                rank = int.Parse(input[1]);
                switch (input[0])
                {
                    case "S":
                        {
                            card[0, rank] = 1;
                            break;
                        }
                    case "H":
                        {
                            card[1, rank] = 1;
                            break;
                        }
                    case "C":
                        {
                            card[2, rank] = 1;
                            break;
                        }
                    case "D":
                        {
                            card[3, rank] = 1;
                            break;
                        }
                }

            }
            for (int i = 0; i <= 3 ; i++)
            {
                for (int k = 1; k <=13; k++)
                {
                    if (card[i,k] != 1)
                    {
                        switch (i)
                        {
                            case 0:
                                {
                                    Console.WriteLine("S "+k);
                                    break;
                                }
                            case 1:
                                {
                                    Console.WriteLine("H "+k);
                                    break;
                                }
                            case 2:
                                {
                                    Console.WriteLine("C "+k);
                                    break;
                                }
                            case 3:
                                {
                                    Console.WriteLine("D "+k);
                                    break;
                                }
                                    
                                

                        }
                    }
                }
            }

        }
    }
}

Measured memory_bytes: 9200
N, *A = map(int, open(0).read().split())

A = sorted(enumerate(A), reverse=True, key=lambda x: x[1])

dp = [[0] * (N + 1) for _ in range(N + 1)]
for i, (p, a) in enumerate(A):
    for j in range(i + 1):
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + a * (p - j))
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a * (N - (i - j) - 1 - p))

print(max(dp[N]))

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<double> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }
    vector<vector<double>> dp(N + 1, vector<double>(N + 1));
    
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= N; j++) {
            dp[i + 1][j] += dp[i][j] * P[i];
            if (j + 1 <= N) dp[i + 1][j + 1] += dp[i][j] * (1 - P[i]);
        }
    }

    double ans = 0;
    for (int j = 0; j <= N; j++) {
        int i = N - j;
        if (i < j) continue;
        ans += dp[N][j];
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 70784