akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int solved[100005];
int penal[100005];
int sol;
int pen;

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int p;
        string s;
        cin >> p >> s;
        if (s == "AC")
        {
            if (!solved[p])
                sol++;
            solved[p] = 1;
        }
        else
        {
            if (!solved[p])
                penal[p]++;
        }
    }
    for (int i = 1; i <= n; ++i)
        if (solved[i])
            pen += penal[i];
    cout << sol _ pen;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main() {
  int t = 1;
  // cin>>t;
  while(t--) {
    int n;
    cin>>n;
    int ans;
    if(400 <= n && n < 600)
      ans = 8;
    if(600 <= n && n < 800)
      ans = 7;
    if(800 <= n && n < 1000)
      ans = 6;
    if(1000 <= n && n < 1200)
      ans = 5;
    if(1200 <= n && n < 1400)
      ans = 4;
    if(1400 <= n && n < 1600)
      ans = 3;
    if(1600 <= n && n < 1800)
      ans = 2;
    if(1800 <= n && n < 2000)
      ans = 1;
    cout<<ans;
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3632
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
 
	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

int main(){

  int sum,b,all=0,cou=0;
  vector<int> val;

  while(true){
    cin>>sum;
    if(sum==0) break;
    all=0;

    for(int i=0; i<9; ++i){
      cin>>b;
      all+=b; 
    }

    val.push_back(sum-all);
    ++cou;
  }

  for(int i=0; i<cou; ++i){
    cout << val[i] << endl;
  }

  
  return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<string> in(n);
  rep(i, n) cin >> in.at(i);
  int m;
  cin >> m;
  vector<string> out(m);
  rep(i, m) cin >> out.at(i);
  
  int ans = 0;
  rep(i, n){
    int count = 0;
    rep(j, n){
      if (in.at(j) == in.at(i)) count++;
    }
    rep(j, m){
      if (out.at(j) == in.at(i)) count--;
    }
    ans = max(ans, count);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
/*                  ___
               :                
               ;                
              :                 
              ;                 
             /                  
           o/                   
         ._/\___,                
             \                  
             /                   
             `      
	bug
*/
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

using namespace std;
#define PI 3.14159265359
#define eps 1e-8
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
const int INF = 1<<29;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

const int MOD=1000000007;
string str;

int main(){
	ios_base::sync_with_stdio(false); //Fast I/O
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("output.txt","w",stdout);	

	cin >> str;
	ll a=0,b=0,c=0;
	ll cc=1;

	for(int i=0;i<(int)str.length();i++){
		if(str[i]=='A')
			a=(a+cc)%MOD;
		else if(str[i]=='B')
			b=(b+a)%MOD;
		else if(str[i]=='C')
			c=(c+b)%MOD;
		else{
			c=(3*c+b)%MOD;
			b=(3*b+a)%MOD;
			a=(3*a+cc)%MOD;
			cc=(cc*3)%MOD;
		}
	}
	cout << c << endl;

    //cerr << tick();

	return 0;
	
}


Measured memory_bytes: 512
a = int(input())
b = int(input())
c = int(input())
x = int(input())
 
count = 0
sum = 0
tempa = 0
tempb = 0
tempc = 0
 
while tempa <= a:
  while tempb <= b:
    while tempc <= c:
      sum = tempa * 500 + tempb * 100 + tempc * 50
      if sum == x:
        count = count + 1
      tempc = tempc + 1
    tempc = 0
    tempb = tempb + 1
  tempb = 0
  tempa = tempa + 1
 
print(count)


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> count(m,0);
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int a;
            cin >> a;
            count[a-1]++;
        }
    }
    int ans=0;
    for(int i=0;i<m;i++){
        if(n==count[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
    public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
    public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}

static class MyMath
{
    static public long GCD(long a, long b) => (a < b) ? GCD(b, a) : ((b == 0) ? a : GCD(b, a % b));
    static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a);
    static private readonly long _m = 1000000000 + 7;
    static public long Mod(long val) => (val % _m + _m) % _m;
    static private long ExtGCD(long a, long b, ref long x, ref long y) => (b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0) : (ExtGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0);
    static private long ModInverseInner(long a, long dummy1 = 0, long dummy2 = 0) => ExtGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1);
    static public long ModInverse(long a) => ModInverseInner(a, 0, 0);
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        var nkq = Console.ReadLine().ToIntArray();
        int N = nkq[0];
        int K = nkq[1];
        int Q = nkq[2];

        int[] aList = ReadLines(Q).Select(line => int.Parse(line)).ToArray();

        int[] members = new int[N];

        int sub = 0;
        foreach (var x in aList)
        {
            sub += 1;
            members[x - 1] += 1;
        }

        for (int i = 0; i < N; i++)
        {
            if (K - sub + members[i] > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 3e3+5;

int dp[N][N], n, m;
pii par[N][N];
string s, t;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s >> t;
    n = s.size();
    m = t.size();
    s = '0' + s;
    t = '0' + t;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i] == t[j]) {
                dp[i][j] = 1 + dp[i-1][j-1];
                par[i][j] = {i-1, j-1};
            } else if (dp[i-1][j] > dp[i][j-1]) {
                dp[i][j] = dp[i-1][j];
                par[i][j] = {i-1, j};
            } else {
                dp[i][j] = dp[i][j-1];
                par[i][j] = {i, j-1};
            }
        }
    }

    string ans = "";
    int i = n;
    int j = m;

    while (i and j) {
        if (par[i][j] == mp(i-1, j-1)) ans.pb(s[i]);
        pii p = par[i][j];
        i = p.st;
        j = p.nd;
    }

    reverse(ans.begin(), ans.end());

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 105984
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int n,m;
	cin >> n >> m;
	int a[m];
	for(int i=0; i<m; i++) cin >> a[i];

	ll dp[n+1]={0};
	dp[0] = 1;
	int p=0;
	for(int i=1; i<n+1; i++){
		if(p<m && i == a[p]){
			p++;
			continue;
		}
		if(i==1) dp[i] = dp[i-1];
		else dp[i] = (dp[i-1] + dp[i-2])%1000000007;
	}
	cout << dp[n] << endl;

}

Measured memory_bytes: 1408
N = int(input())
A = [int(x) for x in input().split()]

flag = 1
count = 0
while flag:
    flag = 0
    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            count += 1
            flag = 1

for _ in range(N):
    if _ == N-1:
        print(A[_], sep=' ',end='')
    else:
        print(A[_], sep='',end=' ')
print()
print(count)


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

const int MOD=1000000000+7;

int main(){
  int n;
  cin >> n;
  ll ans=1;
  map<int,int> mp;
  for(int i=n;i>1;--i){
    int j=i;
    int k=2;
    while(j>1){
      if(j%k==0){
        mp[k]++;
        j=j/k;
      }else{
        k++;
      }
    }
  }
  for(auto p : mp){
    ans=ans*(p.second+1)%MOD;
    ans=ans%MOD;
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())

int main(void){
  int b,r,g,c,s,t;
  while(cin>>b>>r>>g>>c>>s>>t,b+r+g+c+s+t){
    cout<<100-3*(t-s-3*r-5*b)+2*c+7*g+15*(b+r)+13*(5*b+3*r)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 998244353
typedef long long ll;
using namespace std;

set<string> ok;
ll dp[200020][3][2][3];

void brute(string s){
    if(ok.count(s)==1) return;
    ok.insert(s);
    for(int i=0;i+1<s.size();i++){
        if(s[i]==s[i+1]) continue;
        int c=0;
        for(int j=0;j<3;j++){
            if(s[i]!='a'+j&&s[i+1]!='a'+j) c=j;
        }
        string t=s;
        t[i]='a'+c;
        t[i+1]='a'+c;
        brute(t);
    }
    return;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();

    int hash=0;
    bool same=true;
    for(int i=0;i<n;i++){
        hash=(hash+s[i]%3)%3;
    }
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]) same=false;
    }
    if(same){
        cout<<1<<endl;
        return 0;
    }

    if(n==3){
        brute(s);
        cout<<ok.size()<<endl;
        return 0;
    }

    dp[0][0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int rest=0;rest<3;rest++){
            for(int f=0;f<2;f++){
                for(int last=0;last<3;last++){
                    for(int next=0;next<3;next++){
                        int adj=f;
                        if(next==last) adj=1;
                        if(i==0) adj=0;
                        int nextRest=(rest+next)%3;
                        dp[i+1][nextRest][adj][next]+=dp[i][rest][f][last];
                        dp[i+1][nextRest][adj][next]%=MOD;
                    }
                }
            }
        }
    }

    ll ans=0;
    for(int i=0;i<3;i++){
        ans=(ans+dp[n][hash][1][i])%MOD;
    }
    bool adj=false;
    for(int i=1;i<n;i++){
        if(s[i]==s[i-1]) adj=true;
    }
    if(adj) cout<<ans<<endl;
    else cout<<(ans+1)%MOD<<endl;

    return 0;
}


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

int N, K, Q;
int main(){
	cin>>N>>K>>Q;
	int score[N+1];
	int answer[Q+1];
	for(int i=1; i<=N; i++){
		score[i]=K-Q;
	}
	for(int i=1; i<Q+1; i++){
		cin>>answer[i];
		score[answer[i]]++;
	}
	for(int i=1; i<=N; i++){
		if(score[i]<=0){
			cout<<"No"<<'\n';
		}else{
			cout<<"Yes"<<'\n';
		}
	}
}

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


int main(){
	
	ll a,b;
	cin >> a >> b;
	
	ll g = __gcd(a,b);
	
	ll count =0;
		
	for(ll i =2;i*i<=g;i++){
	    
	    if( g%i == 0){
		   
		   while(g%i == 0){
			   g = g/i;
		   }      	
		 count++;	
		}		
		
	}
	
if( g > 1) count++;  
	
	cout << count + 1 <<endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    int ans = 0;
    rep (i, 0, n) {
        if (i < k) {
            if (t[i] == 'r') {
                ans += p;
            } else if (t[i] == 's') {
                ans += r;
            } else {
                ans += s;
            }
        } else {
            if (t[i] != t[i - k]) {
                if (t[i] == 'r') {
                    ans += p;
                } else if (t[i] == 's') {
                    ans += r;
                } else {
                    ans += s;
                }
            } else {
                t[i] = '.';
            }
        }
        // cout << ans << "\n";
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3736
#include<stdio.h>

int main(void){
  char s[5];

  scanf("%c %c %c %c %c", &s[0], &s[1], &s[2], &s[3], &s[4]);

  for(int i = 0; i < 5; i++)
    if(s[i] == '0')
      printf("%d\n", i+1);

  return 0;
}


Measured memory_bytes: 1732
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]

d = Counter(A).most_common()
d = d[::-1]

reCounter = 0

for i in range(len(d)):
    if d[i][0] < d[i][1]:
        reCounter += d[i][1] - d[i][0]
    if d[i][0] > d[i][1]:
        reCounter += d[i][1]
        
print(reCounter)

Measured memory_bytes: 21228
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn = 1e6 + 10;
const int inf = 1e9;

int a[maxn], max1[maxn], max2[maxn], dp[maxn];

int main () {
	ios_base::sync_with_stdio (false);
	int n;
	cin >> n;
	for (int i = 0; i < (1 << n); i++) {
		cin >> a[i];
		max1[i] = i;
		max2[i] = -1;
	}
	for (int mask = 0; mask < (1 << n); mask++) {
		for (int i = 0; i < n; i++) {
			if (mask & (1 << i)) {
				int submask = mask - (1 << i);
				if (max1[submask] != max1[mask] and max1[submask] != max2[mask]) {
					if (max2[mask] == -1 or a[max2[mask]] < a[max1[submask]])
						max2[mask] = max1[submask];
					if (a[max1[mask]] < a[max2[mask]])
						swap (max1[mask], max2[mask]);
				}

				if (max2[submask] != max1[mask] and max2[submask] != max2[mask]) {
					if (max2[submask] != -1 and a[max2[submask]] > a[max2[mask]])
						max2[mask] = max2[submask];
				}
			}
		}
	}
	for (int mask = 1; mask < (1 << n); mask++)
		dp[mask] = max (dp[mask - 1], a[max1[mask]] + a[max2[mask]]);
	for (int mask = 1; mask < (1 << n); mask++) 
		cout << dp[mask] << " ";
	cout << endl;
}


Measured memory_bytes: 16384
n = int(input())
As = input().split()
As = [int(A) for A in As]
ss = [0]
sss = 0
nd = {0: 1}
for i in range(n):
        sss += As[i]
        ss.append(sss)
        if sss in nd:
            nd[sss] += 1
        else:
            nd[sss] = 1
ans = 0
for k in nd:
    if nd[k] > 0:
        ans += (nd[k] * (nd[k] - 1) // 2)
#for i in range(0, n):
#    for j in range(i + 1, n + 1):
#        if ss[j] - ss[i] == 0:
#            ans += 1
print(ans)

Measured memory_bytes: 39644
import numpy as np


def main(n, w, items):
    dp = np.zeros((n + 1, w + 1), dtype=int)
    for i in range(1, n + 1):
        weight, value = items[i - 1]
        dp[i][:weight] = dp[i - 1][:weight]
        dp[i][weight:] = np.maximum(dp[i - 1][weight:], dp[i - 1][:w - weight + 1] + value)
    return dp[n][w]


if __name__ == '__main__':
    N, W = map(int, input().split())
    I = []
    for _ in range(N):
        I.append(tuple(map(int, input().split())))
    print(main(N, W, I))


Measured memory_bytes: 92180
#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
const int q=1000000007;
int n,x[200010],y[200010],u[200010],p=1,r,A,B,D,t[200010],s[200010];
vector<int> a[200010],v,w,b,c,d,e[200010],f[200010],g[200010];
inline int C(int n,int m)
{
	return (L)x[n]*y[m]%q*y[n-m]%q;
}
inline void dfs(int i)
{
	u[i]=1;
	w.pb(i);
	for(auto j:a[i])
	  if(!u[j])
	    dfs(j);
}
inline void dfs(int i,int j)
{
	u[i]=2;
	for(auto k:a[i])
	  if(k!=j)
	    if(u[k]==2)
	      {
		   A=i;
		   B=j;
		   D=k;
		   v.pb(k);
		   return;
		  }
		else
		  {
		   dfs(k,i);
		   if(A)
		     {
			  if(v.size()==1 || v[0]!=v[v.size()-1])
			    {
				 u[i]=3;
			     v.pb(i);
			    }
		      return;
			 }
		  }
}
inline void add(int i,int j)
{
	if(i>n)
	  {
	   b.pb(j);
	   c.pb(i-n);
	   d.pb(2);
	  }
	else
	  {
	   b.pb(i);
	   c.pb(j-n);
	   d.pb(1);
	  }
}
inline void dfs2(int i,int j)
{
	u[i]=4;
	for(auto k:a[i])
	  if(k!=j)
	    {
	     add(k,i);
	     if(u[k]!=4)
		   dfs2(k,i);
		}
	u[i]=1;
}
inline void line(int i,int j)
{
	//cout<<i<<" "<<j<<"---\n";
	e[i].pb(j);
	t[j]++;
}
inline int dp2(int i)
{
	int j,k=1;
	s[i]=0;
	for(auto l:e[i])
	  {
	   j=dp2(l);
	   k=(L)k*j%q*C(s[i]+s[l],s[l])%q;
	   s[i]+=s[l];
	  }
	s[i]++;
	  //cout<<i<<" "<<s[i]<<" "<<k<<"!!\n";
	return k;
}
inline int calc(int A,int B)
{
	dfs2(A,B);
	int i,k=b.size();
	for(i=0;i<k;i++)
	  {
	   f[b[i]].pb(i);
	   g[c[i]].pb(i);
	   //cout<<i<<" "<<b[i]<<" "<<c[i]<<" "<<d[i]<<"!!!!!!!!!!!!\n";
	  }
	for(i=0;i<k;i++)
	  if(d[i]==1)
	    {
	     for(auto j:f[b[i]])
	       if(c[j]<c[i])
	         line(i,j);
		}
	  else
	    {
	     for(auto j:g[c[i]])
	       if(b[j]<b[i])
	         line(i,j);
		}
	for(i=0;i<k;i++)
	  if(!t[i])
	    line(k,i);
	int j=dp2(k);
	//cout<<j<<"\n";
	for(i=0;i<k;i++)
	  {
	   f[b[i]].clear();
	   g[c[i]].clear();
	   e[i].clear();
	   t[i]=0;
	  }
	e[k].clear();
	b.clear();
	c.clear();
	d.clear();
	return j;
}
inline int calc()
{
	A=0;
	dfs(w[0],0);
	v.clear();
	//cout<<A<<" "<<B<<" "<<D<<"\n";
	return (calc(A,B)+calc(A,D))%q;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	x[0]=1;
	for(i=1;i<=2*n+5;i++)
	  x[i]=(L)x[i-1]*i%q;
	y[0]=y[1]=1;
	for(i=2;i<=2*n+5;i++)
	  y[i]=q-(L)q/i*y[q%i]%q;
	for(i=2;i<=2*n+5;i++)
	  y[i]=(L)y[i]*y[i-1]%q;
	for(i=1;i<=2*n;i++)
	  {
	   scanf("%d%d",&j,&k);
	   a[j].pb(k+n);
	   a[k+n].pb(j);
	  }
	for(i=1;i<=2*n;i++)
	  if(!u[i])
	    {
	     dfs(i);
	     k=0;
	     for(auto j:w)
	       k+=a[j].size();
	     k/=2;
	     //cout<<k<<" "<<w.size()<<" "<<r<<"----------------------------------\n";
	     if(k!=w.size())
	       {
	        p=0;
	        break;
		   }
		 p=(L)p*C(2*n-r,k)%q*calc()%q;
		 r+=k;
		 w.clear();
		}
	printf("%d\n",p);
	return 0;
}


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

using namespace std;

void dfs(vector<vector<bool>>& graph, int node, vector<int>& fin){
  int n = (int)graph.size();
  fin[node] = true;
  for(int j = 0; j < n; j++){
    if(graph[node][j] && !fin[j]){
      dfs(graph, j, fin);
    }
  }
}

bool is_bridge(vector<vector<bool>> graph, int node_a, int node_b){
  graph[node_a][node_b] = graph[node_b][node_a] = false;
  int n = (int)graph.size();
  vector<int> fin(n, false);
  dfs(graph, 0, fin);
  int ret = false;
  for(int i = 0; i < n; i++){
    if(!fin[i]) ret = true;
  }
  return ret;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  vector<vector<bool>> graph(N, vector<bool>(N));
  
  for(int i = 0; i < M; i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = 1;
  }
  
  int count = 0;
  for(int i = 0; i < M; i++){
    if(is_bridge(graph, a[i], b[i])) count++;
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int
is_prime(int x)
{
	int i, lim;

	if (x <= 1)
		return 0;

	if (x == 2)
		return 1;

	if (!(x & 1))
		return 0;

	lim = (int)sqrt(x);
	for (i = 3; i <= lim; i += 2)
		if (!(x % i))
			return 0;

	return 1;
}

int
main(void)
{
	int i, n, x, ps = 0;

	scanf("%d", &n);

	for (i = 0;i < n; i++) {
		scanf("%d", &x);
		if (is_prime(x))
			ps++;
	}

	printf("%d\n", ps);

	return 0;
}



Measured memory_bytes: 2024
# test

N = int(input())

arr=[]

for i in range(N):
    S, P = input().split()
    arr.append([i+1, S, int(P)])

arr.sort(key=lambda x: x[2], reverse=True)
arr.sort(key=lambda x: x[1])

for i in range(N):
    print(arr[i][0])



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<array>
#include<algorithm>
#include <random>
std::random_device seed_gen;
std::mt19937 engine(seed_gen());
std::uniform_int_distribution<> dD {0, 364};
std::uniform_int_distribution<> dT {1, 26};

int const INF = 1e9;
int const M = 3e5;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(int& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(int& si: s[d]) std::cin >> si;
  }
  
  // greedy
  std::vector<int> t(D);
  int ans = 0;
  int last[26];
  std::fill_n(last, 26, -1);
  for(int d = 0; d < D; ++d) {
    int ma = -INF;
    t[d] = 0;
    for(int T = 1; T <= 26; ++T) {
      int cur = s[d][T-1];
      int sv = last[T-1];
      last[T-1] = d;
      for(int cx = 0; cx < 26; ++cx) {
        cur -= (d-last[cx])*c[cx];
      }
      last[T-1] = sv;
      if(cur > ma) { ma = cur; t[d] = T; }
    }
    ans += ma;
    last[t[d]-1] = d;
  }
  
  auto score = [&]()->int {
    int ans = 0;
    int last[26];
    std::fill_n(last, 26, -1);
    for(int d = 0; d < D; ++d) {
      ans += s[d][t[d]-1];
      last[t[d]-1] = d;
      for(int cx = 0; cx < 26; ++cx) {
        ans -= (d-last[cx])*c[cx];
      }
    }
    return ans;
  };
  
  // modify
  for(int m = 0; m < M; ++m) {
    int d = dD(engine), T = dT(engine);
    int sv = t[d];
    t[d] = T;
    int new_ans = score();
    if(new_ans > ans) ans = new_ans;
    else t[d] = sv;
  }
  for(int ti: t) std::cout << ti << "\n";
  
  return 0;
}


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

const int MAX = 100;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c + b - a) << endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;

    rep (i, s.size()) {
        s += s.front();
        s.erase(s.begin());
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = [int(i) for i in input().split()]
a = x.copy()
a.sort()
mid = a[int(n/2)-1]
for i in range(n):
    if x[i] <= mid:
        ans = a[int(n/2)]
    else:
        ans = mid
    print(ans)

Measured memory_bytes: 30704
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		double X = Math.floor(N / 1.08);
		if (Math.floor(X * 1.08) == N){
			System.out.println((int)X);
		} else {
			if(Math.floor((X+1) * 1.08) == N){
				System.out.println((int)X+1);
			} else {
				System.out.println(":(");
			}
		}
	}
}

Measured memory_bytes: 21716
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
int main() {
  std::cout.tie(0); std::ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> H(N);
  for (auto& v : H)cin >> v;
  bool ans = true;
  for (int i = N - 2; i >= 0; --i) {
    if (H[i] <= H[i + 1])continue;
    if (H[i] - 1 == H[i + 1]) {
      --H[i];
      continue;
    }
    ans = false;
    break;
  }
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;

int main() {FIN
	
	int n, m = 0;
            cin >> n;
            m = (n / 500) * 1000;
            n = n % 500;
            m += (n / 5) * 5;
            cout << m << "\n";
	return 0;	
}

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

const ll N=(ll)1000*1000+7;
int prm[N];

void seive(){
    for(ll i=2;i<N;i++)
        if(!prm[i]){
            for(ll j=i;j<N;j+=i)
                prm[j]=i;
        }
}

int main(){
    seive();
    nimble;
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,0,n)cin>>a[i];
    ll x=a[0];
    rep(i,1,n)
        x=__gcd(x,a[i]);
    if(x>1){
        cout<<"not coprime";
        return 0;
    }
    int f=0;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        ll x=a[i];
        while(x>1){
            ll p=prm[x];//cout<<p<<' '<<x<<' '<<nl;
            while(x%p==0)
                x/=p;
            mp[p]++;
            if(mp[p]>1){
                f=1;
                break;
            }
        }
        if(f)break;
    }
    if(f)cout<<"setwise coprime";
    else cout<<"pairwise coprime";
    return 0;
}



Measured memory_bytes: 15072
import java.util.*;
public class Main{
  public static void main(String args[]){
  	Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int x=sc.nextInt();
    int t=sc.nextInt();
    int ans=t;
    n-=x;
    while(n>0){
      n-=x;
      ans+=t;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35556
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Maybe (fromJust)
import Debug.Trace

solve :: Int -> Int
solve n = pay - back
    where
        pay = n * 800
        back = (n `div` 15) * 200

main :: IO ()
main = do
    n <- (fst . fromJust . BS.readInt) <$> BS.getLine
    print $ solve n

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

using namespace std ;

#define N  100010

int n , L , m ;
int a[ N ] , to[ N ] ;
int num , block , belong[ N ] ; 
int nxt[ N ] , val[ N ] ;

int find( int x ) {
    int l = x + 1 , r = n , ans = 0 ;
    while( l <= r ) {
        int mid = ( l + r ) >> 1 ;
        if( a[ mid ] - a[ x ] <= L ) l = mid + 1 , ans = mid ;
        else r = mid - 1 ;
    }
    return ans ;
}

int main() {
    scanf( "%d" , &n ) ;
    for( int i = 1 ; i <= n ; i ++ ) {
        scanf( "%d" , &a[ i ] ) ;
    }
    sort( a + 1 , a + n + 1 ) ;
    scanf( "%d%d" , &L , &m ) ;
    for( int i = 1 ; i < n ; i ++ ) {
        to[ i ] = find( i ) ;
    }
    to[ n ] = n + 1 ;
    block = sqrt( n ) ;
    num = n / block ;
    if( n % block ) num ++ ;
    for( int i = 1 ; i <= n ; i ++ ) {
        belong[ i ] = ( i - 1 ) / block + 1 ;
    }
    for( int i = 1 ; i < n ; i ++ ) {
        int t = i , sp = 0 ;
        while( belong[ t ] == belong[ i ] ) {
            t=to[ t ] ;
            sp ++ ;
        }
        val[ i ] = sp ;
        nxt[ i ] = t ;
        if( i >= block * ( num - 1 ) + 1 ) val[ i ] -- , nxt[ i ] -- ;
    }
    for( int i = 1 ; i <= m ; i ++ ) {
        int x , y  , ans = 0 ;
        scanf( "%d%d" , &x ,&y ) ;
        if( x > y )swap( x , y ) ;
        while( belong[ x ] < belong[ y ] ) {
            ans += val[ x ] ;
            x = nxt[ x ] ;
        }
        while( x < y ) {
            x = to[ x ] ;
            ans ++ ;    
        } 
        printf( "%d\n" , ans  ) ;
    }
    return 0 ;
} 

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

const int MOD = 998244353;

ll pow2[11111];

ll add(ll a, ll b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}

ll mult(ll a, ll b)
{
	return (a*b)%MOD;
}

ll subt(ll a, ll b)
{
	a-=b;
	while(a<0) a+=MOD;
	return a;
}

map<pair<ll,ll>,ll> ma;
bool vis[201][201];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ii> vec;
	pow2[0]=1;
	for(int i=1;i<=10000;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
	}
	for(int i = 0; i < n; i++)
	{
		int x,y;
		cin>>x>>y;
		vec.pb(mp(x,y));
	}
	ll ans = pow2[n];
	ans = subt(ans,1); //subtract empty set
	ans = subt(ans,n); //subtract set of size 1
	for(int i = 0; i < n; i++)
	{
		for(int j = i + 1; j < n; j++)
		{
			if(vis[i][j]||vis[j][i]) continue;
			//cerr<<i<<' '<<j<<'\n';
			ll Y = vec[j].se-vec[i].se;
			ll X = vec[j].fi-vec[i].fi;
			ii gradient;
			if(X==0) 
			{
				gradient = mp(1,0);
			}
			else if(Y==0)
			{
				gradient = mp(0,1);
			}
			else
			{
				ll g = __gcd(X,Y);
				Y/=g; X/=g;
				if(X<0)
				{
					X*=-1;
					Y*=-1;
				}
				gradient = mp(Y,X);
			}
			ll cnt=2;
			vis[i][j]=vis[j][i]=1;
			vi V;
			V.pb(i); V.pb(j);
			for(int k = 0; k < n; k++)
			{
				if(k!=i&&k!=j)
				{
					ll Y2 = vec[k].se-vec[i].se;
					ll X2 = vec[k].fi-vec[i].fi;
					ii gradient2;
					if(X2==0) 
					{
						gradient2 = mp(1,0);
					}
					else if(Y2==0)
					{
						gradient2 = mp(0,1);
					}
					else
					{
						ll g2 = __gcd(X2,Y2);
						Y2/=g2; X2/=g2;
						if(X2<0)
						{
							X2*=-1;
							Y2*=-1;
						}
						gradient2 = mp(Y2,X2);
					}
					if(gradient==gradient2) 
					{
						if(!vis[i][k]&&!vis[j][k])
						{
							cnt++;
							V.pb(k);
						}
					}
				}
			}
			for(int z=0;z<V.size();z++)
			{
				for(int z2=0;z2<V.size();z2++)
				{
					vis[V[z]][V[z2]]=1;
					//cerr<<z<<' '<<z2<<'\n';
				}
			}
			//cerr<<cnt<<'\n';
			ans = subt(ans, pow2[cnt]-cnt-1);
		}
	}
	
	ans%=MOD;
	if(ans<0) ans+=MOD;
	cout<<ans<<'\n';
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

// ベルマンフォード法
template<typename T>
class BellmanFord {
    struct edge {
        int from, to;
        T cost;
    };
    const int n;
    const T ZERO, INF;
    std::vector<edge> es;
    std::vector<int> prev;
public:
    // 頂点数と零元と十分大きな値を指定して初期化
    BellmanFord(int n, T ZERO, T INF) : n(n), ZERO(ZERO), INF(INF), prev(n) {}

    // 始点、終点、コストを指定して辺を追加
    void addEdge(int from, int to, T cost) { es.push_back({from, to, cost}); }

    // 頂点sからの最短距離列を取得 (負閉路がある場合、空列を返す)
    std::vector<T> getDist(int s) {
        std::vector<T> d(n);
        std::fill(d.begin(), d.end(), INF);
        d[s] = ZERO;
        std::fill(prev.begin(), prev.end(), -1);
        for (int i = 0; i < n; i++) {
            bool update = false;
            for (int j = 0; j < es.size(); j++) {
                edge e = es[j];
                if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    prev[e.to] = e.from;
                    update = true;
                }
            }
            if (!update) return d;
        }
        return std::vector<T>();
    }

    // 頂点tへの最短路 (getDistを一度実行する必要あり)
    std::vector<int> getPath(int t) {
        std::vector<int> path;
        for (; t != -1; t = prev[t])path.push_back(t);
        reverse(path.begin(), path.end());
        return path;
    }
};


int N, M, P;
int A[110000], B[110000], C[110000];
vector<pint> G[110000];
bool visited[110000];
BellmanFord<int> bf(5500, 0, 1e11);

void dfs(int v) {
    visited[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        bf.addEdge(G[v][i].first, v, G[v][i].second);
        if (!visited[G[v][i].first])dfs(G[v][i].first);
    }
}

signed main() {
    cin >> N >> M >> P;
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
        G[B[i]].push_back(pint(A[i], P - C[i]));
    }
    dfs(N);
    vint d = bf.getDist(1);
    if (d.empty())cout << -1 << endl;
    else cout << max(0LL, -d[N]) << endl;
}

Measured memory_bytes: 4864
N,K = map(int,input().split())

A = list(map(int,input().split()))

sa = [0]

for i in range(N):

    if i == 0:
        sa.append(A[0] % K)
    else:
        sa.append((sa[-1] + A[i]) % K)


#print (sa)
nm = 1
for i in range(N):
    i += 1

    if sa[i] < nm:
        sa[i] += K
    sa[i] -= nm
    nm += 1
    nm %= K

#print (sa)

ndic = {}

ans = 0
for i in range(N+1):

    if sa[i] in ndic:
        ans += ndic[sa[i]]
        ndic[sa[i]] += 1
    else:
        ndic[sa[i]] = 1

    if i - (K-1) >= 0:
        ndic[sa[i-(K-1)]] -= 1

print (ans)


Measured memory_bytes: 116864
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>

#define BIG 998244353
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)

using namespace std;

typedef struct Node{
    vector<long long> weight;
    vector<short> connected;
} node;

long long maxscore = LLMIN;


int main() {
    int n,m;
    cin >> n >> m;
    vector<node> graph(n,{vector<long long>(),vector<short>()});
    for(int i = 0;i < m;++i){
        int a,b,c;
        cin >> a >> b >> c;
        --a;
        --b;
        graph[a].connected.push_back(b);
        graph[a].weight.push_back(c);
    }
    vector<long> scores(n,LLMIN);
    set<short> nexts;
    scores[0] = 0;
    nexts.insert(0);
    for(int i = 0;i < n * 2;++i){
        set<short> nnexts;
        for(auto j = nexts.begin();j != nexts.end();++j){
            for(int k = 0;k < graph[(*j)].connected.size();++k){
                long ns = scores[(*j)] + graph[(*j)].weight[k];
                if(scores[graph[(*j)].connected[k]] < ns){
                    scores[graph[(*j)].connected[k]] = ns;
                    nnexts.insert(graph[(*j)].connected[k]);
                    if(i >= n && graph[(*j)].connected[k] == n - 1){
                        cout << "inf" << endl;
                        return 0;
                    }
                }
            }
        }
        nexts = nnexts;
    }
    cout << scores[n - 1] << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using pdd = pair<double,double>;
auto dif(pdd x, pdd y){
    return hypot(x.first - y.first, x.second - y.second);
}
signed main(){
    pdd x,y,z;
    cin >> x.first >> x.second;
    cin >> y.first >> y.second;
    cin >> z.first >> z.second;
    double a = dif(x,y);
    double b = dif(y,z);
    double c = dif(z,x);
    double r = abs((y.first - x.first)*(z.second-x.second)-(z.first-x.first)*(y.second-x.second))/(a+b+c);
    double d = max(a, max( b , c));
    double ans = d / ( 2 + d / r);
    cout << fixed << setprecision(20) << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int sx, tx , sy , ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i = 0;i< (tx - sx);i++){
        cout << 'R' ;
    }
    for(int i =0;i <(ty-sy);i++){
        cout << 'U';
    }
    
    for(int i = 0;i< (tx - sx);i++){
        cout << 'L' ;
    }
    for(int i =0;i <=(ty-sy);i++){
        cout << 'D';

    }
    for(int i = 0;i<= (tx - sx);i++){
        cout << 'R' ;
    }
    for(int i =0;i <=(ty-sy);i++){
        cout << 'U';
    }
    cout << 'L'<<'U';
    for(int i = 0;i<= (tx - sx);i++){
        cout << 'L' ;
    }
    for(int i =0;i <=(ty-sy);i++){
        cout << 'D';

    }
    cout << 'R';
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next());
        int AC =0;
        int WA =0;
        int TLE = 0;
        int RE = 0;
        while (scanner.hasNext()){
            switch (scanner.next()){
                case "AC":
                    AC++;
                    break;
                case "WA":
                    WA++;
                    break;
                case "TLE":
                    TLE++;
                    break;
                case "RE":
                    RE++;
                    break;
            }
        }
        System.out.println(
                "AC x " + AC + System.lineSeparator() +
                        "WA x " + WA + System.lineSeparator() +
                        "TLE x " + TLE + System.lineSeparator() +
                        "RE x " + RE
        );
        }
    }


Measured memory_bytes: 59184
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll dp[100100][3];

ll n,m;
ll s,t;

int main() {
	rep(i,0,100100)rep(j,0,3)dp[i][j] = 1000000000000000000LL;
	cin>>n>>m;
	vector<vector<ll> > vv(n,vector<ll>());
	rep(i,0,m){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		vv[a].pb(b);
	}
	cin>>s>>t;
	s--;t--;
	queue<ll> q1;
	queue<ll> q2;
	queue<ll> q3;
	q1.push(s);
	q2.push(2);
	q3.push(-1);
	while(!q1.empty()){
		ll a = q1.front();q1.pop();
		ll state = q2.front();q2.pop();
		ll c = q3.front();q3.pop();
		if(dp[a][state]<=c)continue;
		dp[a][state] = c;
		rep(i,0,vv[a].sz){
			q1.push(vv[a][i]);
			q2.push((state+1)%3);
			if(state==2){
				q3.push(c+1);
			}
			else{
				q3.push(c);
			}
		}
	}
	if(dp[t][2]==1000000000000000000LL){
		cout << -1 << endl;
	}
	else{
		cout << dp[t][2]+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n;
	string player1, player2;
	int score1 = 0;
	int score2 = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> player1 >> player2;
		
		if (player1 == player2) {
			score1++;
			score2++;
		}
		else if (player1.length() > player2.length()) {
			if (player1.substr(0, player2.length()) == player2) {
				score1 += 3;
			}else {
				for (int j = 0; j < player2.length(); j++) {
					if (player1.substr(j, 1) > player2.substr(j, 1)) {
						score1 += 3;
						break;
					}
					else if (player1.substr(j, 1) < player2.substr(j, 1)) {
						score2 += 3;
						break;
					}
				}
			}
		}else if (player1.length() < player2.length()){
			if (player2.substr(0, player1.length()) == player1) {
				score2 += 3;
			}else {
				for (int k = 0; k < player1.length(); k++) {
					if (player1.substr(k, 1) > player2.substr(k, 1)) {
						score1 += 3;
						break;
					}
					else if (player1.substr(k, 1) < player2.substr(k, 1)) {
						score2 += 3;
						break;
					}
				}
			}
		}else {
			for (int k = 0; k < player1.length(); k++) {
				if (player1.substr(k, 1) > player2.substr(k, 1)) {
					score1 += 3;
					break;
				}
				else if (player1.substr(k, 1) < player2.substr(k, 1)) {
					score2 += 3;
					break;
				}
			}
		}
	}
	cout << score1 << " " << score2 << endl;
}


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

string s[51];
vector < pair < int, int > > g[51][51];
bool used[51][51];
int d[51][51];

void bfs (pair < int, int > root) {
    queue < pair < int, int > > q;
    q.push(root);
    used[root.first][root.second] = 1;
    while (!q.empty()) {
        pair < int, int > u = q.front();
        q.pop();
        for (auto v: g[u.first][u.second]) {
            if (!used[v.first][v.second]) {
                used[v.first][v.second] = 1;
                q.push(v);
                d[v.first][v.second] = d[u.first][u.second] + 1;
            }
        }
    }
}

signed main () {
    int h, w;
    cin >> h >> w;
    int black = 0;
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
        for (int j = 0; j < w; ++j) {
            if (j && s[i][j] == '.' && s[i][j - 1] == '.') {
                g[i][j].push_back(make_pair(i, j - 1));
                g[i][j - 1].push_back(make_pair(i, j));
            }
            if (i && s[i][j] == '.' && s[i - 1][j] == '.') {
                g[i][j].push_back(make_pair(i - 1, j));
                g[i - 1][j].push_back(make_pair(i, j));
            }
            if (s[i][j] == '#')
                ++black;
        }
    }
    bfs(make_pair(0, 0));
    if (!used[h - 1][w - 1])
        cout << "-1\n";
    else
        cout << h * w - black - 1 - d[h - 1][w - 1] << '\n';
}


Measured memory_bytes: 384
import java.util.Scanner;

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

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

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

        System.out.println(solve(A, B, C) ? YES : NO);
    }

    private static boolean solve(int A, int B, int C) {
        if (A == B && B != C) return true;
        if (B == C && C != A) return true;
        if (C == A && A != B) return true;

        return false;
    }
}

Measured memory_bytes: 21972
S = list(input())
if S[0] != 'A':
    print('WA')
    exit()
S[0] = 'a'
if S.count('C') != 1:
    print('WA')
    exit()
i = S.index('C')
if i == 1 or i == len(S)-1:
    print('WA')
    exit()
S[S.index('C')] = 'c'
if ''.join(S) == ''.join(S).lower():
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    int x,a;cin >>x >> a;
    if(x<a) puts("0");
    else puts("10");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int n;
    cin >> n;
    vector<int> a(n + 2);
    a[0] = a.back() = 0;
    rep(i, n) cin >> a[i + 1];

    int sum = 0;
    rep(i, a.size() - 1) sum += abs(a[i] - a[i + 1]);

    rep(i, n) {
        cout << sum - abs(a[i] - a[i + 1]) - abs(a[i + 1] - a[i + 2]) +
                    abs(a[i] - a[i + 2])
             << "\n";
    }

    return 0;
}

Measured memory_bytes: 3720
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List as List

getRemainCount :: Int -> Int
getRemainCount 0 = 0
getRemainCount x
    | x <= 6 = 1
    | otherwise = 2

solve :: Int -> Int
solve s = a
    where
        c = (div s 11) * 2
        m = mod s 11
        a = c + getRemainCount m    


main :: IO()
main = do
    s <- read <$> getLine :: IO Int
    print $ solve s


Measured memory_bytes: 508
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int N = 1e5+100;

struct node
{
  int id,num,bl,ans;
} e[N];

int cnt[N],n,m;

bool cmp(node a,node b)
{
  return a.num<b.num;
}

bool cmp1(node a,node b)
{
  return a.id<b.id;
}

int main()
{
  scanf("%d%d",&n,&m);
  for(int i=1; i<=m; ++i)
  {
    scanf("%d%d",&e[i].bl,&e[i].num);
    e[i].id=i;
  }
  sort(e+1,e+m+1,cmp);
  for(int i=1; i<=m; ++i)
    e[i].ans=++cnt[e[i].bl];
  sort(e+1,e+m+1,cmp1);
  for(int i=1; i<=m; ++i)
    printf("%06d%06d\n",e[i].bl,e[i].ans);
  return 0;
}


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

#define ll long long
#define endl '\n'

void max_self(int &a, int b){ a = max(a, b);}
void min_self(int &a, int b){ a = min(a, b);}

void solve(){
	ll x, k, d; cin>>x>>k>>d;
	x = abs(x);
	ll k_ = min(x / d, k);
	x -= k_ * d;
	k -= k_;
	if(k&1){
		cout<<abs(x - d)<<endl;
	}else{
		cout<<x<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3616